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/wbmp | |
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/wbmp')
-rw-r--r-- | libraries/evas/src/modules/loaders/wbmp/Makefile.in | 8 | ||||
-rw-r--r-- | libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c | 113 |
2 files changed, 82 insertions, 39 deletions
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@ | |||
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/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 | ||
26 | static int | 27 | static int |
27 | read_mb(unsigned int *data, FILE *f) | 28 | read_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) | |||
44 | static Eina_Bool | 45 | static Eina_Bool |
45 | evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | 46 | evas_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; |
85 | bail: | 93 | bail: |
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 | ||
90 | static Eina_Bool | 99 | static Eina_Bool |
91 | evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | 100 | evas_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; |
137 | bail: | 175 | bail: |
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 | ||