diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/lib/engines/common/evas_image_main.c | 889 |
1 files changed, 0 insertions, 889 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_image_main.c b/libraries/evas/src/lib/engines/common/evas_image_main.c deleted file mode 100644 index 9c233b3..0000000 --- a/libraries/evas/src/lib/engines/common/evas_image_main.c +++ /dev/null | |||
@@ -1,889 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" /* so that EAPI in Eet.h is correctly defined */ | ||
3 | #endif | ||
4 | |||
5 | #ifdef BUILD_LOADER_EET | ||
6 | # include <Eet.h> | ||
7 | #endif | ||
8 | |||
9 | #include "evas_common.h" | ||
10 | #include "evas_private.h" | ||
11 | #include "evas_image_private.h" | ||
12 | #include "evas_convert_yuv.h" | ||
13 | #include "evas_cs.h" | ||
14 | |||
15 | #ifdef HAVE_VALGRIND | ||
16 | # include <memcheck.h> | ||
17 | #endif | ||
18 | |||
19 | //#define SURFDBG 1 | ||
20 | |||
21 | static Evas_Cache_Image * eci = NULL; | ||
22 | static int reference = 0; | ||
23 | |||
24 | /* static RGBA_Image *evas_rgba_line_buffer = NULL; */ | ||
25 | |||
26 | #define EVAS_RGBA_LINE_BUFFER_MIN_LEN 256 | ||
27 | #define EVAS_RGBA_LINE_BUFFER_MAX_LEN 2048 | ||
28 | |||
29 | /* static RGBA_Image *evas_alpha_line_buffer = NULL; */ | ||
30 | |||
31 | #define EVAS_ALPHA_LINE_BUFFER_MIN_LEN 256 | ||
32 | #define EVAS_ALPHA_LINE_BUFFER_MAX_LEN 2048 | ||
33 | |||
34 | |||
35 | static Image_Entry *_evas_common_rgba_image_new(void); | ||
36 | static void _evas_common_rgba_image_delete(Image_Entry *ie); | ||
37 | |||
38 | static int _evas_common_rgba_image_surface_alloc(Image_Entry *ie, unsigned int w, unsigned int h); | ||
39 | static void _evas_common_rgba_image_surface_delete(Image_Entry *ie); | ||
40 | static DATA32 *_evas_common_rgba_image_surface_pixels(Image_Entry *ie); | ||
41 | |||
42 | static void _evas_common_rgba_image_unload(Image_Entry *im); | ||
43 | |||
44 | static void _evas_common_rgba_image_dirty_region(Image_Entry *im, unsigned int x, unsigned int y, unsigned int w, unsigned int h); | ||
45 | |||
46 | static int _evas_common_rgba_image_ram_usage(Image_Entry *ie); | ||
47 | |||
48 | /* Only called when references > 0. Need to provide a fresh copie of im. */ | ||
49 | /* The destination surface does have a surface, but no allocated pixel data. */ | ||
50 | static int _evas_common_rgba_image_dirty(Image_Entry* dst, const Image_Entry* src); | ||
51 | |||
52 | #if 0 | ||
53 | static void | ||
54 | _evas_common_rgba_image_debug(const char* context, Image_Entry *eim) | ||
55 | { | ||
56 | DBG("%p = [%s] {%s,%s} %i [%i|%i]", eim, context, eim->file, eim->key, eim->references, eim->w, eim->h); | ||
57 | } | ||
58 | #endif | ||
59 | |||
60 | static const Evas_Cache_Image_Func _evas_common_image_func = | ||
61 | { | ||
62 | _evas_common_rgba_image_new, | ||
63 | _evas_common_rgba_image_delete, | ||
64 | _evas_common_rgba_image_surface_alloc, | ||
65 | _evas_common_rgba_image_surface_delete, | ||
66 | _evas_common_rgba_image_surface_pixels, | ||
67 | evas_common_load_rgba_image_module_from_file, | ||
68 | _evas_common_rgba_image_unload, | ||
69 | _evas_common_rgba_image_dirty_region, | ||
70 | _evas_common_rgba_image_dirty, | ||
71 | evas_common_rgba_image_size_set, | ||
72 | evas_common_rgba_image_from_copied_data, | ||
73 | evas_common_rgba_image_from_data, | ||
74 | evas_common_rgba_image_colorspace_set, | ||
75 | evas_common_load_rgba_image_data_from_file, | ||
76 | _evas_common_rgba_image_ram_usage, | ||
77 | /* _evas_common_rgba_image_debug */ | ||
78 | NULL | ||
79 | }; | ||
80 | |||
81 | EAPI void | ||
82 | evas_common_image_init(void) | ||
83 | { | ||
84 | if (!eci) | ||
85 | eci = evas_cache_image_init(&_evas_common_image_func); | ||
86 | reference++; | ||
87 | //// ERR("REF++=%i", reference); | ||
88 | |||
89 | #ifdef BUILD_LOADER_EET | ||
90 | eet_init(); | ||
91 | #endif | ||
92 | evas_common_scalecache_init(); | ||
93 | } | ||
94 | |||
95 | EAPI void | ||
96 | evas_common_image_shutdown(void) | ||
97 | { | ||
98 | if (--reference == 0) | ||
99 | { | ||
100 | //// printf("REF--=%i\n", reference); | ||
101 | // DISABLE for now - something wrong with cache shutdown freeing things | ||
102 | // still in use - rage_thumb segv's now. | ||
103 | // | ||
104 | // actually - i think i see it. cache ref goes to 0 (and thus gets freed) | ||
105 | // because in eng_setup() when a buffer changes size it is FIRST freed | ||
106 | // THEN allocated again - thus brignhjing ref to 0 then back to 1 immediately | ||
107 | // where it should stay at 1. - see evas_engine.c in the buffer enigne for | ||
108 | // example. eng_output_free() is called BEFORE _output_setup(). although this | ||
109 | // is only a SIGNE of the problem. we can patch this up with either freeing | ||
110 | // after the setup (so we just pt a ref of 2 then back to 1), or just | ||
111 | // evas_common_image_init() at the start and evas_common_image_shutdown() | ||
112 | // after it all. really ref 0 should only be reached when no more canvases | ||
113 | // with no more objects exist anywhere. | ||
114 | |||
115 | // ENABLE IT AGAIN, hope it is fixed. Gustavo @ January 22nd, 2009. | ||
116 | evas_cache_image_shutdown(eci); | ||
117 | eci = NULL; | ||
118 | } | ||
119 | |||
120 | #ifdef BUILD_LOADER_EET | ||
121 | eet_shutdown(); | ||
122 | #endif | ||
123 | evas_common_scalecache_shutdown(); | ||
124 | } | ||
125 | |||
126 | EAPI void | ||
127 | evas_common_image_image_all_unload(void) | ||
128 | { | ||
129 | evas_common_rgba_image_scalecache_dump(); | ||
130 | evas_cache_image_unload_all(eci); | ||
131 | } | ||
132 | |||
133 | static Image_Entry * | ||
134 | _evas_common_rgba_image_new(void) | ||
135 | { | ||
136 | RGBA_Image *im; | ||
137 | |||
138 | im = calloc(1, sizeof(RGBA_Image)); | ||
139 | if (!im) return NULL; | ||
140 | im->flags = RGBA_IMAGE_NOTHING; | ||
141 | im->ref = 1; | ||
142 | #ifdef EVAS_FRAME_QUEUING | ||
143 | LKI(im->cache_entry.ref_fq_add); | ||
144 | LKI(im->cache_entry.ref_fq_del); | ||
145 | eina_condition_new(&(im->cache_entry.cond_fq_del), | ||
146 | &(im->cache_entry.ref_fq_del)); | ||
147 | #endif | ||
148 | |||
149 | evas_common_rgba_image_scalecache_init(&im->cache_entry); | ||
150 | |||
151 | return &im->cache_entry; | ||
152 | } | ||
153 | |||
154 | static void | ||
155 | _evas_common_rgba_image_delete(Image_Entry *ie) | ||
156 | { | ||
157 | RGBA_Image *im = (RGBA_Image *)ie; | ||
158 | |||
159 | #ifdef BUILD_PIPE_RENDER | ||
160 | evas_common_pipe_free(im); | ||
161 | # ifdef EVAS_FRAME_QUEUING | ||
162 | LKD(im->cache_entry.ref_fq_add); | ||
163 | LKD(im->cache_entry.ref_fq_del); | ||
164 | eina_condition_free(&(im->cache_entry.cond_fq_del)); | ||
165 | # endif | ||
166 | #endif | ||
167 | evas_common_rgba_image_scalecache_shutdown(&im->cache_entry); | ||
168 | if (ie->info.module) evas_module_unref((Evas_Module *)ie->info.module); | ||
169 | /* memset the image to 0x99 because i recently saw a segv where an | ||
170 | * seemed to be used BUT its contents were wrong - it looks like it was | ||
171 | * overwritten by something from efreet - as there was an execute command | ||
172 | * for a command there and some other signs - but to make sure, I am | ||
173 | * going to empty this struct out in case this happens again so i know | ||
174 | * that something else is overwritign this struct - or not */ | ||
175 | // memset(im, 0x99, sizeof(im)); | ||
176 | #ifdef EVAS_CSERVE | ||
177 | if (ie->data1) evas_cserve_image_free(ie); | ||
178 | #endif | ||
179 | /* | ||
180 | * FIXME: This doesn't seem to be needed... But I'm not sure why. | ||
181 | * -- nash | ||
182 | { | ||
183 | Filtered_Image *fi; | ||
184 | |||
185 | EINA_LIST_FREE(im->filtered, fi) | ||
186 | { | ||
187 | free(fi->key); | ||
188 | _evas_common_rgba_image_delete((Image_Entry *)(fi->image)); | ||
189 | free(fi); | ||
190 | } | ||
191 | } | ||
192 | */ | ||
193 | if (ie->frames) | ||
194 | { | ||
195 | Eina_List *l; | ||
196 | Image_Entry_Frame *frame; | ||
197 | EINA_LIST_FOREACH(ie->frames, l, frame) | ||
198 | { | ||
199 | if (frame) | ||
200 | { | ||
201 | if (frame->data) free(frame->data); | ||
202 | if (frame->info) free(frame->info); | ||
203 | free (frame); | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | free(im); | ||
208 | } | ||
209 | |||
210 | EAPI void | ||
211 | evas_common_rgba_image_free(Image_Entry *ie) | ||
212 | { | ||
213 | _evas_common_rgba_image_surface_delete(ie); | ||
214 | _evas_common_rgba_image_delete(ie); | ||
215 | } | ||
216 | |||
217 | #ifdef SURFDBG | ||
218 | static Eina_List *surfs = NULL; | ||
219 | |||
220 | static void | ||
221 | surf_debug(void) | ||
222 | { | ||
223 | Eina_List *l; | ||
224 | Image_Entry *ie; | ||
225 | RGBA_Image *im; | ||
226 | int i = 0; | ||
227 | |||
228 | printf("----SURFS----\n"); | ||
229 | EINA_LIST_FOREACH(surfs, l, ie) | ||
230 | { | ||
231 | im = ie; | ||
232 | printf("%i - %p - %ix%i [%s][%s]\n", | ||
233 | i, im->image.data, ie->allocated.w, ie->allocated.h, | ||
234 | ie->file, ie->key | ||
235 | ); | ||
236 | i++; | ||
237 | } | ||
238 | } | ||
239 | #endif | ||
240 | |||
241 | EAPI void | ||
242 | evas_common_rgba_image_unload(Image_Entry *ie) | ||
243 | { | ||
244 | RGBA_Image *im = (RGBA_Image *) ie; | ||
245 | |||
246 | if (!ie->flags.loaded) return; | ||
247 | if ((!ie->info.module) && (!ie->data1)) return; | ||
248 | if (!ie->file) return; | ||
249 | |||
250 | ie->flags.loaded = 0; | ||
251 | |||
252 | if ((im->cs.data) && (im->image.data)) | ||
253 | { | ||
254 | if (im->cs.data != im->image.data) | ||
255 | { | ||
256 | if (!im->cs.no_free) free(im->cs.data); | ||
257 | } | ||
258 | } | ||
259 | else if (im->cs.data) | ||
260 | { | ||
261 | if (!im->cs.no_free) free(im->cs.data); | ||
262 | } | ||
263 | im->cs.data = NULL; | ||
264 | |||
265 | #ifdef EVAS_CSERVE | ||
266 | if (ie->data1) | ||
267 | { | ||
268 | evas_cserve_image_useless(ie); | ||
269 | im->image.data = NULL; | ||
270 | ie->allocated.w = 0; | ||
271 | ie->allocated.h = 0; | ||
272 | ie->flags.loaded = 0; | ||
273 | #ifdef BUILD_ASYNC_PRELOAD | ||
274 | ie->flags.preload_done = 0; | ||
275 | #endif | ||
276 | return; | ||
277 | } | ||
278 | #endif | ||
279 | |||
280 | if (im->image.data && !im->image.no_free) | ||
281 | { | ||
282 | free(im->image.data); | ||
283 | #ifdef SURFDBG | ||
284 | surfs = eina_list_remove(surfs, ie); | ||
285 | #endif | ||
286 | } | ||
287 | im->image.data = NULL; | ||
288 | ie->allocated.w = 0; | ||
289 | ie->allocated.h = 0; | ||
290 | ie->flags.loaded = 0; | ||
291 | #ifdef BUILD_ASYNC_PRELOAD | ||
292 | ie->flags.preload_done = 0; | ||
293 | #endif | ||
294 | #ifdef SURFDBG | ||
295 | surf_debug(); | ||
296 | #endif | ||
297 | } | ||
298 | |||
299 | void | ||
300 | _evas_common_rgba_image_post_surface(Image_Entry *ie) | ||
301 | { | ||
302 | #ifdef HAVE_PIXMAN | ||
303 | # ifdef PIXMAN_IMAGE | ||
304 | RGBA_Image *im = (RGBA_Image *)ie; | ||
305 | |||
306 | if (im->pixman.im) pixman_image_unref(im->pixman.im); | ||
307 | if (im->cache_entry.flags.alpha) | ||
308 | { | ||
309 | im->pixman.im = pixman_image_create_bits | ||
310 | ( | ||
311 | // FIXME: endianess determines this | ||
312 | PIXMAN_a8r8g8b8, | ||
313 | // PIXMAN_b8g8r8a8, | ||
314 | im->cache_entry.w, im->cache_entry.h, | ||
315 | im->image.data, | ||
316 | im->cache_entry.w * 4 | ||
317 | ); | ||
318 | } | ||
319 | else | ||
320 | { | ||
321 | im->pixman.im = pixman_image_create_bits | ||
322 | ( | ||
323 | // FIXME: endianess determines this | ||
324 | PIXMAN_x8r8g8b8, | ||
325 | // PIXMAN_b8g8r8x8, | ||
326 | im->cache_entry.w, im->cache_entry.h, | ||
327 | im->image.data, | ||
328 | im->cache_entry.w * 4 | ||
329 | ); | ||
330 | } | ||
331 | # else | ||
332 | (void)ie; | ||
333 | # endif | ||
334 | #else | ||
335 | (void)ie; | ||
336 | #endif | ||
337 | } | ||
338 | |||
339 | static int | ||
340 | _evas_common_rgba_image_surface_alloc(Image_Entry *ie, unsigned int w, unsigned int h) | ||
341 | { | ||
342 | RGBA_Image *im = (RGBA_Image *) ie; | ||
343 | size_t siz = 0; | ||
344 | |||
345 | #ifdef EVAS_CSERVE | ||
346 | if (ie->data1) return 0; | ||
347 | #endif | ||
348 | if (im->image.no_free) return 0; | ||
349 | |||
350 | if (im->flags & RGBA_IMAGE_ALPHA_ONLY) | ||
351 | siz = w * h * sizeof(DATA8); | ||
352 | else | ||
353 | siz = w * h * sizeof(DATA32); | ||
354 | |||
355 | if (im->image.data) | ||
356 | { | ||
357 | free(im->image.data); | ||
358 | #ifdef SURFDBG | ||
359 | surfs = eina_list_remove(surfs, ie); | ||
360 | #endif | ||
361 | } | ||
362 | im->image.data = malloc(siz); | ||
363 | if (!im->image.data) return -1; | ||
364 | ie->allocated.w = w; | ||
365 | ie->allocated.h = h; | ||
366 | #ifdef SURFDBG | ||
367 | surfs = eina_list_append(surfs, ie); | ||
368 | #endif | ||
369 | #ifdef HAVE_VALGRIND | ||
370 | # ifdef VALGRIND_MAKE_READABLE | ||
371 | VALGRIND_MAKE_READABLE(im->image.data, siz); | ||
372 | # else | ||
373 | # ifdef VALGRIND_MAKE_MEM_DEFINED | ||
374 | VALGRIND_MAKE_MEM_DEFINED(im->image.data, siz); | ||
375 | # endif | ||
376 | # endif | ||
377 | #endif | ||
378 | _evas_common_rgba_image_post_surface(ie); | ||
379 | #ifdef SURFDBG | ||
380 | surf_debug(); | ||
381 | #endif | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | static void | ||
386 | _evas_common_rgba_image_surface_delete(Image_Entry *ie) | ||
387 | { | ||
388 | RGBA_Image *im = (RGBA_Image *) ie; | ||
389 | |||
390 | #ifdef HAVE_PIXMAN | ||
391 | # ifdef PIXMAN_IMAGE | ||
392 | if (im->pixman.im) | ||
393 | { | ||
394 | pixman_image_unref(im->pixman.im); | ||
395 | im->pixman.im = NULL; | ||
396 | } | ||
397 | # endif | ||
398 | #endif | ||
399 | if (ie->file) | ||
400 | DBG("unload: [%p] %s %s", ie, ie->file, ie->key); | ||
401 | if ((im->cs.data) && (im->image.data)) | ||
402 | { | ||
403 | if (im->cs.data != im->image.data) | ||
404 | { | ||
405 | if (!im->cs.no_free) free(im->cs.data); | ||
406 | } | ||
407 | } | ||
408 | else if (im->cs.data) | ||
409 | { | ||
410 | if (!im->cs.no_free) free(im->cs.data); | ||
411 | } | ||
412 | im->cs.data = NULL; | ||
413 | |||
414 | if (im->image.data && !im->image.no_free) | ||
415 | { | ||
416 | free(im->image.data); | ||
417 | #ifdef SURFDBG | ||
418 | surfs = eina_list_remove(surfs, ie); | ||
419 | #endif | ||
420 | } | ||
421 | #ifdef EVAS_CSERVE | ||
422 | else if (ie->data1) | ||
423 | evas_cserve_image_free(ie); | ||
424 | #endif | ||
425 | |||
426 | im->image.data = NULL; | ||
427 | ie->allocated.w = 0; | ||
428 | ie->allocated.h = 0; | ||
429 | #ifdef BUILD_ASYNC_PRELOAD | ||
430 | ie->flags.preload_done = 0; | ||
431 | #endif | ||
432 | ie->flags.loaded = 0; | ||
433 | evas_common_rgba_image_scalecache_dirty(&im->cache_entry); | ||
434 | #ifdef SURFDBG | ||
435 | surf_debug(); | ||
436 | #endif | ||
437 | } | ||
438 | |||
439 | static void | ||
440 | _evas_common_rgba_image_unload(Image_Entry *im) | ||
441 | { | ||
442 | // DBG("unload: [%p] %s %s", im, im->file, im->key); | ||
443 | evas_common_rgba_image_scalecache_dirty(im); | ||
444 | evas_common_rgba_image_unload(im); | ||
445 | } | ||
446 | |||
447 | static void | ||
448 | _evas_common_rgba_image_dirty_region(Image_Entry* ie, unsigned int x __UNUSED__, unsigned int y __UNUSED__, unsigned int w __UNUSED__, unsigned int h __UNUSED__) | ||
449 | { | ||
450 | RGBA_Image *im = (RGBA_Image *) ie; | ||
451 | |||
452 | #ifdef EVAS_CSERVE | ||
453 | if (ie->data1) evas_cserve_image_free(ie); | ||
454 | #endif | ||
455 | im->flags |= RGBA_IMAGE_IS_DIRTY; | ||
456 | evas_common_rgba_image_scalecache_dirty(&im->cache_entry); | ||
457 | } | ||
458 | |||
459 | /* Only called when references > 0. Need to provide a fresh copie of im. */ | ||
460 | static int | ||
461 | _evas_common_rgba_image_dirty(Image_Entry *ie_dst, const Image_Entry *ie_src) | ||
462 | { | ||
463 | RGBA_Image *dst = (RGBA_Image *) ie_dst; | ||
464 | RGBA_Image *src = (RGBA_Image *) ie_src; | ||
465 | |||
466 | evas_common_rgba_image_scalecache_dirty((Image_Entry *)ie_src); | ||
467 | evas_common_rgba_image_scalecache_dirty(ie_dst); | ||
468 | evas_cache_image_load_data(&src->cache_entry); | ||
469 | if (_evas_common_rgba_image_surface_alloc(&dst->cache_entry, | ||
470 | src->cache_entry.w, src->cache_entry.h)) | ||
471 | { | ||
472 | #ifdef EVAS_CSERVE | ||
473 | if (ie_src->data1) evas_cserve_image_free((Image_Entry*) ie_src); | ||
474 | #endif | ||
475 | return 1; | ||
476 | } | ||
477 | |||
478 | #ifdef EVAS_CSERVE | ||
479 | if (ie_src->data1) evas_cserve_image_free((Image_Entry*) ie_src); | ||
480 | #endif | ||
481 | evas_common_image_colorspace_normalize(src); | ||
482 | evas_common_image_colorspace_normalize(dst); | ||
483 | /* evas_common_blit_rectangle(src, dst, 0, 0, src->cache_entry.w, src->cache_entry.h, 0, 0); */ | ||
484 | /* evas_common_cpu_end_opt(); */ | ||
485 | |||
486 | return 0; | ||
487 | } | ||
488 | |||
489 | static int | ||
490 | _evas_common_rgba_image_ram_usage(Image_Entry *ie) | ||
491 | { | ||
492 | RGBA_Image *im = (RGBA_Image *)ie; | ||
493 | int size = sizeof(struct _RGBA_Image); | ||
494 | |||
495 | if (ie->cache_key) size += strlen(ie->cache_key); | ||
496 | if (ie->file) size += strlen(ie->file); | ||
497 | if (ie->key) size += strlen(ie->key); | ||
498 | |||
499 | if (im->image.data) | ||
500 | { | ||
501 | #ifdef EVAS_CSERVE | ||
502 | if ((!im->image.no_free) || (ie->data1)) | ||
503 | #else | ||
504 | if ((!im->image.no_free)) | ||
505 | #endif | ||
506 | size += im->cache_entry.w * im->cache_entry.h * sizeof(DATA32); | ||
507 | } | ||
508 | size += evas_common_rgba_image_scalecache_usage_get(&im->cache_entry); | ||
509 | return size; | ||
510 | } | ||
511 | |||
512 | static DATA32 * | ||
513 | _evas_common_rgba_image_surface_pixels(Image_Entry *ie) | ||
514 | { | ||
515 | RGBA_Image *im = (RGBA_Image *) ie; | ||
516 | |||
517 | return im->image.data; | ||
518 | } | ||
519 | |||
520 | #if 0 | ||
521 | void | ||
522 | evas_common_image_surface_alpha_tiles_calc(RGBA_Surface *is, int tsize) | ||
523 | { | ||
524 | int x, y; | ||
525 | DATA32 *ptr; | ||
526 | |||
527 | if (is->spans) return; | ||
528 | if (!is->im->cache_entry.flags.alpha) return; | ||
529 | /* FIXME: dont handle alpha only images yet */ | ||
530 | if ((is->im->flags & RGBA_IMAGE_ALPHA_ONLY)) return; | ||
531 | if (tsize < 0) tsize = 0; | ||
532 | is->spans = calloc(1, sizeof(RGBA_Image_Span *) * is->h); | ||
533 | if (!is->spans) return; | ||
534 | ptr = is->data; | ||
535 | for (y = 0; y < is->h; y++) | ||
536 | { | ||
537 | RGBA_Image_Span *sp; | ||
538 | |||
539 | sp = NULL; | ||
540 | for (x = 0; x < is->w; x++) | ||
541 | { | ||
542 | DATA8 a; | ||
543 | |||
544 | a = A_VAL(ptr); | ||
545 | if (sp) | ||
546 | { | ||
547 | if (a == 0) | ||
548 | { | ||
549 | is->spans[y] = eina_inlist_append(is->spans[y], sp); | ||
550 | sp = NULL; | ||
551 | } | ||
552 | else | ||
553 | { | ||
554 | sp->w++; | ||
555 | if ((sp->v == 2) && (a != 255)) sp->v = 1; | ||
556 | } | ||
557 | } | ||
558 | else | ||
559 | { | ||
560 | if (a == 255) | ||
561 | { | ||
562 | sp = calloc(1, sizeof(RGBA_Image_Span)); | ||
563 | sp->x = x; | ||
564 | sp->w = 1; | ||
565 | sp->v = 2; | ||
566 | } | ||
567 | else if (a > 0) | ||
568 | { | ||
569 | sp = calloc(1, sizeof(RGBA_Image_Span)); | ||
570 | sp->x = x; | ||
571 | sp->w = 1; | ||
572 | sp->v = 1; | ||
573 | } | ||
574 | } | ||
575 | ptr++; | ||
576 | } | ||
577 | if (sp) | ||
578 | { | ||
579 | is->spans[y] = eina_inlist_append(is->spans[y], sp); | ||
580 | sp = NULL; | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | #endif | ||
585 | |||
586 | /* EAPI void */ | ||
587 | /* evas_common_image_surface_dealloc(RGBA_Surface *is) */ | ||
588 | /* { */ | ||
589 | /* if ((is->data) && (!is->no_free)) */ | ||
590 | /* { */ | ||
591 | /* free(is->data); */ | ||
592 | /* is->data = NULL; */ | ||
593 | /* } */ | ||
594 | /* } */ | ||
595 | |||
596 | static RGBA_Image * | ||
597 | evas_common_image_create(unsigned int w, unsigned int h) | ||
598 | { | ||
599 | RGBA_Image *im; | ||
600 | |||
601 | im = (RGBA_Image *) _evas_common_rgba_image_new(); | ||
602 | if (!im) return NULL; | ||
603 | im->cache_entry.w = w; | ||
604 | im->cache_entry.h = h; | ||
605 | if (_evas_common_rgba_image_surface_alloc(&im->cache_entry, w, h)) | ||
606 | { | ||
607 | _evas_common_rgba_image_delete(&im->cache_entry); | ||
608 | return NULL; | ||
609 | } | ||
610 | im->cache_entry.flags.cached = 0; | ||
611 | return im; | ||
612 | } | ||
613 | |||
614 | EAPI RGBA_Image * | ||
615 | evas_common_image_alpha_create(unsigned int w, unsigned int h) | ||
616 | { | ||
617 | RGBA_Image *im; | ||
618 | |||
619 | im = (RGBA_Image *) _evas_common_rgba_image_new(); | ||
620 | if (!im) return NULL; | ||
621 | im->cache_entry.w = w; | ||
622 | im->cache_entry.h = h; | ||
623 | im->cache_entry.flags.alpha = 1; | ||
624 | if (_evas_common_rgba_image_surface_alloc(&im->cache_entry, w, h)) | ||
625 | { | ||
626 | _evas_common_rgba_image_delete(&im->cache_entry); | ||
627 | return NULL; | ||
628 | } | ||
629 | im->cache_entry.flags.cached = 0; | ||
630 | return im; | ||
631 | } | ||
632 | |||
633 | EAPI RGBA_Image * | ||
634 | evas_common_image_new(unsigned int w, unsigned int h, unsigned int alpha) | ||
635 | { | ||
636 | if (alpha) | ||
637 | return evas_common_image_alpha_create(w, h); | ||
638 | return evas_common_image_create(w, h); | ||
639 | } | ||
640 | |||
641 | void | ||
642 | evas_common_image_colorspace_normalize(RGBA_Image *im) | ||
643 | { | ||
644 | if ((!im->cs.data) || | ||
645 | ((!im->cs.dirty) && (!(im->flags & RGBA_IMAGE_IS_DIRTY)))) return; | ||
646 | switch (im->cache_entry.space) | ||
647 | { | ||
648 | case EVAS_COLORSPACE_ARGB8888: | ||
649 | if (im->image.data != im->cs.data) | ||
650 | { | ||
651 | #ifdef EVAS_CSERVE | ||
652 | if (((Image_Entry *)im)->data1) evas_cserve_image_free(&im->cache_entry); | ||
653 | #endif | ||
654 | if (!im->image.no_free) | ||
655 | { | ||
656 | free(im->image.data); | ||
657 | #ifdef SURFDBG | ||
658 | surfs = eina_list_remove(surfs, im); | ||
659 | #endif | ||
660 | ((Image_Entry *)im)->allocated.w = 0; | ||
661 | ((Image_Entry *)im)->allocated.h = 0; | ||
662 | } | ||
663 | im->image.data = im->cs.data; | ||
664 | im->cs.no_free = im->image.no_free; | ||
665 | } | ||
666 | break; | ||
667 | case EVAS_COLORSPACE_YCBCR422P601_PL: | ||
668 | #ifdef BUILD_CONVERT_YUV | ||
669 | if ((im->image.data) && (*((unsigned char **)im->cs.data))) | ||
670 | evas_common_convert_yuv_420p_601_rgba(im->cs.data, (DATA8*) im->image.data, | ||
671 | im->cache_entry.w, im->cache_entry.h); | ||
672 | #endif | ||
673 | break; | ||
674 | case EVAS_COLORSPACE_YCBCR422601_PL: | ||
675 | #ifdef BUILD_CONVERT_YUV | ||
676 | if ((im->image.data) && (*((unsigned char **)im->cs.data))) | ||
677 | evas_common_convert_yuv_422_601_rgba(im->cs.data, (DATA8*) im->image.data, | ||
678 | im->cache_entry.w, im->cache_entry.h); | ||
679 | #endif | ||
680 | break; | ||
681 | case EVAS_COLORSPACE_YCBCR420NV12601_PL: | ||
682 | #ifdef BUILD_CONVERT_YUV | ||
683 | if ((im->image.data) && (*((unsigned char **)im->cs.data))) | ||
684 | evas_common_convert_yuv_420_601_rgba(im->cs.data, (DATA8*) im->image.data, | ||
685 | im->cache_entry.w, im->cache_entry.h); | ||
686 | #endif | ||
687 | break; | ||
688 | case EVAS_COLORSPACE_YCBCR420TM12601_PL: | ||
689 | #ifdef BUILD_CONVERT_YUV | ||
690 | if ((im->image.data) && (*((unsigned char **)im->cs.data))) | ||
691 | evas_common_convert_yuv_420T_601_rgba(im->cs.data, (DATA8*) im->image.data, | ||
692 | im->cache_entry.w, im->cache_entry.h); | ||
693 | #endif | ||
694 | break; | ||
695 | default: | ||
696 | break; | ||
697 | } | ||
698 | im->cs.dirty = 0; | ||
699 | #ifdef SURFDBG | ||
700 | surf_debug(); | ||
701 | #endif | ||
702 | } | ||
703 | |||
704 | EAPI void | ||
705 | evas_common_image_colorspace_dirty(RGBA_Image *im) | ||
706 | { | ||
707 | im->cs.dirty = 1; | ||
708 | evas_common_rgba_image_scalecache_dirty(&im->cache_entry); | ||
709 | } | ||
710 | |||
711 | EAPI void | ||
712 | evas_common_image_set_cache(unsigned int size) | ||
713 | { | ||
714 | if (eci) | ||
715 | evas_cache_image_set(eci, size); | ||
716 | } | ||
717 | |||
718 | EAPI int | ||
719 | evas_common_image_get_cache(void) | ||
720 | { | ||
721 | return evas_cache_image_get(eci); | ||
722 | } | ||
723 | |||
724 | EAPI RGBA_Image * | ||
725 | evas_common_load_image_from_file(const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error) | ||
726 | { | ||
727 | if (!file) | ||
728 | { | ||
729 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
730 | return NULL; | ||
731 | } | ||
732 | return (RGBA_Image *) evas_cache_image_request(eci, file, key, lo, error); | ||
733 | } | ||
734 | |||
735 | EAPI void | ||
736 | evas_common_image_cache_free(void) | ||
737 | { | ||
738 | evas_common_image_set_cache(0); | ||
739 | } | ||
740 | |||
741 | EAPI Evas_Cache_Image* | ||
742 | evas_common_image_cache_get(void) | ||
743 | { | ||
744 | return eci; | ||
745 | } | ||
746 | |||
747 | EAPI RGBA_Image * | ||
748 | evas_common_image_line_buffer_obtain(int len) | ||
749 | { | ||
750 | if (len < 1) return NULL; | ||
751 | if (len < EVAS_RGBA_LINE_BUFFER_MIN_LEN) | ||
752 | len = EVAS_RGBA_LINE_BUFFER_MIN_LEN; | ||
753 | return evas_common_image_create(len, 1); | ||
754 | /* | ||
755 | if (evas_rgba_line_buffer) | ||
756 | { | ||
757 | if (evas_rgba_line_buffer->image->w >= len) | ||
758 | return evas_rgba_line_buffer; | ||
759 | evas_rgba_line_buffer->image->data = (DATA32 *)realloc(evas_rgba_line_buffer->image->data, len * sizeof(DATA32)); | ||
760 | if (!evas_rgba_line_buffer->image->data) | ||
761 | { | ||
762 | evas_common_image_free(evas_rgba_line_buffer); | ||
763 | evas_rgba_line_buffer = NULL; | ||
764 | return NULL; | ||
765 | } | ||
766 | evas_rgba_line_buffer->image->w = len; | ||
767 | return evas_rgba_line_buffer; | ||
768 | } | ||
769 | evas_rgba_line_buffer = evas_common_image_create(len, 1); | ||
770 | if (!evas_rgba_line_buffer) return NULL; | ||
771 | return evas_rgba_line_buffer; | ||
772 | */ | ||
773 | } | ||
774 | |||
775 | EAPI void | ||
776 | evas_common_image_line_buffer_release(RGBA_Image *im) | ||
777 | { | ||
778 | _evas_common_rgba_image_delete(&im->cache_entry); | ||
779 | /* | ||
780 | if (!evas_rgba_line_buffer) return; | ||
781 | if (EVAS_RGBA_LINE_BUFFER_MAX_LEN < evas_rgba_line_buffer->image->w) | ||
782 | { | ||
783 | evas_rgba_line_buffer->image->w = EVAS_RGBA_LINE_BUFFER_MAX_LEN; | ||
784 | evas_rgba_line_buffer->image->data = (DATA32 *)realloc(evas_rgba_line_buffer->image->data, | ||
785 | evas_rgba_line_buffer->image->w * sizeof(DATA32)); | ||
786 | if (!evas_rgba_line_buffer->image->data) | ||
787 | { | ||
788 | evas_common_image_free(evas_rgba_line_buffer); | ||
789 | evas_rgba_line_buffer = NULL; | ||
790 | } | ||
791 | } | ||
792 | */ | ||
793 | } | ||
794 | |||
795 | EAPI void | ||
796 | evas_common_image_line_buffer_free(RGBA_Image *im) | ||
797 | { | ||
798 | _evas_common_rgba_image_delete(&im->cache_entry); | ||
799 | /* | ||
800 | if (!evas_rgba_line_buffer) return; | ||
801 | evas_common_image_free(evas_rgba_line_buffer); | ||
802 | evas_rgba_line_buffer = NULL; | ||
803 | */ | ||
804 | } | ||
805 | |||
806 | EAPI RGBA_Image * | ||
807 | evas_common_image_alpha_line_buffer_obtain(int len) | ||
808 | { | ||
809 | if (len < 1) return NULL; | ||
810 | if (len < EVAS_ALPHA_LINE_BUFFER_MIN_LEN) | ||
811 | len = EVAS_ALPHA_LINE_BUFFER_MIN_LEN; | ||
812 | return evas_common_image_alpha_create(len, 1); | ||
813 | /* | ||
814 | if (evas_alpha_line_buffer) | ||
815 | { | ||
816 | if (evas_alpha_line_buffer->image->w >= len) | ||
817 | return evas_alpha_line_buffer; | ||
818 | evas_alpha_line_buffer->image->data = realloc(evas_alpha_line_buffer->image->data, len * sizeof(DATA8)); | ||
819 | if (!evas_alpha_line_buffer->image->data) | ||
820 | { | ||
821 | evas_common_image_free(evas_alpha_line_buffer); | ||
822 | evas_alpha_line_buffer = NULL; | ||
823 | return NULL; | ||
824 | } | ||
825 | evas_alpha_line_buffer->image->w = len; | ||
826 | return evas_alpha_line_buffer; | ||
827 | } | ||
828 | evas_alpha_line_buffer = evas_common_image_alpha_create(len, 1); | ||
829 | return evas_alpha_line_buffer; | ||
830 | */ | ||
831 | } | ||
832 | |||
833 | EAPI void | ||
834 | evas_common_image_alpha_line_buffer_release(RGBA_Image *im) | ||
835 | { | ||
836 | _evas_common_rgba_image_delete(&im->cache_entry); | ||
837 | /* | ||
838 | if (!evas_alpha_line_buffer) return; | ||
839 | if (EVAS_ALPHA_LINE_BUFFER_MAX_LEN < evas_alpha_line_buffer->image->w) | ||
840 | { | ||
841 | evas_alpha_line_buffer->image->w = EVAS_ALPHA_LINE_BUFFER_MAX_LEN; | ||
842 | evas_alpha_line_buffer->image->data = realloc(evas_alpha_line_buffer->image->data, | ||
843 | evas_alpha_line_buffer->image->w * sizeof(DATA8)); | ||
844 | if (!evas_alpha_line_buffer->image->data) | ||
845 | { | ||
846 | evas_common_image_free(evas_alpha_line_buffer); | ||
847 | evas_alpha_line_buffer = NULL; | ||
848 | } | ||
849 | } | ||
850 | */ | ||
851 | } | ||
852 | |||
853 | EAPI void | ||
854 | evas_common_image_premul(Image_Entry *ie) | ||
855 | { | ||
856 | DATA32 nas = 0; | ||
857 | |||
858 | if (!ie) return ; | ||
859 | if (!evas_cache_image_pixels(ie)) return ; | ||
860 | if (!ie->flags.alpha) return; | ||
861 | |||
862 | nas = evas_common_convert_argb_premul(evas_cache_image_pixels(ie), ie->w * ie->h); | ||
863 | if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h)) | ||
864 | ie->flags.alpha_sparse = 1; | ||
865 | } | ||
866 | |||
867 | EAPI void | ||
868 | evas_common_image_set_alpha_sparse(Image_Entry *ie) | ||
869 | { | ||
870 | DATA32 *s, *se; | ||
871 | DATA32 nas = 0; | ||
872 | |||
873 | if (!ie) return; | ||
874 | if (!evas_cache_image_pixels(ie)) return ; | ||
875 | if (!ie->flags.alpha) return; | ||
876 | |||
877 | s = evas_cache_image_pixels(ie); | ||
878 | se = s + (ie->w * ie->h); | ||
879 | while (s < se) | ||
880 | { | ||
881 | DATA32 p = *s & 0xff000000; | ||
882 | |||
883 | if (!p || (p == 0xff000000)) | ||
884 | nas++; | ||
885 | s++; | ||
886 | } | ||
887 | if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h)) | ||
888 | ie->flags.alpha_sparse = 1; | ||
889 | } | ||