diff options
Diffstat (limited to 'libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c')
-rw-r--r-- | libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c | 251 |
1 files changed, 0 insertions, 251 deletions
diff --git a/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c b/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c deleted file mode 100644 index 521161f..0000000 --- a/libraries/evas/src/modules/loaders/edb/evas_image_load_edb.c +++ /dev/null | |||
@@ -1,251 +0,0 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_private.h" | ||
3 | |||
4 | #include <Edb.h> | ||
5 | #include <zlib.h> | ||
6 | |||
7 | |||
8 | #define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24)) | ||
9 | |||
10 | |||
11 | static Eina_Bool evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
12 | static Eina_Bool evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4); | ||
13 | |||
14 | static Evas_Image_Load_Func evas_image_load_edb_func = | ||
15 | { | ||
16 | EINA_TRUE, | ||
17 | evas_image_load_file_head_edb, | ||
18 | evas_image_load_file_data_edb, | ||
19 | NULL, | ||
20 | EINA_FALSE | ||
21 | }; | ||
22 | |||
23 | static Eina_Bool | ||
24 | evas_image_load_file_head_edb(Image_Entry *ie, const char *file, const char *key, int *error) | ||
25 | { | ||
26 | int w, h, alpha, compression, size; | ||
27 | E_DB_File *db; | ||
28 | DATA32 *ret; | ||
29 | DATA32 header[8]; | ||
30 | |||
31 | if (!key) | ||
32 | { | ||
33 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
34 | return EINA_FALSE; | ||
35 | } | ||
36 | db = e_db_open_read((char *)file); | ||
37 | if (!db) | ||
38 | { | ||
39 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
40 | return EINA_FALSE; | ||
41 | } | ||
42 | ret = e_db_data_get(db, (char *)key, &size); | ||
43 | if (!ret) | ||
44 | { | ||
45 | e_db_close(db); | ||
46 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
47 | return EINA_FALSE; | ||
48 | } | ||
49 | if (size < 32) | ||
50 | { | ||
51 | free(ret); | ||
52 | e_db_close(db); | ||
53 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
54 | return EINA_FALSE; | ||
55 | } | ||
56 | memcpy(header, ret, 32); | ||
57 | #ifdef WORDS_BIGENDIAN | ||
58 | { | ||
59 | int i; | ||
60 | |||
61 | for (i = 0; i < 8; i++) SWAP32(header[i]); | ||
62 | } | ||
63 | #endif | ||
64 | if (header[0] != 0xac1dfeed) | ||
65 | { | ||
66 | free(ret); | ||
67 | e_db_close(db); | ||
68 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
69 | return EINA_FALSE; | ||
70 | } | ||
71 | w = header[1]; | ||
72 | h = header[2]; | ||
73 | if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || | ||
74 | IMG_TOO_BIG(w, h)) | ||
75 | { | ||
76 | free(ret); | ||
77 | e_db_close(db); | ||
78 | if (IMG_TOO_BIG(w, h)) | ||
79 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
80 | else | ||
81 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
82 | return EINA_FALSE; | ||
83 | } | ||
84 | alpha = header[3]; | ||
85 | compression = header[4]; | ||
86 | |||
87 | if ((compression == 0) && (size < ((w * h * 4) + 32))) | ||
88 | { | ||
89 | free(ret); | ||
90 | e_db_close(db); | ||
91 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
92 | return EINA_FALSE; | ||
93 | } | ||
94 | if (alpha) ie->flags.alpha = 1; | ||
95 | ie->w = w; | ||
96 | ie->h = h; | ||
97 | free(ret); | ||
98 | e_db_close(db); | ||
99 | *error = EVAS_LOAD_ERROR_NONE; | ||
100 | return EINA_TRUE; | ||
101 | } | ||
102 | |||
103 | static Eina_Bool | ||
104 | evas_image_load_file_data_edb(Image_Entry *ie, const char *file, const char *key, int *error) | ||
105 | { | ||
106 | int w, h, alpha, compression, size; | ||
107 | E_DB_File *db; | ||
108 | DATA32 *ret; | ||
109 | DATA32 *body; | ||
110 | DATA32 *surface; | ||
111 | DATA32 header[8]; | ||
112 | |||
113 | if (!key) | ||
114 | { | ||
115 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
116 | return EINA_FALSE; | ||
117 | } | ||
118 | db = e_db_open_read((char *)file); | ||
119 | if (!db) | ||
120 | { | ||
121 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
122 | return EINA_FALSE; | ||
123 | } | ||
124 | ret = e_db_data_get(db, (char *)key, &size); | ||
125 | if (!ret) | ||
126 | { | ||
127 | e_db_close(db); | ||
128 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
129 | return EINA_FALSE; | ||
130 | } | ||
131 | if (size < 32) | ||
132 | { | ||
133 | free(ret); | ||
134 | e_db_close(db); | ||
135 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
136 | return EINA_FALSE; | ||
137 | } | ||
138 | memcpy(header, ret, 32); | ||
139 | #ifdef WORDS_BIGENDIAN | ||
140 | { | ||
141 | int i; | ||
142 | |||
143 | for (i = 0; i < 8; i++) SWAP32(header[i]); | ||
144 | } | ||
145 | #endif | ||
146 | if (header[0] != 0xac1dfeed) | ||
147 | { | ||
148 | free(ret); | ||
149 | e_db_close(db); | ||
150 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | ||
151 | return EINA_FALSE; | ||
152 | } | ||
153 | w = header[1]; | ||
154 | h = header[2]; | ||
155 | if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || | ||
156 | IMG_TOO_BIG(w, h)) | ||
157 | { | ||
158 | free(ret); | ||
159 | e_db_close(db); | ||
160 | if (IMG_TOO_BIG(w, h)) | ||
161 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
162 | else | ||
163 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
164 | return EINA_FALSE; | ||
165 | } | ||
166 | |||
167 | alpha = header[3]; | ||
168 | compression = header[4]; | ||
169 | |||
170 | if ((compression == 0) && (size < ((w * h * 4) + 32))) | ||
171 | { | ||
172 | free(ret); | ||
173 | e_db_close(db); | ||
174 | *error = EVAS_LOAD_ERROR_GENERIC; | ||
175 | return EINA_FALSE; | ||
176 | } | ||
177 | if (alpha) ie->flags.alpha = 1; | ||
178 | body = &(ret[8]); | ||
179 | evas_cache_image_surface_alloc(ie, w, h); | ||
180 | surface = evas_cache_image_pixels(ie); | ||
181 | if (!surface) | ||
182 | { | ||
183 | free(ret); | ||
184 | e_db_close(db); | ||
185 | *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; | ||
186 | return EINA_FALSE; | ||
187 | } | ||
188 | if (!compression) | ||
189 | { | ||
190 | #ifdef WORDS_BIGENDIAN | ||
191 | { | ||
192 | int x; | ||
193 | |||
194 | memcpy(surface, body, w * h * sizeof(DATA32)); | ||
195 | for (x = 0; x < (w * h); x++) SWAP32(surface[x]); | ||
196 | } | ||
197 | #else | ||
198 | memcpy(surface, body, w * h * sizeof(DATA32)); | ||
199 | #endif | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | uLongf dlen; | ||
204 | |||
205 | dlen = w * h * sizeof(DATA32); | ||
206 | uncompress((Bytef *)surface, &dlen, (Bytef *)body, | ||
207 | (uLongf)(size - 32)); | ||
208 | #ifdef WORDS_BIGENDIAN | ||
209 | { | ||
210 | int x; | ||
211 | |||
212 | for (x = 0; x < (w * h); x++) SWAP32(surface[x]); | ||
213 | } | ||
214 | #endif | ||
215 | } | ||
216 | evas_common_image_premul(ie); | ||
217 | free(ret); | ||
218 | e_db_close(db); | ||
219 | *error = EVAS_LOAD_ERROR_NONE; | ||
220 | return EINA_TRUE; | ||
221 | } | ||
222 | |||
223 | static int | ||
224 | module_open(Evas_Module *em) | ||
225 | { | ||
226 | if (!em) return 0; | ||
227 | em->functions = (void *)(&evas_image_load_edb_func); | ||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | static void | ||
232 | module_close(Evas_Module *em) | ||
233 | { | ||
234 | } | ||
235 | |||
236 | static Evas_Module_Api evas_modapi = | ||
237 | { | ||
238 | EVAS_MODULE_API_VERSION, | ||
239 | "edb", | ||
240 | "none", | ||
241 | { | ||
242 | module_open, | ||
243 | module_close | ||
244 | } | ||
245 | }; | ||
246 | |||
247 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, edb); | ||
248 | |||
249 | #ifndef EVAS_STATIC_BUILD_EDB | ||
250 | EVAS_EINA_MODULE_DEFINE(image_loader, edb); | ||
251 | #endif | ||