summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_scale_smooth.c
blob: 9efcc8b575e2478cd34f448b6b83b866ad1fbaf5 (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
#include "evas_common.h"
#include "evas_scale_smooth.h"
#include "evas_blend_private.h"

#define SCALE_CALC_X_POINTS(P, SW, DW, CX, CW) \
  P = alloca((CW + 1) * sizeof (int));         \
  scale_calc_x_points(P, SW, DW, CX, CW);

#define SCALE_CALC_Y_POINTS(P, SRC, SW, SH, DH, CY, CH) \
  P = alloca((CH + 1) * sizeof (DATA32 *));             \
  scale_calc_y_points(P, SRC, SW, SH, DH, CY, CH);

#define SCALE_CALC_A_POINTS(P, S, D, C, CC) \
  P = alloca(CC * sizeof (int));            \
  scale_calc_a_points(P, S, D, C, CC);

static void scale_calc_y_points(DATA32 **p, DATA32 *src, int sw, int sh, int dh, int cy, int ch);
static void scale_calc_x_points(int *p, int sw, int dw, int cx, int cw);
static void scale_calc_a_points(int *p, int s, int d, int c, int cc);

static void
scale_calc_y_points(DATA32** p, DATA32 *src, int sw, int sh, int dh, int cy, int ch)
{
   int i, val, inc;
   if (sh > SCALE_SIZE_MAX) return;
   val = 0;
   inc = (sh << 16) / dh;
   for (i = 0; i < dh; i++)
     {
        if ((i >= cy) && (i < (cy + ch)))
           p[i - cy] = src + ((val >> 16) * sw);
	val += inc;
     }
   if ((i >= cy) && (i < (cy + ch)))
      p[i - cy] = p[i - cy - 1];
}

static void
scale_calc_x_points(int *p, int sw, int dw, int cx, int cw)
{
   int i, val, inc;
   if (sw > SCALE_SIZE_MAX) return;
   val = 0;
   inc = (sw << 16) / dw;
   for (i = 0; i < dw; i++)
     {
        if ((i >= cx) && (i < (cx + cw)))
           p[i - cx] = val >> 16;
	val += inc;
     }
   if ((i >= cx) && (i < (cx + cw)))
      p[i - cx] = p[i - cx - 1];
}

static void
scale_calc_a_points(int *p, int s, int d, int c, int cc)
{
   int i, val, inc;

   if (s > SCALE_SIZE_MAX) return;
   if (d >= s)
     {
	val = 0;
	inc = (s << 16) / d;
	for (i = 0; i < d; i++)
	  {
             if ((i >= c) && (i < (c + cc)))
               {
                  p[i - c] = (val >> 8) - ((val >> 8) & 0xffffff00);
                  if ((val >> 16) >= (s - 1)) p[i - c] = 0;
               }
	     val += inc;
	  }
     }
   else
     {
	int ap, Cp;

	val = 0;
	inc = (s << 16) / d;
	Cp = ((d << 14) / s) + 1;
	for (i = 0; i < d; i++)
	  {
	     ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
             if ((i >= c) && (i < (c + cc)))
                p[i - c] = ap | (Cp << 16);
	     val += inc;
	  }
     }
}

#ifdef BUILD_MMX
# undef SCALE_FUNC
# define SCALE_FUNC evas_common_scale_rgba_in_to_out_clip_smooth_mmx
# undef SCALE_USING_MMX
# define SCALE_USING_MMX
# include "evas_scale_smooth_scaler.c"
#endif

#undef SCALE_FUNC
#define SCALE_FUNC evas_common_scale_rgba_in_to_out_clip_smooth_c
#undef SCALE_USING_MMX
#include "evas_scale_smooth_scaler.c"

EAPI void
evas_common_scale_rgba_in_to_out_clip_smooth(RGBA_Image *src, RGBA_Image *dst,
                                             RGBA_Draw_Context *dc,
                                             int src_region_x, int src_region_y,
                                             int src_region_w, int src_region_h,
                                             int dst_region_x, int dst_region_y,
                                             int dst_region_w, int dst_region_h)
{
   Evas_Common_Scale_In_To_Out_Clip_Cb cb;
#ifdef BUILD_MMX
   int mmx, sse, sse2;

   evas_common_cpu_can_do(&mmx, &sse, &sse2);
   if (mmx)
     cb = evas_common_scale_rgba_in_to_out_clip_smooth_mmx;
   else
#endif
     cb = evas_common_scale_rgba_in_to_out_clip_smooth_c;

   evas_common_scale_rgba_in_to_out_clip_cb(src, dst, dc,
                                            src_region_x, src_region_y,
                                            src_region_w, src_region_h,
                                            dst_region_x, dst_region_y,
                                            dst_region_w, dst_region_h,
                                            cb);
}

EAPI void
evas_common_scale_rgba_in_to_out_clip_smooth_do(const Cutout_Rects *reuse,
						const Eina_Rectangle *clip,
						RGBA_Image *src, RGBA_Image *dst,
						RGBA_Draw_Context *dc,
						int src_region_x, int src_region_y,
						int src_region_w, int src_region_h,
						int dst_region_x, int dst_region_y,
						int dst_region_w, int dst_region_h)
{
# ifdef BUILD_MMX
   int mmx, sse, sse2;
# endif
   Eina_Rectangle area;
   Cutout_Rect *r;
   int i;

# ifdef BUILD_MMX
   evas_common_cpu_can_do(&mmx, &sse, &sse2);
# endif
   if (!reuse)
     {
        evas_common_draw_context_clip_clip(dc, clip->x, clip->y, clip->w, clip->h);
# ifdef BUILD_MMX
	if (mmx)
	  evas_common_scale_rgba_in_to_out_clip_smooth_mmx(src, dst, dc,
					       src_region_x, src_region_y,
					       src_region_w, src_region_h,
					       dst_region_x, dst_region_y,
					       dst_region_w, dst_region_h);
	else
# endif
	  evas_common_scale_rgba_in_to_out_clip_smooth_c(src, dst, dc,
                                                         src_region_x, src_region_y,
                                                         src_region_w, src_region_h,
                                                         dst_region_x, dst_region_y,
                                                         dst_region_w, dst_region_h);
        return;
     }

   for (i = 0; i < reuse->active; ++i)
     {
        r = reuse->rects + i;

        EINA_RECTANGLE_SET(&area, r->x, r->y, r->w, r->h);
        if (!eina_rectangle_intersection(&area, clip)) continue ;
        evas_common_draw_context_set_clip(dc, area.x, area.y, area.w, area.h);
# ifdef BUILD_MMX
	if (mmx)
	  evas_common_scale_rgba_in_to_out_clip_smooth_mmx(src, dst, dc,
					       src_region_x, src_region_y,
					       src_region_w, src_region_h,
					       dst_region_x, dst_region_y,
					       dst_region_w, dst_region_h);
	else
# endif
	  evas_common_scale_rgba_in_to_out_clip_smooth_c(src, dst, dc,
                                                         src_region_x, src_region_y,
                                                         src_region_w, src_region_h,
                                                         dst_region_x, dst_region_y,
                                                         dst_region_w, dst_region_h);
     }
}