diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/engines/common/evas_scale_sample.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-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_sample.c')
-rw-r--r-- | libraries/evas/src/lib/engines/common/evas_scale_sample.c | 398 |
1 files changed, 398 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_scale_sample.c b/libraries/evas/src/lib/engines/common/evas_scale_sample.c new file mode 100644 index 0000000..54b8e92 --- /dev/null +++ b/libraries/evas/src/lib/engines/common/evas_scale_sample.c | |||
@@ -0,0 +1,398 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_blend_private.h" | ||
3 | |||
4 | void scale_rgba_in_to_out_clip_sample_internal(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); | ||
5 | |||
6 | #ifndef BUILD_SCALE_SMOOTH | ||
7 | #ifdef BUILD_SCALE_SAMPLE | ||
8 | EAPI void | ||
9 | evas_common_scale_rgba_in_to_out_clip_smooth(RGBA_Image *src, RGBA_Image *dst, | ||
10 | RGBA_Draw_Context *dc, | ||
11 | int src_region_x, int src_region_y, | ||
12 | int src_region_w, int src_region_h, | ||
13 | int dst_region_x, int dst_region_y, | ||
14 | int dst_region_w, int dst_region_h) | ||
15 | { | ||
16 | evas_common_scale_rgba_in_to_out_clip_sample(src, dst, dc, | ||
17 | src_region_x, src_region_y, | ||
18 | src_region_w, src_region_h, | ||
19 | dst_region_x, dst_region_y, | ||
20 | dst_region_w, dst_region_h); | ||
21 | } | ||
22 | #endif | ||
23 | #endif | ||
24 | |||
25 | #ifdef BUILD_SCALE_SAMPLE | ||
26 | EAPI void | ||
27 | evas_common_scale_rgba_in_to_out_clip_sample(RGBA_Image *src, RGBA_Image *dst, | ||
28 | RGBA_Draw_Context *dc, | ||
29 | int src_region_x, int src_region_y, | ||
30 | int src_region_w, int src_region_h, | ||
31 | int dst_region_x, int dst_region_y, | ||
32 | int dst_region_w, int dst_region_h) | ||
33 | { | ||
34 | Cutout_Rects *rects; | ||
35 | Cutout_Rect *r; | ||
36 | int c, cx, cy, cw, ch; | ||
37 | int i; | ||
38 | /* handle cutouts here! */ | ||
39 | |||
40 | if ((dst_region_w <= 0) || (dst_region_h <= 0)) return; | ||
41 | 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))) | ||
42 | return; | ||
43 | /* no cutouts - cut right to the chase */ | ||
44 | if (!dc->cutout.rects) | ||
45 | { | ||
46 | scale_rgba_in_to_out_clip_sample_internal(src, dst, dc, | ||
47 | src_region_x, src_region_y, | ||
48 | src_region_w, src_region_h, | ||
49 | dst_region_x, dst_region_y, | ||
50 | dst_region_w, dst_region_h); | ||
51 | return; | ||
52 | } | ||
53 | /* save out clip info */ | ||
54 | c = dc->clip.use; cx = dc->clip.x; cy = dc->clip.y; cw = dc->clip.w; ch = dc->clip.h; | ||
55 | evas_common_draw_context_clip_clip(dc, 0, 0, dst->cache_entry.w, dst->cache_entry.h); | ||
56 | evas_common_draw_context_clip_clip(dc, dst_region_x, dst_region_y, dst_region_w, dst_region_h); | ||
57 | /* our clip is 0 size.. abort */ | ||
58 | if ((dc->clip.w <= 0) || (dc->clip.h <= 0)) | ||
59 | { | ||
60 | dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch; | ||
61 | return; | ||
62 | } | ||
63 | rects = evas_common_draw_context_apply_cutouts(dc); | ||
64 | for (i = 0; i < rects->active; ++i) | ||
65 | { | ||
66 | r = rects->rects + i; | ||
67 | evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h); | ||
68 | scale_rgba_in_to_out_clip_sample_internal(src, dst, dc, | ||
69 | src_region_x, src_region_y, | ||
70 | src_region_w, src_region_h, | ||
71 | dst_region_x, dst_region_y, | ||
72 | dst_region_w, dst_region_h); | ||
73 | |||
74 | } | ||
75 | evas_common_draw_context_apply_clear_cutouts(rects); | ||
76 | /* restore clip info */ | ||
77 | dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch; | ||
78 | } | ||
79 | |||
80 | void | ||
81 | scale_rgba_in_to_out_clip_sample_internal(RGBA_Image *src, RGBA_Image *dst, | ||
82 | RGBA_Draw_Context *dc, | ||
83 | int src_region_x, int src_region_y, | ||
84 | int src_region_w, int src_region_h, | ||
85 | int dst_region_x, int dst_region_y, | ||
86 | int dst_region_w, int dst_region_h) | ||
87 | { | ||
88 | int x, y; | ||
89 | int *lin_ptr; | ||
90 | DATA32 *buf, *dptr; | ||
91 | DATA32 **row_ptr; | ||
92 | DATA32 *ptr, *dst_ptr, *src_data, *dst_data; | ||
93 | int dst_jump; | ||
94 | int dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h; | ||
95 | int m_clip_x = 0, m_clip_y = 0, m_clip_w = 0, m_clip_h = 0, mdx = 0, mdy = 0; | ||
96 | int src_w, src_h, dst_w, dst_h; | ||
97 | RGBA_Gfx_Func func; | ||
98 | RGBA_Image *maskobj = NULL; | ||
99 | DATA8 *mask = NULL; | ||
100 | |||
101 | 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))) | ||
102 | return; | ||
103 | if (!(RECTS_INTERSECT(src_region_x, src_region_y, src_region_w, src_region_h, 0, 0, src->cache_entry.w, src->cache_entry.h))) | ||
104 | return; | ||
105 | |||
106 | src_w = src->cache_entry.w; | ||
107 | src_h = src->cache_entry.h; | ||
108 | dst_w = dst->cache_entry.w; | ||
109 | dst_h = dst->cache_entry.h; | ||
110 | |||
111 | src_data = src->image.data; | ||
112 | dst_data = dst->image.data; | ||
113 | |||
114 | if (dc->clip.use) | ||
115 | { | ||
116 | dst_clip_x = dc->clip.x; | ||
117 | dst_clip_y = dc->clip.y; | ||
118 | dst_clip_w = dc->clip.w; | ||
119 | dst_clip_h = dc->clip.h; | ||
120 | if (dst_clip_x < 0) | ||
121 | { | ||
122 | dst_clip_w += dst_clip_x; | ||
123 | dst_clip_x = 0; | ||
124 | } | ||
125 | if (dst_clip_y < 0) | ||
126 | { | ||
127 | dst_clip_h += dst_clip_y; | ||
128 | dst_clip_y = 0; | ||
129 | } | ||
130 | if ((dst_clip_x + dst_clip_w) > dst_w) | ||
131 | dst_clip_w = dst_w - dst_clip_x; | ||
132 | if ((dst_clip_y + dst_clip_h) > dst_h) | ||
133 | dst_clip_h = dst_h - dst_clip_y; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | dst_clip_x = 0; | ||
138 | dst_clip_y = 0; | ||
139 | dst_clip_w = dst_w; | ||
140 | dst_clip_h = dst_h; | ||
141 | } | ||
142 | |||
143 | if (dc->mask.mask) | ||
144 | { | ||
145 | m_clip_x = dc->mask.x; | ||
146 | m_clip_y = dc->mask.y; | ||
147 | m_clip_w = dc->mask.mask->cache_entry.w; | ||
148 | m_clip_h = dc->mask.mask->cache_entry.h; | ||
149 | RECTS_CLIP_TO_RECT(m_clip_x, m_clip_y, m_clip_w, m_clip_h, | ||
150 | dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h); | ||
151 | if ((m_clip_w <= 0) || (m_clip_h <= 0)) return; | ||
152 | dst_clip_x = m_clip_x; | ||
153 | dst_clip_y = m_clip_y; | ||
154 | dst_clip_w = m_clip_w; | ||
155 | dst_clip_h = m_clip_h; | ||
156 | } | ||
157 | |||
158 | if (dst_clip_x < dst_region_x) | ||
159 | { | ||
160 | dst_clip_w += dst_clip_x - dst_region_x; | ||
161 | dst_clip_x = dst_region_x; | ||
162 | } | ||
163 | if ((dst_clip_x + dst_clip_w) > (dst_region_x + dst_region_w)) | ||
164 | dst_clip_w = dst_region_x + dst_region_w - dst_clip_x; | ||
165 | if (dst_clip_y < dst_region_y) | ||
166 | { | ||
167 | dst_clip_h += dst_clip_y - dst_region_y; | ||
168 | dst_clip_y = dst_region_y; | ||
169 | } | ||
170 | if ((dst_clip_y + dst_clip_h) > (dst_region_y + dst_region_h)) | ||
171 | dst_clip_h = dst_region_y + dst_region_h - dst_clip_y; | ||
172 | |||
173 | if ((src_region_w <= 0) || (src_region_h <= 0) || | ||
174 | (dst_region_w <= 0) || (dst_region_h <= 0) || | ||
175 | (dst_clip_w <= 0) || (dst_clip_h <= 0)) | ||
176 | return; | ||
177 | |||
178 | /* sanitise x */ | ||
179 | if (src_region_x < 0) | ||
180 | { | ||
181 | dst_region_x -= (src_region_x * dst_region_w) / src_region_w; | ||
182 | dst_region_w += (src_region_x * dst_region_w) / src_region_w; | ||
183 | src_region_w += src_region_x; | ||
184 | src_region_x = 0; | ||
185 | } | ||
186 | if (src_region_x >= src_w) return; | ||
187 | if ((src_region_x + src_region_w) > src_w) | ||
188 | { | ||
189 | dst_region_w = (dst_region_w * (src_w - src_region_x)) / (src_region_w); | ||
190 | src_region_w = src_w - src_region_x; | ||
191 | } | ||
192 | if (dst_region_w <= 0) return; | ||
193 | if (src_region_w <= 0) return; | ||
194 | if (dst_clip_x < 0) | ||
195 | { | ||
196 | dst_clip_w += dst_clip_x; | ||
197 | dst_clip_x = 0; | ||
198 | } | ||
199 | if (dst_clip_w <= 0) return; | ||
200 | if (dst_clip_x >= dst_w) return; | ||
201 | if (dst_clip_x < dst_region_x) | ||
202 | { | ||
203 | dst_clip_w += (dst_clip_x - dst_region_x); | ||
204 | dst_clip_x = dst_region_x; | ||
205 | } | ||
206 | if ((dst_clip_x + dst_clip_w) > dst_w) | ||
207 | { | ||
208 | dst_clip_w = dst_w - dst_clip_x; | ||
209 | } | ||
210 | if (dst_clip_w <= 0) return; | ||
211 | |||
212 | /* sanitise y */ | ||
213 | if (src_region_y < 0) | ||
214 | { | ||
215 | dst_region_y -= (src_region_y * dst_region_h) / src_region_h; | ||
216 | dst_region_h += (src_region_y * dst_region_h) / src_region_h; | ||
217 | src_region_h += src_region_y; | ||
218 | src_region_y = 0; | ||
219 | } | ||
220 | if (src_region_y >= src_h) return; | ||
221 | if ((src_region_y + src_region_h) > src_h) | ||
222 | { | ||
223 | dst_region_h = (dst_region_h * (src_h - src_region_y)) / (src_region_h); | ||
224 | src_region_h = src_h - src_region_y; | ||
225 | } | ||
226 | if (dst_region_h <= 0) return; | ||
227 | if (src_region_h <= 0) return; | ||
228 | if (dst_clip_y < 0) | ||
229 | { | ||
230 | dst_clip_h += dst_clip_y; | ||
231 | dst_clip_y = 0; | ||
232 | } | ||
233 | if (dst_clip_h <= 0) return; | ||
234 | if (dst_clip_y >= dst_h) return; | ||
235 | if (dst_clip_y < dst_region_y) | ||
236 | { | ||
237 | dst_clip_h += (dst_clip_y - dst_region_y); | ||
238 | dst_clip_y = dst_region_y; | ||
239 | } | ||
240 | if ((dst_clip_y + dst_clip_h) > dst_h) | ||
241 | { | ||
242 | dst_clip_h = dst_h - dst_clip_y; | ||
243 | } | ||
244 | if (dst_clip_h <= 0) return; | ||
245 | |||
246 | /* allocate scale lookup tables */ | ||
247 | lin_ptr = alloca(dst_clip_w * sizeof(int)); | ||
248 | row_ptr = alloca(dst_clip_h * sizeof(DATA32 *)); | ||
249 | |||
250 | /* figure out dst jump */ | ||
251 | dst_jump = dst_w - dst_clip_w; | ||
252 | |||
253 | /* figure out dest start ptr */ | ||
254 | dst_ptr = dst_data + dst_clip_x + (dst_clip_y * dst_w); | ||
255 | |||
256 | if (dc->mask.mask) | ||
257 | { | ||
258 | func = evas_common_gfx_func_composite_pixel_mask_span_get(src, dst, dst_clip_w, dc->render_op); | ||
259 | maskobj = dc->mask.mask; | ||
260 | mask = maskobj->mask.mask; | ||
261 | /* | ||
262 | if (1 || dst_region_w > src_region_w || dst_region_h > src_region_h){ | ||
263 | printf("Mask w/h: %d/%d\n",maskobj->cache_entry.w, | ||
264 | maskobj->cache_entry.h); | ||
265 | printf("Warning: Unscaled mask (%d/%d) // (%d/%d)\n", | ||
266 | dst_region_w,src_region_w, | ||
267 | dst_region_h,src_region_h); | ||
268 | } | ||
269 | */ | ||
270 | } | ||
271 | else if (dc->mul.use) | ||
272 | func = evas_common_gfx_func_composite_pixel_color_span_get(src, dc->mul.col, dst, dst_clip_w, dc->render_op); | ||
273 | else | ||
274 | func = evas_common_gfx_func_composite_pixel_span_get(src, dst, dst_clip_w, dc->render_op); | ||
275 | |||
276 | if ((dst_region_w == src_region_w) && (dst_region_h == src_region_h)) | ||
277 | { | ||
278 | #ifdef HAVE_PIXMAN | ||
279 | if ((1) && | ||
280 | (src->pixman.im) && (dst->pixman.im) && | ||
281 | ((!dc->mul.use) || | ||
282 | ((dc->mul.use) && (dc->mul.col == 0xffffffff))) && | ||
283 | ((dc->render_op == _EVAS_RENDER_COPY) || | ||
284 | (dc->render_op == _EVAS_RENDER_BLEND)) | ||
285 | ) | ||
286 | { | ||
287 | pixman_op_t op = PIXMAN_OP_SRC; // _EVAS_RENDER_COPY | ||
288 | if (dc->render_op == _EVAS_RENDER_BLEND) op = PIXMAN_OP_OVER; | ||
289 | pixman_image_composite(op, | ||
290 | src->pixman.im, NULL, | ||
291 | dst->pixman.im, | ||
292 | (dst_clip_x - dst_region_x) + src_region_x, | ||
293 | (dst_clip_y - dst_region_y) + src_region_y, | ||
294 | 0, 0, | ||
295 | dst_clip_x, dst_clip_y, | ||
296 | dst_clip_w, dst_clip_h); | ||
297 | } | ||
298 | else | ||
299 | #endif | ||
300 | { | ||
301 | ptr = src_data + ((dst_clip_y - dst_region_y + src_region_y) * src_w) + (dst_clip_x - dst_region_x) + src_region_x; | ||
302 | if (mask) | ||
303 | { | ||
304 | mdx = (m_clip_x - dc->mask.x) + (m_clip_x - dst_clip_x); | ||
305 | mdy = (m_clip_y - dc->mask.y) + (m_clip_y - dst_clip_y); | ||
306 | mask += mdx + (mdy * maskobj->cache_entry.w); | ||
307 | } | ||
308 | for (y = 0; y < dst_clip_h; y++) | ||
309 | { | ||
310 | /* * blend here [clip_w *] ptr -> dst_ptr * */ | ||
311 | #ifdef EVAS_SLI | ||
312 | if (((y + dst_clip_y) % dc->sli.h) == dc->sli.y) | ||
313 | #endif | ||
314 | { | ||
315 | func(ptr, mask, dc->mul.col, dst_ptr, dst_clip_w); | ||
316 | } | ||
317 | ptr += src_w; | ||
318 | dst_ptr += dst_w; | ||
319 | if (mask) mask += maskobj->cache_entry.w; | ||
320 | } | ||
321 | } | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | /* fill scale tables */ | ||
326 | for (x = 0; x < dst_clip_w; x++) | ||
327 | lin_ptr[x] = (((x + dst_clip_x - dst_region_x) * src_region_w) / dst_region_w) + src_region_x; | ||
328 | for (y = 0; y < dst_clip_h; y++) | ||
329 | row_ptr[y] = src_data + (((((y + dst_clip_y - dst_region_y) * src_region_h) / dst_region_h) | ||
330 | + src_region_y) * src_w); | ||
331 | /* scale to dst */ | ||
332 | dptr = dst_ptr; | ||
333 | #ifdef DIRECT_SCALE | ||
334 | if ((!src->cache_entry.flags.alpha) && | ||
335 | (!dst->cache_entry.flags.alpha) && | ||
336 | (!dc->mul.use)) | ||
337 | { | ||
338 | for (y = 0; y < dst_clip_h; y++) | ||
339 | { | ||
340 | #ifdef EVAS_SLI | ||
341 | if (((y + dst_clip_y) % dc->sli.h) == dc->sli.y) | ||
342 | #endif | ||
343 | { | ||
344 | dst_ptr = dptr; | ||
345 | for (x = 0; x < dst_clip_w; x++) | ||
346 | { | ||
347 | ptr = row_ptr[y] + lin_ptr[x]; | ||
348 | *dst_ptr = *ptr; | ||
349 | dst_ptr++; | ||
350 | } | ||
351 | } | ||
352 | dptr += dst_w; | ||
353 | } | ||
354 | } | ||
355 | else | ||
356 | #endif | ||
357 | { | ||
358 | /* a scanline buffer */ | ||
359 | buf = alloca(dst_clip_w * sizeof(DATA32)); | ||
360 | for (y = 0; y < dst_clip_h; y++) | ||
361 | { | ||
362 | #ifdef EVAS_SLI | ||
363 | if (((y + dst_clip_y) % dc->sli.h) == dc->sli.y) | ||
364 | #endif | ||
365 | { | ||
366 | dst_ptr = buf; | ||
367 | for (x = 0; x < dst_clip_w; x++) | ||
368 | { | ||
369 | ptr = row_ptr[y] + lin_ptr[x]; | ||
370 | *dst_ptr = *ptr; | ||
371 | dst_ptr++; | ||
372 | } | ||
373 | /* * blend here [clip_w *] buf -> dptr * */ | ||
374 | func(buf, NULL, dc->mul.col, dptr, dst_clip_w); | ||
375 | } | ||
376 | dptr += dst_w; | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | } | ||
381 | #else | ||
382 | #ifdef BUILD_SCALE_SMOOTH | ||
383 | EAPI void | ||
384 | evas_common_scale_rgba_in_to_out_clip_sample(RGBA_Image *src, RGBA_Image *dst, | ||
385 | RGBA_Draw_Context *dc, | ||
386 | int src_region_x, int src_region_y, | ||
387 | int src_region_w, int src_region_h, | ||
388 | int dst_region_x, int dst_region_y, | ||
389 | int dst_region_w, int dst_region_h) | ||
390 | { | ||
391 | evas_common_scale_rgba_in_to_out_clip_smooth(src, dst, dc, | ||
392 | src_region_x, src_region_y, | ||
393 | src_region_w, src_region_h, | ||
394 | dst_region_x, dst_region_y, | ||
395 | dst_region_w, dst_region_h); | ||
396 | } | ||
397 | #endif | ||
398 | #endif | ||