aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/loaders/bmp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/modules/loaders/bmp')
-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
2 files changed, 274 insertions, 219 deletions
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