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