aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/engines/common/evas_scale_smooth.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/engines/common/evas_scale_smooth.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/lib/engines/common/evas_scale_smooth.c')
-rw-r--r--libraries/evas/src/lib/engines/common/evas_scale_smooth.c532
1 files changed, 532 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_scale_smooth.c b/libraries/evas/src/lib/engines/common/evas_scale_smooth.c
new file mode 100644
index 0000000..d3aada6
--- /dev/null
+++ b/libraries/evas/src/lib/engines/common/evas_scale_smooth.c
@@ -0,0 +1,532 @@
1#include "evas_common.h"
2#include "evas_scale_smooth.h"
3#include "evas_blend_private.h"
4
5#define SCALE_CALC_X_POINTS(P, SW, DW, CX, CW) \
6 P = alloca((CW + 1) * sizeof (int)); \
7 scale_calc_x_points(P, SW, DW, CX, CW);
8
9#define SCALE_CALC_Y_POINTS(P, SRC, SW, SH, DH, CY, CH) \
10 P = alloca((CH + 1) * sizeof (DATA32 *)); \
11 scale_calc_y_points(P, SRC, SW, SH, DH, CY, CH);
12
13#define SCALE_CALC_A_POINTS(P, S, D, C, CC) \
14 P = alloca(CC * sizeof (int)); \
15 scale_calc_a_points(P, S, D, C, CC);
16
17static void scale_calc_y_points(DATA32 **p, DATA32 *src, int sw, int sh, int dh, int cy, int ch);
18static void scale_calc_x_points(int *p, int sw, int dw, int cx, int cw);
19static void scale_calc_a_points(int *p, int s, int d, int c, int cc);
20
21static void
22scale_calc_y_points(DATA32** p, DATA32 *src, int sw, int sh, int dh, int cy, int ch)
23{
24 int i, val, inc;
25 if (sh > SCALE_SIZE_MAX) return;
26 val = 0;
27 inc = (sh << 16) / dh;
28 for (i = 0; i < dh; i++)
29 {
30 if ((i >= cy) && (i < (cy + ch)))
31 p[i - cy] = src + ((val >> 16) * sw);
32 val += inc;
33 }
34 if ((i >= cy) && (i < (cy + ch)))
35 p[i - cy] = p[i - cy - 1];
36}
37
38static void
39scale_calc_x_points(int *p, int sw, int dw, int cx, int cw)
40{
41 int i, val, inc;
42 if (sw > SCALE_SIZE_MAX) return;
43 val = 0;
44 inc = (sw << 16) / dw;
45 for (i = 0; i < dw; i++)
46 {
47 if ((i >= cx) && (i < (cx + cw)))
48 p[i - cx] = val >> 16;
49 val += inc;
50 }
51 if ((i >= cx) && (i < (cx + cw)))
52 p[i - cx] = p[i - cx - 1];
53}
54
55static void
56scale_calc_a_points(int *p, int s, int d, int c, int cc)
57{
58 int i, val, inc;
59
60 if (s > SCALE_SIZE_MAX) return;
61 if (d >= s)
62 {
63 val = 0;
64 inc = (s << 16) / d;
65 for (i = 0; i < d; i++)
66 {
67 if ((i >= c) && (i < (c + cc)))
68 {
69 p[i - c] = (val >> 8) - ((val >> 8) & 0xffffff00);
70 if ((val >> 16) >= (s - 1)) p[i - c] = 0;
71 }
72 val += inc;
73 }
74 }
75 else
76 {
77 int ap, Cp;
78
79 val = 0;
80 inc = (s << 16) / d;
81 Cp = ((d << 14) / s) + 1;
82 for (i = 0; i < d; i++)
83 {
84 ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
85 if ((i >= c) && (i < (c + cc)))
86 p[i - c] = ap | (Cp << 16);
87 val += inc;
88 }
89 }
90}
91
92#ifdef BUILD_SCALE_SMOOTH
93#ifdef BUILD_C
94EAPI void
95evas_common_scale_rgba_mipmap_down_2x2_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
96{
97 int x, y, dst_w, dst_h;
98 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
99
100 dst_w = src_w >> 1;
101 dst_h = src_h >> 1;
102
103 if (dst_w < 1) dst_w = 1;
104 if (dst_h < 1) dst_h = 1;
105
106 src_ptr = src;
107 src_ptr2 = src + src_w;
108 dst_ptr = dst;
109 for (y = 0; y < dst_h; y++)
110 {
111 src_ptr = src + (y * src_w * 2);
112 src_ptr2 = src_ptr + src_w;
113 for (x = 0; x < dst_w; x++)
114 {
115 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr + 1) + R_VAL(src_ptr2) + R_VAL(src_ptr2 + 1)) >> 2;
116 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr + 1) + G_VAL(src_ptr2) + G_VAL(src_ptr2 + 1)) >> 2;
117 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr + 1) + B_VAL(src_ptr2) + B_VAL(src_ptr2 + 1)) >> 2;
118 A_VAL(dst_ptr) = (A_VAL(src_ptr) + A_VAL(src_ptr + 1) + A_VAL(src_ptr2) + A_VAL(src_ptr2 + 1)) >> 2;
119
120 src_ptr+=2;
121 src_ptr2+=2;
122 dst_ptr++;
123 }
124 }
125}
126#endif
127#endif
128
129#ifdef BUILD_SCALE_SMOOTH
130#ifdef BUILD_C
131EAPI void
132evas_common_scale_rgba_mipmap_down_2x1_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
133{
134 int x, y, dst_w, dst_h;
135 DATA32 *src_ptr, *dst_ptr;
136
137 dst_w = src_w >> 1;
138 dst_h = src_h >> 1;
139
140 if (dst_w < 1) dst_w = 1;
141 if (dst_h < 1) dst_h = 1;
142
143 src_ptr = src;
144 dst_ptr = dst;
145 for (y = 0; y < dst_h; y++)
146 {
147 src_ptr = src + (y * src_w * 2);
148 for (x = 0; x < dst_w; x++)
149 {
150 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr + 1)) >> 1;
151 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr + 1)) >> 1;
152 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr + 1)) >> 1;
153 A_VAL(dst_ptr) = (A_VAL(src_ptr) + A_VAL(src_ptr + 1)) >> 1;
154
155 src_ptr+=2;
156 dst_ptr++;
157 }
158 }
159}
160#endif
161#endif
162
163#ifdef BUILD_SCALE_SMOOTH
164#ifdef BUILD_C
165EAPI void
166evas_common_scale_rgba_mipmap_down_1x2_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
167{
168 int x, y, dst_w, dst_h;
169 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
170
171 dst_w = src_w >> 1;
172 dst_h = src_h >> 1;
173
174 if (dst_w < 1) dst_w = 1;
175 if (dst_h < 1) dst_h = 1;
176
177 src_ptr = src;
178 dst_ptr = dst;
179 for (y = 0; y < dst_h; y++)
180 {
181 src_ptr = src + (y * src_w * 2);
182 src_ptr2 = src_ptr + src_w;
183 for (x = 0; x < dst_w; x++)
184 {
185 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr2)) >> 1;
186 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr2)) >> 1;
187 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr2)) >> 1;
188 A_VAL(dst_ptr) = (A_VAL(src_ptr) + A_VAL(src_ptr2)) >> 1;
189
190 src_ptr+=2;
191 src_ptr2+=2;
192 dst_ptr++;
193 }
194 }
195}
196#endif
197#endif
198
199#ifdef BUILD_SCALE_SMOOTH
200#ifdef BUILD_C
201EAPI void
202evas_common_scale_rgb_mipmap_down_2x2_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
203{
204 int x, y, dst_w, dst_h;
205 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
206
207 dst_w = src_w >> 1;
208 dst_h = src_h >> 1;
209
210 if (dst_w < 1) dst_w = 1;
211 if (dst_h < 1) dst_h = 1;
212
213 src_ptr = src;
214 src_ptr2 = src + src_w;
215 dst_ptr = dst;
216 for (y = 0; y < dst_h; y++)
217 {
218 for (x = 0; x < dst_w; x++)
219 {
220 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr + 1) + R_VAL(src_ptr2) + R_VAL(src_ptr2 + 1)) >> 2;
221 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr + 1) + G_VAL(src_ptr2) + G_VAL(src_ptr2 + 1)) >> 2;
222 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr + 1) + B_VAL(src_ptr2) + B_VAL(src_ptr2 + 1)) >> 2;
223 A_VAL(dst_ptr) = 0xff;
224
225 src_ptr+=2;
226 src_ptr2+=2;
227 dst_ptr++;
228 }
229 src_ptr += src_w;
230 src_ptr2 += src_w;
231 }
232}
233#endif
234#endif
235
236#ifdef BUILD_SCALE_SMOOTH
237#ifdef BUILD_C
238EAPI void
239evas_common_scale_rgb_mipmap_down_2x1_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
240{
241 int x, y, dst_w, dst_h;
242 DATA32 *src_ptr, *dst_ptr;
243
244 dst_w = src_w >> 1;
245 dst_h = src_h >> 1;
246
247 if (dst_w < 1) dst_w = 1;
248 if (dst_h < 1) dst_h = 1;
249
250 src_ptr = src;
251 dst_ptr = dst;
252 for (y = 0; y < dst_h; y++)
253 {
254 for (x = 0; x < dst_w; x++)
255 {
256 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr + 1)) >> 1;
257 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr + 1)) >> 1;
258 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr + 1)) >> 1;
259 A_VAL(dst_ptr) = 0xff;
260
261 src_ptr+=2;
262 dst_ptr++;
263 }
264 src_ptr += src_w;
265 }
266}
267#endif
268#endif
269
270#ifdef BUILD_SCALE_SMOOTH
271#ifdef BUILD_C
272EAPI void
273evas_common_scale_rgb_mipmap_down_1x2_c(DATA32 *src, DATA32 *dst, int src_w, int src_h)
274{
275 int x, y, dst_w, dst_h;
276 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
277
278 dst_w = src_w >> 1;
279 dst_h = src_h >> 1;
280
281 if (dst_w < 1) dst_w = 1;
282 if (dst_h < 1) dst_h = 1;
283
284 src_ptr = src;
285 src_ptr2 = src + src_w;
286 dst_ptr = dst;
287 for (y = 0; y < dst_h; y++)
288 {
289 for (x = 0; x < dst_w; x++)
290 {
291 R_VAL(dst_ptr) = (R_VAL(src_ptr) + R_VAL(src_ptr2)) >> 1;
292 G_VAL(dst_ptr) = (G_VAL(src_ptr) + G_VAL(src_ptr2)) >> 1;
293 B_VAL(dst_ptr) = (B_VAL(src_ptr) + B_VAL(src_ptr2)) >> 1;
294 A_VAL(dst_ptr) = 0xff;
295
296 src_ptr+=2;
297 src_ptr2+=2;
298 dst_ptr++;
299 }
300 src_ptr += src_w;
301 src_ptr2 += src_w;
302 }
303}
304#endif
305#endif
306
307#ifdef BUILD_SCALE_SMOOTH
308#ifdef BUILD_MMX
309EAPI void
310evas_common_scale_rgba_mipmap_down_2x2_mmx(DATA32 *src, DATA32 *dst, int src_w, int src_h)
311{
312 int x, y, dst_w, dst_h;
313 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
314
315 dst_w = src_w >> 1;
316 dst_h = src_h >> 1;
317
318 if (dst_w < 1) dst_w = 1;
319 if (dst_h < 1) dst_h = 1;
320
321 /* NB: Dead assignments (reassigned to different values below)
322 src_ptr = src;
323 src_ptr2 = src + src_w;
324 */
325
326 dst_ptr = dst;
327 for (y = 0; y < dst_h; y++)
328 {
329 src_ptr = src + (y * src_w * 2);
330 src_ptr2 = src_ptr + src_w;
331 for (x = 0; x < dst_w; x++)
332 {
333 punpcklbw_m2r(src_ptr[0], mm0);
334 punpcklbw_m2r(src_ptr[1], mm1);
335 punpcklbw_m2r(src_ptr2[0], mm2);
336 punpcklbw_m2r(src_ptr2[1], mm3);
337 psrlw_i2r(8, mm0);
338 psrlw_i2r(8, mm1);
339 psrlw_i2r(8, mm2);
340 psrlw_i2r(8, mm3);
341 paddw_r2r(mm1, mm0);
342 paddw_r2r(mm2, mm0);
343 paddw_r2r(mm3, mm0);
344 psrlw_i2r(2, mm0);
345 packuswb_r2r(mm0, mm0);
346 movd_r2m(mm0, dst_ptr[0]);
347
348 src_ptr+=2;
349 src_ptr2+=2;
350 dst_ptr++;
351 }
352 }
353}
354#endif
355#endif
356
357#ifdef BUILD_SCALE_SMOOTH
358#ifdef BUILD_MMX
359EAPI void
360evas_common_scale_rgba_mipmap_down_2x1_mmx(DATA32 *src, DATA32 *dst, int src_w, int src_h)
361{
362 int x, y, dst_w, dst_h;
363 DATA32 *src_ptr, *dst_ptr;
364
365 dst_w = src_w >> 1;
366 dst_h = src_h >> 1;
367
368 if (dst_w < 1) dst_w = 1;
369 if (dst_h < 1) dst_h = 1;
370
371 src_ptr = src;
372 dst_ptr = dst;
373 for (y = 0; y < dst_h; y++)
374 {
375 src_ptr = src + (y * src_w * 2);
376 for (x = 0; x < dst_w; x++)
377 {
378 punpcklbw_m2r(src_ptr[0], mm0);
379 punpcklbw_m2r(src_ptr[1], mm1);
380 psrlw_i2r(8, mm0);
381 psrlw_i2r(8, mm1);
382 paddw_r2r(mm1, mm0);
383 psrlw_i2r(1, mm0);
384 packuswb_r2r(mm0, mm0);
385 movd_r2m(mm0, dst_ptr[0]);
386
387 src_ptr+=2;
388 dst_ptr++;
389 }
390 }
391}
392#endif
393#endif
394
395#ifdef BUILD_SCALE_SMOOTH
396#ifdef BUILD_MMX
397EAPI void
398evas_common_scale_rgba_mipmap_down_1x2_mmx(DATA32 *src, DATA32 *dst, int src_w, int src_h)
399{
400 int x, y, dst_w, dst_h;
401 DATA32 *src_ptr, *src_ptr2, *dst_ptr;
402
403 dst_w = src_w >> 1;
404 dst_h = src_h >> 1;
405
406 if (dst_w < 1) dst_w = 1;
407 if (dst_h < 1) dst_h = 1;
408
409 /* NB: Dead assignment (gets reassigned later) */
410// src_ptr = src;
411
412 src_ptr2 = src + src_w;
413 dst_ptr = dst;
414 for (y = 0; y < dst_h; y++)
415 {
416 src_ptr = src + (y * src_w * 2);
417 src_ptr2 = src_ptr + src_w;
418 for (x = 0; x < dst_w; x++)
419 {
420 punpcklbw_m2r(src_ptr[0], mm0);
421 punpcklbw_m2r(src_ptr2[0], mm1);
422 psrlw_i2r(8, mm0);
423 psrlw_i2r(8, mm1);
424 paddw_r2r(mm1, mm0);
425 psrlw_i2r(1, mm0);
426 packuswb_r2r(mm0, mm0);
427 movd_r2m(mm0, dst_ptr[0]);
428
429 src_ptr+=2;
430 src_ptr2+=2;
431 dst_ptr++;
432 }
433 }
434}
435#endif
436#endif
437
438#ifdef BUILD_SCALE_SMOOTH
439# ifdef BUILD_MMX
440# undef SCALE_FUNC
441# define SCALE_FUNC evas_common_scale_rgba_in_to_out_clip_smooth_mmx
442# undef SCALE_USING_MMX
443# define SCALE_USING_MMX
444# include "evas_scale_smooth_scaler.c"
445# endif
446# ifdef BUILD_C
447# undef SCALE_FUNC
448# define SCALE_FUNC evas_common_scale_rgba_in_to_out_clip_smooth_c
449# undef SCALE_USING_MMX
450# include "evas_scale_smooth_scaler.c"
451# endif
452EAPI void
453evas_common_scale_rgba_in_to_out_clip_smooth(RGBA_Image *src, RGBA_Image *dst,
454 RGBA_Draw_Context *dc,
455 int src_region_x, int src_region_y,
456 int src_region_w, int src_region_h,
457 int dst_region_x, int dst_region_y,
458 int dst_region_w, int dst_region_h)
459{
460# ifdef BUILD_MMX
461 int mmx, sse, sse2;
462# endif
463 Cutout_Rects *rects;
464 Cutout_Rect *r;
465 int c, cx, cy, cw, ch;
466 int i;
467 /* handle cutouts here! */
468
469 if ((dst_region_w <= 0) || (dst_region_h <= 0)) return;
470 if (!(RECTS_INTERSECT(dst_region_x, dst_region_y, dst_region_w, dst_region_h, 0, 0, dst->cache_entry.w, dst->cache_entry.h)))
471 return;
472# ifdef BUILD_MMX
473 evas_common_cpu_can_do(&mmx, &sse, &sse2);
474# endif
475 /* no cutouts - cut right to the chase */
476 if (!dc->cutout.rects)
477 {
478# ifdef BUILD_MMX
479 if (mmx)
480 evas_common_scale_rgba_in_to_out_clip_smooth_mmx(src, dst, dc,
481 src_region_x, src_region_y,
482 src_region_w, src_region_h,
483 dst_region_x, dst_region_y,
484 dst_region_w, dst_region_h);
485 else
486# endif
487# ifdef BUILD_C
488 evas_common_scale_rgba_in_to_out_clip_smooth_c(src, dst, dc,
489 src_region_x, src_region_y,
490 src_region_w, src_region_h,
491 dst_region_x, dst_region_y,
492 dst_region_w, dst_region_h);
493# endif
494 return;
495 }
496 /* save out clip info */
497 c = dc->clip.use; cx = dc->clip.x; cy = dc->clip.y; cw = dc->clip.w; ch = dc->clip.h;
498 evas_common_draw_context_clip_clip(dc, 0, 0, dst->cache_entry.w, dst->cache_entry.h);
499 evas_common_draw_context_clip_clip(dc, dst_region_x, dst_region_y, dst_region_w, dst_region_h);
500 /* our clip is 0 size.. abort */
501 if ((dc->clip.w <= 0) || (dc->clip.h <= 0))
502 {
503 dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
504 return;
505 }
506 rects = evas_common_draw_context_apply_cutouts(dc);
507 for (i = 0; i < rects->active; ++i)
508 {
509 r = rects->rects + i;
510 evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
511# ifdef BUILD_MMX
512 if (mmx)
513 evas_common_scale_rgba_in_to_out_clip_smooth_mmx(src, dst, dc,
514 src_region_x, src_region_y,
515 src_region_w, src_region_h,
516 dst_region_x, dst_region_y,
517 dst_region_w, dst_region_h);
518 else
519# endif
520# ifdef BUILD_C
521 evas_common_scale_rgba_in_to_out_clip_smooth_c(src, dst, dc,
522 src_region_x, src_region_y,
523 src_region_w, src_region_h,
524 dst_region_x, dst_region_y,
525 dst_region_w, dst_region_h);
526# endif
527 }
528 evas_common_draw_context_apply_clear_cutouts(rects);
529 /* restore clip info */
530 dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
531}
532#endif