summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_scale_smooth_scaler_up.c
blob: e43e0c7a6cad878a8ff0d50e0b89075a9f2960ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{
   int         srx = src_region_x, sry = src_region_y;
   int         srw = src_region_w, srh = src_region_h;
   int         drx = dst_region_x, dry = dst_region_y;
   int         drw = dst_region_w, drh = dst_region_h;

   int         dsxx, dsyy, sxx, syy, sx, sy;
   int         cx, cy;
   int         direct_scale = 0, buf_step = 0;

   DATA32      *psrc, *pdst, *pdst_end;
   DATA32      *buf, *pbuf, *pbuf_end;
   RGBA_Gfx_Func  func = NULL;

   /* check value  to make overflow(only check value related with overflow) */
   if ((src_region_w > SCALE_SIZE_MAX) ||
       (src_region_h > SCALE_SIZE_MAX)) return;

   /* a scanline buffer */
   pdst = dst_ptr;  // it's been set at (dst_clip_x, dst_clip_y)
   pdst_end = pdst + (dst_clip_h * dst_w);
   if (mul_col == 0xffffffff)
     {
	if ((render_op == _EVAS_RENDER_BLEND) && !src->cache_entry.flags.alpha)
	  { direct_scale = 1;  buf_step = dst->cache_entry.w; }
	else if (render_op == _EVAS_RENDER_COPY)
	  {
	    direct_scale = 1;  buf_step = dst->cache_entry.w;
	    if (src->cache_entry.flags.alpha)
		dst->cache_entry.flags.alpha = 1;
	  }
     }
   if (!direct_scale)
     {
	buf = alloca(dst_clip_w * sizeof(DATA32));
	if (mul_col != 0xffffffff)
	   func = evas_common_gfx_func_composite_pixel_color_span_get(src, mul_col, dst, dst_clip_w, render_op);
	else
	   func  = evas_common_gfx_func_composite_pixel_span_get(src, dst, dst_clip_w, render_op);
     }
   else
	buf = pdst;

   if ((srw > 1) && (drw > 1))
	dsxx = ((srw - 1) << 16) / (drw - 1);
   else
	dsxx = (srw << 16) / drw;
   if ((srh > 1) && (drh > 1))
	dsyy = ((srh - 1) << 16) / (drh - 1);
   else
	dsyy = (srh << 16) / drh;

   cx = dst_clip_x - drx;
   cy = dst_clip_y - dry;

   sxx = (dsxx * cx);
   syy = (dsyy * cy);

   sy = syy >> 16;

   if (drh == srh)
     {
	int  sxx0 = sxx;
	psrc = src->image.data + (src_w * (sry + cy)) + srx;
	while (pdst < pdst_end)
	  {
	    pbuf = buf;  pbuf_end = buf + dst_clip_w;
	    sxx = sxx0;
#ifdef SCALE_USING_MMX
	    pxor_r2r(mm0, mm0);
	    MOV_A2R(ALPHA_255, mm5)
#endif
	      while (pbuf < pbuf_end)
		{
		  DATA32   p0, p1;
		  int      ax;

		  sx = (sxx >> 16);
		  ax = 1 + ((sxx - (sx << 16)) >> 8);
		  p0 = p1 = *(psrc + sx);
		  if ((sx + 1) < srw)
		    p1 = *(psrc + sx + 1);
#ifdef SCALE_USING_MMX
		  MOV_P2R(p0, mm1, mm0)
		    if (p0 | p1)
		      {
			MOV_A2R(ax, mm3)
			MOV_P2R(p1, mm2, mm0)
			INTERP_256_R2R(mm3, mm2, mm1, mm5)
		       }
		  MOV_R2P(mm1, *pbuf, mm0)
		  pbuf++;
#else
		  if (p0 | p1)
		    p0 = INTERP_256(ax, p1, p0);
		  *pbuf++ = p0;
#endif
		  sxx += dsxx;
		}
	    /* * blend here [clip_w *] buf -> dptr * */
	    if (!direct_scale)
	      func(buf, NULL, mul_col, pdst, dst_clip_w);

	    pdst += dst_w;
	    psrc += src_w;
	    buf += buf_step;
	  }

	goto done_scale_up;
     }
   else if (drw == srw)
     {
	DATA32  *ps = src->image.data + (src_w * sry) + srx + cx;

	while (pdst < pdst_end)
	  {
	    int        ay;

	    sy = syy >> 16;
	    psrc = ps + (sy * src_w);
	    ay = 1 + ((syy - (sy << 16)) >> 8);
#ifdef SCALE_USING_MMX
	    pxor_r2r(mm0, mm0);
	    MOV_A2R(ALPHA_255, mm5)
	    MOV_A2R(ay, mm4)
#endif
	    pbuf = buf;  pbuf_end = buf + dst_clip_w;
	    while (pbuf < pbuf_end)
	      {
		DATA32  p0 = *psrc, p2 = p0;

		if ((sy + 1) < srh)
		  p2 = *(psrc + src_w);
#ifdef SCALE_USING_MMX
		MOV_P2R(p0, mm1, mm0)
		if (p0 | p2)
		  {
		    MOV_P2R(p2, mm2, mm0)
		    INTERP_256_R2R(mm4, mm2, mm1, mm5)
		  }
		MOV_R2P(mm1, *pbuf, mm0)
		pbuf++;
#else
		if (p0 | p2)
		  p0 = INTERP_256(ay, p2, p0);
		*pbuf++ = p0;
#endif
		psrc++;
	      }
	    /* * blend here [clip_w *] buf -> dptr * */
	    if (!direct_scale)
	      func(buf, NULL, mul_col, pdst, dst_clip_w);
	    pdst += dst_w;
	    syy += dsyy;
	    buf += buf_step;
	  }
	goto done_scale_up;
     }

     {
	DATA32  *ps = src->image.data + (src_w * sry) + srx;
	int     sxx0 = sxx;

	while (pdst < pdst_end)
	  {
	    int   ay;

	    sy = syy >> 16;
	    psrc = ps + (sy * src_w);
	    ay = 1 + ((syy - (sy << 16)) >> 8);
#ifdef SCALE_USING_MMX
	    MOV_A2R(ay, mm4)
	    pxor_r2r(mm0, mm0);
	    MOV_A2R(ALPHA_255, mm5)
#endif
	    pbuf = buf;  pbuf_end = buf + dst_clip_w;
	    sxx = sxx0;
	    while (pbuf < pbuf_end)
	      {
		int     ax;
		DATA32  *p, *q;
		DATA32  p0, p1, p2, p3;

		sx = sxx >> 16;
		ax = 1 + ((sxx - (sx << 16)) >> 8);
		p = psrc + sx;  q = p + src_w;
		p0 = p1 = p2 = p3 = *p;
		if ((sx + 1) < srw)
		  p1 = *(p + 1);
		if ((sy + 1) < srh)
		  {
		    p2 = *q;  p3 = p2;
		    if ((sx + 1) < srw)
		      p3 = *(q + 1);
		  }
#ifdef SCALE_USING_MMX
		MOV_A2R(ax, mm6)
		MOV_P2R(p0, mm1, mm0)
		if (p0 | p1)
		  {
		    MOV_P2R(p1, mm2, mm0)
		    INTERP_256_R2R(mm6, mm2, mm1, mm5)
		  }
		MOV_P2R(p2, mm2, mm0)
		if (p2 | p3)
		  {
		    MOV_P2R(p3, mm3, mm0)
		    INTERP_256_R2R(mm6, mm3, mm2, mm5)
		  }
		INTERP_256_R2R(mm4, mm2, mm1, mm5)
		MOV_R2P(mm1, *pbuf, mm0)
		pbuf++;
#else
		if (p0 | p1)
		  p0 = INTERP_256(ax, p1, p0);
		if (p2 | p3)
		  p2 = INTERP_256(ax, p3, p2);
		if (p0 | p2)
		  p0 = INTERP_256(ay, p2, p0);
		*pbuf++ = p0;
#endif
		sxx += dsxx;
	      }
	    /* * blend here [clip_w *] buf -> dptr * */
	    if (!direct_scale)
	      func(buf, NULL, mul_col, pdst, dst_clip_w);

	    pdst += dst_w;
	    syy += dsyy;
	    buf += buf_step;
	  }
     }
   done_scale_up:
   return;
}