aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/loaders
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/evas/src/modules/loaders/Makefile.in10
-rw-r--r--libraries/evas/src/modules/loaders/TODO5
-rw-r--r--libraries/evas/src/modules/loaders/bmp/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/bmp/evas_image_load_bmp.c485
-rw-r--r--libraries/evas/src/modules/loaders/edb/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c3
-rw-r--r--libraries/evas/src/modules/loaders/eet/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c3
-rw-r--r--libraries/evas/src/modules/loaders/generic/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/generic/evas_image_load_generic.c8
-rw-r--r--libraries/evas/src/modules/loaders/gif/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/gif/evas_image_load_gif.c3
-rw-r--r--libraries/evas/src/modules/loaders/ico/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c216
-rw-r--r--libraries/evas/src/modules/loaders/jpeg/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c3
-rw-r--r--libraries/evas/src/modules/loaders/pmaps/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c54
-rw-r--r--libraries/evas/src/modules/loaders/png/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/png/evas_image_load_png.c3
-rw-r--r--libraries/evas/src/modules/loaders/psd/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/psd/evas_image_load_psd.c264
-rw-r--r--libraries/evas/src/modules/loaders/svg/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/svg/evas_image_load_svg.c3
-rw-r--r--libraries/evas/src/modules/loaders/tga/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/tga/evas_image_load_tga.c3
-rw-r--r--libraries/evas/src/modules/loaders/tiff/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c3
-rw-r--r--libraries/evas/src/modules/loaders/wbmp/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c113
-rw-r--r--libraries/evas/src/modules/loaders/xpm/Makefile.in8
-rw-r--r--libraries/evas/src/modules/loaders/xpm/evas_image_load_xpm.c162
32 files changed, 866 insertions, 595 deletions
diff --git a/libraries/evas/src/modules/loaders/Makefile.in b/libraries/evas/src/modules/loaders/Makefile.in
index 2120a33..454dcd8 100644
--- a/libraries/evas/src/modules/loaders/Makefile.in
+++ b/libraries/evas/src/modules/loaders/Makefile.in
@@ -49,7 +49,7 @@ host_triplet = @host@
49@BUILD_LOADER_WBMP_TRUE@@EVAS_STATIC_BUILD_WBMP_FALSE@am__append_14 = wbmp 49@BUILD_LOADER_WBMP_TRUE@@EVAS_STATIC_BUILD_WBMP_FALSE@am__append_14 = wbmp
50@BUILD_LOADER_XPM_TRUE@@EVAS_STATIC_BUILD_XPM_FALSE@am__append_15 = xpm 50@BUILD_LOADER_XPM_TRUE@@EVAS_STATIC_BUILD_XPM_FALSE@am__append_15 = xpm
51subdir = src/modules/loaders 51subdir = src/modules/loaders
52DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in TODO 52DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
53ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 53ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
54am__aclocal_m4_deps = $(top_srcdir)/m4/efl_attribute.m4 \ 54am__aclocal_m4_deps = $(top_srcdir)/m4/efl_attribute.m4 \
55 $(top_srcdir)/m4/efl_coverage.m4 \ 55 $(top_srcdir)/m4/efl_coverage.m4 \
@@ -222,8 +222,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
222PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 222PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
223PIXMAN_LIBS = @PIXMAN_LIBS@ 223PIXMAN_LIBS = @PIXMAN_LIBS@
224PKG_CONFIG = @PKG_CONFIG@ 224PKG_CONFIG = @PKG_CONFIG@
225PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
226PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
227PNG_CFLAGS = @PNG_CFLAGS@ 225PNG_CFLAGS = @PNG_CFLAGS@
228PNG_LIBS = @PNG_LIBS@ 226PNG_LIBS = @PNG_LIBS@
229RANLIB = @RANLIB@ 227RANLIB = @RANLIB@
@@ -240,6 +238,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
240VALGRIND_LIBS = @VALGRIND_LIBS@ 238VALGRIND_LIBS = @VALGRIND_LIBS@
241VERSION = @VERSION@ 239VERSION = @VERSION@
242VMAJ = @VMAJ@ 240VMAJ = @VMAJ@
241WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
242WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
243WIN32_CFLAGS = @WIN32_CFLAGS@ 243WIN32_CFLAGS = @WIN32_CFLAGS@
244WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 244WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
245XCB_CFLAGS = @XCB_CFLAGS@ 245XCB_CFLAGS = @XCB_CFLAGS@
@@ -321,6 +321,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
321evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 321evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
322evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 322evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
323evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 323evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
324evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
325evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
326evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
327evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
324evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 328evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
325evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 329evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
326evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 330evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/TODO b/libraries/evas/src/modules/loaders/TODO
deleted file mode 100644
index 3b82543..0000000
--- a/libraries/evas/src/modules/loaders/TODO
+++ /dev/null
@@ -1,5 +0,0 @@
1DONE -> bmp tga ico
2id3 gz bz2 <- extraction loaders
3lbm <- aaah amiga days
4ani <- why>
5
diff --git a/libraries/evas/src/modules/loaders/bmp/Makefile.in b/libraries/evas/src/modules/loaders/bmp/Makefile.in
index f2c3e20..943fb74 100644
--- a/libraries/evas/src/modules/loaders/bmp/Makefile.in
+++ b/libraries/evas/src/modules/loaders/bmp/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/bmp/evas_image_load_bmp.c b/libraries/evas/src/modules/loaders/bmp/evas_image_load_bmp.c
index 38e3680..6d15783 100644
--- a/libraries/evas/src/modules/loaders/bmp/evas_image_load_bmp.c
+++ b/libraries/evas/src/modules/loaders/bmp/evas_image_load_bmp.c
@@ -21,50 +21,91 @@ static Evas_Image_Load_Func evas_image_load_bmp_func =
21 EINA_TRUE, 21 EINA_TRUE,
22 evas_image_load_file_head_bmp, 22 evas_image_load_file_head_bmp,
23 evas_image_load_file_data_bmp, 23 evas_image_load_file_data_bmp,
24 NULL 24 NULL,
25 EINA_FALSE
25}; 26};
26 27
27static int 28static Eina_Bool
28read_short(FILE *file, short *ret) 29read_short(unsigned char *map, size_t length, size_t *position, short *ret)
29{ 30{
30 unsigned char b[2]; 31 unsigned char b[2];
31 if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0; 32
33 if (*position + 2 > length) return EINA_FALSE;
34 b[0] = map[(*position)++];
35 b[1] = map[(*position)++];
32 *ret = (b[1] << 8) | b[0]; 36 *ret = (b[1] << 8) | b[0];
33 return 1; 37 return EINA_TRUE;
34} 38}
35 39
36static int 40static Eina_Bool
37read_ushort(FILE *file, unsigned short *ret) 41read_ushort(unsigned char *map, size_t length, size_t *position, unsigned short *ret)
38{ 42{
39 unsigned char b[2]; 43 unsigned char b[2];
40 if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0; 44
45 if (*position + 2 > length) return EINA_FALSE;
46 b[0] = map[(*position)++];
47 b[1] = map[(*position)++];
41 *ret = (b[1] << 8) | b[0]; 48 *ret = (b[1] << 8) | b[0];
42 return 1; 49 return EINA_TRUE;
43} 50}
44 51
45static int 52static Eina_Bool
46read_int(FILE *file, int *ret) 53read_int(unsigned char *map, size_t length, size_t *position, int *ret)
47{ 54{
48 unsigned char b[4]; 55 unsigned char b[4];
49 if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0; 56 int i;
57
58 if (*position + 4 > length) return EINA_FALSE;
59 for (i = 0; i < 4; i++)
60 b[i] = map[(*position)++];
50 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]); 61 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]);
51 return 1; 62 return EINA_TRUE;
52} 63}
53 64
54static int 65static Eina_Bool
55read_uint(FILE *file, unsigned int *ret) 66read_uint(unsigned char *map, size_t length, size_t *position, unsigned int *ret)
56{ 67{
57 unsigned char b[4]; 68 unsigned char b[4];
58 if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0; 69 int i;
70
71 if (*position + 4 > length) return EINA_FALSE;
72 for (i = 0; i < 4; i++)
73 b[i] = map[(*position)++];
59 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]); 74 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]);
60 return 1; 75 return EINA_TRUE;
76}
77
78static Eina_Bool
79read_uchar(unsigned char *map, size_t length, size_t *position, unsigned char *ret)
80{
81 if (*position + 1 > length) return EINA_FALSE;
82 *ret = map[(*position)++];
83 return EINA_TRUE;
84}
85
86static Eina_Bool
87read_skip(size_t length, size_t *position, int skip)
88{
89 if (*position + skip > length) return EINA_FALSE;
90 *position += skip;
91 return EINA_TRUE;
92}
93
94static Eina_Bool
95read_mem(unsigned char *map, size_t length, size_t *position, void *buffer, int size)
96{
97 if (*position + size > length) return EINA_FALSE;
98 memcpy(buffer, map + *position, size);
99 *position += size;
100 return EINA_TRUE;
61} 101}
62 102
63static Eina_Bool 103static Eina_Bool
64evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) 104evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
65{ 105{
66 FILE *f; 106 Eina_File *f;
67 char buf[4096]; 107 void *map = NULL;
108 size_t position = 0;
68 char hasa = 0; 109 char hasa = 0;
69 int w = 0, h = 0, planes = 0, bit_count = 0, 110 int w = 0, h = 0, planes = 0, bit_count = 0,
70 image_size = 0, comp = 0, hdpi = 0, vdpi = 0, 111 image_size = 0, comp = 0, hdpi = 0, vdpi = 0,
@@ -76,7 +117,7 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
76 unsigned int bmpsize; 117 unsigned int bmpsize;
77 unsigned short res1, res2; 118 unsigned short res1, res2;
78 119
79 f = fopen(file, "rb"); 120 f = eina_file_open(file, 0);
80 if (!f) 121 if (!f)
81 { 122 {
82 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 123 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
@@ -84,84 +125,85 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
84 } 125 }
85 126
86 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 127 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
87 fseek(f, 0, SEEK_END); 128 fsize = eina_file_size_get(f);
88 fsize = ftell(f);
89 fseek(f, 0, SEEK_SET);
90 if (fsize < 2) goto close_file; 129 if (fsize < 2) goto close_file;
91 130
92 if (fread(buf, 2, 1, f) != 1) goto close_file; 131 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
93 if (strncmp(buf, "BM", 2)) goto close_file; // magic number 132 if (!map) goto close_file;
133
134 if (strncmp(map, "BM", 2)) goto close_file; // magic number
135 position += 2;
94 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 136 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
95 if (!read_uint(f, &bmpsize)) goto close_file; 137 if (!read_uint(map, fsize, &position, &bmpsize)) goto close_file;
96 if (!read_ushort(f, &res1)) goto close_file; 138 if (!read_ushort(map, fsize, &position, &res1)) goto close_file;
97 if (!read_ushort(f, &res2)) goto close_file; 139 if (!read_ushort(map, fsize, &position, &res2)) goto close_file;
98 if (!read_uint(f, &offset)) goto close_file; 140 if (!read_uint(map, fsize, &position, &offset)) goto close_file;
99 if (!read_uint(f, &head_size)) goto close_file; 141 if (!read_uint(map, fsize, &position, &head_size)) goto close_file;
100 if (head_size == 12) // OS/2 V1 + Windows 3.0 142 if (head_size == 12) // OS/2 V1 + Windows 3.0
101 { 143 {
102 short tmp; 144 short tmp;
103 145
104 if (!read_short(f, &tmp)) goto close_file; 146 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
105 w = tmp; // width 147 w = tmp; // width
106 if (!read_short(f, &tmp)) goto close_file; 148 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
107 h = tmp; // height 149 h = tmp; // height
108 if (!read_short(f, &tmp)) goto close_file; 150 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
109 planes = tmp; // must be 1 151 planes = tmp; // must be 1
110 if (!read_short(f, &tmp)) goto close_file; 152 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
111 bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 153 bit_count = tmp; // bits per pixel: 1, 4, 8 & 24
112 } 154 }
113 else if (head_size == 64) // OS/2 V2 155 else if (head_size == 64) // OS/2 V2
114 { 156 {
115 short tmp; 157 short tmp;
116 int tmp2; 158 int tmp2;
117 159
118 if (!read_int(f, &tmp2)) goto close_file; 160 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
119 w = tmp2; // width 161 w = tmp2; // width
120 if (!read_int(f, &tmp2)) goto close_file; 162 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
121 h = tmp2; // height 163 h = tmp2; // height
122 if (!read_short(f, &tmp)) goto close_file; 164 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
123 planes = tmp; // must be 1 165 planes = tmp; // must be 1
124 if (!read_short(f, &tmp)) goto close_file; 166 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
125 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 167 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
126 if (!read_int(f, &tmp2)) goto close_file; 168 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
127 comp = tmp2; // compression method 169 comp = tmp2; // compression method
128 if (!read_int(f, &tmp2)) goto close_file; 170 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
129 image_size = tmp2; // bitmap data size 171 image_size = tmp2; // bitmap data size
130 if (!read_int(f, &tmp2)) goto close_file; 172 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
131 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 173 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
132 if (!read_int(f, &tmp2)) goto close_file; 174 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
133 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 175 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
134 if (!read_int(f, &tmp2)) goto close_file; 176 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
135 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 177 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
136 if (!read_int(f, &tmp2)) goto close_file; 178 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
137 important_colors = tmp2; // number of important colors - 0 if all 179 important_colors = tmp2; // number of important colors - 0 if all
138 if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header 180 if (!read_skip(fsize, &position, 24)) goto close_file; // skip unused header
139 if (image_size == 0) image_size = fsize - offset; 181 if (image_size == 0) image_size = fsize - offset;
140 } 182 }
141 else if (head_size == 40) // Windows 3.0 + (v3) 183 else if (head_size == 40) // Windows 3.0 + (v3)
142 { 184 {
143 short tmp; 185 short tmp;
144 int tmp2; 186 int tmp2;
145 187
146 if (!read_int(f, &tmp2)) goto close_file; 188 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
147 w = tmp2; // width 189 w = tmp2; // width
148 if (!read_int(f, &tmp2)) goto close_file; 190 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
149 h = tmp2; // height 191 h = tmp2; // height
150 if (!read_short(f, &tmp)) goto close_file; 192 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
151 planes = tmp; // must be 1 193 planes = tmp; // must be 1
152 if (!read_short(f, &tmp)) goto close_file; 194 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
153 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 195 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
154 if (!read_int(f, &tmp2)) goto close_file; 196 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
155 comp = tmp2; // compression method 197 comp = tmp2; // compression method
156 if (!read_int(f, &tmp2)) goto close_file; 198 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
157 image_size = tmp2; // bitmap data size 199 image_size = tmp2; // bitmap data size
158 if (!read_int(f, &tmp2)) goto close_file; 200 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
159 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 201 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
160 if (!read_int(f, &tmp2)) goto close_file; 202 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
161 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 203 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
162 if (!read_int(f, &tmp2)) goto close_file; 204 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
163 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 205 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
164 if (!read_int(f, &tmp2)) goto close_file; 206 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
165 important_colors = tmp2; // number of important colors - 0 if all 207 important_colors = tmp2; // number of important colors - 0 if all
166 if (image_size == 0) image_size = fsize - offset; 208 if (image_size == 0) image_size = fsize - offset;
167 if ((comp == 0) && (bit_count == 32)) hasa = 1; // GIMP seems to store it this way 209 if ((comp == 0) && (bit_count == 32)) hasa = 1; // GIMP seems to store it this way
@@ -170,37 +212,37 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
170 { 212 {
171 short tmp; 213 short tmp;
172 int tmp2; 214 int tmp2;
173 215
174 if (!read_int(f, &tmp2)) goto close_file; 216 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
175 w = tmp2; // width 217 w = tmp2; // width
176 if (!read_int(f, &tmp2)) goto close_file; 218 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
177 h = tmp2; // height 219 h = tmp2; // height
178 if (!read_short(f, &tmp)) goto close_file; 220 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
179 planes = tmp; // must be 1 221 planes = tmp; // must be 1
180 if (!read_short(f, &tmp)) goto close_file; 222 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
181 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 223 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
182 if (!read_int(f, &tmp2)) goto close_file; 224 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
183 comp = tmp2; // compression method 225 comp = tmp2; // compression method
184 if (!read_int(f, &tmp2)) goto close_file; 226 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
185 image_size = tmp2; // bitmap data size 227 image_size = tmp2; // bitmap data size
186 if (!read_int(f, &tmp2)) goto close_file; 228 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
187 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 229 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
188 if (!read_int(f, &tmp2)) goto close_file; 230 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
189 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 231 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
190 if (!read_int(f, &tmp2)) goto close_file; 232 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
191 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 233 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
192 if (!read_int(f, &tmp2)) goto close_file; 234 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
193 important_colors = tmp2; // number of important colors - 0 if all 235 important_colors = tmp2; // number of important colors - 0 if all
194 if (!read_int(f, &tmp2)) goto close_file; 236 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
195 rmask = tmp2; // red mask 237 rmask = tmp2; // red mask
196 if (!read_int(f, &tmp2)) goto close_file; 238 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
197 gmask = tmp2; // green mask 239 gmask = tmp2; // green mask
198 if (!read_int(f, &tmp2)) goto close_file; 240 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
199 bmask = tmp2; // blue mask 241 bmask = tmp2; // blue mask
200 if (!read_int(f, &tmp2)) goto close_file; 242 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
201 amask = tmp2; // alpha mask 243 amask = tmp2; // alpha mask
202 if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie 244 if (!read_skip(fsize, &position, 36)) goto close_file; // skip unused cie
203 if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma 245 if (!read_skip(fsize, &position, 12)) goto close_file; // skip unused gamma
204 if (image_size == 0) image_size = fsize - offset; 246 if (image_size == 0) image_size = fsize - offset;
205 if ((amask) && (bit_count == 32)) hasa = 1; 247 if ((amask) && (bit_count == 32)) hasa = 1;
206 } 248 }
@@ -208,38 +250,38 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
208 { 250 {
209 short tmp; 251 short tmp;
210 int tmp2; 252 int tmp2;
211 253
212 if (!read_int(f, &tmp2)) goto close_file; 254 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
213 w = tmp2; // width 255 w = tmp2; // width
214 if (!read_int(f, &tmp2)) goto close_file; 256 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
215 h = tmp2; // height 257 h = tmp2; // height
216 if (!read_short(f, &tmp)) goto close_file; 258 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
217 planes = tmp; // must be 1 259 planes = tmp; // must be 1
218 if (!read_short(f, &tmp)) goto close_file; 260 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
219 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 261 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
220 if (!read_int(f, &tmp2)) goto close_file; 262 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
221 comp = tmp2; // compression method 263 comp = tmp2; // compression method
222 if (!read_int(f, &tmp2)) goto close_file; 264 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
223 image_size = tmp2; // bitmap data size 265 image_size = tmp2; // bitmap data size
224 if (!read_int(f, &tmp2)) goto close_file; 266 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
225 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 267 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
226 if (!read_int(f, &tmp2)) goto close_file; 268 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
227 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 269 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
228 if (!read_int(f, &tmp2)) goto close_file; 270 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
229 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 271 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
230 if (!read_int(f, &tmp2)) goto close_file; 272 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
231 important_colors = tmp2; // number of important colors - 0 if all 273 important_colors = tmp2; // number of important colors - 0 if all
232 if (!read_int(f, &tmp2)) goto close_file; 274 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
233 rmask = tmp2; // red mask 275 rmask = tmp2; // red mask
234 if (!read_int(f, &tmp2)) goto close_file; 276 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
235 gmask = tmp2; // green mask 277 gmask = tmp2; // green mask
236 if (!read_int(f, &tmp2)) goto close_file; 278 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
237 bmask = tmp2; // blue mask 279 bmask = tmp2; // blue mask
238 if (!read_int(f, &tmp2)) goto close_file; 280 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
239 amask = tmp2; // alpha mask 281 amask = tmp2; // alpha mask
240 if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie 282 if (!read_skip(fsize, &position, 36)) goto close_file; // skip unused cie
241 if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma 283 if (!read_skip(fsize, &position, 12)) goto close_file; // skip unused gamma
242 if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others 284 if (!read_skip(fsize, &position, 16)) goto close_file; // skip others
243 if (image_size == 0) image_size = fsize - offset; 285 if (image_size == 0) image_size = fsize - offset;
244 if ((amask) && (bit_count == 32)) hasa = 1; 286 if ((amask) && (bit_count == 32)) hasa = 1;
245 } 287 }
@@ -251,7 +293,7 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
251 h = -h; 293 h = -h;
252 right_way_up = 1; 294 right_way_up = 1;
253 } 295 }
254 296
255 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || 297 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
256 IMG_TOO_BIG(w, h)) 298 IMG_TOO_BIG(w, h))
257 { 299 {
@@ -327,21 +369,24 @@ evas_image_load_file_head_bmp(Image_Entry *ie, const char *file, const char *key
327 ie->w = w; 369 ie->w = w;
328 ie->h = h; 370 ie->h = h;
329 if (hasa) ie->flags.alpha = 1; 371 if (hasa) ie->flags.alpha = 1;
330 372
331 fclose(f); 373 eina_file_map_free(f, map);
374 eina_file_close(f);
332 *error = EVAS_LOAD_ERROR_NONE; 375 *error = EVAS_LOAD_ERROR_NONE;
333 return EINA_TRUE; 376 return EINA_TRUE;
334 377
335 close_file: 378 close_file:
336 fclose(f); 379 if (map) eina_file_map_free(f, map);
380 eina_file_close(f);
337 return EINA_FALSE; 381 return EINA_FALSE;
338} 382}
339 383
340static Eina_Bool 384static Eina_Bool
341evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) 385evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
342{ 386{
343 FILE *f; 387 Eina_File *f;
344 char buf[4096]; 388 void *map = NULL;
389 size_t position = 0;
345 unsigned char *buffer = NULL, *buffer_end = NULL, *p; 390 unsigned char *buffer = NULL, *buffer_end = NULL, *p;
346 char hasa = 0; 391 char hasa = 0;
347 int x = 0, y = 0, w = 0, h = 0, planes = 0, bit_count = 0, image_size = 0, 392 int x = 0, y = 0, w = 0, h = 0, planes = 0, bit_count = 0, image_size = 0,
@@ -361,96 +406,96 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
361 int row_size = 0; /* Row size is rounded up to a multiple of 4bytes */ 406 int row_size = 0; /* Row size is rounded up to a multiple of 4bytes */
362 int read_line = 0; /* total read line */ 407 int read_line = 0; /* total read line */
363 408
364 409 f = eina_file_open(file, 0);
365 f = fopen(file, "rb");
366 if (!f) 410 if (!f)
367 { 411 {
368 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 412 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
369 return EINA_FALSE; 413 return EINA_FALSE;
370 } 414 }
371 415
372 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 416 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
373 fseek(f, 0, SEEK_END); 417 fsize = eina_file_size_get(f);
374 fsize = ftell(f);
375 fseek(f, 0, SEEK_SET);
376 if (fsize < 2) goto close_file; 418 if (fsize < 2) goto close_file;
419
420 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
421 if (!map) goto close_file;
377 422
378 if (fread(buf, 2, 1, f) != 1) goto close_file; 423 if (strncmp(map, "BM", 2)) goto close_file; // magic number
379 if (strncmp(buf, "BM", 2)) goto close_file; // magic number 424 position += 2;
380 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 425 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
381 if (!read_uint(f, &bmpsize)) goto close_file; 426 if (!read_uint(map, fsize, &position, &bmpsize)) goto close_file;
382 if (!read_ushort(f, &res1)) goto close_file; 427 if (!read_ushort(map, fsize, &position, &res1)) goto close_file;
383 if (!read_ushort(f, &res2)) goto close_file; 428 if (!read_ushort(map, fsize, &position, &res2)) goto close_file;
384 if (!read_uint(f, &offset)) goto close_file; 429 if (!read_uint(map, fsize, &position, &offset)) goto close_file;
385 if (!read_uint(f, &head_size)) goto close_file; 430 if (!read_uint(map, fsize, &position, &head_size)) goto close_file;
386 image_size = fsize - offset; 431 image_size = fsize - offset;
387 if (image_size < 1) goto close_file; 432 if (image_size < 1) goto close_file;
388 433
389 if (head_size == 12) // OS/2 V1 + Windows 3.0 434 if (head_size == 12) // OS/2 V1 + Windows 3.0
390 { 435 {
391 short tmp; 436 short tmp;
392 437
393 if (!read_short(f, &tmp)) goto close_file; 438 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
394 w = tmp; // width 439 w = tmp; // width
395 if (!read_short(f, &tmp)) goto close_file; 440 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
396 h = tmp; // height 441 h = tmp; // height
397 if (!read_short(f, &tmp)) goto close_file; 442 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
398 planes = tmp; // must be 1 443 planes = tmp; // must be 1
399 if (!read_short(f, &tmp)) goto close_file; 444 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
400 bit_count = tmp; // bits per pixel: 1, 4, 8 & 24 445 bit_count = tmp; // bits per pixel: 1, 4, 8 & 24
401 } 446 }
402 else if (head_size == 64) // OS/2 V2 447 else if (head_size == 64) // OS/2 V2
403 { 448 {
404 short tmp; 449 short tmp;
405 int tmp2; 450 int tmp2;
406 451
407 if (!read_int(f, &tmp2)) goto close_file; 452 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
408 w = tmp2; // width 453 w = tmp2; // width
409 if (!read_int(f, &tmp2)) goto close_file; 454 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
410 h = tmp2; // height 455 h = tmp2; // height
411 if (!read_short(f, &tmp)) goto close_file; 456 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
412 planes = tmp; // must be 1 457 planes = tmp; // must be 1
413 if (!read_short(f, &tmp)) goto close_file; 458 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
414 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 459 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
415 if (!read_int(f, &tmp2)) goto close_file; 460 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
416 comp = tmp2; // compression method 461 comp = tmp2; // compression method
417 if (!read_int(f, &tmp2)) goto close_file; 462 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
418 image_size = tmp2; // bitmap data size 463 image_size = tmp2; // bitmap data size
419 if (!read_int(f, &tmp2)) goto close_file; 464 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
420 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 465 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
421 if (!read_int(f, &tmp2)) goto close_file; 466 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
422 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 467 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
423 if (!read_int(f, &tmp2)) goto close_file; 468 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
424 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 469 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
425 if (!read_int(f, &tmp2)) goto close_file; 470 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
426 important_colors = tmp2; // number of important colors - 0 if all 471 important_colors = tmp2; // number of important colors - 0 if all
427 if (fread(buf, 24, 1, f) != 1) goto close_file; // skip unused header 472 if (!read_skip(fsize, &position, 24)) goto close_file; // skip unused header
428 if (image_size == 0) image_size = fsize - offset; 473 if (image_size == 0) image_size = fsize - offset;
429 } 474 }
430 else if (head_size == 40) // Windows 3.0 + (v3) 475 else if (head_size == 40) // Windows 3.0 + (v3)
431 { 476 {
432 short tmp; 477 short tmp;
433 int tmp2; 478 int tmp2;
434 479
435 if (!read_int(f, &tmp2)) goto close_file; 480 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
436 w = tmp2; // width 481 w = tmp2; // width
437 if (!read_int(f, &tmp2)) goto close_file; 482 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
438 h = tmp2; // height 483 h = tmp2; // height
439 if (!read_short(f, &tmp)) goto close_file; 484 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
440 planes = tmp; // must be 1 485 planes = tmp; // must be 1
441 if (!read_short(f, &tmp)) goto close_file; 486 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
442 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 487 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
443 if (!read_int(f, &tmp2)) goto close_file; 488 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
444 comp = tmp2; // compression method 489 comp = tmp2; // compression method
445 if (!read_int(f, &tmp2)) goto close_file; 490 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
446 image_size = tmp2; // bitmap data size 491 image_size = tmp2; // bitmap data size
447 if (!read_int(f, &tmp2)) goto close_file; 492 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
448 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 493 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
449 if (!read_int(f, &tmp2)) goto close_file; 494 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
450 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 495 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
451 if (!read_int(f, &tmp2)) goto close_file; 496 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
452 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 497 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
453 if (!read_int(f, &tmp2)) goto close_file; 498 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
454 important_colors = tmp2; // number of important colors - 0 if all 499 important_colors = tmp2; // number of important colors - 0 if all
455 if (image_size == 0) image_size = fsize - offset; 500 if (image_size == 0) image_size = fsize - offset;
456 if ((comp == 0) && (bit_count == 32)) hasa = 1; // GIMP seems to store it this way 501 if ((comp == 0) && (bit_count == 32)) hasa = 1; // GIMP seems to store it this way
@@ -459,37 +504,37 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
459 { 504 {
460 short tmp; 505 short tmp;
461 int tmp2; 506 int tmp2;
462 507
463 if (!read_int(f, &tmp2)) goto close_file; 508 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
464 w = tmp2; // width 509 w = tmp2; // width
465 if (!read_int(f, &tmp2)) goto close_file; 510 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
466 h = tmp2; // height 511 h = tmp2; // height
467 if (!read_short(f, &tmp)) goto close_file; 512 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
468 planes = tmp; // must be 1 513 planes = tmp; // must be 1
469 if (!read_short(f, &tmp)) goto close_file; 514 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
470 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 515 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
471 if (!read_int(f, &tmp2)) goto close_file; 516 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
472 comp = tmp2; // compression method 517 comp = tmp2; // compression method
473 if (!read_int(f, &tmp2)) goto close_file; 518 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
474 image_size = tmp2; // bitmap data size 519 image_size = tmp2; // bitmap data size
475 if (!read_int(f, &tmp2)) goto close_file; 520 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
476 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 521 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
477 if (!read_int(f, &tmp2)) goto close_file; 522 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
478 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 523 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
479 if (!read_int(f, &tmp2)) goto close_file; 524 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
480 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 525 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
481 if (!read_int(f, &tmp2)) goto close_file; 526 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
482 important_colors = tmp2; // number of important colors - 0 if all 527 important_colors = tmp2; // number of important colors - 0 if all
483 if (!read_int(f, &tmp2)) goto close_file; 528 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
484 rmask = tmp2; // red mask 529 rmask = tmp2; // red mask
485 if (!read_int(f, &tmp2)) goto close_file; 530 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
486 gmask = tmp2; // green mask 531 gmask = tmp2; // green mask
487 if (!read_int(f, &tmp2)) goto close_file; 532 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
488 bmask = tmp2; // blue mask 533 bmask = tmp2; // blue mask
489 if (!read_int(f, &tmp2)) goto close_file; 534 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
490 amask = tmp2; // alpha mask 535 amask = tmp2; // alpha mask
491 if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie 536 if (!read_skip(fsize, &position, 36)) goto close_file; // skip unused cie
492 if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma 537 if (!read_skip(fsize, &position, 12)) goto close_file; // skip unused gamma
493 if (image_size == 0) image_size = fsize - offset; 538 if (image_size == 0) image_size = fsize - offset;
494 if ((amask) && (bit_count == 32)) hasa = 1; 539 if ((amask) && (bit_count == 32)) hasa = 1;
495 } 540 }
@@ -497,38 +542,38 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
497 { 542 {
498 short tmp; 543 short tmp;
499 int tmp2; 544 int tmp2;
500 545
501 if (!read_int(f, &tmp2)) goto close_file; 546 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
502 w = tmp2; // width 547 w = tmp2; // width
503 if (!read_int(f, &tmp2)) goto close_file; 548 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
504 h = tmp2; // height 549 h = tmp2; // height
505 if (!read_short(f, &tmp)) goto close_file; 550 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
506 planes = tmp; // must be 1 551 planes = tmp; // must be 1
507 if (!read_short(f, &tmp)) goto close_file; 552 if (!read_short(map, fsize, &position, &tmp)) goto close_file;
508 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32 553 bit_count = tmp; // bits per pixel: 1, 4, 8, 16, 24 & 32
509 if (!read_int(f, &tmp2)) goto close_file; 554 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
510 comp = tmp2; // compression method 555 comp = tmp2; // compression method
511 if (!read_int(f, &tmp2)) goto close_file; 556 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
512 image_size = tmp2; // bitmap data size 557 image_size = tmp2; // bitmap data size
513 if (!read_int(f, &tmp2)) goto close_file; 558 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
514 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter 559 hdpi = (tmp2 * 254) / 10000; // horizontal pixels/meter
515 if (!read_int(f, &tmp2)) goto close_file; 560 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
516 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter 561 vdpi = (tmp2 * 254) / 10000; // vertical pixles/meter
517 if (!read_int(f, &tmp2)) goto close_file; 562 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
518 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8) 563 palette_size = tmp2; // number of palette colors power (2^n - so 0 - 8)
519 if (!read_int(f, &tmp2)) goto close_file; 564 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
520 important_colors = tmp2; // number of important colors - 0 if all 565 important_colors = tmp2; // number of important colors - 0 if all
521 if (!read_int(f, &tmp2)) goto close_file; 566 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
522 rmask = tmp2; // red mask 567 rmask = tmp2; // red mask
523 if (!read_int(f, &tmp2)) goto close_file; 568 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
524 gmask = tmp2; // green mask 569 gmask = tmp2; // green mask
525 if (!read_int(f, &tmp2)) goto close_file; 570 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
526 bmask = tmp2; // blue mask 571 bmask = tmp2; // blue mask
527 if (!read_int(f, &tmp2)) goto close_file; 572 if (!read_int(map, fsize, &position, &tmp2)) goto close_file;
528 amask = tmp2; // alpha mask 573 amask = tmp2; // alpha mask
529 if (fread(buf, 36, 1, f) != 1) goto close_file; // skip unused cie 574 if (!read_skip(fsize, &position, 36)) goto close_file; // skip unused cie
530 if (fread(buf, 12, 1, f) != 1) goto close_file; // skip unused gamma 575 if (!read_skip(fsize, &position, 12)) goto close_file; // skip unused gamma
531 if (fread(buf, 16, 1, f) != 1) goto close_file; // skip others 576 if (!read_skip(fsize, &position, 16)) goto close_file; // skip others
532 if (image_size == 0) image_size = fsize - offset; 577 if (image_size == 0) image_size = fsize - offset;
533 if ((amask) && (bit_count == 32)) hasa = 1; 578 if ((amask) && (bit_count == 32)) hasa = 1;
534 } 579 }
@@ -605,17 +650,17 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
605 pal = alloca(256 * 4); 650 pal = alloca(256 * 4);
606 for (i = 0; i < pal_num; i++) 651 for (i = 0; i < pal_num; i++)
607 { 652 {
608 if (fread(&b, 1, 1, f) != 1) goto close_file; 653 if (!read_uchar(map, fsize, &position, &b)) goto close_file;
609 if (fread(&g, 1, 1, f) != 1) goto close_file; 654 if (!read_uchar(map, fsize, &position, &g)) goto close_file;
610 if (fread(&r, 1, 1, f) != 1) goto close_file; 655 if (!read_uchar(map, fsize, &position, &r)) goto close_file;
611 if ((head_size != 12) /*&& (palette_size != 0)*/) 656 if ((head_size != 12) /*&& (palette_size != 0)*/)
612 { // OS/2 V1 doesn't do the pad byte 657 { // OS/2 V1 doesn't do the pad byte
613 if (fread(&a, 1, 1, f) != 1) goto close_file; 658 if (!read_uchar(map, fsize, &position, &a)) goto close_file;
614 } 659 }
615 a = 0xff; // fillin a as solid for paletted images 660 a = 0xff; // fillin a as solid for paletted images
616 pal[i] = ARGB_JOIN(a, r, g, b); 661 pal[i] = ARGB_JOIN(a, r, g, b);
617 } 662 }
618 fseek(f, offset, SEEK_SET); 663 position = offset;
619 664
620 if ((scale_ratio == 1) || (comp !=0)) 665 if ((scale_ratio == 1) || (comp !=0))
621 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks 666 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks
@@ -643,11 +688,11 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
643 688
644 if ((scale_ratio == 1) || (comp !=0)) 689 if ((scale_ratio == 1) || (comp !=0))
645 { 690 {
646 if (fread(buffer, image_size, 1, f) != 1) goto close_file; 691 if (!read_mem(map, fsize, &position, buffer, image_size)) goto close_file;
647 } 692 }
648 else 693 else
649 { 694 {
650 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 695 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
651 } 696 }
652 697
653 if (bit_count == 1) 698 if (bit_count == 1)
@@ -715,8 +760,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
715 read_line += scale_ratio; 760 read_line += scale_ratio;
716 if (read_line >= image_h) break; 761 if (read_line >= image_h) break;
717 762
718 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 763 position += row_size * (scale_ratio - 1);
719 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 764 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
720 p = buffer; 765 p = buffer;
721 buffer_end = buffer + row_size; 766 buffer_end = buffer + row_size;
722 } 767 }
@@ -770,8 +815,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
770 read_line += scale_ratio; 815 read_line += scale_ratio;
771 if (read_line >= image_h) break; 816 if (read_line >= image_h) break;
772 817
773 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 818 position += row_size * (scale_ratio - 1);
774 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 819 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
775 p = buffer; 820 p = buffer;
776 buffer_end = buffer + row_size; 821 buffer_end = buffer + row_size;
777 } 822 }
@@ -960,8 +1005,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
960 read_line += scale_ratio; 1005 read_line += scale_ratio;
961 if (read_line >= image_h) break; 1006 if (read_line >= image_h) break;
962 1007
963 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1008 position += row_size * (scale_ratio - 1);
964 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1009 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
965 p = buffer; 1010 p = buffer;
966 buffer_end = buffer + row_size; 1011 buffer_end = buffer + row_size;
967 } 1012 }
@@ -1088,7 +1133,7 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1088 { 1133 {
1089 if (comp == 0) // no compression 1134 if (comp == 0) // no compression
1090 { 1135 {
1091 fseek(f, offset, SEEK_SET); 1136 position = offset;
1092 if (scale_ratio == 1) 1137 if (scale_ratio == 1)
1093 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks 1138 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks
1094 else 1139 else
@@ -1106,11 +1151,11 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1106 p = buffer; 1151 p = buffer;
1107 if (scale_ratio == 1) 1152 if (scale_ratio == 1)
1108 { 1153 {
1109 if (fread(buffer, image_size, 1, f) != 1) goto close_file; 1154 if (!read_mem(map, fsize, &position, buffer, image_size)) goto close_file;
1110 } 1155 }
1111 else 1156 else
1112 { 1157 {
1113 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1158 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1114 } 1159 }
1115 if (bit_count == 16) 1160 if (bit_count == 16)
1116 { 1161 {
@@ -1139,8 +1184,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1139 read_line += scale_ratio; 1184 read_line += scale_ratio;
1140 if (read_line >= image_h) break; 1185 if (read_line >= image_h) break;
1141 1186
1142 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1187 position += row_size * (scale_ratio - 1);
1143 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1188 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1144 p = buffer; 1189 p = buffer;
1145 buffer_end = buffer + row_size; 1190 buffer_end = buffer + row_size;
1146 } 1191 }
@@ -1173,8 +1218,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1173 read_line += scale_ratio; 1218 read_line += scale_ratio;
1174 if (read_line >= image_h) break; 1219 if (read_line >= image_h) break;
1175 1220
1176 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1221 position += row_size * (scale_ratio - 1);
1177 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1222 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1178 p = buffer; 1223 p = buffer;
1179 buffer_end = buffer + row_size; 1224 buffer_end = buffer + row_size;
1180 } 1225 }
@@ -1212,8 +1257,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1212 read_line += scale_ratio; 1257 read_line += scale_ratio;
1213 if (read_line >= image_h) break; 1258 if (read_line >= image_h) break;
1214 1259
1215 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1260 position += row_size * (scale_ratio - 1);
1216 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1261 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1217 p = buffer; 1262 p = buffer;
1218 buffer_end = buffer + row_size; 1263 buffer_end = buffer + row_size;
1219 } 1264 }
@@ -1230,7 +1275,7 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1230 if (hasa) 1275 if (hasa)
1231 { 1276 {
1232 unsigned int *pixend = surface + (w * h); 1277 unsigned int *pixend = surface + (w * h);
1233 1278
1234 for (pix = surface; pix < pixend; pix++) 1279 for (pix = surface; pix < pixend; pix++)
1235 A_VAL(pix) = 0xff; 1280 A_VAL(pix) = 0xff;
1236 } 1281 }
@@ -1241,11 +1286,11 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1241 } 1286 }
1242 else if (comp == 3) // bit field 1287 else if (comp == 3) // bit field
1243 { 1288 {
1244 if (!read_uint(f, &rmask)) goto close_file; 1289 if (!read_uint(map, fsize, &position, &rmask)) goto close_file;
1245 if (!read_uint(f, &gmask)) goto close_file; 1290 if (!read_uint(map, fsize, &position, &gmask)) goto close_file;
1246 if (!read_uint(f, &bmask)) goto close_file; 1291 if (!read_uint(map, fsize, &position, &bmask)) goto close_file;
1247 1292
1248 fseek(f, offset, SEEK_SET); 1293 position = offset;
1249 if (scale_ratio == 1) 1294 if (scale_ratio == 1)
1250 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks 1295 buffer = malloc(image_size + 8); // add 8 for padding to avoid checks
1251 else 1296 else
@@ -1264,14 +1309,14 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1264 p = buffer; 1309 p = buffer;
1265 if (scale_ratio == 1) 1310 if (scale_ratio == 1)
1266 { 1311 {
1267 if (fread(buffer, image_size, 1, f) != 1) goto close_file; 1312 if (!read_mem(map, fsize, &position, buffer, image_size)) goto close_file;
1268 } 1313 }
1269 else 1314 else
1270 { 1315 {
1271 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1316 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1272 } 1317 }
1273 1318
1274 if ((bit_count == 16) && 1319 if ((bit_count == 16) &&
1275 (rmask == 0xf800) && (gmask == 0x07e0) && (bmask == 0x001f) 1320 (rmask == 0xf800) && (gmask == 0x07e0) && (bmask == 0x001f)
1276 ) 1321 )
1277 { 1322 {
@@ -1299,8 +1344,9 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1299 { 1344 {
1300 read_line += scale_ratio; 1345 read_line += scale_ratio;
1301 if (read_line >= image_h) break; 1346 if (read_line >= image_h) break;
1302 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1347
1303 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1348 position += row_size * (scale_ratio - 1);
1349 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1304 p = buffer; 1350 p = buffer;
1305 buffer_end = buffer + row_size; 1351 buffer_end = buffer + row_size;
1306 } 1352 }
@@ -1338,8 +1384,9 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1338 { 1384 {
1339 read_line += scale_ratio; 1385 read_line += scale_ratio;
1340 if (read_line >= image_h) break; 1386 if (read_line >= image_h) break;
1341 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1387
1342 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1388 position += row_size * (scale_ratio - 1);
1389 if (!read_mem(map, fsize, &position, buffer_end, row_size)) goto close_file;
1343 p = buffer; 1390 p = buffer;
1344 buffer_end = buffer + row_size; 1391 buffer_end = buffer + row_size;
1345 } 1392 }
@@ -1375,8 +1422,9 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1375 { 1422 {
1376 read_line += scale_ratio; 1423 read_line += scale_ratio;
1377 if (read_line >= image_h) break; 1424 if (read_line >= image_h) break;
1378 fseek(f, row_size * (scale_ratio - 1), SEEK_CUR); 1425
1379 if (fread(buffer, row_size, 1, f) != 1) goto close_file; 1426 position += row_size * (scale_ratio - 1);
1427 if (!read_mem(map, fsize, &position, buffer, row_size)) goto close_file;
1380 p = buffer; 1428 p = buffer;
1381 buffer_end = buffer + row_size; 1429 buffer_end = buffer + row_size;
1382 } 1430 }
@@ -1404,10 +1452,12 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1404 } 1452 }
1405 else 1453 else
1406 goto close_file; 1454 goto close_file;
1407 1455
1408 if (buffer) free(buffer); 1456 if (buffer) free(buffer);
1409 if (scale_surface) free(scale_surface); 1457 if (scale_surface) free(scale_surface);
1410 fclose(f); 1458
1459 eina_file_map_free(f, map);
1460 eina_file_close(f);
1411 1461
1412 evas_common_image_premul(ie); 1462 evas_common_image_premul(ie);
1413 *error = EVAS_LOAD_ERROR_NONE; 1463 *error = EVAS_LOAD_ERROR_NONE;
@@ -1416,7 +1466,8 @@ evas_image_load_file_data_bmp(Image_Entry *ie, const char *file, const char *key
1416 close_file: 1466 close_file:
1417 if (buffer) free(buffer); 1467 if (buffer) free(buffer);
1418 if (scale_surface) free(scale_surface); 1468 if (scale_surface) free(scale_surface);
1419 fclose(f); 1469 if (map) eina_file_map_free(f, map);
1470 eina_file_close(f);
1420 return EINA_FALSE; 1471 return EINA_FALSE;
1421} 1472}
1422 1473
diff --git a/libraries/evas/src/modules/loaders/edb/Makefile.in b/libraries/evas/src/modules/loaders/edb/Makefile.in
index 38c1fa2..87356b4 100644
--- a/libraries/evas/src/modules/loaders/edb/Makefile.in
+++ b/libraries/evas/src/modules/loaders/edb/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c b/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c
index 94b121e..521161f 100644
--- a/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c
+++ b/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c
@@ -16,7 +16,8 @@ static Evas_Image_Load_Func evas_image_load_edb_func =
16 EINA_TRUE, 16 EINA_TRUE,
17 evas_image_load_file_head_edb, 17 evas_image_load_file_head_edb,
18 evas_image_load_file_data_edb, 18 evas_image_load_file_data_edb,
19 NULL 19 NULL,
20 EINA_FALSE
20}; 21};
21 22
22static Eina_Bool 23static Eina_Bool
diff --git a/libraries/evas/src/modules/loaders/eet/Makefile.in b/libraries/evas/src/modules/loaders/eet/Makefile.in
index 6a6c40e..25a30cf 100644
--- a/libraries/evas/src/modules/loaders/eet/Makefile.in
+++ b/libraries/evas/src/modules/loaders/eet/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c b/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
index a187b9e..f86246a 100644
--- a/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
+++ b/libraries/evas/src/modules/loaders/eet/evas_image_load_eet.c
@@ -16,7 +16,8 @@ Evas_Image_Load_Func evas_image_load_eet_func =
16 EINA_TRUE, 16 EINA_TRUE,
17 evas_image_load_file_head_eet, 17 evas_image_load_file_head_eet,
18 evas_image_load_file_data_eet, 18 evas_image_load_file_data_eet,
19 NULL 19 NULL,
20 EINA_FALSE
20}; 21};
21 22
22 23
diff --git a/libraries/evas/src/modules/loaders/generic/Makefile.in b/libraries/evas/src/modules/loaders/generic/Makefile.in
index 65a0bac..dfd5294 100644
--- a/libraries/evas/src/modules/loaders/generic/Makefile.in
+++ b/libraries/evas/src/modules/loaders/generic/Makefile.in
@@ -232,8 +232,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
232PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 232PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
233PIXMAN_LIBS = @PIXMAN_LIBS@ 233PIXMAN_LIBS = @PIXMAN_LIBS@
234PKG_CONFIG = @PKG_CONFIG@ 234PKG_CONFIG = @PKG_CONFIG@
235PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
236PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
237PNG_CFLAGS = @PNG_CFLAGS@ 235PNG_CFLAGS = @PNG_CFLAGS@
238PNG_LIBS = @PNG_LIBS@ 236PNG_LIBS = @PNG_LIBS@
239RANLIB = @RANLIB@ 237RANLIB = @RANLIB@
@@ -250,6 +248,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
250VALGRIND_LIBS = @VALGRIND_LIBS@ 248VALGRIND_LIBS = @VALGRIND_LIBS@
251VERSION = @VERSION@ 249VERSION = @VERSION@
252VMAJ = @VMAJ@ 250VMAJ = @VMAJ@
251WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
252WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
253WIN32_CFLAGS = @WIN32_CFLAGS@ 253WIN32_CFLAGS = @WIN32_CFLAGS@
254WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 254WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
255XCB_CFLAGS = @XCB_CFLAGS@ 255XCB_CFLAGS = @XCB_CFLAGS@
@@ -331,6 +331,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
331evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 331evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
332evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 332evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
333evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 333evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
334evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
335evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
336evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
337evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
334evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 338evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
335evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 339evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
336evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 340evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/generic/evas_image_load_generic.c b/libraries/evas/src/modules/loaders/generic/evas_image_load_generic.c
index 88c189d..2bbfd3e 100644
--- a/libraries/evas/src/modules/loaders/generic/evas_image_load_generic.c
+++ b/libraries/evas/src/modules/loaders/generic/evas_image_load_generic.c
@@ -24,7 +24,8 @@ Evas_Image_Load_Func evas_image_load_generic_func =
24 EINA_TRUE, 24 EINA_TRUE,
25 evas_image_load_file_head_generic, 25 evas_image_load_file_head_generic,
26 evas_image_load_file_data_generic, 26 evas_image_load_file_data_generic,
27 NULL 27 NULL,
28 EINA_FALSE
28}; 29};
29 30
30static Eina_Bool 31static Eina_Bool
@@ -117,7 +118,7 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
117 int read_data = 0; 118 int read_data = 0;
118 char *tmpfname = NULL, *shmfname = NULL; 119 char *tmpfname = NULL, *shmfname = NULL;
119 DATA32 *body; 120 DATA32 *body;
120 FILE *f; 121 FILE *f = NULL;
121 122
122 libdir = _evas_module_libdir_get(); 123 libdir = _evas_module_libdir_get();
123 cmd_len = strlen(libdir); 124 cmd_len = strlen(libdir);
@@ -125,6 +126,7 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
125 img_loader = alloca(cmd_len + 1); 126 img_loader = alloca(cmd_len + 1);
126 strcpy(img_loader, libdir); 127 strcpy(img_loader, libdir);
127 strcat(img_loader, loader); 128 strcat(img_loader, loader);
129
128 // params excluding file, key and loadopts 130 // params excluding file, key and loadopts
129 cmd_len += 1024; 131 cmd_len += 1024;
130 cmd_len += strlen(file) * 2; 132 cmd_len += strlen(file) * 2;
@@ -188,6 +190,8 @@ _load(Image_Entry *ie, const char *file, const char *key, int *error, Eina_Bool
188 // will interpret shell stuff and path hunt that will then exec the 190 // will interpret shell stuff and path hunt that will then exec the
189 // program itself that will dynamically link that will again 191 // program itself that will dynamically link that will again
190 // parse the arguments and finally do something... 192 // parse the arguments and finally do something...
193 if (access(decoders[try_count], X_OK)) continue;
194
191 strcpy(cmd, decoders[try_count]); 195 strcpy(cmd, decoders[try_count]);
192 strcat(cmd, " "); 196 strcat(cmd, " ");
193 // filename first arg 197 // filename first arg
diff --git a/libraries/evas/src/modules/loaders/gif/Makefile.in b/libraries/evas/src/modules/loaders/gif/Makefile.in
index 7fcd6a7..f32fcf4 100644
--- a/libraries/evas/src/modules/loaders/gif/Makefile.in
+++ b/libraries/evas/src/modules/loaders/gif/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/gif/evas_image_load_gif.c b/libraries/evas/src/modules/loaders/gif/evas_image_load_gif.c
index 976df0d..9cd6f6e 100644
--- a/libraries/evas/src/modules/loaders/gif/evas_image_load_gif.c
+++ b/libraries/evas/src/modules/loaders/gif/evas_image_load_gif.c
@@ -50,7 +50,8 @@ static Evas_Image_Load_Func evas_image_load_gif_func =
50 EINA_TRUE, 50 EINA_TRUE,
51 evas_image_load_file_head_gif, 51 evas_image_load_file_head_gif,
52 evas_image_load_file_data_gif, 52 evas_image_load_file_data_gif,
53 evas_image_load_frame_duration_gif 53 evas_image_load_frame_duration_gif,
54 EINA_FALSE
54}; 55};
55#define byte2_to_int(a,b) (((b)<<8)|(a)) 56#define byte2_to_int(a,b) (((b)<<8)|(a))
56 57
diff --git a/libraries/evas/src/modules/loaders/ico/Makefile.in b/libraries/evas/src/modules/loaders/ico/Makefile.in
index 5c26adf..f65ace0 100644
--- a/libraries/evas/src/modules/loaders/ico/Makefile.in
+++ b/libraries/evas/src/modules/loaders/ico/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c b/libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c
index 17a7f7e..6e31191 100644
--- a/libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c
+++ b/libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c
@@ -19,32 +19,57 @@ static Evas_Image_Load_Func evas_image_load_ico_func =
19 EINA_TRUE, 19 EINA_TRUE,
20 evas_image_load_file_head_ico, 20 evas_image_load_file_head_ico,
21 evas_image_load_file_data_ico, 21 evas_image_load_file_data_ico,
22 NULL 22 NULL,
23 EINA_FALSE
23}; 24};
24 25
25static int 26static Eina_Bool
26read_ushort(FILE *file, unsigned short *ret) 27read_ushort(unsigned char *map, size_t length, size_t *position, unsigned short *ret)
27{ 28{
28 unsigned char b[2]; 29 unsigned char b[2];
29 if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0; 30
31 if (*position + 2 > length) return EINA_FALSE;
32 b[0] = map[(*position)++];
33 b[1] = map[(*position)++];
30 *ret = (b[1] << 8) | b[0]; 34 *ret = (b[1] << 8) | b[0];
31 return 1; 35 return EINA_TRUE;
32} 36}
33 37
34static int 38static Eina_Bool
35read_uint(FILE *file, unsigned int *ret) 39read_uint(unsigned char *map, size_t length, size_t *position, unsigned int *ret)
36{ 40{
37 unsigned char b[4]; 41 unsigned char b[4];
38 if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0; 42 unsigned int i;
43
44 if (*position + 4 > length) return EINA_FALSE;
45 for (i = 0; i < 4; i++)
46 b[i] = map[(*position)++];
39 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]); 47 *ret = ARGB_JOIN(b[3], b[2], b[1], b[0]);
40 return 1; 48 return EINA_TRUE;
49}
50
51static Eina_Bool
52read_uchar(unsigned char *map, size_t length, size_t *position, unsigned char *ret)
53{
54 if (*position + 1 > length) return EINA_FALSE;
55 *ret = map[(*position)++];
56 return EINA_TRUE;
57}
58
59static Eina_Bool
60read_mem(unsigned char *map, size_t length, size_t *position, void *buffer, int size)
61{
62 if (*position + size > length) return EINA_FALSE;
63 memcpy(buffer, map + *position, size);
64 *position += size;
65 return EINA_TRUE;
41} 66}
42 67
43enum 68enum
44{ 69{
45 SMALLEST, 70 SMALLEST,
46 BIGGEST, 71 BIGGEST,
47 SMALLER, 72 SMALLER,
48 BIGGER 73 BIGGER
49}; 74};
50 75
@@ -57,9 +82,11 @@ enum
57static Eina_Bool 82static Eina_Bool
58evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key, int *error) 83evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key, int *error)
59{ 84{
85 Eina_File *f;
86 void *map = NULL;
87 size_t position = 0;
60 unsigned short word; 88 unsigned short word;
61 unsigned char byte; 89 unsigned char byte;
62 FILE *f;
63 int wanted_w = 0, wanted_h = 0, w, h, cols, i, planes = 0, 90 int wanted_w = 0, wanted_h = 0, w, h, cols, i, planes = 0,
64 hot_x = 0, hot_y = 0, bpp = 0, pdelta, search = -1, have_choice = 0, 91 hot_x = 0, hot_y = 0, bpp = 0, pdelta, search = -1, have_choice = 0,
65 hasa = 1; 92 hasa = 1;
@@ -74,7 +101,7 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
74 unsigned int bmoffset, bmsize; 101 unsigned int bmoffset, bmsize;
75 } chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 102 } chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
76 103
77 f = fopen(file, "rb"); 104 f = eina_file_open(file, EINA_FALSE);
78 if (!f) 105 if (!f)
79 { 106 {
80 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 107 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
@@ -82,16 +109,17 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
82 } 109 }
83 110
84 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 111 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
85 fseek(f, 0, SEEK_END); 112 fsize = eina_file_size_get(f);
86 fsize = ftell(f);
87 fseek(f, 0, SEEK_SET);
88 if (fsize < (6 + 16 + 40)) goto close_file; 113 if (fsize < (6 + 16 + 40)) goto close_file;
89 114
115 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
116 if (!map) goto close_file;
117
90 // key: 118 // key:
91 // NULL == highest res 119 // NULL == highest res
92 // biggest == highest res 120 // biggest == highest res
93 // smallest == lowest res 121 // smallest == lowest res
94 // 122 //
95 // smaller == next size SMALLER than load opts WxH (if possible) 123 // smaller == next size SMALLER than load opts WxH (if possible)
96 // bigger == next size BIGGER than load opts WxH (if possible) 124 // bigger == next size BIGGER than load opts WxH (if possible)
97 // more ? 125 // more ?
@@ -103,10 +131,10 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
103 wanted_h = ie->load_opts.h; 131 wanted_h = ie->load_opts.h;
104 search = SMALLER; 132 search = SMALLER;
105 } 133 }
106 134
107 if (!read_ushort(f, &reserved)) goto close_file; 135 if (!read_ushort(map, fsize, &position, &reserved)) goto close_file;
108 if (!read_ushort(f, &type)) goto close_file; 136 if (!read_ushort(map, fsize, &position, &type)) goto close_file;
109 if (!read_ushort(f, &count)) goto close_file; 137 if (!read_ushort(map, fsize, &position, &count)) goto close_file;
110 if (!((reserved == 0) && 138 if (!((reserved == 0) &&
111 ((type == ICON) || (type == CURSOR)) && (count > 0))) 139 ((type == ICON) || (type == CURSOR)) && (count > 0)))
112 goto close_file; 140 goto close_file;
@@ -141,24 +169,25 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
141 } 169 }
142 for (i = 0; i < count; i++) 170 for (i = 0; i < count; i++)
143 { 171 {
144 if (fread(&byte, 1, 1, f) != 1) goto close_file; 172 unsigned char tw = 0, th = 0, tcols = 0;
145 w = byte; 173 if (!read_uchar(map, fsize, &position, &tw)) goto close_file;
174 w = tw;
146 if (w <= 0) w = 256; 175 if (w <= 0) w = 256;
147 if (fread(&byte, 1, 1, f) != 1) goto close_file; 176 if (!read_uchar(map, fsize, &position, &th)) goto close_file;
148 h = byte; 177 h = th;
149 if (h <= 0) h = 256; 178 if (h <= 0) h = 256;
150 if (fread(&byte, 1, 1, f) != 1) goto close_file; 179 if (!read_uchar(map, fsize, &position, &tcols)) goto close_file;
151 cols = byte; 180 cols = tcols;
152 if (cols <= 0) cols = 256; 181 if (cols <= 0) cols = 256;
153 if (fread(&byte, 1, 1, f) != 1) goto close_file; 182 if (!read_uchar(map, fsize, &position, &byte)) goto close_file;
154 if (!read_ushort(f, &word)) goto close_file; 183 if (!read_ushort(map, fsize, &position, &word)) goto close_file;
155 if (type == CURSOR) planes = word; 184 if (type == CURSOR) planes = word;
156 else hot_x = word; 185 else hot_x = word;
157 if (!read_ushort(f, &word)) goto close_file; 186 if (!read_ushort(map, fsize, &position, &word)) goto close_file;
158 if (type == CURSOR) bpp = word; 187 if (type == CURSOR) bpp = word;
159 else hot_y = word; 188 else hot_y = word;
160 if (!read_uint(f, &bmsize)) goto close_file; 189 if (!read_uint(map, fsize, &position, &bmsize)) goto close_file;
161 if (!read_uint(f, &bmoffset)) goto close_file; 190 if (!read_uint(map, fsize, &position, &bmoffset)) goto close_file;
162 if ((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize)) goto close_file; 191 if ((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize)) goto close_file;
163 if (search == BIGGEST) 192 if (search == BIGGEST)
164 { 193 {
@@ -245,7 +274,7 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
245 } 274 }
246 } 275 }
247 if (chosen.bmoffset == 0) goto close_file; 276 if (chosen.bmoffset == 0) goto close_file;
248 if (fseek(f, chosen.bmoffset, SEEK_SET) != 0) goto close_file; 277 position = chosen.bmoffset;
249 278
250 w = chosen.w; 279 w = chosen.w;
251 h = chosen.h; 280 h = chosen.h;
@@ -263,23 +292,28 @@ evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key
263 ie->w = w; 292 ie->w = w;
264 ie->h = h; 293 ie->h = h;
265 if (hasa) ie->flags.alpha = 1; 294 if (hasa) ie->flags.alpha = 1;
266 295
267 fclose(f); 296 eina_file_map_free(f, map);
297 eina_file_close(f);
298
268 *error = EVAS_LOAD_ERROR_NONE; 299 *error = EVAS_LOAD_ERROR_NONE;
269 return EINA_TRUE; 300 return EINA_TRUE;
270 301
271 close_file: 302 close_file:
272 fclose(f); 303 if (map) eina_file_map_free(f, map);
304 eina_file_close(f);
273 return EINA_FALSE; 305 return EINA_FALSE;
274} 306}
275 307
276static Eina_Bool 308static Eina_Bool
277evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key, int *error) 309evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key, int *error)
278{ 310{
311 Eina_File *f;
312 void *map = NULL;
313 size_t position = 0;
279 unsigned short word; 314 unsigned short word;
280 unsigned char byte; 315 unsigned char byte;
281 unsigned int dword; 316 unsigned int dword;
282 FILE *f;
283 int wanted_w = 0, wanted_h = 0, w, h, cols, i, planes = 0, 317 int wanted_w = 0, wanted_h = 0, w, h, cols, i, planes = 0,
284 hot_x = 0, hot_y = 0, bpp = 0, pdelta, search = -1, have_choice = 0, 318 hot_x = 0, hot_y = 0, bpp = 0, pdelta, search = -1, have_choice = 0,
285 stride, pstride, j, right_way_up = 0, diff_size = 0, cols2; 319 stride, pstride, j, right_way_up = 0, diff_size = 0, cols2;
@@ -296,7 +330,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
296 unsigned int bmoffset, bmsize; 330 unsigned int bmoffset, bmsize;
297 } chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 331 } chosen = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
298 332
299 f = fopen(file, "rb"); 333 f = eina_file_open(file, EINA_FALSE);
300 if (!f) 334 if (!f)
301 { 335 {
302 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 336 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
@@ -304,11 +338,12 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
304 } 338 }
305 339
306 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 340 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
307 fseek(f, 0, SEEK_END); 341 fsize = eina_file_size_get(f);
308 fsize = ftell(f);
309 fseek(f, 0, SEEK_SET);
310 if (fsize < (6 + 16 + 40)) goto close_file; 342 if (fsize < (6 + 16 + 40)) goto close_file;
311 343
344 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
345 if (!map) goto close_file;
346
312 // key: 347 // key:
313 // NULL == highest res 348 // NULL == highest res
314 // biggest == highest res 349 // biggest == highest res
@@ -325,11 +360,11 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
325 wanted_h = ie->load_opts.h; 360 wanted_h = ie->load_opts.h;
326 search = SMALLER; 361 search = SMALLER;
327 } 362 }
328 363
329 if (!read_ushort(f, &reserved)) goto close_file; 364 if (!read_ushort(map, fsize, &position, &reserved)) goto close_file;
330 if (!read_ushort(f, &type)) goto close_file; 365 if (!read_ushort(map, fsize, &position, &type)) goto close_file;
331 if (!read_ushort(f, &count)) goto close_file; 366 if (!read_ushort(map, fsize, &position, &count)) goto close_file;
332 if (!((reserved == 0) && 367 if (!((reserved == 0) &&
333 ((type == ICON) || (type == CURSOR)) && (count > 0))) 368 ((type == ICON) || (type == CURSOR)) && (count > 0)))
334 goto close_file; 369 goto close_file;
335 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 370 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
@@ -363,24 +398,25 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
363 } 398 }
364 for (i = 0; i < count; i++) 399 for (i = 0; i < count; i++)
365 { 400 {
366 if (fread(&byte, 1, 1, f) != 1) goto close_file; 401 unsigned char tw = 0, th = 0, tcols = 0;
367 w = byte; 402 if (!read_uchar(map, fsize, &position, &tw)) goto close_file;
403 w = tw;
368 if (w <= 0) w = 256; 404 if (w <= 0) w = 256;
369 if (fread(&byte, 1, 1, f) != 1) goto close_file; 405 if (!read_uchar(map, fsize, &position, &th)) goto close_file;
370 h = byte; 406 h = th;
371 if (h <= 0) h = 256; 407 if (h <= 0) h = 256;
372 if (fread(&byte, 1, 1, f) != 1) goto close_file; 408 if (!read_uchar(map, fsize, &position, &tcols)) goto close_file;
373 cols = byte; 409 cols = tcols;
374 if (cols <= 0) cols = 256; 410 if (cols <= 0) cols = 256;
375 if (fread(&byte, 1, 1, f) != 1) goto close_file; 411 if (!read_uchar(map, fsize, &position, &byte)) goto close_file;
376 if (!read_ushort(f, &word)) goto close_file; 412 if (!read_ushort(map, fsize, &position, &word)) goto close_file;
377 if (type == 1) planes = word; 413 if (type == 1) planes = word;
378 else hot_x = word; 414 else hot_x = word;
379 if (!read_ushort(f, &word)) goto close_file; 415 if (!read_ushort(map, fsize, &position, &word)) goto close_file;
380 if (type == 1) bpp = word; 416 if (type == 1) bpp = word;
381 else hot_y = word; 417 else hot_y = word;
382 if (!read_uint(f, &bmsize)) goto close_file; 418 if (!read_uint(map, fsize, &position, &bmsize)) goto close_file;
383 if (!read_uint(f, &bmoffset)) goto close_file; 419 if (!read_uint(map, fsize, &position, &bmoffset)) goto close_file;
384 if ((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize)) goto close_file; 420 if ((bmsize <= 0) || (bmoffset <= 0) || (bmoffset >= fsize)) goto close_file;
385 if (search == BIGGEST) 421 if (search == BIGGEST)
386 { 422 {
@@ -467,7 +503,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
467 } 503 }
468 } 504 }
469 if (chosen.bmoffset == 0) goto close_file; 505 if (chosen.bmoffset == 0) goto close_file;
470 if (fseek(f, chosen.bmoffset, SEEK_SET) != 0) goto close_file; 506 position = chosen.bmoffset;
471 507
472 w = chosen.w; 508 w = chosen.w;
473 h = chosen.h; 509 h = chosen.h;
@@ -477,8 +513,8 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
477 if (((int)ie->w != w) || ((int)ie->h != h)) goto close_file; 513 if (((int)ie->w != w) || ((int)ie->h != h)) goto close_file;
478 514
479 // read bmp header time... let's do some checking 515 // read bmp header time... let's do some checking
480 if (!read_uint(f, &dword)) goto close_file; // headersize - dont care 516 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // headersize - dont care
481 if (!read_uint(f, &dword)) goto close_file; // width 517 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // width
482 if (dword > 0) 518 if (dword > 0)
483 { 519 {
484 if ((int)dword != w) 520 if ((int)dword != w)
@@ -487,7 +523,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
487 diff_size = 1; 523 diff_size = 1;
488 } 524 }
489 } 525 }
490 if (!read_uint(f, &dword)) goto close_file; // height 526 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // height
491 if (dword > 0) 527 if (dword > 0)
492 { 528 {
493 if ((int)dword != (h * 2)) 529 if ((int)dword != (h * 2))
@@ -503,19 +539,19 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
503 " May be expanded or cropped.", 539 " May be expanded or cropped.",
504 file, ie->w, ie->h, w, h); 540 file, ie->w, ie->h, w, h);
505 } 541 }
506 if (!read_ushort(f, &word)) goto close_file; // planes 542 if (!read_ushort(map, fsize, &position, &word)) goto close_file; // planes
507 planes2 = word; 543 planes2 = word;
508 if (!read_ushort(f, &word)) goto close_file; // bitcount 544 if (!read_ushort(map, fsize, &position, &word)) goto close_file; // bitcount
509 bitcount = word; 545 bitcount = word;
510 if (!read_uint(f, &dword)) goto close_file; // compression 546 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // compression
511 compression = dword; 547 compression = dword;
512 if (!read_uint(f, &dword)) goto close_file; // imagesize 548 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // imagesize
513 imagesize = dword; 549 imagesize = dword;
514 if (!read_uint(f, &dword)) goto close_file; // z pixels per m 550 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // z pixels per m
515 if (!read_uint(f, &dword)) goto close_file; // y pizels per m 551 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // y pizels per m
516 if (!read_uint(f, &dword)) goto close_file; // colors used 552 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // colors used
517 colorsused = dword; 553 colorsused = dword;
518 if (!read_uint(f, &dword)) goto close_file; // colors important 554 if (!read_uint(map, fsize, &position, &dword)) goto close_file; // colors important
519 colorsimportant = dword; 555 colorsimportant = dword;
520 556
521 evas_cache_image_surface_alloc(ie, ie->w, ie->h); 557 evas_cache_image_surface_alloc(ie, ie->w, ie->h);
@@ -545,11 +581,11 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
545 for (i = 0; i < cols; i++) 581 for (i = 0; i < cols; i++)
546 { 582 {
547 unsigned char a, r, g, b; 583 unsigned char a, r, g, b;
548 584
549 if (fread(&b, 1, 1, f) != 1) goto close_file; 585 if (!read_uchar(map, fsize, &position, &b)) goto close_file;
550 if (fread(&g, 1, 1, f) != 1) goto close_file; 586 if (!read_uchar(map, fsize, &position, &g)) goto close_file;
551 if (fread(&r, 1, 1, f) != 1) goto close_file; 587 if (!read_uchar(map, fsize, &position, &r)) goto close_file;
552 if (fread(&a, 1, 1, f) != 1) goto close_file; 588 if (!read_uchar(map, fsize, &position, &a)) goto close_file;
553 a = 0xff; 589 a = 0xff;
554 pal[i] = ARGB_JOIN(a, r, g, b); 590 pal[i] = ARGB_JOIN(a, r, g, b);
555 } 591 }
@@ -563,7 +599,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
563 { 599 {
564 pix = surface + (i * ie->w); 600 pix = surface + (i * ie->w);
565 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 601 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
566 if (fread(pixbuf, pstride, 1, f) != 1) goto close_file; 602 if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
567 p = pixbuf; 603 p = pixbuf;
568 if (i >= (int)ie->h) continue; 604 if (i >= (int)ie->h) continue;
569 for (j = 0; j < w; j++) 605 for (j = 0; j < w; j++)
@@ -613,7 +649,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
613 { 649 {
614 pix = surface + (i * ie->w); 650 pix = surface + (i * ie->w);
615 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 651 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
616 if (fread(pixbuf, pstride, 1, f) != 1) goto close_file; 652 if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
617 p = pixbuf; 653 p = pixbuf;
618 if (i >= (int)ie->h) continue; 654 if (i >= (int)ie->h) continue;
619 for (j = 0; j < w; j++) 655 for (j = 0; j < w; j++)
@@ -639,7 +675,7 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
639 { 675 {
640 pix = surface + (i * ie->w); 676 pix = surface + (i * ie->w);
641 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 677 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
642 if (fread(pixbuf, pstride, 1, f) != 1) goto close_file; 678 if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
643 p = pixbuf; 679 p = pixbuf;
644 if (i >= (int)ie->h) continue; 680 if (i >= (int)ie->h) continue;
645 for (j = 0; j < w; j++) 681 for (j = 0; j < w; j++)
@@ -658,13 +694,13 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
658 { 694 {
659 pix = surface + (i * ie->w); 695 pix = surface + (i * ie->w);
660 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 696 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
661 if (fread(pixbuf, pstride, 1, f) != 1) goto close_file; 697 if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
662 p = pixbuf; 698 p = pixbuf;
663 if (i >= (int)ie->h) continue; 699 if (i >= (int)ie->h) continue;
664 for (j = 0; j < w; j++) 700 for (j = 0; j < w; j++)
665 { 701 {
666 unsigned char a, r, g, b; 702 unsigned char a, r, g, b;
667 703
668 if (j >= (int)ie->w) break; 704 if (j >= (int)ie->w) break;
669 b = p[0]; 705 b = p[0];
670 g = p[1]; 706 g = p[1];
@@ -683,13 +719,13 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
683 { 719 {
684 pix = surface + (i * ie->w); 720 pix = surface + (i * ie->w);
685 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 721 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
686 if (fread(pixbuf, pstride, 1, f) != 1) goto close_file; 722 if (!read_mem(map, fsize, &position, pixbuf, pstride)) goto close_file;
687 p = pixbuf; 723 p = pixbuf;
688 if (i >= (int)ie->h) continue; 724 if (i >= (int)ie->h) continue;
689 for (j = 0; j < w; j++) 725 for (j = 0; j < w; j++)
690 { 726 {
691 unsigned char a, r, g, b; 727 unsigned char a, r, g, b;
692 728
693 if (j >= (int)ie->w) break; 729 if (j >= (int)ie->w) break;
694 b = p[0]; 730 b = p[0];
695 g = p[1]; 731 g = p[1];
@@ -704,13 +740,13 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
704 } 740 }
705 if (!none_zero_alpha) 741 if (!none_zero_alpha)
706 { 742 {
707 if (fread(maskbuf, stride * 4 * h, 1, f) != 1) goto close_file; 743 if (!read_mem(map, fsize, &position, maskbuf, stride * 4 * h)) goto close_file;
708 // apply mask 744 // apply mask
709 pix = surface; 745 pix = surface;
710 for (i = 0; i < h; i++) 746 for (i = 0; i < h; i++)
711 { 747 {
712 unsigned char *m; 748 unsigned char *m;
713 749
714 pix = surface + (i * ie->w); 750 pix = surface + (i * ie->w);
715 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w); 751 if (!right_way_up) pix = surface + ((ie->h - 1 - i) * ie->w);
716 m = maskbuf + (stride * i * 4); 752 m = maskbuf + (stride * i * 4);
@@ -727,15 +763,17 @@ evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key
727 } 763 }
728 } 764 }
729 } 765 }
730 766
731 fclose(f); 767 eina_file_map_free(f, map);
732 768 eina_file_close(f);
769
733 evas_common_image_premul(ie); 770 evas_common_image_premul(ie);
734 *error = EVAS_LOAD_ERROR_NONE; 771 *error = EVAS_LOAD_ERROR_NONE;
735 return EINA_TRUE; 772 return EINA_TRUE;
736 773
737 close_file: 774 close_file:
738 fclose(f); 775 if (map) eina_file_map_free(f, map);
776 eina_file_close(f);
739 return EINA_FALSE; 777 return EINA_FALSE;
740} 778}
741 779
diff --git a/libraries/evas/src/modules/loaders/jpeg/Makefile.in b/libraries/evas/src/modules/loaders/jpeg/Makefile.in
index ce4b194..7c0ca18 100644
--- a/libraries/evas/src/modules/loaders/jpeg/Makefile.in
+++ b/libraries/evas/src/modules/loaders/jpeg/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c b/libraries/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
index 0dbabab..797c76d 100644
--- a/libraries/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
+++ b/libraries/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c
@@ -46,7 +46,8 @@ static Evas_Image_Load_Func evas_image_load_jpeg_func =
46 EINA_TRUE, 46 EINA_TRUE,
47 evas_image_load_file_head_jpeg, 47 evas_image_load_file_head_jpeg,
48 evas_image_load_file_data_jpeg, 48 evas_image_load_file_data_jpeg,
49 NULL 49 NULL,
50 EINA_TRUE
50}; 51};
51 52
52 53
diff --git a/libraries/evas/src/modules/loaders/pmaps/Makefile.in b/libraries/evas/src/modules/loaders/pmaps/Makefile.in
index de7b779..745e79b 100644
--- a/libraries/evas/src/modules/loaders/pmaps/Makefile.in
+++ b/libraries/evas/src/modules/loaders/pmaps/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c b/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
index 9ba8f81..393e407 100644
--- a/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
+++ b/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c
@@ -19,7 +19,8 @@ Evas_Image_Load_Func evas_image_load_pmaps_func = {
19 EINA_TRUE, 19 EINA_TRUE,
20 evas_image_load_file_head_pmaps, 20 evas_image_load_file_head_pmaps,
21 evas_image_load_file_data_pmaps, 21 evas_image_load_file_data_pmaps,
22 NULL 22 NULL,
23 EINA_FALSE
23}; 24};
24 25
25/* The buffer to load pmaps images */ 26/* The buffer to load pmaps images */
@@ -27,7 +28,9 @@ typedef struct Pmaps_Buffer Pmaps_Buffer;
27 28
28struct Pmaps_Buffer 29struct Pmaps_Buffer
29{ 30{
30 FILE *file; 31 Eina_File *file;
32 void *map;
33 size_t position;
31 34
32 /* the buffer */ 35 /* the buffer */
33 DATA8 buffer[FILE_BUFFER_SIZE]; 36 DATA8 buffer[FILE_BUFFER_SIZE];
@@ -160,13 +163,23 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error)
160{ 163{
161 size_t len; 164 size_t len;
162 165
163 b->file = fopen(filename, "rb"); 166 b->file = eina_file_open(filename, EINA_FALSE);
164 if (!b->file) 167 if (!b->file)
165 { 168 {
166 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 169 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
167 return EINA_FALSE; 170 return EINA_FALSE;
168 } 171 }
169 172
173 b->map = eina_file_map_all(b->file, EINA_FILE_SEQUENTIAL);
174 if (!b->map)
175 {
176 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
177 eina_file_close(b->file);
178 b->file = NULL;
179 return EINA_FALSE;
180 }
181
182 b->position = 0;
170 *b->buffer = 0; 183 *b->buffer = 0;
171 *b->unread = 0; 184 *b->unread = 0;
172 b->last_buffer = 0; 185 b->last_buffer = 0;
@@ -177,7 +190,9 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error)
177 if (len < 3) 190 if (len < 3)
178 { 191 {
179 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 192 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
180 fclose(b->file); 193 eina_file_map_free(b->file, b->map);
194 eina_file_close(b->file);
195 b->map = NULL;
181 b->file = NULL; 196 b->file = NULL;
182 return EINA_FALSE; 197 return EINA_FALSE;
183 } 198 }
@@ -197,7 +212,12 @@ static void
197pmaps_buffer_close(Pmaps_Buffer *b) 212pmaps_buffer_close(Pmaps_Buffer *b)
198{ 213{
199 if (b->file) 214 if (b->file)
200 fclose(b->file); 215 {
216 if (b->map) eina_file_map_free(b->file, b->map);
217 b->map = NULL;
218 eina_file_close(b->file);
219 b->file = NULL;
220 }
201} 221}
202 222
203static Eina_Bool 223static Eina_Bool
@@ -295,6 +315,7 @@ static size_t
295pmaps_buffer_plain_update(Pmaps_Buffer *b) 315pmaps_buffer_plain_update(Pmaps_Buffer *b)
296{ 316{
297 size_t r; 317 size_t r;
318 size_t max;
298 319
299 /* if we already are in the last buffer we can not update it */ 320 /* if we already are in the last buffer we can not update it */
300 if (b->last_buffer) 321 if (b->last_buffer)
@@ -304,9 +325,14 @@ pmaps_buffer_plain_update(Pmaps_Buffer *b)
304 * stuff */ 325 * stuff */
305 if (b->unread_len) 326 if (b->unread_len)
306 memcpy(b->buffer, b->unread, b->unread_len); 327 memcpy(b->buffer, b->unread, b->unread_len);
307 328
308 r = fread(&b->buffer[b->unread_len], 1, 329 max = FILE_BUFFER_SIZE - b->unread_len - 1;
309 FILE_BUFFER_SIZE - b->unread_len - 1, b->file) + b->unread_len; 330 if (b->position + max > eina_file_size_get(b->file))
331 max = eina_file_size_get(b->file) - b->position;
332
333 memcpy(&b->buffer[b->unread_len], b->map + b->position, max);
334 b->position += max;
335 r = max + b->unread_len;
310 336
311 /* we haven't read anything nor have we bytes in the unread buffer */ 337 /* we haven't read anything nor have we bytes in the unread buffer */
312 if (r == 0) 338 if (r == 0)
@@ -324,7 +350,7 @@ pmaps_buffer_plain_update(Pmaps_Buffer *b)
324 } 350 }
325 351
326 b->buffer[r] = 0; 352 b->buffer[r] = 0;
327 353
328 b->unread[0] = '\0'; 354 b->unread[0] = '\0';
329 b->unread_len = 0; 355 b->unread_len = 0;
330 356
@@ -339,6 +365,7 @@ static size_t
339pmaps_buffer_raw_update(Pmaps_Buffer *b) 365pmaps_buffer_raw_update(Pmaps_Buffer *b)
340{ 366{
341 size_t r; 367 size_t r;
368 size_t max;
342 369
343 if (b->last_buffer) 370 if (b->last_buffer)
344 return 0; 371 return 0;
@@ -346,8 +373,13 @@ pmaps_buffer_raw_update(Pmaps_Buffer *b)
346 if (b->unread_len) 373 if (b->unread_len)
347 memcpy(b->buffer, b->unread, b->unread_len); 374 memcpy(b->buffer, b->unread, b->unread_len);
348 375
349 r = fread(&b->buffer[b->unread_len], 1, FILE_BUFFER_SIZE - b->unread_len, 376 max = FILE_BUFFER_SIZE - b->unread_len;
350 b->file) + b->unread_len; 377 if (b->position + max > eina_file_size_get(b->file))
378 max = eina_file_size_get(b->file) - b->position;
379
380 memcpy(&b->buffer[b->unread_len], b->map + b->position, max);
381 b->position += max;
382 r = max + b->unread_len;
351 383
352 if (r < FILE_BUFFER_SIZE) 384 if (r < FILE_BUFFER_SIZE)
353 { 385 {
diff --git a/libraries/evas/src/modules/loaders/png/Makefile.in b/libraries/evas/src/modules/loaders/png/Makefile.in
index 0717299..3bd4919 100644
--- a/libraries/evas/src/modules/loaders/png/Makefile.in
+++ b/libraries/evas/src/modules/loaders/png/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/png/evas_image_load_png.c b/libraries/evas/src/modules/loaders/png/evas_image_load_png.c
index a1480ae..3007a57 100644
--- a/libraries/evas/src/modules/loaders/png/evas_image_load_png.c
+++ b/libraries/evas/src/modules/loaders/png/evas_image_load_png.c
@@ -35,7 +35,8 @@ static Evas_Image_Load_Func evas_image_load_png_func =
35 EINA_TRUE, 35 EINA_TRUE,
36 evas_image_load_file_head_png, 36 evas_image_load_file_head_png,
37 evas_image_load_file_data_png, 37 evas_image_load_file_data_png,
38 NULL 38 NULL,
39 EINA_FALSE
39}; 40};
40 41
41static Eina_Bool 42static Eina_Bool
diff --git a/libraries/evas/src/modules/loaders/psd/Makefile.in b/libraries/evas/src/modules/loaders/psd/Makefile.in
index 98d340a..3dc9c38 100644
--- a/libraries/evas/src/modules/loaders/psd/Makefile.in
+++ b/libraries/evas/src/modules/loaders/psd/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/psd/evas_image_load_psd.c b/libraries/evas/src/modules/loaders/psd/evas_image_load_psd.c
index 5a85e17..27f5f24 100644
--- a/libraries/evas/src/modules/loaders/psd/evas_image_load_psd.c
+++ b/libraries/evas/src/modules/loaders/psd/evas_image_load_psd.c
@@ -61,48 +61,57 @@ enum {
61}; 61};
62 62
63static Eina_Bool get_compressed_channels_length(PSD_Header *Head, 63static Eina_Bool get_compressed_channels_length(PSD_Header *Head,
64 FILE *file, 64 const unsigned char *map, size_t length, size_t *position,
65 unsigned short *rle_table, 65 unsigned short *rle_table,
66 unsigned int *chanlen); 66 unsigned int *chanlen);
67 67
68static int 68static int
69read_ushort(FILE *file, unsigned short *ret) 69read_ushort(const unsigned char *map, size_t length, size_t *position, unsigned short *ret)
70{ 70{
71 unsigned char b[2]; 71 if (*position + 2 > length) return 0;
72 if (fread(b, sizeof(unsigned char), 2, file) != 2) return 0;
73 // FIXME: need to check order 72 // FIXME: need to check order
74 *ret = (b[0] << 8) | b[1]; 73 *ret = (map[(*position) + 0] << 8) | map[(*position) + 1];
74 *position += 2;
75 return 1; 75 return 1;
76} 76}
77 77
78static int 78static int
79read_uint(FILE *file, unsigned int *ret) 79read_uint(const unsigned char *map, size_t length, size_t *position, unsigned int *ret)
80{ 80{
81 unsigned char b[4]; 81 if (*position + 4 > length) return 0;
82 if (fread(b, sizeof(unsigned char), 4, file) != 4) return 0;
83 // FIXME: need to check order 82 // FIXME: need to check order
84 *ret = ARGB_JOIN(b[0], b[1], b[2], b[3]); 83 *ret = ARGB_JOIN(map[(*position) + 0], map[(*position) + 1], map[(*position) + 2], map[(*position) + 3]);
84 *position += 4;
85 return 1;
86}
87
88static int
89read_block(const unsigned char *map, size_t length, size_t *position, void *target, size_t size)
90{
91 if (*position + size > length) return 0;
92 memcpy(target, map + *position, size);
93 *position += size;
85 return 1; 94 return 1;
86} 95}
87 96
88// Internal function used to get the Psd header from the current file. 97// Internal function used to get the Psd header from the current file.
89Eina_Bool 98Eina_Bool
90psd_get_header(PSD_Header *header, FILE * file) 99psd_get_header(PSD_Header *header, const unsigned char *map, size_t length, size_t *position)
91{ 100{
92 unsigned short tmp; 101 unsigned short tmp;
93 102
94#define CHECK_RET(Call, Value) \ 103#define CHECK_RET(Call) \
95 if (Call != Value) return EINA_FALSE; 104 if (!Call) return EINA_FALSE;
96 105
97 CHECK_RET(fread(header->signature, sizeof (unsigned char), 4, file), 4); 106 CHECK_RET(read_block(map, length, position, header->signature, 4));
98 CHECK_RET(read_ushort(file, &header->version), 1); 107 CHECK_RET(read_ushort(map, length, position, &header->version));
99 CHECK_RET(fread(header->reserved, sizeof (unsigned char), 6, file), 6); 108 CHECK_RET(read_block(map, length, position, header->reserved, 6));
100 CHECK_RET(read_ushort(file, &header->channels), 1); 109 CHECK_RET(read_ushort(map, length, position, &header->channels));
101 CHECK_RET(read_uint(file, &header->height), 1); 110 CHECK_RET(read_uint(map, length, position, &header->height));
102 CHECK_RET(read_uint(file, &header->width), 1); 111 CHECK_RET(read_uint(map, length, position, &header->width));
103 CHECK_RET(read_ushort(file, &header->depth), 1); 112 CHECK_RET(read_ushort(map, length, position, &header->depth));
104 113
105 CHECK_RET(read_ushort(file, &tmp), 1); 114 CHECK_RET(read_ushort(map, length, position, &tmp));
106 header->mode = tmp; 115 header->mode = tmp;
107 116
108#undef CHECK_RET 117#undef CHECK_RET
@@ -144,20 +153,35 @@ static Eina_Bool
144evas_image_load_file_head_psd(Image_Entry *ie, const char *FileName, 153evas_image_load_file_head_psd(Image_Entry *ie, const char *FileName,
145 const char *key __UNUSED__, int *error) 154 const char *key __UNUSED__, int *error)
146{ 155{
147 FILE *f; 156 Eina_File *f;
157 void *map;
158 size_t length;
159 size_t position;
148 PSD_Header header; 160 PSD_Header header;
149 Eina_Bool correct; 161 Eina_Bool correct;
150 162
151 *error = EVAS_LOAD_ERROR_NONE; 163 *error = EVAS_LOAD_ERROR_NONE;
152 164
153 f = fopen(FileName, "rb"); 165 f = eina_file_open(FileName, 0);
154 if (f == NULL) 166 if (f == NULL)
155 { 167 {
156 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 168 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
157 return EINA_FALSE; 169 return EINA_FALSE;
158 } 170 }
159 correct = psd_get_header(&header, f); 171
160 fclose(f); 172 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
173 length = eina_file_size_get(f);
174 position = 0;
175 if (!map || length < 1)
176 {
177 eina_file_close(f);
178 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
179 return EINA_FALSE;
180 }
181 correct = psd_get_header(&header, map, length, &position);
182
183 eina_file_map_free(f, map);
184 eina_file_close(f);
161 185
162 if (!correct || !is_psd(&header)) 186 if (!correct || !is_psd(&header))
163 { 187 {
@@ -174,7 +198,7 @@ evas_image_load_file_head_psd(Image_Entry *ie, const char *FileName,
174} 198}
175 199
176static unsigned int 200static unsigned int
177read_compressed_channel(FILE* file, 201read_compressed_channel(const unsigned char *map, size_t length, size_t *position,
178 const unsigned int channel_length __UNUSED__, 202 const unsigned int channel_length __UNUSED__,
179 unsigned int size, 203 unsigned int size,
180 unsigned char* channel) 204 unsigned char* channel)
@@ -183,19 +207,18 @@ read_compressed_channel(FILE* file,
183 unsigned int i; 207 unsigned int i;
184 char headbyte, c; 208 char headbyte, c;
185 209
186#define CHECK_RET(Call, Value) \ 210#define CHECK_RET(Call) \
187 if (Call != Value) return READ_COMPRESSED_ERROR_FILE_READ_ERROR; 211 if (!Call) return READ_COMPRESSED_ERROR_FILE_READ_ERROR; \
188 212
189 for (i = 0; i < size; ) 213 for (i = 0; i < size; )
190 { 214 {
191 CHECK_RET(fread(&headbyte, 1, 1, file), 1); 215 CHECK_RET(read_block(map, length, position, &headbyte, 1));
192 216
193 if (headbyte >= 0) 217 if (headbyte >= 0)
194 { 218 {
195 if (i + headbyte > size) 219 if (i + headbyte > size)
196 return READ_COMPRESSED_ERROR_FILE_CORRUPT; 220 return READ_COMPRESSED_ERROR_FILE_CORRUPT;
197 221 CHECK_RET(read_block(map, length, position, channel + i, headbyte + 1));
198 CHECK_RET(fread(channel + i, headbyte + 1, 1, file), 1);
199 222
200 i += headbyte + 1; 223 i += headbyte + 1;
201 } 224 }
@@ -203,14 +226,14 @@ read_compressed_channel(FILE* file,
203 { 226 {
204 int run; 227 int run;
205 228
206 CHECK_RET(fread(&c, 1, 1, file), 1); 229 CHECK_RET(read_block(map, length, position, &c, 1));
207 230
208 run = c; 231 run = c;
209 /* if (run == -1) */ 232 /* if (run == -1) */
210 /* return READ_COMPRESSED_ERROR_FILE_READ_ERROR; */ 233 /* return READ_COMPRESSED_ERROR_FILE_READ_ERROR; */
211 234
212 if (i + (-headbyte + 1) > size) 235 if (i + (-headbyte + 1) > size)
213 return READ_COMPRESSED_ERROR_FILE_CORRUPT; 236 return READ_COMPRESSED_ERROR_FILE_CORRUPT;
214 237
215 memset(channel + i, run, -headbyte + 1); 238 memset(channel + i, run, -headbyte + 1);
216 i += -headbyte + 1; 239 i += -headbyte + 1;
@@ -226,7 +249,7 @@ read_compressed_channel(FILE* file,
226Eina_Bool 249Eina_Bool
227psd_get_data(Image_Entry *ie __UNUSED__, 250psd_get_data(Image_Entry *ie __UNUSED__,
228 PSD_Header *head, 251 PSD_Header *head,
229 FILE *f, 252 const unsigned char *map, size_t length, size_t *position,
230 unsigned char *buffer, Eina_Bool compressed, 253 unsigned char *buffer, Eina_Bool compressed,
231 int *error) 254 int *error)
232{ 255{
@@ -268,13 +291,12 @@ psd_get_data(Image_Entry *ie __UNUSED__,
268 { 291 {
269 free(data); 292 free(data);
270 free(channel); 293 free(channel);
271 fprintf(stderr, "unsupported file format.\n");
272 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 294 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
273 return EINA_FALSE; 295 return EINA_FALSE;
274 } 296 }
275 297
276#define CHECK_RET(Call, Value) \ 298#define CHECK_RET(Call) \
277 if (Call != Value) \ 299 if (!Call) \
278 { \ 300 { \
279 free(data); \ 301 free(data); \
280 free(channel); \ 302 free(channel); \
@@ -289,7 +311,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
289 { 311 {
290 unsigned char *tmp = channel; 312 unsigned char *tmp = channel;
291 313
292 CHECK_RET(fread(tmp, pixels_count, 1, f), 1); 314 CHECK_RET(read_block(map, length, position, tmp, pixels_count));
293 315
294 for (y = 0; y < head->height * bps; y += bps) 316 for (y = 0; y < head->height * bps; y += bps)
295 { 317 {
@@ -306,7 +328,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
306 { 328 {
307 unsigned char *tmp = channel; 329 unsigned char *tmp = channel;
308 330
309 CHECK_RET(fread(channel, pixels_count, 1, f), 1); 331 CHECK_RET(read_block(map, length, position, channel, pixels_count));
310 332
311 for (y = 0; y < head->height * bps; y += bps) 333 for (y = 0; y < head->height * bps; y += bps)
312 { 334 {
@@ -333,7 +355,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
333 { 355 {
334 unsigned short *shortptr = (unsigned short*) channel; 356 unsigned short *shortptr = (unsigned short*) channel;
335 357
336 CHECK_RET(fread(channel, pixels_count * 2, 1, f), 1); 358 CHECK_RET(read_block(map, length, position, channel, pixels_count * 2));
337 359
338 for (y = 0; y < head->height * bps2; y += bps2) 360 for (y = 0; y < head->height * bps2; y += bps2)
339 { 361 {
@@ -350,7 +372,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
350 { 372 {
351 unsigned short *shortptr = (unsigned short*) channel; 373 unsigned short *shortptr = (unsigned short*) channel;
352 374
353 CHECK_RET(fread(channel, pixels_count * 2, 1, f), 1); 375 CHECK_RET(read_block(map, length, position, channel, pixels_count * 2));
354 376
355 for (y = 0; y < head->height * bps2; y += bps2) 377 for (y = 0; y < head->height * bps2; y += bps2)
356 { 378 {
@@ -373,7 +395,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
373 395
374 rle_table = alloca(head->height * head->channel_num * sizeof (unsigned short)); 396 rle_table = alloca(head->height * head->channel_num * sizeof (unsigned short));
375 chanlen = alloca(head->channel_num * sizeof (unsigned int)); 397 chanlen = alloca(head->channel_num * sizeof (unsigned int));
376 if (!get_compressed_channels_length(head, f, rle_table, chanlen)) 398 if (!get_compressed_channels_length(head, map, length, position, rle_table, chanlen))
377 goto file_read_error; 399 goto file_read_error;
378 400
379 for (c = 0; c < numchan; c++) 401 for (c = 0; c < numchan; c++)
@@ -381,7 +403,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
381 unsigned char *tmp = channel; 403 unsigned char *tmp = channel;
382 int err; 404 int err;
383 405
384 err = read_compressed_channel(f, 406 err = read_compressed_channel(map, length, position,
385 chanlen[c], 407 chanlen[c],
386 pixels_count, 408 pixels_count,
387 channel); 409 channel);
@@ -416,7 +438,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
416 unsigned char *tmp = channel; 438 unsigned char *tmp = channel;
417 int err; 439 int err;
418 440
419 err = read_compressed_channel(f, 441 err = read_compressed_channel(map, length, position,
420 chanlen[c], 442 chanlen[c],
421 pixels_count, 443 pixels_count,
422 channel); 444 channel);
@@ -482,7 +504,7 @@ psd_get_data(Image_Entry *ie __UNUSED__,
482Eina_Bool 504Eina_Bool
483get_single_channel(Image_Entry *ie __UNUSED__, 505get_single_channel(Image_Entry *ie __UNUSED__,
484 PSD_Header *head, 506 PSD_Header *head,
485 FILE *f, 507 const unsigned char *map, size_t length, size_t *position,
486 unsigned char *buffer, 508 unsigned char *buffer,
487 Eina_Bool compressed) 509 Eina_Bool compressed)
488{ 510{
@@ -496,29 +518,29 @@ get_single_channel(Image_Entry *ie __UNUSED__,
496 bpc = (head->depth / 8); 518 bpc = (head->depth / 8);
497 pixels_count = head->width * head->height; 519 pixels_count = head->width * head->height;
498 520
499#define CHECK_RET(Call, Value) \ 521#define CHECK_RET(Call) \
500 if (Call != Value) return EINA_FALSE; 522 if (!Call) return EINA_FALSE;
501 523
502 if (!compressed) 524 if (!compressed)
503 { 525 {
504 if (bpc == 1) 526 if (bpc == 1)
505 { 527 {
506 CHECK_RET(fread(buffer, pixels_count, 1, f), 1); 528 CHECK_RET(read_block(map, length, position, buffer, pixels_count));
507 } 529 }
508 else 530 else
509 { // Bpc == 2 531 { // Bpc == 2
510 CHECK_RET(fread(buffer, pixels_count * 2, 1, f), 1); 532 CHECK_RET(read_block(map, length, position, buffer, pixels_count * 2));
511 } 533 }
512 } 534 }
513 else 535 else
514 { 536 {
515 for (i = 0; i < (unsigned int)pixels_count; ) 537 for (i = 0; i < (unsigned int)pixels_count; )
516 { 538 {
517 CHECK_RET(fread(&headbyte, 1, 1, f), 1); 539 CHECK_RET(read_block(map, length, position, &headbyte, 1));
518 540
519 if (headbyte >= 0) 541 if (headbyte >= 0)
520 { // && HeadByte <= 127 542 { // && HeadByte <= 127
521 CHECK_RET(fread(buffer + i, headbyte + 1, 1, f), 1); 543 CHECK_RET(read_block(map, length, position, buffer + i, headbyte + 1));
522 544
523 i += headbyte + 1; 545 i += headbyte + 1;
524 } 546 }
@@ -526,7 +548,7 @@ get_single_channel(Image_Entry *ie __UNUSED__,
526 { 548 {
527 int run; 549 int run;
528 550
529 CHECK_RET(fread(&c, 1, 1, f), 1); 551 CHECK_RET(read_block(map, length, position, &c, 1));
530 552
531 run = c; 553 run = c;
532 if (run == -1) return EINA_FALSE; 554 if (run == -1) return EINA_FALSE;
@@ -543,7 +565,7 @@ get_single_channel(Image_Entry *ie __UNUSED__,
543} 565}
544 566
545Eina_Bool 567Eina_Bool
546read_psd_grey(Image_Entry *ie, PSD_Header *head, FILE * f, int *error) 568read_psd_grey(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
547{ 569{
548 unsigned int color_mode, resource_size, misc_info; 570 unsigned int color_mode, resource_size, misc_info;
549 unsigned short compressed; 571 unsigned short compressed;
@@ -552,22 +574,21 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
552 574
553 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 575 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
554 576
555#define CHECK_RET(Call, Value) \ 577#define CHECK_RET(Call) \
556 if (Call != Value) return EINA_FALSE; 578 if (!Call) return EINA_FALSE;
557 579
558 CHECK_RET(read_uint(f, &color_mode), 1); 580 CHECK_RET(read_uint(map, length, position, &color_mode));
559 // Skip over the 'color mode data section' 581 // Skip over the 'color mode data section'
560 CHECK_RET(fseek(f, color_mode, SEEK_CUR), 0); 582 *position += color_mode;
561 583
562 CHECK_RET(read_uint(f, &resource_size), 1); 584 CHECK_RET(read_uint(map, length, position, &resource_size));
563 // Read the 'image resources section' 585 // Read the 'image resources section'
586 *position += resource_size;
564 587
565 CHECK_RET(fseek(f, resource_size, SEEK_CUR), 0); 588 CHECK_RET(read_uint(map, length, position, &misc_info));
589 *position += misc_info;
566 590
567 CHECK_RET(read_uint(f, &misc_info), 1); 591 CHECK_RET(read_ushort(map, length, position, &compressed));
568 CHECK_RET(fseek(f, misc_info, SEEK_CUR), 0);
569
570 CHECK_RET(read_ushort(f, &compressed), 1);
571 592
572 ie->w = head->width; 593 ie->w = head->width;
573 ie->h = head->height; 594 ie->h = head->height;
@@ -599,7 +620,7 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
599 goto cleanup_error; 620 goto cleanup_error;
600 } 621 }
601 622
602 if (!psd_get_data(ie, head, f, surface, compressed, error)) 623 if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
603 goto cleanup_error; 624 goto cleanup_error;
604 625
605 return EINA_TRUE; 626 return EINA_TRUE;
@@ -612,7 +633,7 @@ read_psd_grey(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
612 633
613 634
614Eina_Bool 635Eina_Bool
615read_psd_indexed(Image_Entry *ie, PSD_Header *head, FILE * f, int *error) 636read_psd_indexed(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
616{ 637{
617 unsigned int color_mode, resource_size, misc_info; 638 unsigned int color_mode, resource_size, misc_info;
618 unsigned short compressed; 639 unsigned short compressed;
@@ -620,11 +641,11 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
620 641
621 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 642 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
622 643
623#define CHECK_RET(Call, Value) \ 644#define CHECK_RET(Call) \
624 if (Call != Value) return EINA_FALSE; 645 if (!(Call)) return EINA_FALSE;
625 646
626 CHECK_RET(read_uint(f, &color_mode), 1); 647 CHECK_RET(read_uint(map, length, position, &color_mode));
627 CHECK_RET((color_mode % 3), 0); 648 CHECK_RET(!(color_mode % 3));
628 /* 649 /*
629 Palette = (unsigned char*)malloc(Colormode); 650 Palette = (unsigned char*)malloc(Colormode);
630 if (Palette == NULL) 651 if (Palette == NULL)
@@ -633,16 +654,16 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
633 goto cleanup_error; 654 goto cleanup_error;
634 */ 655 */
635 // Skip over the 'color mode data section' 656 // Skip over the 'color mode data section'
636 CHECK_RET(fseek(f, color_mode, SEEK_CUR), 0); 657 *position += color_mode;
637 658
638 // Read the 'image resources section' 659 // Read the 'image resources section'
639 CHECK_RET(read_uint(f, &resource_size), 1); 660 CHECK_RET(read_uint(map, length, position, &resource_size));
640 CHECK_RET(fseek(f, resource_size, SEEK_CUR), 0); 661 *position += resource_size;
641 662
642 CHECK_RET(read_uint(f, &misc_info), 1); 663 CHECK_RET(read_uint(map, length, position, &misc_info));
643 CHECK_RET(fseek(f, misc_info, SEEK_CUR), 0); 664 *position += misc_info;
644 665
645 CHECK_RET(read_ushort(f, &compressed), 1); 666 CHECK_RET(read_ushort(map, length, position, &compressed));
646 667
647 if (head->channels != 1 || head->depth != 8) 668 if (head->channels != 1 || head->depth != 8)
648 { 669 {
@@ -664,7 +685,7 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
664 return EINA_FALSE; 685 return EINA_FALSE;
665 } 686 }
666 687
667 if (!psd_get_data(ie, head, f, surface, compressed, error)) 688 if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
668 return EINA_FALSE; 689 return EINA_FALSE;
669 return EINA_TRUE; 690 return EINA_TRUE;
670 691
@@ -672,28 +693,28 @@ read_psd_indexed(Image_Entry *ie, PSD_Header *head, FILE * f, int *error)
672} 693}
673 694
674Eina_Bool 695Eina_Bool
675read_psd_rgb(Image_Entry *ie, PSD_Header *head, FILE *f, int *error) 696read_psd_rgb(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
676{ 697{
677 unsigned int color_mode, resource_size, misc_info; 698 unsigned int color_mode, resource_size, misc_info;
678 unsigned short compressed; 699 unsigned short compressed;
679 unsigned int type; 700 unsigned int type;
680 void *surface; 701 void *surface;
681 702
682#define CHECK_RET(Call, Value) \ 703#define CHECK_RET(Call) \
683 if (Call != Value) return EINA_FALSE; 704 if (!Call) return EINA_FALSE;
684 705
685 CHECK_RET(read_uint(f, &color_mode), 1); 706 CHECK_RET(read_uint(map, length, position, &color_mode));
686 // Skip over the 'color mode data section' 707 // Skip over the 'color mode data section'
687 CHECK_RET(fseek(f, color_mode, SEEK_CUR), 0); 708 *position += color_mode;
688 709
689 // Read the 'image resources section' 710 // Read the 'image resources section'
690 CHECK_RET(read_uint(f, &resource_size), 1); 711 CHECK_RET(read_uint(map, length, position, &resource_size));
691 CHECK_RET(fseek(f, resource_size, SEEK_CUR), 0); 712 *position += resource_size;
692 713
693 CHECK_RET(read_uint(f, &misc_info), 1); 714 CHECK_RET(read_uint(map, length, position, &misc_info));
694 CHECK_RET(fseek(f, misc_info, SEEK_CUR), 0); 715 *position += misc_info;
695 716
696 CHECK_RET(read_ushort(f, &compressed), 1); 717 CHECK_RET(read_ushort(map, length, position, &compressed));
697 718
698 head->channel_num = head->channels; 719 head->channel_num = head->channels;
699 720
@@ -722,7 +743,7 @@ read_psd_rgb(Image_Entry *ie, PSD_Header *head, FILE *f, int *error)
722 goto cleanup_error; 743 goto cleanup_error;
723 } 744 }
724 745
725 if (!psd_get_data(ie, head, f, surface, compressed, error)) 746 if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
726 goto cleanup_error; 747 goto cleanup_error;
727 748
728 evas_common_image_premul(ie); 749 evas_common_image_premul(ie);
@@ -735,7 +756,7 @@ read_psd_rgb(Image_Entry *ie, PSD_Header *head, FILE *f, int *error)
735} 756}
736 757
737Eina_Bool 758Eina_Bool
738read_psd_cmyk(Image_Entry *ie, PSD_Header *head, FILE *f, int *error) 759read_psd_cmyk(Image_Entry *ie, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
739{ 760{
740 unsigned int color_mode, resource_size, misc_info, size, i, j, data_size; 761 unsigned int color_mode, resource_size, misc_info, size, i, j, data_size;
741 unsigned short compressed; 762 unsigned short compressed;
@@ -745,21 +766,21 @@ read_psd_cmyk(Image_Entry *ie, PSD_Header *head, FILE *f, int *error)
745 766
746 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 767 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
747 768
748#define CHECK_RET(Call, Value) \ 769#define CHECK_RET(Call) \
749 if (Call != Value) return EINA_FALSE; 770 if (!Call) return EINA_FALSE;
750 771
751 CHECK_RET(read_uint(f, &color_mode), 1); 772 CHECK_RET(read_uint(map, length, position, &color_mode));
752 // Skip over the 'color mode data section' 773 // Skip over the 'color mode data section'
753 CHECK_RET(fseek(f, color_mode, SEEK_CUR), 0); 774 *position += color_mode;
754 775
755 CHECK_RET(read_uint(f, &resource_size), 1); 776 CHECK_RET(read_uint(map, length, position, &resource_size));
756 // Read the 'image resources section' 777 // Read the 'image resources section'
757 CHECK_RET(fseek(f, resource_size, SEEK_CUR), 0); 778 *position += resource_size;
758 779
759 CHECK_RET(read_uint(f, &misc_info), 1); 780 CHECK_RET(read_uint(map, length, position, &misc_info));
760 CHECK_RET(fseek(f, misc_info, SEEK_CUR), 0); 781 *position += misc_info;
761 782
762 CHECK_RET(read_ushort(f, &compressed), 1); 783 CHECK_RET(read_ushort(map, length, position, &compressed));
763 784
764 switch (head->channels) 785 switch (head->channels)
765 { 786 {
@@ -804,14 +825,14 @@ read_psd_cmyk(Image_Entry *ie, PSD_Header *head, FILE *f, int *error)
804 goto cleanup_error; 825 goto cleanup_error;
805 } 826 }
806 827
807 if (!psd_get_data(ie, head, f, surface, compressed, error)) 828 if (!psd_get_data(ie, head, map, length, position, surface, compressed, error))
808 goto cleanup_error; 829 goto cleanup_error;
809 830
810 size = type * ie->w * ie->h; 831 size = type * ie->w * ie->h;
811 kchannel = malloc(size); 832 kchannel = malloc(size);
812 if (kchannel == NULL) 833 if (kchannel == NULL)
813 goto cleanup_error; 834 goto cleanup_error;
814 if (!get_single_channel(ie, head, f, kchannel, compressed)) 835 if (!get_single_channel(ie, head, map, length, position, kchannel, compressed))
815 goto cleanup_error; 836 goto cleanup_error;
816 837
817 data_size = head->channels * type * ie->w * ie->h; 838 data_size = head->channels * type * ie->w * ie->h;
@@ -861,20 +882,34 @@ evas_image_load_file_data_psd(Image_Entry *ie,
861 const char *key __UNUSED__, 882 const char *key __UNUSED__,
862 int *error) 883 int *error)
863{ 884{
864 FILE *f; 885 Eina_File *f;
886 void *map;
887 size_t length;
888 size_t position;
865 PSD_Header header; 889 PSD_Header header;
866 Eina_Bool bpsd = EINA_FALSE; 890 Eina_Bool bpsd = EINA_FALSE;
867 891
868 f = fopen(file, "rb"); 892 f = eina_file_open(file, 0);
869 if (f == NULL) 893 if (f == NULL)
870 { 894 {
871 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 895 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
872 return bpsd; 896 return bpsd;
873 } 897 }
874 898
875 if (!psd_get_header(&header, f) || !is_psd(&header)) 899 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
900 length = eina_file_size_get(f);
901 position = 0;
902 if (!map || length < 1)
903 {
904 eina_file_close(f);
905 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
906 return EINA_FALSE;
907 }
908
909 if (!psd_get_header(&header, map, length, &position) || !is_psd(&header))
876 { 910 {
877 fclose(f); 911 eina_file_map_free(f, map);
912 eina_file_close(f);
878 *error = EVAS_LOAD_ERROR_GENERIC; 913 *error = EVAS_LOAD_ERROR_GENERIC;
879 return EINA_FALSE; 914 return EINA_FALSE;
880 } 915 }
@@ -887,39 +922,39 @@ evas_image_load_file_data_psd(Image_Entry *ie,
887 switch (header.mode) 922 switch (header.mode)
888 { 923 {
889 case PSD_GREYSCALE: // Greyscale 924 case PSD_GREYSCALE: // Greyscale
890 bpsd = read_psd_grey(ie, &header, f, error); 925 bpsd = read_psd_grey(ie, &header, map, length, &position, error);
891 break; 926 break;
892 case PSD_INDEXED: // Indexed 927 case PSD_INDEXED: // Indexed
893 bpsd = read_psd_indexed(ie, &header, f, error); 928 bpsd = read_psd_indexed(ie, &header, map, length, &position, error);
894 break; 929 break;
895 case PSD_RGB: // RGB 930 case PSD_RGB: // RGB
896 bpsd = read_psd_rgb(ie, &header, f, error); 931 bpsd = read_psd_rgb(ie, &header, map, length, &position, error);
897 break; 932 break;
898 case PSD_CMYK: // CMYK 933 case PSD_CMYK: // CMYK
899 bpsd = read_psd_cmyk(ie, &header, f, error); 934 bpsd = read_psd_cmyk(ie, &header, map, length, &position, error);
900 break; 935 break;
901 default : 936 default :
902 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 937 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
903 bpsd = EINA_FALSE; 938 bpsd = EINA_FALSE;
904 } 939 }
905 fclose(f); 940
941 eina_file_map_free(f, map);
942 eina_file_close(f);
906 943
907 return bpsd; 944 return bpsd;
908} 945}
909 946
910static Eina_Bool 947static Eina_Bool
911get_compressed_channels_length(PSD_Header *head, 948get_compressed_channels_length(PSD_Header *head,
912 FILE * file, 949 const unsigned char *map, size_t length, size_t *position,
913 unsigned short *rle_table, 950 unsigned short *rle_table,
914 unsigned int *chanlen) 951 unsigned int *chanlen)
915{ 952{
916 unsigned int j; 953 unsigned int j;
917 unsigned int c; 954 unsigned int c;
918 955
919 if (fread(rle_table, 956 if (!read_block(map, length, position, rle_table,
920 sizeof(unsigned short), 957 sizeof (unsigned short) * head->height * head->channel_num))
921 head->height * head->channel_num,
922 file) != head->height * head->channel_num)
923 return EINA_FALSE; 958 return EINA_FALSE;
924 959
925 memset(chanlen, 0, head->channel_num * sizeof(unsigned int)); 960 memset(chanlen, 0, head->channel_num * sizeof(unsigned int));
@@ -941,7 +976,8 @@ static const Evas_Image_Load_Func evas_image_load_psd_func = {
941 EINA_TRUE, 976 EINA_TRUE,
942 evas_image_load_file_head_psd, 977 evas_image_load_file_head_psd,
943 evas_image_load_file_data_psd, 978 evas_image_load_file_data_psd,
944 NULL 979 NULL,
980 EINA_FALSE
945}; 981};
946 982
947static int 983static int
diff --git a/libraries/evas/src/modules/loaders/svg/Makefile.in b/libraries/evas/src/modules/loaders/svg/Makefile.in
index f81a3c3..b742842 100644
--- a/libraries/evas/src/modules/loaders/svg/Makefile.in
+++ b/libraries/evas/src/modules/loaders/svg/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/svg/evas_image_load_svg.c b/libraries/evas/src/modules/loaders/svg/evas_image_load_svg.c
index f1c8452..dc0fc8d 100644
--- a/libraries/evas/src/modules/loaders/svg/evas_image_load_svg.c
+++ b/libraries/evas/src/modules/loaders/svg/evas_image_load_svg.c
@@ -13,7 +13,8 @@ Evas_Image_Load_Func evas_image_load_svg_func =
13 EINA_FALSE, 13 EINA_FALSE,
14 evas_image_load_file_head_svg, 14 evas_image_load_file_head_svg,
15 evas_image_load_file_data_svg, 15 evas_image_load_file_data_svg,
16 NULL 16 NULL,
17 EINA_FALSE
17}; 18};
18 19
19static int rsvg_initialized = 0; 20static int rsvg_initialized = 0;
diff --git a/libraries/evas/src/modules/loaders/tga/Makefile.in b/libraries/evas/src/modules/loaders/tga/Makefile.in
index 645c77a..4d822d1 100644
--- a/libraries/evas/src/modules/loaders/tga/Makefile.in
+++ b/libraries/evas/src/modules/loaders/tga/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/tga/evas_image_load_tga.c b/libraries/evas/src/modules/loaders/tga/evas_image_load_tga.c
index 61b99f6..9b4073c 100644
--- a/libraries/evas/src/modules/loaders/tga/evas_image_load_tga.c
+++ b/libraries/evas/src/modules/loaders/tga/evas_image_load_tga.c
@@ -65,7 +65,8 @@ static Evas_Image_Load_Func evas_image_load_tga_func =
65 EINA_TRUE, 65 EINA_TRUE,
66 evas_image_load_file_head_tga, 66 evas_image_load_file_head_tga,
67 evas_image_load_file_data_tga, 67 evas_image_load_file_data_tga,
68 NULL 68 NULL,
69 EINA_FALSE
69}; 70};
70 71
71static Eina_Bool 72static Eina_Bool
diff --git a/libraries/evas/src/modules/loaders/tiff/Makefile.in b/libraries/evas/src/modules/loaders/tiff/Makefile.in
index a2deea7..2b102a1 100644
--- a/libraries/evas/src/modules/loaders/tiff/Makefile.in
+++ b/libraries/evas/src/modules/loaders/tiff/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c b/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
index b9bea91..e17d5a6 100644
--- a/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
+++ b/libraries/evas/src/modules/loaders/tiff/evas_image_load_tiff.c
@@ -34,7 +34,8 @@ static Evas_Image_Load_Func evas_image_load_tiff_func =
34 EINA_TRUE, 34 EINA_TRUE,
35 evas_image_load_file_head_tiff, 35 evas_image_load_file_head_tiff,
36 evas_image_load_file_data_tiff, 36 evas_image_load_file_data_tiff,
37 NULL 37 NULL,
38 EINA_FALSE
38}; 39};
39 40
40typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra; 41typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
diff --git a/libraries/evas/src/modules/loaders/wbmp/Makefile.in b/libraries/evas/src/modules/loaders/wbmp/Makefile.in
index 41a3bb9..5c01e1c 100644
--- a/libraries/evas/src/modules/loaders/wbmp/Makefile.in
+++ b/libraries/evas/src/modules/loaders/wbmp/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c b/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c
index fa6fab2..54e28d5 100644
--- a/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c
+++ b/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c
@@ -19,21 +19,22 @@ static Evas_Image_Load_Func evas_image_load_wbmp_func =
19 EINA_TRUE, 19 EINA_TRUE,
20 evas_image_load_file_head_wbmp, 20 evas_image_load_file_head_wbmp,
21 evas_image_load_file_data_wbmp, 21 evas_image_load_file_data_wbmp,
22 NULL 22 NULL,
23 EINA_FALSE
23}; 24};
24 25
25 26
26static int 27static int
27read_mb(unsigned int *data, FILE *f) 28read_mb(unsigned int *data, void *map, size_t length, size_t *position)
28{ 29{
29 int ac = 0, ct; 30 int ac = 0, ct;
30 unsigned char buf; 31 unsigned char buf;
31 32
32 for (ct = 0;;) 33 for (ct = 0;;)
33 { 34 {
34 if ((ct++) == 5) return -1; 35 if ((ct++) == 5) return -1;
35 if ((fread(&buf, 1, 1, f)) < 1) 36 if (*position > length) return -1;
36 return -1; 37 buf = ((unsigned char *) map)[(*position)++];
37 ac = (ac << 7) | (buf & 0x7f); 38 ac = (ac << 7) | (buf & 0x7f);
38 if ((buf & 0x80) == 0) break; 39 if ((buf & 0x80) == 0) break;
39 } 40 }
@@ -44,70 +45,105 @@ read_mb(unsigned int *data, FILE *f)
44static Eina_Bool 45static Eina_Bool
45evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) 46evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
46{ 47{
47 FILE *f; 48 Eina_File *f;
49 void *map = NULL;
50 size_t position = 0;
51 size_t length;
48 unsigned int type, w, h; 52 unsigned int type, w, h;
49 unsigned char fixed_header; 53
50 struct stat statbuf;
51
52 *error = EVAS_LOAD_ERROR_GENERIC; 54 *error = EVAS_LOAD_ERROR_GENERIC;
53 f = fopen(file, "rb"); 55 f = eina_file_open(file, 0);
54 if (!f) 56 if (!f)
55 { 57 {
56 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 58 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
57 return EINA_FALSE; 59 return EINA_FALSE;
58 } 60 }
59 61
60 if (stat(file, &statbuf) == -1) goto bail; 62 length = eina_file_size_get(f);
61 if (read_mb(&type, f) < 0) goto bail; 63 if (length <= 4) goto bail;
62 64
65 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
66 if (!map) goto bail;
67
68 if (read_mb(&type, map, length, &position) < 0) goto bail;
69
63 if (type != 0) 70 if (type != 0)
64 { 71 {
65 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 72 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
66 goto bail; 73 goto bail;
67 } 74 }
68 75
69 if (fread(&fixed_header, 1, 1, f) != 1) goto bail; 76 position++; /* skipping one byte */
70 if (read_mb(&w, f) < 0) goto bail; 77 if (read_mb(&w, map, length, &position) < 0) goto bail;
71 if (read_mb(&h, f) < 0) goto bail; 78 if (read_mb(&h, map, length, &position) < 0) goto bail;
72 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || 79 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
73 IMG_TOO_BIG(w, h)) 80 IMG_TOO_BIG(w, h))
74 { 81 {
75 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 82 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
76 goto bail; 83 goto bail;
77 } 84 }
78 85
79 fclose(f); 86 eina_file_map_free(f, map);
87 eina_file_close(f);
80 ie->w = w; 88 ie->w = w;
81 ie->h = h; 89 ie->h = h;
82 90
83 *error = EVAS_LOAD_ERROR_NONE; 91 *error = EVAS_LOAD_ERROR_NONE;
84 return EINA_TRUE; 92 return EINA_TRUE;
85bail: 93bail:
86 fclose(f); 94 if (map) eina_file_map_free(f, map);
95 eina_file_close(f);
87 return EINA_FALSE; 96 return EINA_FALSE;
88} 97}
89 98
90static Eina_Bool 99static Eina_Bool
91evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) 100evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
92{ 101{
93 FILE *f; 102 Eina_File *f;
94 unsigned int dummy, line_length; 103 void *map = NULL;
104 size_t position = 0;
105 size_t length;
106 unsigned int type, w, h;
107 unsigned int line_length;
95 unsigned char *line = NULL; 108 unsigned char *line = NULL;
96 int cur = 0, x, y; 109 int cur = 0, x, y;
97 DATA32 *dst_data; 110 DATA32 *dst_data;
98 111
99 *error = EVAS_LOAD_ERROR_GENERIC; 112 *error = EVAS_LOAD_ERROR_GENERIC;
100 f = fopen(file, "rb"); 113 f = eina_file_open(file, EINA_FALSE);
101 if (!f) 114 if (!f)
102 { 115 {
103 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 116 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
104 return EINA_FALSE; 117 return EINA_FALSE;
105 } 118 }
106 if (read_mb(&dummy, f) < 0) goto bail; 119
107 if (fread(&dummy, 1, 1, f) != 1) goto bail; 120 length = eina_file_size_get(f);
108 if (read_mb(&dummy, f) < 0) goto bail; 121 if (length <= 4) goto bail;
109 if (read_mb(&dummy, f) < 0) goto bail; 122
110 123 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
124 if (!map) goto bail;
125
126 if (read_mb(&type, map, length, &position) < 0) goto bail;
127 position++; /* skipping one byte */
128 if (read_mb(&w, map, length, &position) < 0) goto bail;
129 if (read_mb(&h, map, length, &position) < 0) goto bail;
130
131 if (type != 0)
132 {
133 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
134 goto bail;
135 }
136
137 if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
138 IMG_TOO_BIG(w, h))
139 {
140 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
141 goto bail;
142 }
143
144 ie->w = w;
145 ie->h = h;
146
111 evas_cache_image_surface_alloc(ie, ie->w, ie->h); 147 evas_cache_image_surface_alloc(ie, ie->w, ie->h);
112 dst_data = evas_cache_image_pixels(ie); 148 dst_data = evas_cache_image_pixels(ie);
113 if (!dst_data) 149 if (!dst_data)
@@ -115,13 +151,14 @@ evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *ke
115 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 151 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
116 goto bail; 152 goto bail;
117 } 153 }
118 154
119 line_length = (ie->w + 7) >> 3; 155 line_length = (ie->w + 7) >> 3;
120 line = alloca(line_length); 156
121
122 for (y = 0; y < (int)ie->h; y++) 157 for (y = 0; y < (int)ie->h; y++)
123 { 158 {
124 if (fread(line, 1, line_length, f) != line_length) goto bail; 159 if (position + line_length > length) goto bail;
160 line = ((unsigned char*) map) + position;
161 position += line_length;
125 for (x = 0; x < (int)ie->w; x++) 162 for (x = 0; x < (int)ie->w; x++)
126 { 163 {
127 int idx = x >> 3; 164 int idx = x >> 3;
@@ -131,11 +168,13 @@ evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *ke
131 cur++; 168 cur++;
132 } 169 }
133 } 170 }
134 fclose(f); 171 eina_file_map_free(f, map);
172 eina_file_close(f);
135 *error = EVAS_LOAD_ERROR_NONE; 173 *error = EVAS_LOAD_ERROR_NONE;
136 return EINA_TRUE; 174 return EINA_TRUE;
137bail: 175bail:
138 fclose(f); 176 if (map) eina_file_map_free(f, map);
177 eina_file_close(f);
139 return EINA_FALSE; 178 return EINA_FALSE;
140} 179}
141 180
diff --git a/libraries/evas/src/modules/loaders/xpm/Makefile.in b/libraries/evas/src/modules/loaders/xpm/Makefile.in
index eba8f60..6383d9e 100644
--- a/libraries/evas/src/modules/loaders/xpm/Makefile.in
+++ b/libraries/evas/src/modules/loaders/xpm/Makefile.in
@@ -231,8 +231,6 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ 231PIXMAN_CFLAGS = @PIXMAN_CFLAGS@
232PIXMAN_LIBS = @PIXMAN_LIBS@ 232PIXMAN_LIBS = @PIXMAN_LIBS@
233PKG_CONFIG = @PKG_CONFIG@ 233PKG_CONFIG = @PKG_CONFIG@
234PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
235PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
236PNG_CFLAGS = @PNG_CFLAGS@ 234PNG_CFLAGS = @PNG_CFLAGS@
237PNG_LIBS = @PNG_LIBS@ 235PNG_LIBS = @PNG_LIBS@
238RANLIB = @RANLIB@ 236RANLIB = @RANLIB@
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
249VALGRIND_LIBS = @VALGRIND_LIBS@ 247VALGRIND_LIBS = @VALGRIND_LIBS@
250VERSION = @VERSION@ 248VERSION = @VERSION@
251VMAJ = @VMAJ@ 249VMAJ = @VMAJ@
250WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@
251WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@
252WIN32_CFLAGS = @WIN32_CFLAGS@ 252WIN32_CFLAGS = @WIN32_CFLAGS@
253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ 253WIN32_CPPFLAGS = @WIN32_CPPFLAGS@
254XCB_CFLAGS = @XCB_CFLAGS@ 254XCB_CFLAGS = @XCB_CFLAGS@
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@
330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ 330evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@
331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ 331evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@
332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ 332evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@
333evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@
334evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@
335evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@
336evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@
333evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ 337evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@
334evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ 338evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@
335evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ 339evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@
diff --git a/libraries/evas/src/modules/loaders/xpm/evas_image_load_xpm.c b/libraries/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
index 3a04f84..c764f6d 100644
--- a/libraries/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
+++ b/libraries/evas/src/modules/loaders/xpm/evas_image_load_xpm.c
@@ -24,16 +24,20 @@ static Evas_Image_Load_Func evas_image_load_xpm_func =
24 EINA_FALSE, 24 EINA_FALSE,
25 evas_image_load_file_head_xpm, 25 evas_image_load_file_head_xpm,
26 evas_image_load_file_data_xpm, 26 evas_image_load_file_data_xpm,
27 NULL 27 NULL,
28 EINA_FALSE
28}; 29};
29 30
30// TODO: REWRITE THIS WITH THREAD SAFE VERSION NOT USING THIS HANDLE!!!! 31static Eina_File *rgb_txt;
31static FILE *rgb_txt = NULL; 32static void *rgb_txt_map;
32 33
33static void 34static void
34xpm_parse_color(char *color, int *r, int *g, int *b) 35xpm_parse_color(char *color, int *r, int *g, int *b)
35{ 36{
36 char buf[4096]; 37 char *tmp;
38 char *max;
39 char *endline;
40 char buf[4096];
37 41
38 /* is a #ff00ff like color */ 42 /* is a #ff00ff like color */
39 if (color[0] == '#') 43 if (color[0] == '#')
@@ -75,20 +79,23 @@ xpm_parse_color(char *color, int *r, int *g, int *b)
75 return; 79 return;
76 } 80 }
77 /* look in rgb txt database */ 81 /* look in rgb txt database */
78 if (!rgb_txt) rgb_txt = fopen("/usr/lib/X11/rgb.txt", "r");
79 if (!rgb_txt) rgb_txt = fopen("/usr/X11/lib/X11/rgb.txt", "r");
80 if (!rgb_txt) rgb_txt = fopen("/usr/X11R6/lib/X11/rgb.txt", "r");
81 if (!rgb_txt) rgb_txt = fopen("/usr/openwin/lib/X11/rgb.txt", "r");
82 if (!rgb_txt) return; 82 if (!rgb_txt) return;
83 fseek(rgb_txt, 0, SEEK_SET); 83 tmp = rgb_txt_map;
84 while (fgets(buf, sizeof(buf), rgb_txt)) 84 max = tmp + eina_file_size_get(rgb_txt);
85
86 while (tmp < max)
85 { 87 {
86 buf[sizeof(buf) - 1] = 0; 88 endline = memchr(tmp, '\n', max - tmp);
87 if (buf[0] != '!') 89 if (!endline) endline = max;
90 if ((*tmp != '!') && ((endline - tmp) < (int) (sizeof(buf) - 1)))
88 { 91 {
89 int rr, gg, bb; 92 int rr, gg, bb;
90 char name[4096]; 93 char name[4096];
91 94
95 /* FIXME: not really efficient */
96 memcpy(buf, tmp, endline - tmp);
97 buf[endline - tmp + 1] = '\0';
98
92 if (sscanf(buf, "%i %i %i %[^\n]", &rr, &gg, &bb, name) == 4) 99 if (sscanf(buf, "%i %i %i %[^\n]", &rr, &gg, &bb, name) == 4)
93 { 100 {
94 if (!strcasecmp(name, color)) 101 if (!strcasecmp(name, color))
@@ -100,33 +107,30 @@ xpm_parse_color(char *color, int *r, int *g, int *b)
100 } 107 }
101 } 108 }
102 } 109 }
110 tmp = endline + 1;
103 } 111 }
104} 112}
105 113
106static void
107xpm_parse_done(void)
108{
109 if (rgb_txt) fclose(rgb_txt);
110 rgb_txt = NULL;
111}
112
113
114/** FIXME: clean this up and make more efficient **/ 114/** FIXME: clean this up and make more efficient **/
115static Eina_Bool 115static Eina_Bool
116evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UNUSED__, int load_data, int *error) 116evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UNUSED__, int load_data, int *error)
117{ 117{
118 DATA32 *ptr, *end; 118 DATA32 *ptr, *end;
119 FILE *f; 119 Eina_File *f;
120 const char *map;
121 size_t length;
122 size_t position;
120 123
121 int pc, c, i, j, k, w, h, ncolors, cpp, comment, transp, 124 int pc, c, i, j, k, w, h, ncolors, cpp, comment, transp,
122 quote, context, len, done, r, g, b, backslash, lu1, lu2; 125 quote, context, len, done, r, g, b, backslash, lu1, lu2;
123 char *line, s[256], tok[128], col[256], *tl; 126 char *line = NULL;
127 char s[256], tok[128], col[256], *tl;
124 int lsz = 256; 128 int lsz = 256;
125 struct _cmap { 129 struct _cmap {
126 char str[6]; 130 char str[6];
127 unsigned char transp; 131 unsigned char transp;
128 short r, g, b; 132 short r, g, b;
129 } *cmap; 133 } *cmap = NULL;
130 134
131 short lookup[128 - 32][128 - 32]; 135 short lookup[128 - 32][128 - 32];
132 int count, pixels; 136 int count, pixels;
@@ -138,30 +142,39 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
138 /* if immediate_load is 1, then dont delay image laoding as below, or */ 142 /* if immediate_load is 1, then dont delay image laoding as below, or */
139 /* already data in this image - dont load it again */ 143 /* already data in this image - dont load it again */
140 144
141 f = fopen(file, "rb"); 145 f = eina_file_open(file, 0);
142 if (!f) 146 if (!f)
143 { 147 {
144 xpm_parse_done(); 148 ERR("XPM ERROR: file failed to open");
145 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 149 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
146 return EINA_FALSE; 150 return EINA_FALSE;
147 } 151 }
148 if (fread(s, 9, 1, f) != 1) 152 length = eina_file_size_get(f);
153 position = 0;
154 if (length < 9)
149 { 155 {
150 fclose(f); 156 ERR("XPM ERROR: file size, %i, is to small", length);
151 xpm_parse_done(); 157 eina_file_close(f);
152 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 158 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
153 return EINA_FALSE; 159 return EINA_FALSE;
154 } 160 }
155 rewind(f); 161
156 s[9] = 0; 162 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
157 if (strcmp("/* XPM */", s)) 163 if (!map)
158 { 164 {
159 fclose(f); 165 ERR("XPM ERROR: file failed to mmap");
160 xpm_parse_done(); 166 eina_file_close(f);
161 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 167 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
162 return EINA_FALSE; 168 return EINA_FALSE;
163 } 169 }
164 170
171 if (strncmp("/* XPM */", map, 9))
172 {
173 ERR("XPM ERROR: header not found");
174 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
175 goto on_error;
176 }
177
165 i = 0; 178 i = 0;
166 j = 0; 179 j = 0;
167 cmap = NULL; 180 cmap = NULL;
@@ -178,10 +191,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
178 line = malloc(lsz); 191 line = malloc(lsz);
179 if (!line) 192 if (!line)
180 { 193 {
181 fclose(f);
182 xpm_parse_done();
183 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 194 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
184 return EINA_FALSE; 195 goto on_error;
185 } 196 }
186 197
187 backslash = 0; 198 backslash = 0;
@@ -189,8 +200,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
189 while (!done) 200 while (!done)
190 { 201 {
191 pc = c; 202 pc = c;
192 c = fgetc(f); 203 if (position == length) break ;
193 if (c == EOF) break; 204 c = (char) map[position++];
194 if (!quote) 205 if (!quote)
195 { 206 {
196 if ((pc == '/') && (c == '*')) 207 if ((pc == '/') && (c == '*'))
@@ -215,56 +226,38 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
215 if (sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp) != 4) 226 if (sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp) != 4)
216 { 227 {
217 ERR("XPM ERROR: XPM file malformed header"); 228 ERR("XPM ERROR: XPM file malformed header");
218 free(line);
219 fclose(f);
220 xpm_parse_done();
221 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 229 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
222 return EINA_FALSE; 230 goto on_error;
223 } 231 }
224 if ((ncolors > 32766) || (ncolors < 1)) 232 if ((ncolors > 32766) || (ncolors < 1))
225 { 233 {
226 ERR("XPM ERROR: XPM files with colors > 32766 or < 1 not supported"); 234 ERR("XPM ERROR: XPM files with colors > 32766 or < 1 not supported");
227 free(line);
228 fclose(f);
229 xpm_parse_done();
230 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 235 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
231 return EINA_FALSE; 236 goto on_error;
232 } 237 }
233 if ((cpp > 5) || (cpp < 1)) 238 if ((cpp > 5) || (cpp < 1))
234 { 239 {
235 ERR("XPM ERROR: XPM files with characters per pixel > 5 or < 1not supported"); 240 ERR("XPM ERROR: XPM files with characters per pixel > 5 or < 1not supported");
236 free(line);
237 fclose(f);
238 xpm_parse_done();
239 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 241 *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
240 return EINA_FALSE; 242 goto on_error;
241 } 243 }
242 if ((w > IMG_MAX_SIZE) || (w < 1)) 244 if ((w > IMG_MAX_SIZE) || (w < 1))
243 { 245 {
244 ERR("XPM ERROR: Image width > IMG_MAX_SIZE or < 1 pixels for file"); 246 ERR("XPM ERROR: Image width > IMG_MAX_SIZE or < 1 pixels for file");
245 free(line);
246 fclose(f);
247 xpm_parse_done();
248 *error = EVAS_LOAD_ERROR_GENERIC; 247 *error = EVAS_LOAD_ERROR_GENERIC;
249 return EINA_FALSE; 248 goto on_error;
250 } 249 }
251 if ((h > IMG_MAX_SIZE) || (h < 1)) 250 if ((h > IMG_MAX_SIZE) || (h < 1))
252 { 251 {
253 ERR("XPM ERROR: Image height > IMG_MAX_SIZE or < 1 pixels for file"); 252 ERR("XPM ERROR: Image height > IMG_MAX_SIZE or < 1 pixels for file");
254 free(line);
255 fclose(f);
256 xpm_parse_done();
257 *error = EVAS_LOAD_ERROR_GENERIC; 253 *error = EVAS_LOAD_ERROR_GENERIC;
258 return EINA_FALSE; 254 goto on_error;
259 } 255 }
260 if (IMG_TOO_BIG(w, h)) 256 if (IMG_TOO_BIG(w, h))
261 { 257 {
262 ERR("XPM ERROR: Image just too big to ever allocate"); 258 ERR("XPM ERROR: Image just too big to ever allocate");
263 free(line);
264 fclose(f);
265 xpm_parse_done();
266 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 259 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
267 return EINA_FALSE; 260 goto on_error;
268 } 261 }
269 262
270 if (!cmap) 263 if (!cmap)
@@ -272,11 +265,8 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
272 cmap = malloc(sizeof(struct _cmap) * ncolors); 265 cmap = malloc(sizeof(struct _cmap) * ncolors);
273 if (!cmap) 266 if (!cmap)
274 { 267 {
275 free(line);
276 fclose(f);
277 xpm_parse_done();
278 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 268 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
279 return EINA_FALSE; 269 goto on_error;
280 } 270 }
281 } 271 }
282 ie->w = w; 272 ie->w = w;
@@ -398,24 +388,16 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
398 ptr = evas_cache_image_pixels(ie); 388 ptr = evas_cache_image_pixels(ie);
399 if (!ptr) 389 if (!ptr)
400 { 390 {
401 free(cmap);
402 free(line);
403 fclose(f);
404 xpm_parse_done();
405 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 391 *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
406 return EINA_FALSE; 392 goto on_error;
407 } 393 }
408 pixels = w * h; 394 pixels = w * h;
409 end = ptr + pixels; 395 end = ptr + pixels;
410 } 396 }
411 else 397 else
412 { 398 {
413 free(cmap);
414 free(line);
415 fclose(f);
416 xpm_parse_done();
417 *error = EVAS_LOAD_ERROR_NONE; 399 *error = EVAS_LOAD_ERROR_NONE;
418 return EINA_TRUE; 400 goto on_success;
419 } 401 }
420 } 402 }
421 else 403 else
@@ -631,13 +613,21 @@ evas_image_load_file_xpm(Image_Entry *ie, const char *file, const char *key __UN
631 break; 613 break;
632 } 614 }
633 615
616 on_success:
634 free(cmap); 617 free(cmap);
635 free(line); 618 free(line);
636 fclose(f);
637 619
638 xpm_parse_done(); 620 eina_file_map_free(f, (void*) map);
621 eina_file_close(f);
622
639 *error = EVAS_LOAD_ERROR_NONE; 623 *error = EVAS_LOAD_ERROR_NONE;
640 return EINA_TRUE; 624 return EINA_TRUE;
625
626 on_error:
627 free(line);
628 eina_file_map_free(f, (void*) map);
629 eina_file_close(f);
630 return EINA_FALSE;
641} 631}
642 632
643static Eina_Bool 633static Eina_Bool
@@ -663,6 +653,14 @@ module_open(Evas_Module *em)
663 EINA_LOG_ERR("Can not create a module log domain."); 653 EINA_LOG_ERR("Can not create a module log domain.");
664 return 0; 654 return 0;
665 } 655 }
656
657 /* Shouldn't we make that PATH configurable ? */
658 rgb_txt = eina_file_open("/usr/lib/X11/rgb.txt", 0);
659 if (!rgb_txt) rgb_txt = eina_file_open("/usr/X11/lib/X11/rgb.txt", 0);
660 if (!rgb_txt) rgb_txt = eina_file_open("/usr/X11R6/lib/X11/rgb.txt", 0);
661 if (!rgb_txt) rgb_txt = eina_file_open("/usr/openwin/lib/X11/rgb.txt", 0);
662 if (rgb_txt)
663 rgb_txt_map = eina_file_map_all(rgb_txt, EINA_FILE_SEQUENTIAL);
666 em->functions = (void *)(&evas_image_load_xpm_func); 664 em->functions = (void *)(&evas_image_load_xpm_func);
667 return 1; 665 return 1;
668} 666}
@@ -670,6 +668,12 @@ module_open(Evas_Module *em)
670static void 668static void
671module_close(Evas_Module *em __UNUSED__) 669module_close(Evas_Module *em __UNUSED__)
672{ 670{
671 if (rgb_txt)
672 {
673 eina_file_map_free(rgb_txt, rgb_txt_map);
674 eina_file_close(rgb_txt);
675 rgb_txt = NULL;
676 }
673 eina_log_domain_unregister(_evas_loader_xpm_log_dom); 677 eina_log_domain_unregister(_evas_loader_xpm_log_dom);
674} 678}
675 679