summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2009-12-22 23:11:57 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2009-12-22 23:11:57 +0000
commit51c00c6526821e97442204e8a18e46fcc4b73fd9 (patch)
treec83cb571f577b3191b3507005c5211d4632599bf /legacy
parent0a9456ccf73706efac262f5844cb58e22984bd19 (diff)
fix evas image loading error reporting.
Evas image load was always reporint "generic" error, since it was disconnected from actual loader modules. This commit will break the module loader API (as it's restricted to inside Evas, this should be no problem). The return was turned into "Eina_Bool" for clarity, while an extra "int *error" is responsible to report errors. This approach was choosen to force compiler warnings and to try avoid mistakes as EINA_FALSE == EVAS_LOAD_ERROR_NONE and thus we'd get opposite behavior if something slips. Most loaders play well, except by eet that does not provide means to know if the file open failed due missing file, incorrect format or corrupted file :-( Please report any issues. I added eina_log debugging to loader functions, just run your Evas application as: EINA_LOG_LEVELS=evas_main:4 your_app SVN revision: 44666
Diffstat (limited to 'legacy')
-rw-r--r--legacy/evas/src/lib/Evas.h5
-rw-r--r--legacy/evas/src/lib/cache/evas_cache.h4
-rw-r--r--legacy/evas/src/lib/cache/evas_cache_engine_image.c18
-rw-r--r--legacy/evas/src/lib/cache/evas_cache_image.c41
-rw-r--r--legacy/evas/src/lib/canvas/evas_object_image.c3
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image.h2
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_load.c125
-rw-r--r--legacy/evas/src/lib/engines/common/evas_image_main.c12
-rw-r--r--legacy/evas/src/lib/imaging/evas_imaging.c8
-rw-r--r--legacy/evas/src/lib/include/evas_common.h2
-rw-r--r--legacy/evas/src/lib/include/evas_private.h4
-rw-r--r--legacy/evas/src/modules/engines/cairo_x11/evas_engine.c13
-rw-r--r--legacy/evas/src/modules/engines/directfb/evas_engine.c8
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_common.h2
-rw-r--r--legacy/evas/src/modules/engines/gl_common/evas_gl_image.c11
-rw-r--r--legacy/evas/src/modules/engines/gl_glew/evas_engine.c4
-rw-r--r--legacy/evas/src/modules/engines/gl_x11/evas_engine.c4
-rw-r--r--legacy/evas/src/modules/engines/quartz/evas_engine.c10
-rw-r--r--legacy/evas/src/modules/engines/software_16_sdl/evas_engine.c2
-rw-r--r--legacy/evas/src/modules/engines/software_generic/evas_engine.c4
-rw-r--r--legacy/evas/src/modules/engines/software_sdl/evas_engine.c2
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine.h3
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine_xcb_image.c24
-rw-r--r--legacy/evas/src/modules/engines/xrender_x11/evas_engine_xlib_image.c26
-rw-r--r--legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c83
-rw-r--r--legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c83
-rw-r--r--legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c52
-rw-r--r--legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c113
-rw-r--r--legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c101
-rw-r--r--legacy/evas/src/modules/loaders/png/evas_image_load_png.c76
-rw-r--r--legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c186
-rw-r--r--legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c90
-rw-r--r--legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c65
33 files changed, 755 insertions, 431 deletions
diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h
index 438bb3eff3..90f434dc2e 100644
--- a/legacy/evas/src/lib/Evas.h
+++ b/legacy/evas/src/lib/Evas.h
@@ -1087,6 +1087,11 @@ extern "C" {
1087 typedef struct _Evas_Imaging_Image Evas_Imaging_Image; 1087 typedef struct _Evas_Imaging_Image Evas_Imaging_Image;
1088 typedef struct _Evas_Imaging_Font Evas_Imaging_Font; 1088 typedef struct _Evas_Imaging_Font Evas_Imaging_Font;
1089 1089
1090 /**
1091 * Error identifier or EVAS_LOAD_ERROR_NONE. see evas_load_error_str().
1092 */
1093 EAPI extern int evas_imaging_image_load_error;
1094
1090 EAPI Evas_Imaging_Image *evas_imaging_image_load (const char *file, const char *key) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_MALLOC; 1095 EAPI Evas_Imaging_Image *evas_imaging_image_load (const char *file, const char *key) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_MALLOC;
1091 EAPI void evas_imaging_image_free (Evas_Imaging_Image *im) EINA_ARG_NONNULL(1); 1096 EAPI void evas_imaging_image_free (Evas_Imaging_Image *im) EINA_ARG_NONNULL(1);
1092 EAPI void evas_imaging_image_size_get (const Evas_Imaging_Image *im, int *w, int *h) EINA_ARG_NONNULL(1); 1097 EAPI void evas_imaging_image_size_get (const Evas_Imaging_Image *im, int *w, int *h) EINA_ARG_NONNULL(1);
diff --git a/legacy/evas/src/lib/cache/evas_cache.h b/legacy/evas/src/lib/cache/evas_cache.h
index 9ada0da07f..c146db322a 100644
--- a/legacy/evas/src/lib/cache/evas_cache.h
+++ b/legacy/evas/src/lib/cache/evas_cache.h
@@ -19,7 +19,7 @@ struct _Evas_Cache_Image_Func
19 DATA32 *(*surface_pixels)(Image_Entry *im); 19 DATA32 *(*surface_pixels)(Image_Entry *im);
20 20
21 /* The cache is doing the allocation and deallocation, you must just do the rest. */ 21 /* The cache is doing the allocation and deallocation, you must just do the rest. */
22 int (*constructor)(Image_Entry *im); 22 int (*constructor)(Image_Entry *im); /**< return is EVAS_LOAD_ERROR_* or EVAS_LOAD_ERROR_NONE! */
23 void (*destructor)(Image_Entry *im); 23 void (*destructor)(Image_Entry *im);
24 24
25 void (*dirty_region)(Image_Entry *im, int x, int y, int w, int h); 25 void (*dirty_region)(Image_Entry *im, int x, int y, int w, int h);
@@ -37,7 +37,7 @@ struct _Evas_Cache_Image_Func
37 int (*color_space)(Image_Entry *dst, int cspace); 37 int (*color_space)(Image_Entry *dst, int cspace);
38 38
39 /* This function need to update im->w and im->h. */ 39 /* This function need to update im->w and im->h. */
40 int (*load)(Image_Entry *im); 40 int (*load)(Image_Entry *im);; /**< return is EVAS_LOAD_ERROR_* or EVAS_LOAD_ERROR_NONE! */
41 int (*mem_size_get)(Image_Entry *im); 41 int (*mem_size_get)(Image_Entry *im);
42 void (*debug)(const char *context, Image_Entry *im); 42 void (*debug)(const char *context, Image_Entry *im);
43}; 43};
diff --git a/legacy/evas/src/lib/cache/evas_cache_engine_image.c b/legacy/evas/src/lib/cache/evas_cache_engine_image.c
index 71ef944fe4..ca9f9aaa97 100644
--- a/legacy/evas/src/lib/cache/evas_cache_engine_image.c
+++ b/legacy/evas/src/lib/cache/evas_cache_engine_image.c
@@ -309,7 +309,7 @@ evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache,
309 309
310 assert(cache != NULL); 310 assert(cache != NULL);
311 311
312 *error = -1; 312 *error = EVAS_LOAD_ERROR_NONE;
313 313
314 ekey = NULL; 314 ekey = NULL;
315 eim = NULL; 315 eim = NULL;
@@ -323,7 +323,10 @@ evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache,
323 else 323 else
324 ekey = eina_stringshare_add(im->cache_key); 324 ekey = eina_stringshare_add(im->cache_key);
325 if (!ekey) 325 if (!ekey)
326 goto on_error; 326 {
327 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
328 goto on_error;
329 }
327 330
328 eim = eina_hash_find(cache->activ, ekey); 331 eim = eina_hash_find(cache->activ, ekey);
329 if (eim) 332 if (eim)
@@ -342,10 +345,14 @@ evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache,
342 } 345 }
343 346
344 eim = _evas_cache_engine_image_alloc(cache, im, ekey); 347 eim = _evas_cache_engine_image_alloc(cache, im, ekey);
345 if (!eim) return NULL; 348 if (!eim)
349 {
350 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
351 return NULL;
352 }
346 353
347 *error = cache->func.constructor(eim, data); 354 *error = cache->func.constructor(eim, data);
348 if (*error != 0) goto on_error; 355 if (*error != EVAS_LOAD_ERROR_NONE) goto on_error;
349 if (cache->func.debug) 356 if (cache->func.debug)
350 cache->func.debug("constructor-engine", eim); 357 cache->func.debug("constructor-engine", eim);
351 358
@@ -497,7 +504,8 @@ evas_cache_engine_image_alone(Engine_Image_Entry *eim, void *data)
497 504
498 eim->references = 1; 505 eim->references = 1;
499 506
500 if (cache->func.constructor(eim, data)) goto on_error; 507 if (cache->func.constructor(eim, data) != EVAS_LOAD_ERROR_NONE)
508 goto on_error;
501 } 509 }
502 /* FIXME */ 510 /* FIXME */
503 return eim; 511 return eim;
diff --git a/legacy/evas/src/lib/cache/evas_cache_image.c b/legacy/evas/src/lib/cache/evas_cache_image.c
index 883c7e01de..17d409720a 100644
--- a/legacy/evas/src/lib/cache/evas_cache_image.c
+++ b/legacy/evas/src/lib/cache/evas_cache_image.c
@@ -10,6 +10,7 @@
10#include <assert.h> 10#include <assert.h>
11#include <sys/types.h> 11#include <sys/types.h>
12#include <sys/stat.h> 12#include <sys/stat.h>
13#include <errno.h>
13 14
14#ifdef HAVE_EVIL 15#ifdef HAVE_EVIL
15# include <Evil.h> 16# include <Evil.h>
@@ -218,7 +219,10 @@ _evas_cache_image_entry_new(Evas_Cache_Image *cache,
218 219
219 ie = cache->func.alloc(); 220 ie = cache->func.alloc();
220 if (!ie) 221 if (!ie)
221 return NULL; 222 {
223 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
224 return NULL;
225 }
222 226
223 cache_key = hkey ? eina_stringshare_add(hkey) : NULL; 227 cache_key = hkey ? eina_stringshare_add(hkey) : NULL;
224 228
@@ -265,7 +269,7 @@ _evas_cache_image_entry_new(Evas_Cache_Image *cache,
265 if (file) 269 if (file)
266 { 270 {
267 *error = cache->func.constructor(ie); 271 *error = cache->func.constructor(ie);
268 if (*error != 0) 272 if (*error != EVAS_LOAD_ERROR_NONE)
269 { 273 {
270 _evas_cache_image_entry_delete(cache, ie); 274 _evas_cache_image_entry_delete(cache, ie);
271 return NULL; 275 return NULL;
@@ -340,7 +344,7 @@ _evas_cache_image_async_heavy(void *data)
340 error = cache->func.load(current); 344 error = cache->func.load(current);
341 if (cache->func.debug) 345 if (cache->func.debug)
342 cache->func.debug("load", current); 346 cache->func.debug("load", current);
343 if (error) 347 if (error != EVAS_LOAD_ERROR_NONE)
344 { 348 {
345 current->flags.loaded = 0; 349 current->flags.loaded = 0;
346 _evas_cache_image_entry_surface_alloc(cache, current, 350 _evas_cache_image_entry_surface_alloc(cache, current,
@@ -626,8 +630,11 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
626 630
627 assert(cache != NULL); 631 assert(cache != NULL);
628 632
629 if (!file && !key) return NULL; 633 if ((!file) || ((!file) && (!key)))
630 if (!file) return NULL; 634 {
635 *error = EVAS_LOAD_ERROR_GENERIC;
636 return NULL;
637 }
631 638
632 file_length = strlen(file); 639 file_length = strlen(file);
633 key_length = key ? strlen(key) : 6; 640 key_length = key ? strlen(key) : 6;
@@ -715,7 +722,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
715 if ((t - im->laststat) > STAT_GAP) 722 if ((t - im->laststat) > STAT_GAP)
716 { 723 {
717 stat_done = 1; 724 stat_done = 1;
718 if (stat(file, &st) < 0) goto on_error; 725 if (stat(file, &st) < 0) goto on_stat_error;
719 726
720 im->laststat = t; 727 im->laststat = t;
721 if (st.st_mtime != im->timestamp) ok = 0; 728 if (st.st_mtime != im->timestamp) ok = 0;
@@ -740,7 +747,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
740 if ((t - im->laststat) > STAT_GAP) 747 if ((t - im->laststat) > STAT_GAP)
741 { 748 {
742 stat_done = 1; 749 stat_done = 1;
743 if (stat(file, &st) < 0) goto on_error; 750 if (stat(file, &st) < 0) goto on_stat_error;
744 751
745 im->laststat = t; 752 im->laststat = t;
746 if (st.st_mtime != im->timestamp) ok = 0; 753 if (st.st_mtime != im->timestamp) ok = 0;
@@ -761,7 +768,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
761 768
762 if (!stat_done) 769 if (!stat_done)
763 { 770 {
764 if (stat(file, &st) < 0) return NULL; 771 if (stat(file, &st) < 0) goto on_stat_error;
765 } 772 }
766 773
767 im = _evas_cache_image_entry_new(cache, hkey, st.st_mtime, file, key, lo, error); 774 im = _evas_cache_image_entry_new(cache, hkey, st.st_mtime, file, key, lo, error);
@@ -771,15 +778,25 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
771 cache->func.debug("request", im); 778 cache->func.debug("request", im);
772 779
773 on_ok: 780 on_ok:
774 *error = 0; 781 *error = EVAS_LOAD_ERROR_NONE;
775 im->references++; 782 im->references++;
776 if (im->references > 1 && im->flags.lru_nodata) 783 if (im->references > 1 && im->flags.lru_nodata)
777 _evas_cache_image_remove_lru_nodata(cache, im); 784 _evas_cache_image_remove_lru_nodata(cache, im);
778 785
779 return im; 786 return im;
780 787
781 on_error: 788 on_stat_error:
782 _evas_cache_image_entry_delete(cache, im); 789 if ((errno == ENOENT) || (errno == ENOTDIR) ||
790 (errno == ENAMETOOLONG) || (errno == ELOOP))
791 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
792 else if ((errno == ENOMEM) || (errno == EOVERFLOW))
793 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
794 else if (errno == EACCES)
795 *error = EVAS_LOAD_ERROR_PERMISSION_DENIED;
796 else
797 *error = EVAS_LOAD_ERROR_GENERIC;
798
799 if (im) _evas_cache_image_entry_delete(cache, im);
783 return NULL; 800 return NULL;
784} 801}
785 802
@@ -1142,7 +1159,7 @@ evas_cache_image_load_data(Image_Entry *im)
1142 if (cache->func.debug) 1159 if (cache->func.debug)
1143 cache->func.debug("load", im); 1160 cache->func.debug("load", im);
1144 1161
1145 if (error) 1162 if (error != EVAS_LOAD_ERROR_NONE)
1146 { 1163 {
1147 _evas_cache_image_entry_surface_alloc(cache, im, im->w, im->h); 1164 _evas_cache_image_entry_surface_alloc(cache, im, im->w, im->h);
1148 im->flags.loaded = 0; 1165 im->flags.loaded = 0;
diff --git a/legacy/evas/src/lib/canvas/evas_object_image.c b/legacy/evas/src/lib/canvas/evas_object_image.c
index 4372788eec..60cb19a9cf 100644
--- a/legacy/evas/src/lib/canvas/evas_object_image.c
+++ b/legacy/evas/src/lib/canvas/evas_object_image.c
@@ -342,7 +342,8 @@ evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
342 } 342 }
343 else 343 else
344 { 344 {
345 o->load_error = EVAS_LOAD_ERROR_GENERIC; 345 if (o->load_error == EVAS_LOAD_ERROR_NONE)
346 o->load_error = EVAS_LOAD_ERROR_GENERIC;
346 o->cur.has_alpha = 1; 347 o->cur.has_alpha = 1;
347 o->cur.cspace = EVAS_COLORSPACE_ARGB8888; 348 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
348 o->cur.image.w = 0; 349 o->cur.image.w = 0;
diff --git a/legacy/evas/src/lib/engines/common/evas_image.h b/legacy/evas/src/lib/engines/common/evas_image.h
index c589eb1763..c8b75cfe20 100644
--- a/legacy/evas/src/lib/engines/common/evas_image.h
+++ b/legacy/evas/src/lib/engines/common/evas_image.h
@@ -27,7 +27,7 @@ EAPI RGBA_Image *evas_common_image_alpha_line_buffer_obtain (int len);
27EAPI void evas_common_image_alpha_line_buffer_release (RGBA_Image *im); 27EAPI void evas_common_image_alpha_line_buffer_release (RGBA_Image *im);
28EAPI void evas_common_image_alpha_line_buffer_free (RGBA_Image *im); 28EAPI void evas_common_image_alpha_line_buffer_free (RGBA_Image *im);
29 29
30EAPI RGBA_Image *evas_common_load_image_from_file (const char *file, const char *key, RGBA_Image_Loadopts *lo); 30EAPI RGBA_Image *evas_common_load_image_from_file (const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
31EAPI int evas_common_save_image_to_file (RGBA_Image *im, const char *file, const char *key, int quality, int compress); 31EAPI int evas_common_save_image_to_file (RGBA_Image *im, const char *file, const char *key, int quality, int compress);
32 32
33EAPI void evas_common_rgba_image_scalecache_size_set(int size); 33EAPI void evas_common_rgba_image_scalecache_size_set(int size);
diff --git a/legacy/evas/src/lib/engines/common/evas_image_load.c b/legacy/evas/src/lib/engines/common/evas_image_load.c
index af705eb6f3..dd54235cba 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_load.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_load.c
@@ -36,21 +36,31 @@ static const char *loaders_name[] = {
36 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb" 36 "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "edb"
37}; 37};
38 38
39struct evas_image_foreach_loader_data
40{
41 Image_Entry *ie;
42 int *error;
43 Evas_Module *em;
44};
45
46
39static Eina_Bool 47static Eina_Bool
40_evas_image_foreach_loader(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata) 48_evas_image_foreach_loader(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata)
41{ 49{
42 Evas_Image_Load_Func *evas_image_load_func = NULL; 50 Evas_Image_Load_Func *evas_image_load_func = NULL;
43 Evas_Module *em = data; 51 Evas_Module *em = data;
44 Image_Entry *ie = fdata; 52 struct evas_image_foreach_loader_data *d = fdata;
53 Image_Entry *ie = d->ie;
45 54
46 if (!evas_module_load(em)) return EINA_TRUE; 55 if (!evas_module_load(em)) return EINA_TRUE;
47 evas_image_load_func = em->functions; 56 evas_image_load_func = em->functions;
48 evas_module_use(em); 57 evas_module_use(em);
49 if (evas_image_load_func && evas_image_load_func->file_head(ie, ie->file, ie->key)) 58 *(d->error) = EVAS_LOAD_ERROR_NONE;
59 if (evas_image_load_func &&
60 evas_image_load_func->file_head(ie, ie->file, ie->key, d->error) &&
61 (*(d->error) == EVAS_LOAD_ERROR_NONE))
50 { 62 {
51 ie->info.module = (void *)em; 63 d->em = em;
52 ie->info.loader = (void *)evas_image_load_func;
53 evas_module_ref((Evas_Module *)ie->info.module);
54 return EINA_FALSE; 64 return EINA_FALSE;
55 } 65 }
56 66
@@ -65,14 +75,20 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
65 Evas_Module *em; 75 Evas_Module *em;
66 char *dot; 76 char *dot;
67 int i; 77 int i;
78 int ret = EVAS_LOAD_ERROR_NONE;
79 struct evas_image_foreach_loader_data fdata;
68 80
69 81
70#ifdef EVAS_CSERVE 82#ifdef EVAS_CSERVE
71 if (evas_cserve_use_get()) 83 if (evas_cserve_use_get())
72 { 84 {
85 // TODO: handle errors from server and return them?
86 DBG("try cserve '%s' '%s'", ie->file, ie->key ? ie->key : "");
73 if (evas_cserve_image_load(ie, ie->file, ie->key, &(ie->load_opts))) 87 if (evas_cserve_image_load(ie, ie->file, ie->key, &(ie->load_opts)))
74 { 88 {
75 return 0; 89 DBG("try cserve '%s' '%s' loaded!",
90 ie->file, ie->key ? ie->key : "");
91 return EVAS_LOAD_ERROR_NONE;
76 } 92 }
77 } 93 }
78#endif 94#endif
@@ -84,6 +100,8 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
84 if (!strcasecmp(dot, loaders[i].extention)) 100 if (!strcasecmp(dot, loaders[i].extention))
85 { 101 {
86 loader = loaders[i].loader; 102 loader = loaders[i].loader;
103 DBG("found loader '%s' matching extension in file '%s'",
104 loader, ie->file);
87 break; 105 break;
88 } 106 }
89 } 107 }
@@ -94,19 +112,35 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
94 em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader); 112 em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
95 if (em) 113 if (em)
96 { 114 {
115 DBG("found image loader '%s' (%p)", loader, em);
97 if (evas_module_load(em)) 116 if (evas_module_load(em))
98 { 117 {
99 evas_module_use(em); 118 evas_module_use(em);
100 evas_image_load_func = em->functions; 119 evas_image_load_func = em->functions;
101 if (evas_image_load_func->file_head(ie, ie->file, ie->key)) 120 ret = EVAS_LOAD_ERROR_NONE;
102 goto ok; 121 if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret))
122 {
123 DBG("loaded file head using module '%s' (%p): %s",
124 loader, em, ie->file);
125 goto end;
126 }
103 evas_module_unload(em); 127 evas_module_unload(em);
128 DBG("failed to load file head using module '%s' (%p): "
129 "%s (%s)",
130 loader, em, ie->file, evas_load_error_str(ret));
104 } 131 }
132 else
133 WRN("failed to load module '%s' (%p)", loader, em);
105 } 134 }
106 } 135 }
107 136
108 evas_module_foreach_image_loader(_evas_image_foreach_loader, ie); 137 fdata.ie = ie;
109 if (ie->info.module) return 0; 138 fdata.error = &ret;
139 fdata.em = NULL;
140 ret = EVAS_LOAD_ERROR_NONE;
141 evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata);
142 em = fdata.em;
143 if (em) goto end;
110 144
111 /* This is our last chance, try all known image loader. */ 145 /* This is our last chance, try all known image loader. */
112 /* FIXME: We could use eina recursive module search ability. */ 146 /* FIXME: We could use eina recursive module search ability. */
@@ -119,28 +153,67 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
119 { 153 {
120 evas_module_use(em); 154 evas_module_use(em);
121 evas_image_load_func = em->functions; 155 evas_image_load_func = em->functions;
122 if (evas_image_load_func->file_head(ie, ie->file, ie->key)) 156 ret = EVAS_LOAD_ERROR_NONE;
123 goto ok; 157 if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret))
158 {
159 DBG("brute force loader '%s' (%p) worked on %s",
160 loaders_name[i], em, ie->file);
161 goto end;
162 }
163 else
164 DBG("brute force loader '%s' (%p) failed on %s (%s)",
165 loaders_name[i], em, ie->file,
166 evas_load_error_str(ret));
167
124 evas_module_unload(em); 168 evas_module_unload(em);
125 } 169 }
170 else
171 WRN("failed to load module '%s' (%p)", loaders_name[i], em);
126 } 172 }
173 else
174 DBG("could not find module '%s'", loaders_name[i]);
127 } 175 }
128 176
129 return -1; 177 DBG("exhausted all means to load image '%s'", ie->file);
178 return EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
179
180 end:
181
182 if (ret != EVAS_LOAD_ERROR_NONE)
183 {
184 const char *modname = NULL;
185 int modversion = -1;
186 if (em && em->definition)
187 {
188 modname = em->definition->name;
189 modversion = em->definition->version;
190 }
191 WRN("loader '%s' (version %d) "
192 "handled file '%s', key '%s' with errors: %s",
193 modname ? modname : "<UNKNOWN>", modversion,
194 ie->file, ie->key ? ie->key : "",
195 evas_load_error_str(ret));
196 goto end;
197 }
198
199 DBG("loader '%s' used for file %s",
200 (em && em->definition && em->definition->name) ?
201 em->definition->name : "<UNKNOWN>",
202 ie->file);
130 203
131 ok:
132 ie->info.module = (void*) em; 204 ie->info.module = (void*) em;
133 ie->info.loader = (void*) evas_image_load_func; 205 ie->info.loader = (void*) evas_image_load_func;
134 evas_module_ref((Evas_Module*) ie->info.module); 206 evas_module_ref((Evas_Module*) ie->info.module);
135 return 0; 207 return ret;
136} 208}
137 209
138EAPI int 210EAPI int
139evas_common_load_rgba_image_data_from_file(Image_Entry *ie) 211evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
140{ 212{
141 Evas_Image_Load_Func *evas_image_load_func = NULL; 213 Evas_Image_Load_Func *evas_image_load_func = NULL;
214 int ret = EVAS_LOAD_ERROR_NONE;
142 215
143 if (ie->flags.loaded) return -1; 216 if (ie->flags.loaded) return EVAS_LOAD_ERROR_GENERIC;
144 217
145#ifdef EVAS_CSERVE 218#ifdef EVAS_CSERVE
146 if (ie->data1) 219 if (ie->data1)
@@ -148,31 +221,29 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
148 if (evas_cserve_image_data_load(ie)) 221 if (evas_cserve_image_data_load(ie))
149 { 222 {
150 RGBA_Image *im = (RGBA_Image *)ie; 223 RGBA_Image *im = (RGBA_Image *)ie;
151 Mem *mem; 224 Mem *mem = ie->data2;
152
153 mem = ie->data2;
154 if (mem) 225 if (mem)
155 { 226 {
156 im->image.data = (void*) (mem->data + mem->offset); 227 im->image.data = (void*) (mem->data + mem->offset);
157 im->image.no_free = 1; 228 im->image.no_free = 1;
158 return 0; 229 return EVAS_LOAD_ERROR_NONE;
159 } 230 }
160 } 231 }
161 return -1; 232 return EVAS_LOAD_ERROR_GENERIC;
162 } 233 }
163#endif 234#endif
164 235
165 if (!ie->info.module) return -1; 236 if (!ie->info.module) return EVAS_LOAD_ERROR_GENERIC;
166 237
167 evas_image_load_func = ie->info.loader; 238 evas_image_load_func = ie->info.loader;
168 evas_module_use((Evas_Module*) ie->info.module); 239 evas_module_use((Evas_Module*) ie->info.module);
169 if (!evas_image_load_func->file_data(ie, ie->file, ie->key)) 240 if (!evas_image_load_func->file_data(ie, ie->file, ie->key, &ret))
170 { 241 {
171 return -1; 242 return ret;
172 } 243 }
173 244
174// evas_module_unref((Evas_Module*) ie->info.module); 245// evas_module_unref((Evas_Module*) ie->info.module);
175// ie->info.module = NULL; 246// ie->info.module = NULL;
176 247
177 return 0; 248 return EVAS_LOAD_ERROR_NONE;
178} 249}
diff --git a/legacy/evas/src/lib/engines/common/evas_image_main.c b/legacy/evas/src/lib/engines/common/evas_image_main.c
index 47b18efbfd..3fc6367628 100644
--- a/legacy/evas/src/lib/engines/common/evas_image_main.c
+++ b/legacy/evas/src/lib/engines/common/evas_image_main.c
@@ -523,12 +523,14 @@ evas_common_image_get_cache(void)
523} 523}
524 524
525EAPI RGBA_Image * 525EAPI RGBA_Image *
526evas_common_load_image_from_file(const char *file, const char *key, RGBA_Image_Loadopts *lo) 526evas_common_load_image_from_file(const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error)
527{ 527{
528 int error; 528 if (file == NULL)
529 529 {
530 if (file == NULL) return NULL; 530 *error = EVAS_LOAD_ERROR_GENERIC;
531 return (RGBA_Image *) evas_cache_image_request(eci, file, key, lo, &error); 531 return NULL;
532 }
533 return (RGBA_Image *) evas_cache_image_request(eci, file, key, lo, error);
532} 534}
533 535
534EAPI void 536EAPI void
diff --git a/legacy/evas/src/lib/imaging/evas_imaging.c b/legacy/evas/src/lib/imaging/evas_imaging.c
index 6892136d37..cb948ddf71 100644
--- a/legacy/evas/src/lib/imaging/evas_imaging.c
+++ b/legacy/evas/src/lib/imaging/evas_imaging.c
@@ -9,21 +9,27 @@
9#include "evas_common.h" 9#include "evas_common.h"
10#include "evas_private.h" 10#include "evas_private.h"
11 11
12EAPI int evas_imaging_image_load_error = EVAS_LOAD_ERROR_NONE;
13
12EAPI Evas_Imaging_Image * 14EAPI Evas_Imaging_Image *
13evas_imaging_image_load(const char *file, const char *key) 15evas_imaging_image_load(const char *file, const char *key)
14{ 16{
15 Evas_Imaging_Image *im; 17 Evas_Imaging_Image *im;
16 RGBA_Image *image; 18 RGBA_Image *image;
17 19
20 evas_imaging_image_load_error = EVAS_LOAD_ERROR_NONE;
21
18 if (!file) file = ""; 22 if (!file) file = "";
19 if (!key) key = ""; 23 if (!key) key = "";
20 evas_common_cpu_init(); 24 evas_common_cpu_init();
21 evas_common_image_init(); 25 evas_common_image_init();
22 image = evas_common_load_image_from_file(file, key, NULL); 26 image = evas_common_load_image_from_file
27 (file, key, NULL, &evas_imaging_image_load_error);
23 if (!image) return NULL; 28 if (!image) return NULL;
24 im = calloc(1, sizeof(Evas_Imaging_Image)); 29 im = calloc(1, sizeof(Evas_Imaging_Image));
25 if (!im) 30 if (!im)
26 { 31 {
32 evas_imaging_image_load_error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
27 evas_cache_image_drop(&image->cache_entry); 33 evas_cache_image_drop(&image->cache_entry);
28 return NULL; 34 return NULL;
29 } 35 }
diff --git a/legacy/evas/src/lib/include/evas_common.h b/legacy/evas/src/lib/include/evas_common.h
index 05d40b980f..aab86c33f2 100644
--- a/legacy/evas/src/lib/include/evas_common.h
+++ b/legacy/evas/src/lib/include/evas_common.h
@@ -119,7 +119,7 @@ extern EAPI int _evas_log_dom_global;
119# undef BUILD_PIPE_RENDER 119# undef BUILD_PIPE_RENDER
120#endif 120#endif
121 121
122#ifdef BUILD_ASYNC_PRELOAD 122#if defined(BUILD_ASYNC_PRELOAD) && !defined(BUILD_PTHREAD)
123# define BUILD_PTHREAD 123# define BUILD_PTHREAD
124#endif 124#endif
125 125
diff --git a/legacy/evas/src/lib/include/evas_private.h b/legacy/evas/src/lib/include/evas_private.h
index 06f5651850..154db590a5 100644
--- a/legacy/evas/src/lib/include/evas_private.h
+++ b/legacy/evas/src/lib/include/evas_private.h
@@ -707,8 +707,8 @@ struct _Evas_Func
707 707
708struct _Evas_Image_Load_Func 708struct _Evas_Image_Load_Func
709{ 709{
710 int (*file_head) (Image_Entry *ie, const char *file, const char *key); 710 Eina_Bool (*file_head) (Image_Entry *ie, const char *file, const char *key, int *error);
711 int (*file_data) (Image_Entry *ie, const char *file, const char *key); 711 Eina_Bool (*file_data) (Image_Entry *ie, const char *file, const char *key, int *error);
712}; 712};
713 713
714struct _Evas_Image_Save_Func 714struct _Evas_Image_Save_Func
diff --git a/legacy/evas/src/modules/engines/cairo_x11/evas_engine.c b/legacy/evas/src/modules/engines/cairo_x11/evas_engine.c
index 90a4f1ab1e..da3b0aa38d 100644
--- a/legacy/evas/src/modules/engines/cairo_x11/evas_engine.c
+++ b/legacy/evas/src/modules/engines/cairo_x11/evas_engine.c
@@ -915,14 +915,17 @@ eng_image_load(void *data, char *file, char *key, int *error, Evas_Image_Load_Op
915{ 915{
916 Render_Engine *re; 916 Render_Engine *re;
917 Evas_Cairo_Image *im; 917 Evas_Cairo_Image *im;
918
919 re = (Render_Engine *)data;
920 if (error) *error = 0;
921 918
919 re = (Render_Engine *)data;
922 im = calloc(1, sizeof(Evas_Cairo_Image)); 920 im = calloc(1, sizeof(Evas_Cairo_Image));
923 if (!im) return NULL; 921 if (!im)
922 {
923 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
924 return NULL;
925 }
924 926
925 im->im = evas_common_load_image_from_file(file, key, lo); 927 *error = EVAS_LOAD_ERROR_NONE;
928 im->im = evas_common_load_image_from_file(file, key, lo, error);
926 if (!im->im) 929 if (!im->im)
927 { 930 {
928 free(im); 931 free(im);
diff --git a/legacy/evas/src/modules/engines/directfb/evas_engine.c b/legacy/evas/src/modules/engines/directfb/evas_engine.c
index 91a751e30e..c55cb5ea75 100644
--- a/legacy/evas/src/modules/engines/directfb/evas_engine.c
+++ b/legacy/evas/src/modules/engines/directfb/evas_engine.c
@@ -476,20 +476,20 @@ evas_cache_image_dfb_constructor(Engine_Image_Entry *eie, void *data)
476 476
477 im = (RGBA_Image *)eie->src; 477 im = (RGBA_Image *)eie->src;
478 if (!im) 478 if (!im)
479 return 0; 479 return EVAS_LOAD_ERROR_NONE; // XXX TODO: confirm?
480 480
481 evas_cache_image_load_data(&im->cache_entry); 481 evas_cache_image_load_data(&im->cache_entry);
482 if (!im->image.data) 482 if (!im->image.data)
483 return 0; 483 return EVAS_LOAD_ERROR_NONE; // XXX TODO: confirm?
484 484
485 s = _dfb_surface_from_data(re->spec->dfb, eie->w, eie->h, im->image.data); 485 s = _dfb_surface_from_data(re->spec->dfb, eie->w, eie->h, im->image.data);
486 if (!s) 486 if (!s)
487 return -1; 487 return EVAS_LOAD_ERROR_GENERIC;
488 488
489 deie->surface = s; 489 deie->surface = s;
490 deie->flags.engine_surface = 0; 490 deie->flags.engine_surface = 0;
491 491
492 return 0; 492 return EVAS_LOAD_ERROR_NONE;
493} 493}
494 494
495static void 495static void
diff --git a/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h b/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h
index 36203f722a..919d58fc9a 100644
--- a/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h
+++ b/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h
@@ -283,7 +283,7 @@ void evas_gl_common_texture_alpha_update(Evas_GL_Texture *tex, DATA
283Evas_GL_Texture *evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, int w, int h); 283Evas_GL_Texture *evas_gl_common_texture_yuv_new(Evas_GL_Context *gc, DATA8 **rows, int w, int h);
284void evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, DATA8 **rows, int w, int h); 284void evas_gl_common_texture_yuv_update(Evas_GL_Texture *tex, DATA8 **rows, int w, int h);
285 285
286Evas_GL_Image *evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo); 286Evas_GL_Image *evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error);
287Evas_GL_Image *evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace); 287Evas_GL_Image *evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace);
288Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace); 288Evas_GL_Image *evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace);
289Evas_GL_Image *evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h, int alpha, int cspace); 289Evas_GL_Image *evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h, int alpha, int cspace);
diff --git a/legacy/evas/src/modules/engines/gl_common/evas_gl_image.c b/legacy/evas/src/modules/engines/gl_common/evas_gl_image.c
index 05d9ffbbb4..60926bc637 100644
--- a/legacy/evas/src/modules/engines/gl_common/evas_gl_image.c
+++ b/legacy/evas/src/modules/engines/gl_common/evas_gl_image.c
@@ -1,13 +1,13 @@
1#include "evas_gl_private.h" 1#include "evas_gl_private.h"
2 2
3Evas_GL_Image * 3Evas_GL_Image *
4evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo) 4evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error)
5{ 5{
6 Evas_GL_Image *im; 6 Evas_GL_Image *im;
7 RGBA_Image *im_im; 7 RGBA_Image *im_im;
8 Eina_List *l; 8 Eina_List *l;
9 9
10 im_im = evas_common_load_image_from_file(file, key, lo); 10 im_im = evas_common_load_image_from_file(file, key, lo, error);
11 if (!im_im) return NULL; 11 if (!im_im) return NULL;
12 12
13 EINA_LIST_FOREACH(gc->shared->images, l, im) 13 EINA_LIST_FOREACH(gc->shared->images, l, im)
@@ -18,12 +18,17 @@ evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key
18 gc->shared->images = eina_list_remove_list(gc->shared->images, l); 18 gc->shared->images = eina_list_remove_list(gc->shared->images, l);
19 gc->shared->images = eina_list_prepend(gc->shared->images, im); 19 gc->shared->images = eina_list_prepend(gc->shared->images, im);
20 im->references++; 20 im->references++;
21 *error = EVAS_LOAD_ERROR_NONE;
21 return im; 22 return im;
22 } 23 }
23 } 24 }
24 25
25 im = calloc(1, sizeof(Evas_GL_Image)); 26 im = calloc(1, sizeof(Evas_GL_Image));
26 if (!im) return NULL; 27 if (!im)
28 {
29 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
30 return NULL;
31 }
27 im->references = 1; 32 im->references = 1;
28 im->im = im_im; 33 im->im = im_im;
29 im->gc = gc; 34 im->gc = gc;
diff --git a/legacy/evas/src/modules/engines/gl_glew/evas_engine.c b/legacy/evas/src/modules/engines/gl_glew/evas_engine.c
index 2d94a1b0a8..b215de8528 100644
--- a/legacy/evas/src/modules/engines/gl_glew/evas_engine.c
+++ b/legacy/evas/src/modules/engines/gl_glew/evas_engine.c
@@ -708,9 +708,9 @@ eng_image_load(void *data, const char *file, const char *key, int *error, Evas_I
708 Render_Engine *re; 708 Render_Engine *re;
709 709
710 re = (Render_Engine *)data; 710 re = (Render_Engine *)data;
711 *error = 0; 711 *error = EVAS_LOAD_ERROR_NONE;
712 eng_window_use(re->window); 712 eng_window_use(re->window);
713 return evas_gl_common_image_load(re->window->gl_context, file, key, lo); 713 return evas_gl_common_image_load(re->window->gl_context, file, key, lo, error);
714} 714}
715 715
716static void * 716static void *
diff --git a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
index 5d4939bef2..26f217cc1b 100644
--- a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
+++ b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
@@ -788,9 +788,9 @@ eng_image_load(void *data, const char *file, const char *key, int *error, Evas_I
788 Render_Engine *re; 788 Render_Engine *re;
789 789
790 re = (Render_Engine *)data; 790 re = (Render_Engine *)data;
791 *error = 0; 791 *error = EVAS_LOAD_ERROR_NONE;
792 eng_window_use(re->win); 792 eng_window_use(re->win);
793 return evas_gl_common_image_load(re->win->gl_context, file, key, lo); 793 return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
794} 794}
795 795
796static void * 796static void *
diff --git a/legacy/evas/src/modules/engines/quartz/evas_engine.c b/legacy/evas/src/modules/engines/quartz/evas_engine.c
index 1f4633819e..68437029ad 100644
--- a/legacy/evas/src/modules/engines/quartz/evas_engine.c
+++ b/legacy/evas/src/modules/engines/quartz/evas_engine.c
@@ -732,10 +732,14 @@ eng_image_load(void *data, const char *file, const char *key, int *error, Evas_I
732 // I can't figure out what to set it to, even trying to follow through the core code. 732 // I can't figure out what to set it to, even trying to follow through the core code.
733 // Also, none of the other engines set it. 733 // Also, none of the other engines set it.
734 734
735 if (error) *error = 0; 735 if (!im)
736 if (!im) return NULL; 736 {
737 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
738 return NULL;
739 }
737 740
738 im->im = (RGBA_Image *)evas_common_load_image_from_file(file, key, lo); 741 *error = EVAS_LOAD_ERROR_NONE;
742 im->im = (RGBA_Image *)evas_common_load_image_from_file(file, key, lo, error);
739 if (!im->im) 743 if (!im->im)
740 { 744 {
741 free(im); 745 free(im);
diff --git a/legacy/evas/src/modules/engines/software_16_sdl/evas_engine.c b/legacy/evas/src/modules/engines/software_16_sdl/evas_engine.c
index f215769e76..6fc11cd4d9 100644
--- a/legacy/evas/src/modules/engines/software_16_sdl/evas_engine.c
+++ b/legacy/evas/src/modules/engines/software_16_sdl/evas_engine.c
@@ -1156,7 +1156,7 @@ _sdl16_image_constructor(Engine_Image_Entry *ie, void* data __UNUSED__)
1156 eim->flags.engine_surface = 0; 1156 eim->flags.engine_surface = 0;
1157 } 1157 }
1158 1158
1159 return 0; 1159 return EVAS_LOAD_ERROR_NONE;
1160} 1160}
1161 1161
1162static void 1162static void
diff --git a/legacy/evas/src/modules/engines/software_generic/evas_engine.c b/legacy/evas/src/modules/engines/software_generic/evas_engine.c
index 684d0f95d0..b6647397fc 100644
--- a/legacy/evas/src/modules/engines/software_generic/evas_engine.c
+++ b/legacy/evas/src/modules/engines/software_generic/evas_engine.c
@@ -589,8 +589,8 @@ eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
589static void * 589static void *
590eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo) 590eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
591{ 591{
592 *error = 0; 592 *error = EVAS_LOAD_ERROR_NONE;
593 return evas_common_load_image_from_file(file, key, lo); 593 return evas_common_load_image_from_file(file, key, lo, error);
594} 594}
595 595
596static void * 596static void *
diff --git a/legacy/evas/src/modules/engines/software_sdl/evas_engine.c b/legacy/evas/src/modules/engines/software_sdl/evas_engine.c
index f5191637f9..33d6f7f1ae 100644
--- a/legacy/evas/src/modules/engines/software_sdl/evas_engine.c
+++ b/legacy/evas/src/modules/engines/software_sdl/evas_engine.c
@@ -1045,7 +1045,7 @@ _sdl_image_constructor(Engine_Image_Entry *ie, void *data __UNUSED__)
1045 } 1045 }
1046 } 1046 }
1047 1047
1048 return 0; 1048 return EVAS_LOAD_ERROR_NONE;
1049} 1049}
1050 1050
1051static void 1051static void
diff --git a/legacy/evas/src/modules/engines/xrender_x11/evas_engine.h b/legacy/evas/src/modules/engines/xrender_x11/evas_engine.h
index b1510cf9d6..2c6d1d7298 100644
--- a/legacy/evas/src/modules/engines/xrender_x11/evas_engine.h
+++ b/legacy/evas/src/modules/engines/xrender_x11/evas_engine.h
@@ -186,6 +186,7 @@ struct _XR_Image
186 const char *comment; 186 const char *comment;
187 Tilebuf *updates; 187 Tilebuf *updates;
188 RGBA_Image_Loadopts load_opts; 188 RGBA_Image_Loadopts load_opts;
189 int *load_error; /* points to Evas_Object's load_error field */
189 struct { 190 struct {
190 int space; 191 int space;
191 void *data; 192 void *data;
@@ -196,7 +197,7 @@ struct _XR_Image
196 unsigned char free_data : 1; 197 unsigned char free_data : 1;
197}; 198};
198 199
199XR_Image *_xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo); 200XR_Image *_xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error);
200XR_Image *_xre_xlib_image_new_from_data(Ximage_Info *xinf, int w, int h, void *data, int alpha, int cspace); 201XR_Image *_xre_xlib_image_new_from_data(Ximage_Info *xinf, int w, int h, void *data, int alpha, int cspace);
201XR_Image *_xre_xlib_image_new_from_copied_data(Ximage_Info *xinf, int w, int h, void *data, int alpha, int cspace); 202XR_Image *_xre_xlib_image_new_from_copied_data(Ximage_Info *xinf, int w, int h, void *data, int alpha, int cspace);
202XR_Image *_xre_xlib_image_new(Ximage_Info *xinf, int w, int h); 203XR_Image *_xre_xlib_image_new(Ximage_Info *xinf, int w, int h);
diff --git a/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xcb_image.c b/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xcb_image.c
index c9fbcd63b9..f1be566a14 100644
--- a/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xcb_image.c
+++ b/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xcb_image.c
@@ -67,12 +67,16 @@ __xre_xcb_image_find(char *fkey)
67} 67}
68 68
69XR_Image * 69XR_Image *
70_xre_xcb_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo) 70_xre_xcb_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error)
71{ 71{
72 char buf[4096]; 72 char buf[4096];
73 XR_Image *im; 73 XR_Image *im;
74 74
75 if (!file) return NULL; 75 if (!file)
76 {
77 *error = EVAS_LOAD_ERROR_GENERIC;
78 return NULL;
79 }
76 if (!lo) 80 if (!lo)
77 { 81 {
78 if (key) 82 if (key)
@@ -90,12 +94,17 @@ _xre_xcb_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_I
90 im = __xre_xcb_image_find(buf); 94 im = __xre_xcb_image_find(buf);
91 if (im) 95 if (im)
92 { 96 {
97 *error = EVAS_LOAD_ERROR_NONE;
93 return im; 98 return im;
94 } 99 }
95 100
96 im = calloc(1, sizeof(XR_Image)); 101 im = calloc(1, sizeof(XR_Image));
97 if (!im) return NULL; 102 if (!im)
98 im->im = evas_common_load_image_from_file(file, key, lo); 103 {
104 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
105 return NULL;
106 }
107 im->im = evas_common_load_image_from_file(file, key, lo, error);
99 if (!im->im) 108 if (!im->im)
100 { 109 {
101 free(im); 110 free(im);
@@ -111,6 +120,7 @@ _xre_xcb_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_I
111 im->h = im->im->cache_entry.h; 120 im->h = im->im->cache_entry.h;
112 im->references = 1; 121 im->references = 1;
113 if (lo) im->load_opts = *lo; 122 if (lo) im->load_opts = *lo;
123 im->load_error = error; /* points to object's load_error */
114 if (im->im->info.comment) im->comment = (char *)eina_stringshare_add(im->im->info.comment); 124 if (im->im->info.comment) im->comment = (char *)eina_stringshare_add(im->im->info.comment);
115/* if (im->im->info.format == 1) im->format = eina_stringshare_add("png"); */ 125/* if (im->im->info.format == 1) im->format = eina_stringshare_add("png"); */
116 if (im->im->cache_entry.flags.alpha) im->alpha = 1; 126 if (im->im->cache_entry.flags.alpha) im->alpha = 1;
@@ -300,7 +310,7 @@ _xre_xcb_image_copy(XR_Image *im)
300 else 310 else
301 { 311 {
302 if (!im->im) 312 if (!im->im)
303 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 313 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
304 if (im->im) 314 if (im->im)
305 { 315 {
306 evas_cache_image_load_data(&im->im->cache_entry); 316 evas_cache_image_load_data(&im->im->cache_entry);
@@ -391,7 +401,7 @@ _xre_xcb_image_data_get(XR_Image *im)
391 else if (im->cs.data) data = im->cs.data; 401 else if (im->cs.data) data = im->cs.data;
392 else 402 else
393 { 403 {
394 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 404 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
395 if (im->im) 405 if (im->im)
396 { 406 {
397 evas_cache_image_load_data(&im->im->cache_entry); 407 evas_cache_image_load_data(&im->im->cache_entry);
@@ -560,7 +570,7 @@ _xre_xcb_image_surface_gen(XR_Image *im)
560 if (im->data) data = im->data; 570 if (im->data) data = im->data;
561 else 571 else
562 { 572 {
563 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 573 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
564 if (im->im) 574 if (im->im)
565 { 575 {
566 evas_cache_image_load_data(&im->im->cache_entry); 576 evas_cache_image_load_data(&im->im->cache_entry);
diff --git a/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xlib_image.c b/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xlib_image.c
index 8590b11ca1..2e4078e236 100644
--- a/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xlib_image.c
+++ b/legacy/evas/src/modules/engines/xrender_x11/evas_engine_xlib_image.c
@@ -68,12 +68,16 @@ __xre_xlib_image_find(char *fkey)
68} 68}
69 69
70XR_Image * 70XR_Image *
71_xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo) 71_xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_Image_Load_Opts *lo, int *error)
72{ 72{
73 XR_Image *im; 73 XR_Image *im;
74 char buf[4096]; 74 char buf[4096];
75 75
76 if (!file) return NULL; 76 if (!file)
77 {
78 *error = EVAS_LOAD_ERROR_GENERIC;
79 return NULL;
80 }
77 if (!lo) 81 if (!lo)
78 { 82 {
79 if (key) 83 if (key)
@@ -91,12 +95,17 @@ _xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_
91 im = __xre_xlib_image_find(buf); 95 im = __xre_xlib_image_find(buf);
92 if (im) 96 if (im)
93 { 97 {
98 *error = EVAS_LOAD_ERROR_NONE;
94 return im; 99 return im;
95 } 100 }
96 101
97 im = calloc(1, sizeof(XR_Image)); 102 im = calloc(1, sizeof(XR_Image));
98 if (!im) return NULL; 103 if (!im)
99 im->im = evas_common_load_image_from_file(file, key, lo); 104 {
105 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
106 return NULL;
107 }
108 im->im = evas_common_load_image_from_file(file, key, lo, error);
100 if (!im->im) 109 if (!im->im)
101 { 110 {
102 free(im); 111 free(im);
@@ -112,6 +121,7 @@ _xre_xlib_image_load(Ximage_Info *xinf, const char *file, const char *key, Evas_
112 im->h = im->im->cache_entry.h; 121 im->h = im->im->cache_entry.h;
113 im->references = 1; 122 im->references = 1;
114 if (lo) im->load_opts = *lo; 123 if (lo) im->load_opts = *lo;
124 im->load_error = error; /* points to object's load_error */
115 if (im->im->info.comment) im->comment = eina_stringshare_add(im->im->info.comment); 125 if (im->im->info.comment) im->comment = eina_stringshare_add(im->im->info.comment);
116// if (im->im->info.format == 1) im->format = eina_stringshare_add("png"); 126// if (im->im->info.format == 1) im->format = eina_stringshare_add("png");
117 if (im->im->cache_entry.flags.alpha) im->alpha = 1; 127 if (im->im->cache_entry.flags.alpha) im->alpha = 1;
@@ -301,7 +311,7 @@ _xre_xlib_image_copy(XR_Image *im)
301 else 311 else
302 { 312 {
303 if (!im->im) 313 if (!im->im)
304 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 314 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
305 if (im->im) 315 if (im->im)
306 { 316 {
307 evas_cache_image_load_data(&im->im->cache_entry); 317 evas_cache_image_load_data(&im->im->cache_entry);
@@ -391,7 +401,8 @@ _xre_xlib_image_data_get(XR_Image *im)
391 else if (im->cs.data) data = im->cs.data; 401 else if (im->cs.data) data = im->cs.data;
392 else 402 else
393 { 403 {
394 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 404 if (!im->im)
405 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
395 if (im->im) 406 if (im->im)
396 { 407 {
397 evas_cache_image_load_data(&im->im->cache_entry); 408 evas_cache_image_load_data(&im->im->cache_entry);
@@ -559,7 +570,8 @@ _xre_xlib_image_surface_gen(XR_Image *im)
559 if (im->data) data = im->data; 570 if (im->data) data = im->data;
560 else 571 else
561 { 572 {
562 if (!im->im) im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts)); 573 if (!im->im)
574 im->im = evas_common_load_image_from_file(im->file, im->key, &(im->load_opts), im->load_error);
563 if (im->im) 575 if (im->im)
564 { 576 {
565 evas_cache_image_load_data(&im->im->cache_entry); 577 evas_cache_image_load_data(&im->im->cache_entry);
diff --git a/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c b/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c
index 59f10ae39f..adc0818168 100644
--- a/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c
+++ b/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c
@@ -1,4 +1,4 @@
1#include "evas_common.h" 1s#include "evas_common.h"
2#include "evas_private.h" 2#include "evas_private.h"
3 3
4#include <Edb.h> 4#include <Edb.h>
@@ -8,8 +8,8 @@
8#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24)) 8#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24))
9 9
10 10
11static int evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key); 11static Eina_Bool evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
12static int evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key); 12static Eina_Bool evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
13 13
14static Evas_Image_Load_Func evas_image_load_edb_func = 14static Evas_Image_Load_Func evas_image_load_edb_func =
15{ 15{
@@ -17,28 +17,38 @@ static Evas_Image_Load_Func evas_image_load_edb_func =
17 evas_image_load_file_data_edb 17 evas_image_load_file_data_edb
18}; 18};
19 19
20static int 20static Eina_Bool
21evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key) 21evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key, int *error)
22{ 22{
23 int w, h, alpha, compression, size; 23 int w, h, alpha, compression, size;
24 E_DB_File *db; 24 E_DB_File *db;
25 DATA32 *ret; 25 DATA32 *ret;
26 DATA32 header[8]; 26 DATA32 header[8];
27 27
28 if ((!file) || (!key)) return 0; 28 if (!key)
29 {
30 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
31 return EINA_FALSE;
32 }
29 db = e_db_open_read((char *)file); 33 db = e_db_open_read((char *)file);
30 if (!db) return 0; 34 if (!db)
35 {
36 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
37 return EINA_FALSE;
38 }
31 ret = e_db_data_get(db, (char *)key, &size); 39 ret = e_db_data_get(db, (char *)key, &size);
32 if (!ret) 40 if (!ret)
33 { 41 {
34 e_db_close(db); 42 e_db_close(db);
35 return 0; 43 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
44 return EINA_FALSE;
36 } 45 }
37 if (size < 32) 46 if (size < 32)
38 { 47 {
39 free(ret); 48 free(ret);
40 e_db_close(db); 49 e_db_close(db);
41 return 0; 50 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
51 return EINA_FALSE;
42 } 52 }
43 memcpy(header, ret, 32); 53 memcpy(header, ret, 32);
44#ifdef WORDS_BIGENDIAN 54#ifdef WORDS_BIGENDIAN
@@ -52,7 +62,8 @@ evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key
52 { 62 {
53 free(ret); 63 free(ret);
54 e_db_close(db); 64 e_db_close(db);
55 return 0; 65 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
66 return EINA_FALSE;
56 } 67 }
57 w = header[1]; 68 w = header[1];
58 h = header[2]; 69 h = header[2];
@@ -61,7 +72,11 @@ evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key
61 { 72 {
62 free(ret); 73 free(ret);
63 e_db_close(db); 74 e_db_close(db);
64 return 0; 75 if (IMG_TOO_BIG(w, h))
76 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
77 else
78 *error = EVAS_LOAD_ERROR_GENERIC;
79 return EINA_FALSE;
65 } 80 }
66 alpha = header[3]; 81 alpha = header[3];
67 compression = header[4]; 82 compression = header[4];
@@ -70,18 +85,20 @@ evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key
70 { 85 {
71 free(ret); 86 free(ret);
72 e_db_close(db); 87 e_db_close(db);
73 return 0; 88 *error = EVAS_LOAD_ERROR_GENERIC;
89 return EINA_FALSE;
74 } 90 }
75 if (alpha) ie->flags.alpha = 1; 91 if (alpha) ie->flags.alpha = 1;
76 ie->w = w; 92 ie->w = w;
77 ie->h = h; 93 ie->h = h;
78 free(ret); 94 free(ret);
79 e_db_close(db); 95 e_db_close(db);
80 return 1; 96 *error = EVAS_LOAD_ERROR_NONE;
97 return EINA_TRUE;
81} 98}
82 99
83static int 100static Eina_Bool
84evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key) 101evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key, int *error)
85{ 102{
86 int w, h, alpha, compression, size; 103 int w, h, alpha, compression, size;
87 E_DB_File *db; 104 E_DB_File *db;
@@ -90,20 +107,30 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
90 DATA32 *surface; 107 DATA32 *surface;
91 DATA32 header[8]; 108 DATA32 header[8];
92 109
93 if ((!file) || (!key)) return 0; 110 if (!key)
111 {
112 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
113 return EINA_FALSE;
114 }
94 db = e_db_open_read((char *)file); 115 db = e_db_open_read((char *)file);
95 if (!db) return 0; 116 if (!db)
117 {
118 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
119 return EINA_FALSE;
120 }
96 ret = e_db_data_get(db, (char *)key, &size); 121 ret = e_db_data_get(db, (char *)key, &size);
97 if (!ret) 122 if (!ret)
98 { 123 {
99 e_db_close(db); 124 e_db_close(db);
100 return 0; 125 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
126 return EINA_FALSE;
101 } 127 }
102 if (size < 32) 128 if (size < 32)
103 { 129 {
104 free(ret); 130 free(ret);
105 e_db_close(db); 131 e_db_close(db);
106 return 0; 132 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
133 return EINA_FALSE;
107 } 134 }
108 memcpy(header, ret, 32); 135 memcpy(header, ret, 32);
109#ifdef WORDS_BIGENDIAN 136#ifdef WORDS_BIGENDIAN
@@ -117,7 +144,8 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
117 { 144 {
118 free(ret); 145 free(ret);
119 e_db_close(db); 146 e_db_close(db);
120 return 0; 147 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
148 return EINA_FALSE;
121 } 149 }
122 w = header[1]; 150 w = header[1];
123 h = header[2]; 151 h = header[2];
@@ -126,7 +154,11 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
126 { 154 {
127 free(ret); 155 free(ret);
128 e_db_close(db); 156 e_db_close(db);
129 return 0; 157 if (IMG_TOO_BIG(w, h))
158 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
159 else
160 *error = EVAS_LOAD_ERROR_GENERIC;
161 return EINA_FALSE;
130 } 162 }
131 163
132 alpha = header[3]; 164 alpha = header[3];
@@ -136,7 +168,8 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
136 { 168 {
137 free(ret); 169 free(ret);
138 e_db_close(db); 170 e_db_close(db);
139 return 0; 171 *error = EVAS_LOAD_ERROR_GENERIC;
172 return EINA_FALSE;
140 } 173 }
141 if (alpha) ie->flags.alpha = 1; 174 if (alpha) ie->flags.alpha = 1;
142 body = &(ret[8]); 175 body = &(ret[8]);
@@ -146,7 +179,8 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
146 { 179 {
147 free(ret); 180 free(ret);
148 e_db_close(db); 181 e_db_close(db);
149 return 0; 182 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
183 return EINA_FALSE;
150 } 184 }
151 if (!compression) 185 if (!compression)
152 { 186 {
@@ -179,7 +213,8 @@ evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key
179 evas_common_image_premul(ie); 213 evas_common_image_premul(ie);
180 free(ret); 214 free(ret);
181 e_db_close(db); 215 e_db_close(db);
182 return 1; 216 *error = EVAS_LOAD_ERROR_NONE;
217 return EINA_TRUE;
183} 218}
184 219
185static int 220static int
diff --git a/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c b/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c
index f3d2819bc2..93fb5927da 100644
--- a/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c
+++ b/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c
@@ -8,8 +8,8 @@
8#include "evas_private.h" 8#include "evas_private.h"
9 9
10 10
11int evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key); 11static Eina_Bool evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
12int evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key); 12static Eina_Bool evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
13 13
14Evas_Image_Load_Func evas_image_load_eet_func = 14Evas_Image_Load_Func evas_image_load_eet_func =
15{ 15{
@@ -18,55 +18,97 @@ Evas_Image_Load_Func evas_image_load_eet_func =
18}; 18};
19 19
20 20
21int 21static Eina_Bool
22evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key) 22evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error)
23{ 23{
24 int alpha, compression, quality, lossy; 24 int alpha, compression, quality, lossy;
25 unsigned int w, h; 25 unsigned int w, h;
26 Eet_File *ef; 26 Eet_File *ef;
27 int ok; 27 int ok;
28 int res = 0; 28 Eina_Bool res = EINA_FALSE;
29
30 if (!key)
31 {
32 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
33 return EINA_FALSE;
34 }
29 35
30 if ((!file) || (!key)) return 0;
31 ef = eet_open((char *)file, EET_FILE_MODE_READ); 36 ef = eet_open((char *)file, EET_FILE_MODE_READ);
32 if (!ef) return 0; 37 if (!ef)
38 {
39 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
40 return EINA_FALSE;
41 }
33 ok = eet_data_image_header_read(ef, key, 42 ok = eet_data_image_header_read(ef, key,
34 &w, &h, &alpha, &compression, &quality, &lossy); 43 &w, &h, &alpha, &compression, &quality, &lossy);
35 if (IMG_TOO_BIG(w, h)) goto on_error; 44 if (IMG_TOO_BIG(w, h))
36 if (!ok) goto on_error; 45 {
46 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
47 goto on_error;
48 }
49 if (!ok)
50 {
51 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
52 goto on_error;
53 }
37 if (alpha) ie->flags.alpha = 1; 54 if (alpha) ie->flags.alpha = 1;
38 ie->w = w; 55 ie->w = w;
39 ie->h = h; 56 ie->h = h;
40 res = 1; 57 res = EINA_TRUE;
58 *error = EVAS_LOAD_ERROR_NONE;
41 59
42 on_error: 60 on_error:
43 eet_close(ef); 61 eet_close(ef);
44 return res; 62 return res;
45} 63}
46 64
47int 65Eina_Bool
48evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key) 66evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error)
49{ 67{
50 unsigned int w, h; 68 unsigned int w, h;
51 int alpha, compression, quality, lossy, ok; 69 int alpha, compression, quality, lossy, ok;
52 Eet_File *ef; 70 Eet_File *ef;
53 DATA32 *body, *p, *end; 71 DATA32 *body, *p, *end;
54 DATA32 nas = 0; 72 DATA32 nas = 0;
55 int res = 0; 73 Eina_Bool res = EINA_FALSE;
56 74
57 if ((!file) || (!key)) return 0; 75 if (!key)
58 if (ie->flags.loaded) return 1; 76 {
77 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
78 return EINA_FALSE;
79 }
80 if (ie->flags.loaded)
81 {
82 *error = EVAS_LOAD_ERROR_NONE;
83 return EINA_TRUE;
84 }
59 ef = eet_open(file, EET_FILE_MODE_READ); 85 ef = eet_open(file, EET_FILE_MODE_READ);
60 if (!ef) return 0; 86 if (!ef)
87 {
88 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
89 return EINA_FALSE;
90 }
61 ok = eet_data_image_header_read(ef, key, 91 ok = eet_data_image_header_read(ef, key,
62 &w, &h, &alpha, &compression, &quality, &lossy); 92 &w, &h, &alpha, &compression, &quality, &lossy);
63 if (IMG_TOO_BIG(w, h)) goto on_error; 93 if (IMG_TOO_BIG(w, h))
64 if (!ok) goto on_error; 94 {
95 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
96 goto on_error;
97 }
98 if (!ok)
99 {
100 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
101 goto on_error;
102 }
65 evas_cache_image_surface_alloc(ie, w, h); 103 evas_cache_image_surface_alloc(ie, w, h);
66 ok = eet_data_image_read_to_surface(ef, key, 0, 0, 104 ok = eet_data_image_read_to_surface(ef, key, 0, 0,
67 evas_cache_image_pixels(ie), w, h, w * 4, 105 evas_cache_image_pixels(ie), w, h, w * 4,
68 &alpha, &compression, &quality, &lossy); 106 &alpha, &compression, &quality, &lossy);
69 if (!ok) goto on_error; 107 if (!ok)
108 {
109 *error = EVAS_LOAD_ERROR_GENERIC;
110 goto on_error;
111 }
70 if (alpha) 112 if (alpha)
71 { 113 {
72 ie->flags.alpha = 1; 114 ie->flags.alpha = 1;
@@ -93,7 +135,8 @@ evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key
93 } 135 }
94// result is already premultiplied now if u compile with edje 136// result is already premultiplied now if u compile with edje
95// evas_common_image_premul(im); 137// evas_common_image_premul(im);
96 res = 1; 138 *error = EVAS_LOAD_ERROR_NONE;
139 res = EINA_TRUE;
97 140
98 on_error: 141 on_error:
99 eet_close(ef); 142 eet_close(ef);
diff --git a/legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c b/legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c
index 5269f4a47a..63485f2f8c 100644
--- a/legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c
+++ b/legacy/evas/src/modules/loaders/gif/evas_image_load_gif.c
@@ -7,8 +7,8 @@
7 7
8#include <gif_lib.h> 8#include <gif_lib.h>
9 9
10static int evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key); 10static Eina_Bool evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
11static int evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key); 11static Eina_Bool evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
12 12
13static Evas_Image_Load_Func evas_image_load_gif_func = 13static Evas_Image_Load_Func evas_image_load_gif_func =
14{ 14{
@@ -16,8 +16,8 @@ static Evas_Image_Load_Func evas_image_load_gif_func =
16 evas_image_load_file_data_gif 16 evas_image_load_file_data_gif
17}; 17};
18 18
19static int 19static Eina_Bool
20evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__) 20evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
21{ 21{
22 int fd; 22 int fd;
23 GifFileType *gif; 23 GifFileType *gif;
@@ -32,21 +32,23 @@ evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key
32 h = 0; 32 h = 0;
33 alpha = -1; 33 alpha = -1;
34 34
35 if (!file) return 0;
36
37#ifndef __EMX__ 35#ifndef __EMX__
38 fd = open(file, O_RDONLY); 36 fd = open(file, O_RDONLY);
39#else 37#else
40 fd = open(file, O_RDONLY | O_BINARY); 38 fd = open(file, O_RDONLY | O_BINARY);
41#endif 39#endif
42 if (fd < 0) 40 if (fd < 0)
43 return 0; 41 {
42 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
43 return EINA_FALSE;
44 }
44 45
45 gif = DGifOpenFileHandle(fd); 46 gif = DGifOpenFileHandle(fd);
46 if (!gif) 47 if (!gif)
47 { 48 {
48 close(fd); 49 close(fd);
49 return 0; 50 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
51 return EINA_FALSE;
50 } 52 }
51 53
52 do 54 do
@@ -69,7 +71,11 @@ evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key
69 IMG_TOO_BIG(w, h)) 71 IMG_TOO_BIG(w, h))
70 { 72 {
71 DGifCloseFile(gif); 73 DGifCloseFile(gif);
72 return 0; 74 if (IMG_TOO_BIG(w, h))
75 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
76 else
77 *error = EVAS_LOAD_ERROR_GENERIC;
78 return EINA_FALSE;
73 } 79 }
74 done = 1; 80 done = 1;
75 } 81 }
@@ -77,7 +83,7 @@ evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key
77 { 83 {
78 int ext_code; 84 int ext_code;
79 GifByteType *ext; 85 GifByteType *ext;
80 86
81 ext = NULL; 87 ext = NULL;
82 DGifGetExtension(gif, &ext_code, &ext); 88 DGifGetExtension(gif, &ext_code, &ext);
83 while (ext) 89 while (ext)
@@ -97,11 +103,12 @@ evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key
97 ie->h = h; 103 ie->h = h;
98 104
99 DGifCloseFile(gif); 105 DGifCloseFile(gif);
100 return 1; 106 *error = EVAS_LOAD_ERROR_NONE;
107 return EINA_TRUE;
101} 108}
102 109
103static int 110static Eina_Bool
104evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__) 111evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
105{ 112{
106 int intoffset[] = { 0, 4, 2, 1 }; 113 int intoffset[] = { 0, 4, 2, 1 };
107 int intjump[] = { 8, 8, 4, 2 }; 114 int intjump[] = { 8, 8, 4, 2 };
@@ -135,21 +142,23 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
135 h = 0; 142 h = 0;
136 alpha = -1; 143 alpha = -1;
137 144
138 if (!file) return 0;
139
140#ifndef __EMX__ 145#ifndef __EMX__
141 fd = open(file, O_RDONLY); 146 fd = open(file, O_RDONLY);
142#else 147#else
143 fd = open(file, O_RDONLY | O_BINARY); 148 fd = open(file, O_RDONLY | O_BINARY);
144#endif 149#endif
145 if (fd < 0) 150 if (fd < 0)
146 return 0; 151 {
152 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
153 return EINA_FALSE;
154 }
147 155
148 gif = DGifOpenFileHandle(fd); 156 gif = DGifOpenFileHandle(fd);
149 if (!gif) 157 if (!gif)
150 { 158 {
151 close(fd); 159 close(fd);
152 return 0; 160 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
161 return EINA_FALSE;
153 } 162 }
154 do 163 do
155 { 164 {
@@ -191,7 +200,8 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
191 } 200 }
192 } 201 }
193 free(rows); 202 free(rows);
194 return 0; 203 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
204 return EINA_FALSE;
195 } 205 }
196 } 206 }
197 if (gif->Image.Interlace) 207 if (gif->Image.Interlace)
@@ -242,7 +252,8 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
242 free(rows[i]); 252 free(rows[i]);
243 } 253 }
244 free(rows); 254 free(rows);
245 return 0; 255 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
256 return EINA_FALSE;
246 } 257 }
247 258
248 bg = gif->SBackGroundColor; 259 bg = gif->SBackGroundColor;
@@ -280,7 +291,8 @@ evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key
280 } 291 }
281 free(rows); 292 free(rows);
282 293
283 return 1; 294 *error = EVAS_LOAD_ERROR_NONE;
295 return EINA_TRUE;
284} 296}
285 297
286static int 298static int
diff --git a/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c b/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
index 1a3ff43949..560215f27e 100644
--- a/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
+++ b/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
@@ -25,14 +25,14 @@ static void _JPEGFatalErrorHandler(j_common_ptr cinfo);
25static void _JPEGErrorHandler(j_common_ptr cinfo); 25static void _JPEGErrorHandler(j_common_ptr cinfo);
26static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level); 26static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
27 27
28static int evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f); 28static Eina_Bool evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f, int *error) EINA_ARG_NONNULL(1, 2, 3);
29static int evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f); 29static Eina_Bool evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f, int *error) EINA_ARG_NONNULL(1, 2, 3);
30#if 0 /* not used at the moment */ 30#if 0 /* not used at the moment */
31static int evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f); 31static int evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f) EINA_ARG_NONNULL(1, 2);
32#endif 32#endif
33 33
34static int evas_image_load_file_head_jpeg(Image_Entry *ie, const char *file, const char *key); 34static Eina_Bool evas_image_load_file_head_jpeg(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
35static int evas_image_load_file_data_jpeg(Image_Entry *ie, const char *file, const char *key); 35static Eina_Bool evas_image_load_file_data_jpeg(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
36 36
37static Evas_Image_Load_Func evas_image_load_jpeg_func = 37static Evas_Image_Load_Func evas_image_load_jpeg_func =
38{ 38{
@@ -74,14 +74,13 @@ _JPEGErrorHandler2(j_common_ptr cinfo __UNUSED__, int msg_level __UNUSED__)
74 return; 74 return;
75} 75}
76 76
77static int 77static Eina_Bool
78evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f) 78evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f, int *error)
79{ 79{
80 int w, h, scalew, scaleh; 80 int w, h, scalew, scaleh;
81 struct jpeg_decompress_struct cinfo; 81 struct jpeg_decompress_struct cinfo;
82 struct _JPEG_error_mgr jerr; 82 struct _JPEG_error_mgr jerr;
83 83
84 if (!f) return 0;
85 cinfo.err = jpeg_std_error(&(jerr.pub)); 84 cinfo.err = jpeg_std_error(&(jerr.pub));
86 jerr.pub.error_exit = _JPEGFatalErrorHandler; 85 jerr.pub.error_exit = _JPEGFatalErrorHandler;
87 jerr.pub.emit_message = _JPEGErrorHandler2; 86 jerr.pub.emit_message = _JPEGErrorHandler2;
@@ -89,7 +88,11 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f)
89 if (setjmp(jerr.setjmp_buffer)) 88 if (setjmp(jerr.setjmp_buffer))
90 { 89 {
91 jpeg_destroy_decompress(&cinfo); 90 jpeg_destroy_decompress(&cinfo);
92 return 0; 91 if (cinfo.saw_JFIF_marker)
92 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
93 else
94 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
95 return EINA_FALSE;
93 } 96 }
94 jpeg_create_decompress(&cinfo); 97 jpeg_create_decompress(&cinfo);
95 jpeg_stdio_src(&cinfo, f); 98 jpeg_stdio_src(&cinfo, f);
@@ -107,7 +110,11 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f)
107 (IMG_TOO_BIG(w, h))) 110 (IMG_TOO_BIG(w, h)))
108 { 111 {
109 jpeg_destroy_decompress(&cinfo); 112 jpeg_destroy_decompress(&cinfo);
110 return 0; 113 if (IMG_TOO_BIG(w, h))
114 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
115 else
116 *error = EVAS_LOAD_ERROR_GENERIC;
117 return EINA_FALSE;
111 } 118 }
112 if (ie->load_opts.scale_down_by > 1) 119 if (ie->load_opts.scale_down_by > 1)
113 { 120 {
@@ -188,7 +195,8 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f)
188 if ((ie->load_opts.region.w <= 0) || (ie->load_opts.region.h <= 0)) 195 if ((ie->load_opts.region.w <= 0) || (ie->load_opts.region.h <= 0))
189 { 196 {
190 jpeg_destroy_decompress(&cinfo); 197 jpeg_destroy_decompress(&cinfo);
191 return 0; 198 *error = EVAS_LOAD_ERROR_GENERIC;
199 return EINA_FALSE;
192 } 200 }
193 ie->w = ie->load_opts.region.w; 201 ie->w = ie->load_opts.region.w;
194 ie->h = ie->load_opts.region.h; 202 ie->h = ie->load_opts.region.h;
@@ -196,7 +204,8 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f)
196/* end head decoding */ 204/* end head decoding */
197 205
198 jpeg_destroy_decompress(&cinfo); 206 jpeg_destroy_decompress(&cinfo);
199 return 1; 207 *error = EVAS_LOAD_ERROR_NONE;
208 return EINA_TRUE;
200} 209}
201 210
202/* 211/*
@@ -210,8 +219,8 @@ get_time(void)
210} 219}
211*/ 220*/
212 221
213static int 222static Eina_Bool
214evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f) 223evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f, int *error)
215{ 224{
216 int w, h; 225 int w, h;
217 struct jpeg_decompress_struct cinfo; 226 struct jpeg_decompress_struct cinfo;
@@ -221,7 +230,6 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
221 int x, y, l, i, scans, count; 230 int x, y, l, i, scans, count;
222 int region = 0; 231 int region = 0;
223 232
224 if (!f) return 0;
225 cinfo.err = jpeg_std_error(&(jerr.pub)); 233 cinfo.err = jpeg_std_error(&(jerr.pub));
226 jerr.pub.error_exit = _JPEGFatalErrorHandler; 234 jerr.pub.error_exit = _JPEGFatalErrorHandler;
227 jerr.pub.emit_message = _JPEGErrorHandler2; 235 jerr.pub.emit_message = _JPEGErrorHandler2;
@@ -229,7 +237,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
229 if (setjmp(jerr.setjmp_buffer)) 237 if (setjmp(jerr.setjmp_buffer))
230 { 238 {
231 jpeg_destroy_decompress(&cinfo); 239 jpeg_destroy_decompress(&cinfo);
232 return 0; 240 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
241 return EINA_FALSE;
233 } 242 }
234 jpeg_create_decompress(&cinfo); 243 jpeg_create_decompress(&cinfo);
235 jpeg_stdio_src(&cinfo, f); 244 jpeg_stdio_src(&cinfo, f);
@@ -284,7 +293,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
284 { 293 {
285 // OK. region decode happening. a sub-set of the image 294 // OK. region decode happening. a sub-set of the image
286// jpeg_destroy_decompress(&cinfo); 295// jpeg_destroy_decompress(&cinfo);
287// return 0; 296// *error = EVAS_LOAD_ERROR_GENERIC;
297// return EINA_FALSE;
288 } 298 }
289 if ((region) && 299 if ((region) &&
290 ((ie->w != ie->load_opts.region.w) || (ie->h != ie->load_opts.region.h))) 300 ((ie->w != ie->load_opts.region.w) || (ie->h != ie->load_opts.region.h)))
@@ -298,7 +308,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
298 ((cinfo.out_color_space == JCS_CMYK) && (cinfo.output_components == 4)))) 308 ((cinfo.out_color_space == JCS_CMYK) && (cinfo.output_components == 4))))
299 { 309 {
300 jpeg_destroy_decompress(&cinfo); 310 jpeg_destroy_decompress(&cinfo);
301 return 0; 311 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
312 return EINA_FALSE;
302 } 313 }
303 314
304/* end head decoding */ 315/* end head decoding */
@@ -306,14 +317,16 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
306 if (cinfo.rec_outbuf_height > 16) 317 if (cinfo.rec_outbuf_height > 16)
307 { 318 {
308 jpeg_destroy_decompress(&cinfo); 319 jpeg_destroy_decompress(&cinfo);
309 return 0; 320 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
321 return EINA_FALSE;
310 } 322 }
311 data = alloca(w * 16 * cinfo.output_components); 323 data = alloca(w * 16 * cinfo.output_components);
312 evas_cache_image_surface_alloc(ie, ie->w, ie->h); 324 evas_cache_image_surface_alloc(ie, ie->w, ie->h);
313 if (ie->flags.loaded) 325 if (ie->flags.loaded)
314 { 326 {
315 jpeg_destroy_decompress(&cinfo); 327 jpeg_destroy_decompress(&cinfo);
316 return 1; 328 *error = EVAS_LOAD_ERROR_NONE;
329 return EINA_TRUE;
317 } 330 }
318 ptr2 = evas_cache_image_pixels(ie); 331 ptr2 = evas_cache_image_pixels(ie);
319 count = 0; 332 count = 0;
@@ -382,7 +395,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
382 if (l >= (ie->load_opts.region.y + ie->load_opts.region.h)) 395 if (l >= (ie->load_opts.region.y + ie->load_opts.region.h))
383 { 396 {
384 jpeg_destroy_decompress(&cinfo); 397 jpeg_destroy_decompress(&cinfo);
385 return 1; 398 *error = EVAS_LOAD_ERROR_NONE;
399 return EINA_FALSE;
386 } 400 }
387 // els if scan block intersects region start or later 401 // els if scan block intersects region start or later
388 else if ((l + scans) > 402 else if ((l + scans) >
@@ -494,7 +508,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
494 t = get_time() - t; 508 t = get_time() - t;
495 printf("%3.3f\n", t); 509 printf("%3.3f\n", t);
496 */ 510 */
497 return 1; 511 *error = EVAS_LOAD_ERROR_NONE;
512 return EINA_TRUE;
498 } 513 }
499 // else if scan block intersects region start or later 514 // else if scan block intersects region start or later
500 else if ((l + scans) > 515 else if ((l + scans) >
@@ -556,7 +571,8 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
556 if (l >= (ie->load_opts.region.y + ie->load_opts.region.h)) 571 if (l >= (ie->load_opts.region.y + ie->load_opts.region.h))
557 { 572 {
558 jpeg_destroy_decompress(&cinfo); 573 jpeg_destroy_decompress(&cinfo);
559 return 1; 574 *error = EVAS_LOAD_ERROR_NONE;
575 return EINA_TRUE;
560 } 576 }
561 // els if scan block intersects region start or later 577 // els if scan block intersects region start or later
562 else if ((l + scans) > 578 else if ((l + scans) >
@@ -587,12 +603,13 @@ evas_image_load_file_data_jpeg_internal(Image_Entry *ie, FILE *f)
587/* end data decoding */ 603/* end data decoding */
588 jpeg_finish_decompress(&cinfo); 604 jpeg_finish_decompress(&cinfo);
589 jpeg_destroy_decompress(&cinfo); 605 jpeg_destroy_decompress(&cinfo);
590 return 1; 606 *error = EVAS_LOAD_ERROR_NONE;
607 return EINA_TRUE;
591} 608}
592 609
593#if 0 /* not used at the moment */ 610#if 0 /* not used at the moment */
594static int 611static Eina_Bool
595evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f) 612evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f, int *error)
596{ 613{
597 int w, h; 614 int w, h;
598 struct jpeg_decompress_struct cinfo; 615 struct jpeg_decompress_struct cinfo;
@@ -601,7 +618,11 @@ evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f)
601 DATA32 *ptr2; 618 DATA32 *ptr2;
602 int x, y, l, i, scans, count, prevy; 619 int x, y, l, i, scans, count, prevy;
603 620
604 if (!f) return 0; 621 if (!f)
622 {
623 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
624 return EINA_FALSE;
625 }
605 cinfo.err = jpeg_std_error(&(jerr.pub)); 626 cinfo.err = jpeg_std_error(&(jerr.pub));
606 jerr.pub.error_exit = _JPEGFatalErrorHandler; 627 jerr.pub.error_exit = _JPEGFatalErrorHandler;
607 jerr.pub.emit_message = _JPEGErrorHandler2; 628 jerr.pub.emit_message = _JPEGErrorHandler2;
@@ -609,7 +630,8 @@ evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f)
609 if (setjmp(jerr.setjmp_buffer)) 630 if (setjmp(jerr.setjmp_buffer))
610 { 631 {
611 jpeg_destroy_decompress(&cinfo); 632 jpeg_destroy_decompress(&cinfo);
612 return 0; 633 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
634 return EINA_FALSE;
613 } 635 }
614 jpeg_create_decompress(&cinfo); 636 jpeg_create_decompress(&cinfo);
615 jpeg_stdio_src(&cinfo, f); 637 jpeg_stdio_src(&cinfo, f);
@@ -626,13 +648,15 @@ evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f)
626 if (cinfo.rec_outbuf_height > 16) 648 if (cinfo.rec_outbuf_height > 16)
627 { 649 {
628 jpeg_destroy_decompress(&cinfo); 650 jpeg_destroy_decompress(&cinfo);
629 return 0; 651 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
652 return EINA_FALSE;;
630 } 653 }
631 data = alloca(w * 16 * 3); 654 data = alloca(w * 16 * 3);
632 if (!ie->flags.loaded) 655 if (!ie->flags.loaded)
633 { 656 {
634 jpeg_destroy_decompress(&cinfo); 657 jpeg_destroy_decompress(&cinfo);
635 return 0; 658 *error = EVAS_LOAD_ERROR_NONE;
659 return EINA_TRUE;
636 } 660 }
637 ptr2 = evas_cache_image_pixels(ie); 661 ptr2 = evas_cache_image_pixels(ie);
638 count = 0; 662 count = 0;
@@ -686,35 +710,42 @@ evas_image_load_file_data_jpeg_alpha_internal(Image_Entry *ie, FILE *f)
686/* end data decoding */ 710/* end data decoding */
687 jpeg_finish_decompress(&cinfo); 711 jpeg_finish_decompress(&cinfo);
688 jpeg_destroy_decompress(&cinfo); 712 jpeg_destroy_decompress(&cinfo);
689 return 1; 713 *error = EVAS_LOAD_ERROR_NONE;
714 return EINA_TRUE;
690} 715}
691#endif 716#endif
692 717
693static int 718static Eina_Bool
694evas_image_load_file_head_jpeg(Image_Entry *ie, const char *file, const char *key) 719evas_image_load_file_head_jpeg(Image_Entry *ie, const char *file, const char *key, int *error)
695{ 720{
696 int val; 721 int val;
697 FILE *f; 722 FILE *f;
698 723
699 if ((!file)) return 0;
700 f = fopen(file, "rb"); 724 f = fopen(file, "rb");
701 if (!f) return 0; 725 if (!f)
702 val = evas_image_load_file_head_jpeg_internal(ie, f); 726 {
727 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
728 return EINA_FALSE;
729 }
730 val = evas_image_load_file_head_jpeg_internal(ie, f, error);
703 fclose(f); 731 fclose(f);
704 return val; 732 return val;
705 key = 0; 733 key = 0;
706} 734}
707 735
708static int 736static Eina_Bool
709evas_image_load_file_data_jpeg(Image_Entry *ie, const char *file, const char *key) 737evas_image_load_file_data_jpeg(Image_Entry *ie, const char *file, const char *key, int *error)
710{ 738{
711 int val; 739 int val;
712 FILE *f; 740 FILE *f;
713 741
714 if ((!file)) return 0;
715 f = fopen(file, "rb"); 742 f = fopen(file, "rb");
716 if (!f) return 0; 743 if (!f)
717 val = evas_image_load_file_data_jpeg_internal(ie, f); 744 {
745 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
746 return EINA_FALSE;
747 }
748 val = evas_image_load_file_data_jpeg_internal(ie, f, error);
718 fclose(f); 749 fclose(f);
719 return val; 750 return val;
720 key = 0; 751 key = 0;
diff --git a/legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c b/legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
index 20f6f31fc1..0884058c30 100644
--- a/legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
+++ b/legacy/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
@@ -17,10 +17,8 @@
17#define FILE_BUFFER_SIZE 1024 17#define FILE_BUFFER_SIZE 1024
18#define FILE_BUFFER_UNREAD_SIZE 16 18#define FILE_BUFFER_UNREAD_SIZE 16
19 19
20static int evas_image_load_file_head_pmaps(Image_Entry *ie, 20static Eina_Bool evas_image_load_file_head_pmaps(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
21 const char *file, const char *key); 21static Eina_Bool evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
22static int evas_image_load_file_data_pmaps(Image_Entry *ie,
23 const char *file, const char *key);
24 22
25Evas_Image_Load_Func evas_image_load_pmaps_func = { 23Evas_Image_Load_Func evas_image_load_pmaps_func = {
26 evas_image_load_file_head_pmaps, 24 evas_image_load_file_head_pmaps,
@@ -54,9 +52,9 @@ struct Pmaps_Buffer
54}; 52};
55 53
56/* internal used functions */ 54/* internal used functions */
57static int pmaps_buffer_open(Pmaps_Buffer *b, const char *filename); 55static Eina_Bool pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error);
58static void pmaps_buffer_close(Pmaps_Buffer *b); 56static void pmaps_buffer_close(Pmaps_Buffer *b);
59static int pmaps_buffer_header_parse(Pmaps_Buffer *b); 57static Eina_Bool pmaps_buffer_header_parse(Pmaps_Buffer *b, int *error);
60static int pmaps_buffer_plain_int_get(Pmaps_Buffer *b, int *val); 58static int pmaps_buffer_plain_int_get(Pmaps_Buffer *b, int *val);
61static int pmaps_buffer_1byte_int_get(Pmaps_Buffer *b, int *val); 59static int pmaps_buffer_1byte_int_get(Pmaps_Buffer *b, int *val);
62static int pmaps_buffer_2byte_int_get(Pmaps_Buffer *b, int *val); 60static int pmaps_buffer_2byte_int_get(Pmaps_Buffer *b, int *val);
@@ -68,70 +66,61 @@ static size_t pmaps_buffer_plain_update(Pmaps_Buffer *b);
68static size_t pmaps_buffer_raw_update(Pmaps_Buffer *b); 66static size_t pmaps_buffer_raw_update(Pmaps_Buffer *b);
69static int pmaps_buffer_comment_skip(Pmaps_Buffer *b); 67static int pmaps_buffer_comment_skip(Pmaps_Buffer *b);
70 68
71static int 69static Eina_Bool
72evas_image_load_file_head_pmaps(Image_Entry *ie, const char *file, 70evas_image_load_file_head_pmaps(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
73 const char *key)
74{ 71{
75 Pmaps_Buffer b; 72 Pmaps_Buffer b;
76 73
77 if ((!file)) 74 if (!pmaps_buffer_open(&b, file, error))
78 return 0;
79
80 if (!pmaps_buffer_open(&b, file))
81 { 75 {
82 pmaps_buffer_close(&b); 76 pmaps_buffer_close(&b);
83 return 0; 77 return EINA_FALSE;
84 } 78 }
85 79
86 if (!pmaps_buffer_header_parse(&b)) 80 if (!pmaps_buffer_header_parse(&b, error))
87 { 81 {
88 pmaps_buffer_close(&b); 82 pmaps_buffer_close(&b);
89 return 0; 83 return EINA_FALSE;
90 } 84 }
91 85
92 ie->w = b.w; 86 ie->w = b.w;
93 ie->h = b.h; 87 ie->h = b.h;
94 88
95 pmaps_buffer_close(&b); 89 pmaps_buffer_close(&b);
96 return 1; 90 *error = EVAS_LOAD_ERROR_NONE;
97 /* we don't have a use for key, skip warnings */ 91 return EINA_TRUE;
98 key = NULL;
99} 92}
100 93
101static int 94static Eina_Bool
102evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, 95evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
103 const char *key)
104{ 96{
105 Pmaps_Buffer b; 97 Pmaps_Buffer b;
106 int pixels; 98 int pixels;
107 DATA32 *ptr; 99 DATA32 *ptr;
108 100
109 if ((!file)) 101 if (!pmaps_buffer_open(&b, file, error))
110 return 0;
111
112 if (!pmaps_buffer_open(&b, file))
113 { 102 {
114 pmaps_buffer_close(&b); 103 pmaps_buffer_close(&b);
115 return 0; 104 return EINA_FALSE;
116 } 105 }
117 106
118 if (!pmaps_buffer_header_parse(&b)) 107 if (!pmaps_buffer_header_parse(&b, error))
119 { 108 {
120 pmaps_buffer_close(&b); 109 pmaps_buffer_close(&b);
121 return 0; 110 return EINA_FALSE;
122 } 111 }
123 112
124 pixels = b.w * b.h; 113 pixels = b.w * b.h;
125 114
126 evas_cache_image_surface_alloc(ie, b.w, b.h); 115 evas_cache_image_surface_alloc(ie, b.w, b.h);
127 if (!evas_cache_image_pixels(ie)) 116 ptr = evas_cache_image_pixels(ie);
117 if (!ptr)
128 { 118 {
129 pmaps_buffer_close(&b); 119 pmaps_buffer_close(&b);
130 return 0; 120 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
121 return EINA_FALSE;
131 } 122 }
132 123
133 ptr = evas_cache_image_pixels(ie);
134
135 if (b.type[1] != '4') 124 if (b.type[1] != '4')
136 { 125 {
137 while (pixels > 0 && b.color_get(&b, ptr)) 126 while (pixels > 0 && b.color_get(&b, ptr))
@@ -164,20 +153,22 @@ evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file,
164 memset(ptr, 0xff, 4 * pixels); 153 memset(ptr, 0xff, 4 * pixels);
165 pmaps_buffer_close(&b); 154 pmaps_buffer_close(&b);
166 155
167 return 1; 156 *error = EVAS_LOAD_ERROR_NONE;
168 /* we don't have a use for key, skip warnings */ 157 return EINA_TRUE;
169 key = NULL;
170} 158}
171 159
172/* internal used functions */ 160/* internal used functions */
173static int 161static Eina_Bool
174pmaps_buffer_open(Pmaps_Buffer *b, const char *filename) 162pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error)
175{ 163{
176 size_t len; 164 size_t len;
177 165
178 b->file = fopen(filename, "rb"); 166 b->file = fopen(filename, "rb");
179 if (!b->file) 167 if (!b->file)
180 return 0; 168 {
169 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
170 return EINA_FALSE;
171 }
181 172
182 *b->buffer = 0; 173 *b->buffer = 0;
183 *b->unread = 0; 174 *b->unread = 0;
@@ -187,7 +178,10 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename)
187 len = pmaps_buffer_plain_update(b); 178 len = pmaps_buffer_plain_update(b);
188 179
189 if (len < 3) 180 if (len < 3)
190 return 0; 181 {
182 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
183 return EINA_FALSE;
184 }
191 185
192 /* copy the type */ 186 /* copy the type */
193 b->type[0] = b->buffer[0]; 187 b->type[0] = b->buffer[0];
@@ -196,7 +190,8 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename)
196 /* skip the PX */ 190 /* skip the PX */
197 b->current = b->buffer + 2; 191 b->current = b->buffer + 2;
198 192
199 return 1; 193 *error = EVAS_LOAD_ERROR_NONE;
194 return EINA_TRUE;
200} 195}
201 196
202static void 197static void
@@ -206,25 +201,37 @@ pmaps_buffer_close(Pmaps_Buffer *b)
206 fclose(b->file); 201 fclose(b->file);
207} 202}
208 203
209static int 204static Eina_Bool
210pmaps_buffer_header_parse(Pmaps_Buffer *b) 205pmaps_buffer_header_parse(Pmaps_Buffer *b, int *error)
211{ 206{
212 /* if there is no P at the beginning it is not a file we can parse */ 207 /* if there is no P at the beginning it is not a file we can parse */
213 if (b->type[0] != 'P') 208 if (b->type[0] != 'P')
214 return 0; 209 {
210 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
211 return EINA_FALSE;
212 }
215 213
216 /* get the width */ 214 /* get the width */
217 if (!pmaps_buffer_plain_int_get(b, &(b->w)) || b->w < 1) 215 if (!pmaps_buffer_plain_int_get(b, &(b->w)) || b->w < 1)
218 return 0; 216 {
217 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
218 return EINA_FALSE;
219 }
219 220
220 /* get the height */ 221 /* get the height */
221 if (!pmaps_buffer_plain_int_get(b, &(b->h)) || b->h < 1) 222 if (!pmaps_buffer_plain_int_get(b, &(b->h)) || b->h < 1)
222 return 0; 223 {
224 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
225 return EINA_FALSE;
226 }
223 227
224 /* get the maximum value. P1 and P4 don't have a maximum value. */ 228 /* get the maximum value. P1 and P4 don't have a maximum value. */
225 if (!(b->type[1] == '1' || b->type[1] == '4') 229 if (!(b->type[1] == '1' || b->type[1] == '4')
226 && (!pmaps_buffer_plain_int_get(b, &(b->max)) || b->max < 1)) 230 && (!pmaps_buffer_plain_int_get(b, &(b->max)) || b->max < 1))
227 return 0; 231 {
232 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
233 return EINA_FALSE;
234 }
228 235
229 /* set up the color get callback */ 236 /* set up the color get callback */
230 switch (b->type[1]) 237 switch (b->type[1])
diff --git a/legacy/evas/src/modules/loaders/png/evas_image_load_png.c b/legacy/evas/src/modules/loaders/png/evas_image_load_png.c
index 2e6738f40f..2b88511342 100644
--- a/legacy/evas/src/modules/loaders/png/evas_image_load_png.c
+++ b/legacy/evas/src/modules/loaders/png/evas_image_load_png.c
@@ -32,8 +32,8 @@
32#define PNG_BYTES_TO_CHECK 4 32#define PNG_BYTES_TO_CHECK 4
33 33
34 34
35static int evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key); 35static Eina_Bool evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
36static int evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key); 36static Eina_Bool evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
37 37
38static Evas_Image_Load_Func evas_image_load_png_func = 38static Evas_Image_Load_Func evas_image_load_png_func =
39{ 39{
@@ -41,8 +41,8 @@ static Evas_Image_Load_Func evas_image_load_png_func =
41 evas_image_load_file_data_png 41 evas_image_load_file_data_png
42}; 42};
43 43
44static int 44static Eina_Bool
45evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key) 45evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
46{ 46{
47 png_uint_32 w32, h32; 47 png_uint_32 w32, h32;
48 FILE *f; 48 FILE *f;
@@ -52,31 +52,45 @@ evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key
52 unsigned char buf[PNG_BYTES_TO_CHECK]; 52 unsigned char buf[PNG_BYTES_TO_CHECK];
53 char hasa; 53 char hasa;
54 54
55 if ((!file)) return 0;
56 hasa = 0; 55 hasa = 0;
57 f = E_FOPEN(file, "rb"); 56 f = E_FOPEN(file, "rb");
58 if (!f) return 0; 57 if (!f)
58 {
59 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
60 return EINA_FALSE;
61 }
59 62
60 /* if we havent read the header before, set the header data */ 63 /* if we havent read the header before, set the header data */
61 if (E_FREAD(buf, PNG_BYTES_TO_CHECK, 1, f) != 1) 64 if (E_FREAD(buf, PNG_BYTES_TO_CHECK, 1, f) != 1)
62 goto close_file; 65 {
66 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
67 goto close_file;
68 }
63 69
64 if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) 70 if (!png_check_sig(buf, PNG_BYTES_TO_CHECK))
65 goto close_file; 71 {
72 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
73 goto close_file;
74 }
66 75
67 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 76 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
68 if (!png_ptr) 77 if (!png_ptr)
69 goto close_file; 78 {
79 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
80 goto close_file;
81 }
70 82
71 info_ptr = png_create_info_struct(png_ptr); 83 info_ptr = png_create_info_struct(png_ptr);
72 if (!info_ptr) 84 if (!info_ptr)
73 { 85 {
74 png_destroy_read_struct(&png_ptr, NULL, NULL); 86 png_destroy_read_struct(&png_ptr, NULL, NULL);
87 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
75 goto close_file; 88 goto close_file;
76 } 89 }
77 if (setjmp(png_jmpbuf(png_ptr))) 90 if (setjmp(png_jmpbuf(png_ptr)))
78 { 91 {
79 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 92 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
93 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
80 goto close_file; 94 goto close_file;
81 } 95 }
82 png_init_io(png_ptr, f); 96 png_init_io(png_ptr, f);
@@ -89,6 +103,10 @@ evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key
89 IMG_TOO_BIG(w32, h32)) 103 IMG_TOO_BIG(w32, h32))
90 { 104 {
91 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 105 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
106 if (IMG_TOO_BIG(w32, h32))
107 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
108 else
109 *error = EVAS_LOAD_ERROR_GENERIC;
92 goto close_file; 110 goto close_file;
93 } 111 }
94 ie->w = (int) w32; 112 ie->w = (int) w32;
@@ -99,17 +117,17 @@ evas_image_load_file_head_png(Image_Entry *ie, const char *file, const char *key
99 if (hasa) ie->flags.alpha = 1; 117 if (hasa) ie->flags.alpha = 1;
100 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 118 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
101 E_FCLOSE(f); 119 E_FCLOSE(f);
102 return 1; 120
121 *error = EVAS_LOAD_ERROR_NONE;
122 return EINA_TRUE;
103 123
104 close_file: 124 close_file:
105 E_FCLOSE(f); 125 E_FCLOSE(f);
106 return 0; 126 return EINA_FALSE;
107
108 key = 0;
109} 127}
110 128
111static int 129static Eina_Bool
112evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key) 130evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
113{ 131{
114 unsigned char *surface; 132 unsigned char *surface;
115 png_uint_32 w32, h32; 133 png_uint_32 w32, h32;
@@ -123,28 +141,39 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
123 char hasa; 141 char hasa;
124 int i; 142 int i;
125 143
126 if ((!file)) return 0;
127 hasa = 0; 144 hasa = 0;
128 f = E_FOPEN(file, "rb"); 145 f = E_FOPEN(file, "rb");
129 if (!f) return 0; 146 if (!f)
147 {
148 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
149 return EINA_FALSE;
150 }
130 151
131 /* if we havent read the header before, set the header data */ 152 /* if we havent read the header before, set the header data */
132 E_FREAD(buf, 1, PNG_BYTES_TO_CHECK, f); 153 E_FREAD(buf, 1, PNG_BYTES_TO_CHECK, f);
133 if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) 154 if (!png_check_sig(buf, PNG_BYTES_TO_CHECK))
134 goto close_file; 155 {
156 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
157 goto close_file;
158 }
135 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 159 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
136 if (!png_ptr) 160 if (!png_ptr)
137 goto close_file; 161 {
162 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
163 goto close_file;
164 }
138 165
139 info_ptr = png_create_info_struct(png_ptr); 166 info_ptr = png_create_info_struct(png_ptr);
140 if (!info_ptr) 167 if (!info_ptr)
141 { 168 {
142 png_destroy_read_struct(&png_ptr, NULL, NULL); 169 png_destroy_read_struct(&png_ptr, NULL, NULL);
170 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
143 goto close_file; 171 goto close_file;
144 } 172 }
145 if (setjmp(png_jmpbuf(png_ptr))) 173 if (setjmp(png_jmpbuf(png_ptr)))
146 { 174 {
147 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 175 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
176 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
148 goto close_file; 177 goto close_file;
149 } 178 }
150 png_init_io(png_ptr, f); 179 png_init_io(png_ptr, f);
@@ -158,11 +187,13 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
158 if (!surface) 187 if (!surface)
159 { 188 {
160 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 189 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
190 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
161 goto close_file; 191 goto close_file;
162 } 192 }
163 if ((w32 != ie->w) || (h32 != ie->h)) 193 if ((w32 != ie->w) || (h32 != ie->h))
164 { 194 {
165 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); 195 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
196 *error = EVAS_LOAD_ERROR_GENERIC;
166 goto close_file; 197 goto close_file;
167 } 198 }
168 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1; 199 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1;
@@ -208,13 +239,12 @@ evas_image_load_file_data_png(Image_Entry *ie, const char *file, const char *key
208 E_FCLOSE(f); 239 E_FCLOSE(f);
209 evas_common_image_premul(ie); 240 evas_common_image_premul(ie);
210 241
211 return 1; 242 *error = EVAS_LOAD_ERROR_NONE;
243 return EINA_TRUE;
212 244
213 close_file: 245 close_file:
214 E_FCLOSE(f); 246 E_FCLOSE(f);
215 return 0; 247 return EINA_FALSE;
216
217 key = 0;
218} 248}
219 249
220static int 250static int
diff --git a/legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c b/legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c
index f441de873b..75bbf31118 100644
--- a/legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c
+++ b/legacy/evas/src/modules/loaders/svg/evas_image_load_svg.c
@@ -4,8 +4,9 @@
4#include <librsvg/rsvg.h> 4#include <librsvg/rsvg.h>
5#include <librsvg/rsvg-cairo.h> 5#include <librsvg/rsvg-cairo.h>
6 6
7static int evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key); 7static inline Eina_Bool evas_image_load_file_is_svg(const char *file) EINA_ARG_NONNULL(1) EINA_PURE;
8static int evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key); 8static Eina_Bool evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
9static Eina_Bool evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
9 10
10Evas_Image_Load_Func evas_image_load_svg_func = 11Evas_Image_Load_Func evas_image_load_svg_func =
11{ 12{
@@ -15,51 +16,63 @@ Evas_Image_Load_Func evas_image_load_svg_func =
15 16
16static int rsvg_initialized = 0; 17static int rsvg_initialized = 0;
17 18
18static int 19
19evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key __UNUSED__) 20static inline Eina_Bool evas_image_load_file_is_svg(const char *file)
21{
22 int i, len = strlen(file);
23 Eina_Bool is_gz = EINA_FALSE;
24
25 for (i = len - 1; i > 0; i--)
26 {
27 if (file[i] == '.')
28 {
29 if (is_gz)
30 break;
31 else if (strcasecmp(file + i + 1, "gz") == 0)
32 is_gz = EINA_TRUE;
33 else
34 break;
35 }
36 }
37
38 if (i < 1) return EINA_FALSE;
39 i++;
40 if (i >= len) return EINA_FALSE;
41 if (strncasecmp(file + i, "svg", 3) != 0) return EINA_FALSE;
42 i += 3;
43 if (is_gz)
44 {
45 if (file[i] == '.') return EINA_TRUE;
46 else return EINA_FALSE;
47 }
48 else
49 {
50 if (file[i] == '\0') return EINA_TRUE;
51 else if (((file[i] == 'z') || (file[i] == 'Z')) && (!file[i + 1])) return EINA_TRUE;
52 else return EINA_FALSE;
53 }
54}
55
56static Eina_Bool
57evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
20{ 58{
21 char cwd[PATH_MAX], pcwd[PATH_MAX], *p;
22
23 RsvgHandle *rsvg; 59 RsvgHandle *rsvg;
24 RsvgDimensionData dim; 60 RsvgDimensionData dim;
25 int w, h; 61 int w, h;
26 char *ext;
27
28 if (!file) return 0;
29 62
30 /* ignore all files not called .svg or .svg.gz - because rsvg has a leak 63 /* ignore all files not called .svg or .svg.gz - because rsvg has a leak
31 * where closing the handle doesn't free mem */ 64 * where closing the handle doesn't free mem */
32 ext = strrchr(file, '.'); 65 if (!evas_image_load_file_is_svg(file))
33 if (!ext) return 0;
34 if (!strcasecmp(ext, ".gz"))
35 { 66 {
36 if (p > file) 67 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
37 { 68 return EINA_FALSE;
38 ext = p - 1;
39 while ((*p != '.') && (p > file))
40 {
41 p--;
42 }
43 if (p <= file) return 0;
44 if (strcasecmp(p, ".svg.gz")) return 0;
45 }
46 else
47 return 0;
48 } 69 }
49 else if (strcasecmp(ext, ".svg")) return 0;
50 70
51 getcwd(pcwd, sizeof(pcwd));
52 strncpy(cwd, file, sizeof(cwd) - 1);
53 cwd[sizeof(cwd) - 1] = 0;
54 p = strrchr(cwd, '/');
55 if (p) *p = 0;
56 chdir(cwd);
57
58 rsvg = rsvg_handle_new_from_file(file, NULL); 71 rsvg = rsvg_handle_new_from_file(file, NULL);
59 if (!rsvg) 72 if (!rsvg)
60 { 73 {
61 chdir(pcwd); 74 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
62 return 0; 75 return EINA_FALSE;
63 } 76 }
64 77
65 rsvg_handle_set_dpi(rsvg, 75.0); 78 rsvg_handle_set_dpi(rsvg, 75.0);
@@ -69,11 +82,13 @@ evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key
69 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || 82 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
70 IMG_TOO_BIG(w, h)) 83 IMG_TOO_BIG(w, h))
71 { 84 {
72// rsvg_handle_close(rsvg, NULL); 85 rsvg_handle_close(rsvg, NULL);
73 g_object_unref(rsvg); 86 g_object_unref(rsvg);
74// rsvg_handle_free(rsvg); 87 if (IMG_TOO_BIG(w, h))
75 chdir(pcwd); 88 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
76 return 0; 89 else
90 *error = EVAS_LOAD_ERROR_GENERIC;
91 return EINA_FALSE;
77 } 92 }
78 if (ie->load_opts.scale_down_by > 1) 93 if (ie->load_opts.scale_down_by > 1)
79 { 94 {
@@ -105,61 +120,37 @@ evas_image_load_file_head_svg(Image_Entry *ie, const char *file, const char *key
105 ie->w = w; 120 ie->w = w;
106 ie->h = h; 121 ie->h = h;
107 ie->flags.alpha = 1; 122 ie->flags.alpha = 1;
108// rsvg_handle_close(rsvg, NULL); 123 rsvg_handle_close(rsvg, NULL);
109 g_object_unref(rsvg); 124 g_object_unref(rsvg);
110// rsvg_handle_free(rsvg); 125
111 chdir(pcwd); 126 *error = EVAS_LOAD_ERROR_NONE;
112 return 1; 127 return EINA_TRUE;
113} 128}
114 129
115/** FIXME: All evas loaders need to be tightened up **/ 130/** FIXME: All evas loaders need to be tightened up **/
116static int 131static Eina_Bool
117evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key __UNUSED__) 132evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
118{ 133{
119 DATA32 *pixels; 134 DATA32 *pixels;
120 char cwd[PATH_MAX], pcwd[PATH_MAX], *p;
121 RsvgHandle *rsvg; 135 RsvgHandle *rsvg;
122 RsvgDimensionData dim; 136 RsvgDimensionData dim;
123 int w, h; 137 int w, h;
124 cairo_surface_t *surface; 138 cairo_surface_t *surface;
125 cairo_t *cr; 139 cairo_t *cr;
126 char *ext;
127
128 if (!file) return 0;
129 140
130 /* ignore all files not called .svg or .svg.gz - because rsvg has a leak 141 /* ignore all files not called .svg or .svg.gz - because rsvg has a leak
131 * where closing the handle doesn't free mem */ 142 * where closing the handle doesn't free mem */
132 ext = strrchr(file, '.'); 143 if (!evas_image_load_file_is_svg(file))
133 if (!ext) return 0;
134 if (!strcasecmp(ext, ".gz"))
135 { 144 {
136 if (p > file) 145 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
137 { 146 return EINA_FALSE;
138 ext = p - 1;
139 while ((*p != '.') && (p > file))
140 {
141 p--;
142 }
143 if (p <= file) return 0;
144 if (strcasecmp(p, ".svg.gz")) return 0;
145 }
146 else
147 return 0;
148 } 147 }
149 else if (strcasecmp(ext, ".svg")) return 0;
150 148
151 getcwd(pcwd, sizeof(pcwd));
152 strncpy(cwd, file, sizeof(cwd) - 1);
153 cwd[sizeof(cwd) - 1] = 0;
154 p = strrchr(cwd, '/');
155 if (p) *p = 0;
156 chdir(cwd);
157
158 rsvg = rsvg_handle_new_from_file(file, NULL); 149 rsvg = rsvg_handle_new_from_file(file, NULL);
159 if (!rsvg) 150 if (!rsvg)
160 { 151 {
161 chdir(pcwd); 152 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
162 return 0; 153 return EINA_FALSE;
163 } 154 }
164 155
165 rsvg_handle_set_dpi(rsvg, 75.0); 156 rsvg_handle_set_dpi(rsvg, 75.0);
@@ -168,11 +159,13 @@ evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key
168 h = dim.height; 159 h = dim.height;
169 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE)) 160 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE))
170 { 161 {
171// rsvg_handle_close(rsvg, NULL); 162 rsvg_handle_close(rsvg, NULL);
172 g_object_unref(rsvg); 163 g_object_unref(rsvg);
173// rsvg_handle_free(rsvg); 164 if (IMG_TOO_BIG(w, h))
174 chdir(pcwd); 165 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
175 return 0; 166 else
167 *error = EVAS_LOAD_ERROR_GENERIC;
168 return EINA_FALSE;
176 } 169 }
177 if (ie->load_opts.scale_down_by > 1) 170 if (ie->load_opts.scale_down_by > 1)
178 { 171 {
@@ -206,49 +199,42 @@ evas_image_load_file_data_svg(Image_Entry *ie, const char *file, const char *key
206 pixels = evas_cache_image_pixels(ie); 199 pixels = evas_cache_image_pixels(ie);
207 if (!pixels) 200 if (!pixels)
208 { 201 {
209// rsvg_handle_close(rsvg, NULL); 202 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
210 g_object_unref(rsvg); 203 goto error;
211// rsvg_handle_free(rsvg);
212 chdir(pcwd);
213 return 0;
214 } 204 }
215 205
216 memset(pixels, 0, w * h * sizeof(DATA32)); 206 memset(pixels, 0, w * h * sizeof(DATA32));
217
218 surface = cairo_image_surface_create_for_data((unsigned char *)pixels, CAIRO_FORMAT_ARGB32, 207 surface = cairo_image_surface_create_for_data((unsigned char *)pixels, CAIRO_FORMAT_ARGB32,
219 w, h, w * sizeof(DATA32)); 208 w, h, w * sizeof(DATA32));
220 if (!surface) 209 if (!surface)
221 { 210 {
222// rsvg_handle_close(rsvg, NULL); 211 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
223 g_object_unref(rsvg); 212 goto error;
224// rsvg_handle_free(rsvg);
225 chdir(pcwd);
226 return 0;
227 } 213 }
228 cr = cairo_create(surface); 214 cr = cairo_create(surface);
229 if (!cr) 215 if (!cr)
230 { 216 {
231 cairo_surface_destroy(surface); 217 cairo_surface_destroy(surface);
232// rsvg_handle_close(rsvg, NULL); 218 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
233 g_object_unref(rsvg); 219 goto error;
234// rsvg_handle_free(rsvg);
235 chdir(pcwd);
236 return 0;
237 } 220 }
238 221
239 cairo_scale(cr, 222 cairo_scale(cr,
240 (double)ie->w / dim.em, 223 (double)ie->w / dim.em,
241 (double)ie->h / dim.ex); 224 (double)ie->h / dim.ex);
242 rsvg_handle_render_cairo(rsvg, cr); 225 rsvg_handle_render_cairo(rsvg, cr);
243 cairo_surface_destroy(surface); 226 cairo_surface_destroy(surface);
244 /* need to check if this is required... */ 227 /* need to check if this is required... */
245 cairo_destroy(cr); 228 cairo_destroy(cr);
246// rsvg_handle_close(rsvg, NULL); 229 rsvg_handle_close(rsvg, NULL);
247 g_object_unref(rsvg); 230 g_object_unref(rsvg);
248// rsvg_handle_free(rsvg);
249 chdir(pcwd);
250 evas_common_image_set_alpha_sparse(ie); 231 evas_common_image_set_alpha_sparse(ie);
251 return 1; 232 return EINA_TRUE;
233
234 error:
235 rsvg_handle_close(rsvg, NULL);
236 g_object_unref(rsvg);
237 return EINA_FALSE;
252} 238}
253 239
254static int 240static int
diff --git a/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c b/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
index 8d5772a39d..1428c278fa 100644
--- a/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
+++ b/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
@@ -13,8 +13,8 @@
13#include "evas_common.h" 13#include "evas_common.h"
14#include "evas_private.h" 14#include "evas_private.h"
15 15
16static int evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key); 16static Eina_Bool evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
17static int evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key); 17static Eina_Bool evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
18 18
19static Evas_Image_Load_Func evas_image_load_tiff_func = 19static Evas_Image_Load_Func evas_image_load_tiff_func =
20{ 20{
@@ -117,8 +117,8 @@ raster(TIFFRGBAImage_Extra * img, uint32 * rast,
117 } 117 }
118} 118}
119 119
120static int 120static Eina_Bool
121evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__) 121evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
122{ 122{
123 char txt[1024]; 123 char txt[1024];
124 TIFFRGBAImage tiff_image; 124 TIFFRGBAImage tiff_image;
@@ -127,17 +127,18 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
127 int fd; 127 int fd;
128 uint16 magic_number; 128 uint16 magic_number;
129 129
130 if (!file)
131 return 0;
132
133 ffile = fopen(file, "rb"); 130 ffile = fopen(file, "rb");
134 if (!ffile) 131 if (!ffile)
135 return 0; 132 {
133 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
134 return EINA_FALSE;
135 }
136 136
137 if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1) 137 if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1)
138 { 138 {
139 fclose(ffile); 139 fclose(ffile);
140 return 0; 140 *error = EVAS_LOAD_ERROR_GENERIC;
141 return EINA_FALSE;
141 } 142 }
142 /* Apparently rewind(f) isn't sufficient */ 143 /* Apparently rewind(f) isn't sufficient */
143 fseek(ffile, (long)0, SEEK_SET); 144 fseek(ffile, (long)0, SEEK_SET);
@@ -146,7 +147,8 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
146 && (magic_number != TIFF_LITTLEENDIAN)) 147 && (magic_number != TIFF_LITTLEENDIAN))
147 { 148 {
148 fclose(ffile); 149 fclose(ffile);
149 return 0; 150 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
151 return EINA_FALSE;
150 } 152 }
151 153
152 fd = fileno(ffile); 154 fd = fileno(ffile);
@@ -156,19 +158,24 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
156 158
157 tif = TIFFFdOpen(fd, file, "r"); 159 tif = TIFFFdOpen(fd, file, "r");
158 if (!tif) 160 if (!tif)
159 return 0; 161 {
162 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
163 return EINA_FALSE;
164 }
160 165
161 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); 166 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
162 if (!TIFFRGBAImageOK(tif, txt)) 167 if (!TIFFRGBAImageOK(tif, txt))
163 { 168 {
164 TIFFClose(tif); 169 TIFFClose(tif);
165 return 0; 170 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
171 return EINA_FALSE;
166 } 172 }
167 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); 173 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
168 if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt)) 174 if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt))
169 { 175 {
170 TIFFClose(tif); 176 TIFFClose(tif);
171 return 0; 177 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
178 return EINA_FALSE;
172 } 179 }
173 180
174 if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED) 181 if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED)
@@ -178,18 +185,23 @@ evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *ke
178 IMG_TOO_BIG(tiff_image.width, tiff_image.height)) 185 IMG_TOO_BIG(tiff_image.width, tiff_image.height))
179 { 186 {
180 TIFFClose(tif); 187 TIFFClose(tif);
181 return 0; 188 if (IMG_TOO_BIG(tiff_image.width, tiff_image.height))
189 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
190 else
191 *error = EVAS_LOAD_ERROR_GENERIC;
192 return EINA_FALSE;
182 } 193 }
183 ie->w = tiff_image.width; 194 ie->w = tiff_image.width;
184 ie->h = tiff_image.height; 195 ie->h = tiff_image.height;
185 196
186 TIFFRGBAImageEnd(&tiff_image); 197 TIFFRGBAImageEnd(&tiff_image);
187 TIFFClose(tif); 198 TIFFClose(tif);
188 return 1; 199 *error = EVAS_LOAD_ERROR_NONE;
200 return EINA_TRUE;
189} 201}
190 202
191static int 203static Eina_Bool
192evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__) 204evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
193{ 205{
194 char txt[1024]; 206 char txt[1024];
195 TIFFRGBAImage_Extra rgba_image; 207 TIFFRGBAImage_Extra rgba_image;
@@ -200,12 +212,12 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
200 int fd; 212 int fd;
201 uint16 magic_number; 213 uint16 magic_number;
202 214
203 if (!file)
204 return 0;
205
206 ffile = fopen(file, "rb"); 215 ffile = fopen(file, "rb");
207 if (!ffile) 216 if (!ffile)
208 return 0; 217 {
218 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
219 return EINA_FALSE;
220 }
209 221
210 fread(&magic_number, sizeof(uint16), 1, ffile); 222 fread(&magic_number, sizeof(uint16), 1, ffile);
211 /* Apparently rewind(f) isn't sufficient */ 223 /* Apparently rewind(f) isn't sufficient */
@@ -215,7 +227,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
215 && (magic_number != TIFF_LITTLEENDIAN)) 227 && (magic_number != TIFF_LITTLEENDIAN))
216 { 228 {
217 fclose(ffile); 229 fclose(ffile);
218 return 0; 230 *error = EVAS_LOAD_ERROR_GENERIC;
231 return EINA_FALSE;
219 } 232 }
220 233
221 fd = fileno(ffile); 234 fd = fileno(ffile);
@@ -225,19 +238,24 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
225 238
226 tif = TIFFFdOpen(fd, file, "r"); 239 tif = TIFFFdOpen(fd, file, "r");
227 if (!tif) 240 if (!tif)
228 return 0; 241 {
242 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
243 return EINA_FALSE;
244 }
229 245
230 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff"); 246 strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
231 if (!TIFFRGBAImageOK(tif, txt)) 247 if (!TIFFRGBAImageOK(tif, txt))
232 { 248 {
233 TIFFClose(tif); 249 TIFFClose(tif);
234 return 0; 250 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
251 return EINA_FALSE;
235 } 252 }
236 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff"); 253 strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
237 if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt)) 254 if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt))
238 { 255 {
239 TIFFClose(tif); 256 TIFFClose(tif);
240 return 0; 257 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
258 return EINA_FALSE;
241 } 259 }
242 rgba_image.image = ie; 260 rgba_image.image = ie;
243 261
@@ -247,7 +265,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
247 (rgba_image.rgba.height != ie->h)) 265 (rgba_image.rgba.height != ie->h))
248 { 266 {
249 TIFFClose(tif); 267 TIFFClose(tif);
250 return 0; 268 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
269 return EINA_FALSE;
251 } 270 }
252 271
253 evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height); 272 evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height);
@@ -255,8 +274,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
255 { 274 {
256 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); 275 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
257 TIFFClose(tif); 276 TIFFClose(tif);
258 277 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
259 return 0; 278 return EINA_FALSE;
260 } 279 }
261 280
262 rgba_image.num_pixels = num_pixels = ie->w * ie->h; 281 rgba_image.num_pixels = num_pixels = ie->w * ie->h;
@@ -267,11 +286,11 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
267 if (!rast) 286 if (!rast)
268 { 287 {
269 ERR("Evas Tiff loader: out of memory"); 288 ERR("Evas Tiff loader: out of memory");
270 289
271 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); 290 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
272 TIFFClose(tif); 291 TIFFClose(tif);
273 292 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
274 return 0; 293 return EINA_FALSE;
275 } 294 }
276 295
277 if (rgba_image.rgba.put.any == NULL) 296 if (rgba_image.rgba.put.any == NULL)
@@ -282,7 +301,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
282 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); 301 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
283 TIFFClose(tif); 302 TIFFClose(tif);
284 303
285 return 0; 304 *error = EVAS_LOAD_ERROR_GENERIC;
305 return EINA_FALSE;
286 } 306 }
287 else 307 else
288 { 308 {
@@ -307,7 +327,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
307 _TIFFfree(rast); 327 _TIFFfree(rast);
308 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image); 328 TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
309 TIFFClose(tif); 329 TIFFClose(tif);
310 return 0; 330 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
331 return EINA_FALSE;
311 } 332 }
312 } 333 }
313 else 334 else
@@ -322,7 +343,8 @@ evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *ke
322 TIFFClose(tif); 343 TIFFClose(tif);
323 344
324 evas_common_image_set_alpha_sparse(ie); 345 evas_common_image_set_alpha_sparse(ie);
325 return 1; 346 *error = EVAS_LOAD_ERROR_NONE;
347 return EINA_TRUE;
326} 348}
327 349
328static int 350static int
diff --git a/legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c b/legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
index 46d1424dd4..b7af63ed58 100644
--- a/legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
+++ b/legacy/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
@@ -10,8 +10,8 @@
10#include "evas_common.h" 10#include "evas_common.h"
11#include "evas_private.h" 11#include "evas_private.h"
12 12
13static int evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key); 13static Eina_Bool evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
14static int evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key); 14static Eina_Bool evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
15 15
16static Evas_Image_Load_Func evas_image_load_xpm_func = 16static Evas_Image_Load_Func evas_image_load_xpm_func =
17{ 17{
@@ -19,6 +19,7 @@ static Evas_Image_Load_Func evas_image_load_xpm_func =
19 evas_image_load_file_data_xpm 19 evas_image_load_file_data_xpm
20}; 20};
21 21
22// TODO: REWRITE THIS WITH THREAD SAFE VERSION NOT USING THIS HANDLE!!!!
22static FILE *rgb_txt = NULL; 23static FILE *rgb_txt = NULL;
23 24
24static void 25static void
@@ -103,8 +104,8 @@ xpm_parse_done(void)
103 104
104 105
105/** FIXME: clean this up and make more efficient **/ 106/** FIXME: clean this up and make more efficient **/
106static int 107static Eina_Bool
107evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UNUSED__, int load_data) 108evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UNUSED__, int load_data, int *error)
108{ 109{
109 DATA32 *ptr, *end; 110 DATA32 *ptr, *end;
110 FILE *f; 111 FILE *f;
@@ -122,7 +123,6 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
122 short lookup[128 - 32][128 - 32]; 123 short lookup[128 - 32][128 - 32];
123 int count, pixels; 124 int count, pixels;
124 125
125 if (!file) return 0;
126 done = 0; 126 done = 0;
127// transp = -1; 127// transp = -1;
128 transp = 1; 128 transp = 1;
@@ -134,13 +134,15 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
134 if (!f) 134 if (!f)
135 { 135 {
136 xpm_parse_done(); 136 xpm_parse_done();
137 return 0; 137 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
138 return EINA_FALSE;
138 } 139 }
139 if (fread(s, 9, 1, f) != 1) 140 if (fread(s, 9, 1, f) != 1)
140 { 141 {
141 fclose(f); 142 fclose(f);
142 xpm_parse_done(); 143 xpm_parse_done();
143 return 0; 144 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
145 return EINA_FALSE;
144 } 146 }
145 rewind(f); 147 rewind(f);
146 s[9] = 0; 148 s[9] = 0;
@@ -148,7 +150,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
148 { 150 {
149 fclose(f); 151 fclose(f);
150 xpm_parse_done(); 152 xpm_parse_done();
151 return 0; 153 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
154 return EINA_FALSE;
152 } 155 }
153 156
154 i = 0; 157 i = 0;
@@ -169,7 +172,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
169 { 172 {
170 fclose(f); 173 fclose(f);
171 xpm_parse_done(); 174 xpm_parse_done();
172 return 0; 175 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
176 return EINA_FALSE;
173 } 177 }
174 178
175 backslash = 0; 179 backslash = 0;
@@ -206,7 +210,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
206 free(line); 210 free(line);
207 fclose(f); 211 fclose(f);
208 xpm_parse_done(); 212 xpm_parse_done();
209 return 0; 213 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
214 return EINA_FALSE;
210 } 215 }
211 if ((ncolors > 32766) || (ncolors < 1)) 216 if ((ncolors > 32766) || (ncolors < 1))
212 { 217 {
@@ -214,7 +219,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
214 free(line); 219 free(line);
215 fclose(f); 220 fclose(f);
216 xpm_parse_done(); 221 xpm_parse_done();
217 return 0; 222 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
223 return EINA_FALSE;
218 } 224 }
219 if ((cpp > 5) || (cpp < 1)) 225 if ((cpp > 5) || (cpp < 1))
220 { 226 {
@@ -222,7 +228,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
222 free(line); 228 free(line);
223 fclose(f); 229 fclose(f);
224 xpm_parse_done(); 230 xpm_parse_done();
225 return 0; 231 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
232 return EINA_FALSE;
226 } 233 }
227 if ((w > IMG_MAX_SIZE) || (w < 1)) 234 if ((w > IMG_MAX_SIZE) || (w < 1))
228 { 235 {
@@ -230,7 +237,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
230 free(line); 237 free(line);
231 fclose(f); 238 fclose(f);
232 xpm_parse_done(); 239 xpm_parse_done();
233 return 0; 240 *error = EVAS_LOAD_ERROR_GENERIC;
241 return EINA_FALSE;
234 } 242 }
235 if ((h > IMG_MAX_SIZE) || (h < 1)) 243 if ((h > IMG_MAX_SIZE) || (h < 1))
236 { 244 {
@@ -238,7 +246,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
238 free(line); 246 free(line);
239 fclose(f); 247 fclose(f);
240 xpm_parse_done(); 248 xpm_parse_done();
241 return 0; 249 *error = EVAS_LOAD_ERROR_GENERIC;
250 return EINA_FALSE;
242 } 251 }
243 if (IMG_TOO_BIG(w, h)) 252 if (IMG_TOO_BIG(w, h))
244 { 253 {
@@ -246,7 +255,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
246 free(line); 255 free(line);
247 fclose(f); 256 fclose(f);
248 xpm_parse_done(); 257 xpm_parse_done();
249 return 0; 258 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
259 return EINA_FALSE;
250 } 260 }
251 261
252 if (!cmap) 262 if (!cmap)
@@ -257,7 +267,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
257 free(line); 267 free(line);
258 fclose(f); 268 fclose(f);
259 xpm_parse_done(); 269 xpm_parse_done();
260 return 0; 270 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
271 return EINA_FALSE;
261 } 272 }
262 } 273 }
263 ie->w = w; 274 ie->w = w;
@@ -383,7 +394,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
383 free(line); 394 free(line);
384 fclose(f); 395 fclose(f);
385 xpm_parse_done(); 396 xpm_parse_done();
386 return 0; 397 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
398 return EINA_FALSE;
387 } 399 }
388 pixels = w * h; 400 pixels = w * h;
389 end = ptr + pixels; 401 end = ptr + pixels;
@@ -394,7 +406,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
394 free(line); 406 free(line);
395 fclose(f); 407 fclose(f);
396 xpm_parse_done(); 408 xpm_parse_done();
397 return 1; 409 *error = EVAS_LOAD_ERROR_NONE;
410 return EINA_TRUE;
398 } 411 }
399 } 412 }
400 else 413 else
@@ -615,20 +628,20 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
615 if (f) fclose(f); 628 if (f) fclose(f);
616 629
617 xpm_parse_done(); 630 xpm_parse_done();
618 631 *error = EVAS_LOAD_ERROR_NONE;
619 return 1; 632 return EINA_TRUE;
620} 633}
621 634
622static int 635static Eina_Bool
623evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key) 636evas_image_load_file_head_xpm(Image_Entry *ie, const char *file, const char *key, int *error)
624{ 637{
625 return evas_image_load_file_xpm(ie, file, key, 0); 638 return evas_image_load_file_xpm(ie, file, key, 0, error);
626} 639}
627 640
628static int 641static Eina_Bool
629evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key) 642evas_image_load_file_data_xpm(Image_Entry *ie, const char *file, const char *key, int *error)
630{ 643{
631 return evas_image_load_file_xpm(ie, file, key, 1); 644 return evas_image_load_file_xpm(ie, file, key, 1, error);
632} 645}
633 646
634static int 647static int