diff options
author | David Walter Seikel | 2012-01-23 23:30:42 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-23 23:30:42 +1000 |
commit | 825a3d837a33f226c879cd02ad15c3fba57e8b2c (patch) | |
tree | 75f57bd9c4253508d338dc79ba8e57a7abc42255 /libraries/evas/src/modules/loaders/ico | |
parent | Add ability to disable the test harness, or the Lua compile test. (diff) | |
download | SledjHamr-825a3d837a33f226c879cd02ad15c3fba57e8b2c.zip SledjHamr-825a3d837a33f226c879cd02ad15c3fba57e8b2c.tar.gz SledjHamr-825a3d837a33f226c879cd02ad15c3fba57e8b2c.tar.bz2 SledjHamr-825a3d837a33f226c879cd02ad15c3fba57e8b2c.tar.xz |
Update the EFL to what I'm actually using, coz I'm using some stuff not yet released.
Diffstat (limited to 'libraries/evas/src/modules/loaders/ico')
-rw-r--r-- | libraries/evas/src/modules/loaders/ico/Makefile.in | 8 | ||||
-rw-r--r-- | libraries/evas/src/modules/loaders/ico/evas_image_load_ico.c | 216 |
2 files changed, 133 insertions, 91 deletions
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@ | |||
231 | PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ | 231 | PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ |
232 | PIXMAN_LIBS = @PIXMAN_LIBS@ | 232 | PIXMAN_LIBS = @PIXMAN_LIBS@ |
233 | PKG_CONFIG = @PKG_CONFIG@ | 233 | PKG_CONFIG = @PKG_CONFIG@ |
234 | PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ | ||
235 | PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ | ||
236 | PNG_CFLAGS = @PNG_CFLAGS@ | 234 | PNG_CFLAGS = @PNG_CFLAGS@ |
237 | PNG_LIBS = @PNG_LIBS@ | 235 | PNG_LIBS = @PNG_LIBS@ |
238 | RANLIB = @RANLIB@ | 236 | RANLIB = @RANLIB@ |
@@ -249,6 +247,8 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@ | |||
249 | VALGRIND_LIBS = @VALGRIND_LIBS@ | 247 | VALGRIND_LIBS = @VALGRIND_LIBS@ |
250 | VERSION = @VERSION@ | 248 | VERSION = @VERSION@ |
251 | VMAJ = @VMAJ@ | 249 | VMAJ = @VMAJ@ |
250 | WAYLAND_EGL_CFLAGS = @WAYLAND_EGL_CFLAGS@ | ||
251 | WAYLAND_EGL_LIBS = @WAYLAND_EGL_LIBS@ | ||
252 | WIN32_CFLAGS = @WIN32_CFLAGS@ | 252 | WIN32_CFLAGS = @WIN32_CFLAGS@ |
253 | WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ | 253 | WIN32_CPPFLAGS = @WIN32_CPPFLAGS@ |
254 | XCB_CFLAGS = @XCB_CFLAGS@ | 254 | XCB_CFLAGS = @XCB_CFLAGS@ |
@@ -330,6 +330,10 @@ evas_engine_software_xcb_cflags = @evas_engine_software_xcb_cflags@ | |||
330 | evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ | 330 | evas_engine_software_xcb_libs = @evas_engine_software_xcb_libs@ |
331 | evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ | 331 | evas_engine_software_xlib_cflags = @evas_engine_software_xlib_cflags@ |
332 | evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ | 332 | evas_engine_software_xlib_libs = @evas_engine_software_xlib_libs@ |
333 | evas_engine_wayland_egl_cflags = @evas_engine_wayland_egl_cflags@ | ||
334 | evas_engine_wayland_egl_libs = @evas_engine_wayland_egl_libs@ | ||
335 | evas_engine_wayland_shm_cflags = @evas_engine_wayland_shm_cflags@ | ||
336 | evas_engine_wayland_shm_libs = @evas_engine_wayland_shm_libs@ | ||
333 | evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ | 337 | evas_image_loader_bmp_cflags = @evas_image_loader_bmp_cflags@ |
334 | evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ | 338 | evas_image_loader_bmp_libs = @evas_image_loader_bmp_libs@ |
335 | evas_image_loader_edb_cflags = @evas_image_loader_edb_cflags@ | 339 | evas_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 | ||
25 | static int | 26 | static Eina_Bool |
26 | read_ushort(FILE *file, unsigned short *ret) | 27 | read_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 | ||
34 | static int | 38 | static Eina_Bool |
35 | read_uint(FILE *file, unsigned int *ret) | 39 | read_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 | |||
51 | static Eina_Bool | ||
52 | read_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 | |||
59 | static Eina_Bool | ||
60 | read_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 | ||
43 | enum | 68 | enum |
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 | |||
57 | static Eina_Bool | 82 | static Eina_Bool |
58 | evas_image_load_file_head_ico(Image_Entry *ie, const char *file, const char *key, int *error) | 83 | evas_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 | ||
276 | static Eina_Bool | 308 | static Eina_Bool |
277 | evas_image_load_file_data_ico(Image_Entry *ie, const char *file, const char *key, int *error) | 309 | evas_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 | ||