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