aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/engines/common/evas_scale_smooth_scaler_up.c
blob: 7327ac5495de3ac7ed07a474da4b65cf024e5ad6 (plain)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{
   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 (!dc->mul.use)
     {
	if ((dc->render_op == _EVAS_RENDER_BLEND) && !src->cache_entry.flags.alpha)
	  { direct_scale = 1;  buf_step = dst->cache_entry.w; }
	else if (dc->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 (dc->mul.use)
	   func = evas_common_gfx_func_composite_pixel_color_span_get(src, dc->mul.col, dst, dst_clip_w, dc->render_op);
	else
	   func  = evas_common_gfx_func_composite_pixel_span_get(src, dst, dst_clip_w, dc->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;
#ifdef EVAS_SLI
	int ysli = dst_clip_y;
#endif
	psrc = src->image.data + (src_w * (sry + cy)) + srx;
	while (pdst < pdst_end)
	  {
#ifdef EVAS_SLI
	     if (((ysli) % dc->sli.h) == dc->sli.y)
#endif
	       {
		  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, dc->mul.col, pdst, dst_clip_w);
	       }
#ifdef EVAS_SLI
	     ysli++;
#endif
	     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;
#ifdef EVAS_SLI
	int ysli = dst_clip_y;
#endif

	while (pdst < pdst_end)
	  {
#ifdef EVAS_SLI
	     if (((ysli) % dc->sli.h) == dc->sli.y)
#endif
	       {
		  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, dc->mul.col, pdst, dst_clip_w);
	       }
#ifdef EVAS_SLI
	     ysli++;
#endif
	    pdst += dst_w;
	    syy += dsyy;
	    buf += buf_step;
	  }
	goto done_scale_up;
     }

     {
	DATA32  *ps = src->image.data + (src_w * sry) + srx;
	int     sxx0 = sxx;
#ifdef EVAS_SLI
	int ysli = dst_clip_y;
#endif

	while (pdst < pdst_end)
	  {
#ifdef EVAS_SLI
	     if (((ysli) % dc->sli.h) == dc->sli.y)
#endif
	       {
		  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, dc->mul.col, pdst, dst_clip_w);
	       }
#ifdef EVAS_SLI
	     ysli++;
#endif
	     pdst += dst_w;
	     syy += dsyy;
	     buf += buf_step;
	  }
     }
   done_scale_up:
   return;
}