diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c | 209 |
1 files changed, 0 insertions, 209 deletions
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 deleted file mode 100644 index 54e28d5..0000000 --- a/libraries/evas/src/modules/loaders/wbmp/evas_image_load_wbmp.c +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | |||
7 | #ifdef HAVE_EVIL | ||
8 | # include <Evil.h> | ||
9 | #endif | ||
10 | |||
11 | #include "evas_common.h" | ||
12 | #include "evas_private.h" | ||
13 | |||
14 | static Eina_Bool evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
15 | static Eina_Bool evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
16 | |||
17 | static Evas_Image_Load_Func evas_image_load_wbmp_func = | ||
18 | { | ||
19 | EINA_TRUE, | ||
20 | evas_image_load_file_head_wbmp, | ||
21 | evas_image_load_file_data_wbmp, | ||
22 | NULL, | ||
23 | EINA_FALSE | ||
24 | }; | ||
25 | |||
26 | |||
27 | static int | ||
28 | read_mb(unsigned int *data, void *map, size_t length, size_t *position) | ||
29 | { | ||
30 | int ac = 0, ct; | ||
31 | unsigned char buf; | ||
32 | |||
33 | for (ct = 0;;) | ||
34 | { | ||
35 | if ((ct++) == 5) return -1; | ||
36 | if (*position > length) return -1; | ||
37 | buf = ((unsigned char *) map)[(*position)++]; | ||
38 | ac = (ac << 7) | (buf & 0x7f); | ||
39 | if ((buf & 0x80) == 0) break; | ||
40 | } | ||
41 | *data = ac; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static Eina_Bool | ||
46 | evas_image_load_file_head_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
47 | { | ||
48 | Eina_File *f; | ||
49 | void *map = NULL; | ||
50 | size_t position = 0; | ||
51 | size_t length; | ||
52 | unsigned int type, w, h; | ||
53 | |||
54 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
55 | f = eina_file_open(file, 0); | ||
56 | if (!f) | ||
57 | { | ||
58 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
59 | return EINA_FALSE; | ||
60 | } | ||
61 | |||
62 | length = eina_file_size_get(f); | ||
63 | if (length <= 4) goto bail; | ||
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 | |||
70 | if (type != 0) | ||
71 | { | ||
72 | *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT; | ||
73 | goto bail; | ||
74 | } | ||
75 | |||
76 | position++; /* skipping one byte */ | ||
77 | if (read_mb(&w, map, length, &position) < 0) goto bail; | ||
78 | if (read_mb(&h, map, length, &position) < 0) goto bail; | ||
79 | if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || | ||
80 | IMG_TOO_BIG(w, h)) | ||
81 | { | ||
82 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
83 | goto bail; | ||
84 | } | ||
85 | |||
86 | eina_file_map_free(f, map); | ||
87 | eina_file_close(f); | ||
88 | ie->w = w; | ||
89 | ie->h = h; | ||
90 | |||
91 | *error = EVAS_LOAD_ERROR_NONE; | ||
92 | return EINA_TRUE; | ||
93 | bail: | ||
94 | if (map) eina_file_map_free(f, map); | ||
95 | eina_file_close(f); | ||
96 | return EINA_FALSE; | ||
97 | } | ||
98 | |||
99 | static Eina_Bool | ||
100 | evas_image_load_file_data_wbmp(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error) | ||
101 | { | ||
102 | Eina_File *f; | ||
103 | void *map = NULL; | ||
104 | size_t position = 0; | ||
105 | size_t length; | ||
106 | unsigned int type, w, h; | ||
107 | unsigned int line_length; | ||
108 | unsigned char *line = NULL; | ||
109 | int cur = 0, x, y; | ||
110 | DATA32 *dst_data; | ||
111 | |||
112 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
113 | f = eina_file_open(file, EINA_FALSE); | ||
114 | if (!f) | ||
115 | { | ||
116 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
117 | return EINA_FALSE; | ||
118 | } | ||
119 | |||
120 | length = eina_file_size_get(f); | ||
121 | if (length <= 4) goto bail; | ||
122 | |||
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 | |||
147 | evas_cache_image_surface_alloc(ie, ie->w, ie->h); | ||
148 | dst_data = evas_cache_image_pixels(ie); | ||
149 | if (!dst_data) | ||
150 | { | ||
151 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
152 | goto bail; | ||
153 | } | ||
154 | |||
155 | line_length = (ie->w + 7) >> 3; | ||
156 | |||
157 | for (y = 0; y < (int)ie->h; y++) | ||
158 | { | ||
159 | if (position + line_length > length) goto bail; | ||
160 | line = ((unsigned char*) map) + position; | ||
161 | position += line_length; | ||
162 | for (x = 0; x < (int)ie->w; x++) | ||
163 | { | ||
164 | int idx = x >> 3; | ||
165 | int offset = 1 << (0x07 - (x & 0x07)); | ||
166 | if (line[idx] & offset) dst_data[cur] = 0xffffffff; | ||
167 | else dst_data[cur] = 0xff000000; | ||
168 | cur++; | ||
169 | } | ||
170 | } | ||
171 | eina_file_map_free(f, map); | ||
172 | eina_file_close(f); | ||
173 | *error = EVAS_LOAD_ERROR_NONE; | ||
174 | return EINA_TRUE; | ||
175 | bail: | ||
176 | if (map) eina_file_map_free(f, map); | ||
177 | eina_file_close(f); | ||
178 | return EINA_FALSE; | ||
179 | } | ||
180 | |||
181 | static int | ||
182 | module_open(Evas_Module *em) | ||
183 | { | ||
184 | if (!em) return 0; | ||
185 | em->functions = (void *)(&evas_image_load_wbmp_func); | ||
186 | return 1; | ||
187 | } | ||
188 | |||
189 | static void | ||
190 | module_close(Evas_Module *em __UNUSED__) | ||
191 | { | ||
192 | } | ||
193 | |||
194 | static Evas_Module_Api evas_modapi = | ||
195 | { | ||
196 | EVAS_MODULE_API_VERSION, | ||
197 | "wbmp", | ||
198 | "none", | ||
199 | { | ||
200 | module_open, | ||
201 | module_close | ||
202 | } | ||
203 | }; | ||
204 | |||
205 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, wbmp); | ||
206 | |||
207 | #ifndef EVAS_STATIC_BUILD_WBMP | ||
208 | EVAS_EINA_MODULE_DEFINE(image_loader, wbmp); | ||
209 | #endif | ||