diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/evas/src/lib/engines/common/evas_image_load.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/lib/engines/common/evas_image_load.c | 385 |
1 files changed, 0 insertions, 385 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_image_load.c b/libraries/evas/src/lib/engines/common/evas_image_load.c deleted file mode 100644 index 21ac5d4..0000000 --- a/libraries/evas/src/lib/engines/common/evas_image_load.c +++ /dev/null | |||
@@ -1,385 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/stat.h> | ||
7 | #include <unistd.h> | ||
8 | |||
9 | #include "evas_common.h" | ||
10 | #include "evas_private.h" | ||
11 | #include "evas_cs.h" | ||
12 | |||
13 | struct ext_loader_s | ||
14 | { | ||
15 | unsigned int length; | ||
16 | const char *extension; | ||
17 | const char *loader; | ||
18 | }; | ||
19 | |||
20 | #define MATCHING(Ext, Module) \ | ||
21 | { sizeof (Ext), Ext, Module } | ||
22 | |||
23 | static const struct ext_loader_s loaders[] = | ||
24 | { /* map extensions to loaders to use for good first-guess tries */ | ||
25 | MATCHING(".png", "png"), | ||
26 | MATCHING(".jpg", "jpeg"), | ||
27 | MATCHING(".jpeg", "jpeg"), | ||
28 | MATCHING(".jfif", "jpeg"), | ||
29 | MATCHING(".eet", "eet"), | ||
30 | MATCHING(".edj", "eet"), | ||
31 | MATCHING(".eap", "eet"), | ||
32 | MATCHING(".edb", "edb"), | ||
33 | MATCHING(".xpm", "xpm"), | ||
34 | MATCHING(".tiff", "tiff"), | ||
35 | MATCHING(".tif", "tiff"), | ||
36 | MATCHING(".svg", "svg"), | ||
37 | MATCHING(".svgz", "svg"), | ||
38 | MATCHING(".svg.gz", "svg"), | ||
39 | MATCHING(".gif", "gif"), | ||
40 | MATCHING(".pbm", "pmaps"), | ||
41 | MATCHING(".pgm", "pmaps"), | ||
42 | MATCHING(".ppm", "pmaps"), | ||
43 | MATCHING(".pnm", "pmaps"), | ||
44 | MATCHING(".bmp", "bmp"), | ||
45 | MATCHING(".tga", "tga"), | ||
46 | MATCHING(".wbmp", "wbmp"), | ||
47 | MATCHING(".ico", "ico"), | ||
48 | MATCHING(".cur", "ico"), | ||
49 | MATCHING(".psd", "psd"), | ||
50 | MATCHING(".pdf", "generic"), | ||
51 | MATCHING(".ps", "generic"), | ||
52 | MATCHING(".xcf", "generic"), | ||
53 | MATCHING(".xcf.gz", "generic"), | ||
54 | /* RAW */ | ||
55 | MATCHING(".arw", "generic"), | ||
56 | MATCHING(".cr2", "generic"), | ||
57 | MATCHING(".crw", "generic"), | ||
58 | MATCHING(".dcr", "generic"), | ||
59 | MATCHING(".dng", "generic"), | ||
60 | MATCHING(".k25", "generic"), | ||
61 | MATCHING(".kdc", "generic"), | ||
62 | MATCHING(".erf", "generic"), | ||
63 | MATCHING(".mrw", "generic"), | ||
64 | MATCHING(".nef", "generic"), | ||
65 | MATCHING(".nrf", "generic"), | ||
66 | MATCHING(".nrw", "generic"), | ||
67 | MATCHING(".orf", "generic"), | ||
68 | MATCHING(".raw", "generic"), | ||
69 | MATCHING(".rw2", "generic"), | ||
70 | MATCHING(".pef", "generic"), | ||
71 | MATCHING(".raf", "generic"), | ||
72 | MATCHING(".sr2", "generic"), | ||
73 | MATCHING(".srf", "generic"), | ||
74 | MATCHING(".x3f", "generic"), | ||
75 | /* video */ | ||
76 | MATCHING(".264", "generic"), | ||
77 | MATCHING(".3g2", "generic"), | ||
78 | MATCHING(".3gp", "generic"), | ||
79 | MATCHING(".3gp2", "generic"), | ||
80 | MATCHING(".3gpp", "generic"), | ||
81 | MATCHING(".3gpp2", "generic"), | ||
82 | MATCHING(".3p2", "generic"), | ||
83 | MATCHING(".asf", "generic"), | ||
84 | MATCHING(".avi", "generic"), | ||
85 | MATCHING(".bdm", "generic"), | ||
86 | MATCHING(".bdmv", "generic"), | ||
87 | MATCHING(".clpi", "generic"), | ||
88 | MATCHING(".clp", "generic"), | ||
89 | MATCHING(".fla", "generic"), | ||
90 | MATCHING(".flv", "generic"), | ||
91 | MATCHING(".m1v", "generic"), | ||
92 | MATCHING(".m2v", "generic"), | ||
93 | MATCHING(".m2t", "generic"), | ||
94 | MATCHING(".m4v", "generic"), | ||
95 | MATCHING(".mkv", "generic"), | ||
96 | MATCHING(".mov", "generic"), | ||
97 | MATCHING(".mp2", "generic"), | ||
98 | MATCHING(".mp2ts", "generic"), | ||
99 | MATCHING(".mp4", "generic"), | ||
100 | MATCHING(".mpe", "generic"), | ||
101 | MATCHING(".mpeg", "generic"), | ||
102 | MATCHING(".mpg", "generic"), | ||
103 | MATCHING(".mpl", "generic"), | ||
104 | MATCHING(".mpls", "generic"), | ||
105 | MATCHING(".mts", "generic"), | ||
106 | MATCHING(".mxf", "generic"), | ||
107 | MATCHING(".nut", "generic"), | ||
108 | MATCHING(".nuv", "generic"), | ||
109 | MATCHING(".ogg", "generic"), | ||
110 | MATCHING(".ogm", "generic"), | ||
111 | MATCHING(".ogv", "generic"), | ||
112 | MATCHING(".rm", "generic"), | ||
113 | MATCHING(".rmj", "generic"), | ||
114 | MATCHING(".rmm", "generic"), | ||
115 | MATCHING(".rms", "generic"), | ||
116 | MATCHING(".rmx", "generic"), | ||
117 | MATCHING(".rmvb", "generic"), | ||
118 | MATCHING(".swf", "generic"), | ||
119 | MATCHING(".ts", "generic"), | ||
120 | MATCHING(".weba", "generic"), | ||
121 | MATCHING(".webm", "generic"), | ||
122 | MATCHING(".wmv", "generic") | ||
123 | }; | ||
124 | |||
125 | static const char *loaders_name[] = | ||
126 | { /* in order of most likely needed */ | ||
127 | "png", "jpeg", "eet", "xpm", "tiff", "gif", "svg", "pmaps", "bmp", "tga", "wbmp", "ico", "psd", "edb", "generic" | ||
128 | }; | ||
129 | |||
130 | struct evas_image_foreach_loader_data | ||
131 | { | ||
132 | Image_Entry *ie; | ||
133 | int *error; | ||
134 | Evas_Module *em; | ||
135 | }; | ||
136 | |||
137 | |||
138 | static Eina_Bool | ||
139 | _evas_image_foreach_loader(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata) | ||
140 | { | ||
141 | Evas_Image_Load_Func *evas_image_load_func = NULL; | ||
142 | Evas_Module *em = data; | ||
143 | struct evas_image_foreach_loader_data *d = fdata; | ||
144 | Image_Entry *ie = d->ie; | ||
145 | |||
146 | if (!evas_module_load(em)) return EINA_TRUE; | ||
147 | evas_image_load_func = em->functions; | ||
148 | evas_module_use(em); | ||
149 | *(d->error) = EVAS_LOAD_ERROR_NONE; | ||
150 | if (evas_image_load_func && | ||
151 | evas_image_load_func->file_head(ie, ie->file, ie->key, d->error) && | ||
152 | (*(d->error) == EVAS_LOAD_ERROR_NONE)) | ||
153 | { | ||
154 | d->em = em; | ||
155 | return EINA_FALSE; | ||
156 | } | ||
157 | |||
158 | return EINA_TRUE; | ||
159 | } | ||
160 | |||
161 | EAPI int | ||
162 | evas_common_load_rgba_image_module_from_file(Image_Entry *ie) | ||
163 | { | ||
164 | Evas_Image_Load_Func *evas_image_load_func = NULL; | ||
165 | const char *loader = NULL, *end; | ||
166 | Evas_Module *em; | ||
167 | struct stat st; | ||
168 | unsigned int i; | ||
169 | int len, ret = EVAS_LOAD_ERROR_NONE; | ||
170 | struct evas_image_foreach_loader_data fdata; | ||
171 | |||
172 | |||
173 | #ifdef EVAS_CSERVE | ||
174 | if (evas_cserve_use_get()) | ||
175 | { | ||
176 | // TODO: handle errors from server and return them? | ||
177 | DBG("try cserve '%s' '%s'", ie->file, ie->key ? ie->key : ""); | ||
178 | if (evas_cserve_image_load(ie, ie->file, ie->key, &(ie->load_opts))) | ||
179 | { | ||
180 | DBG("try cserve '%s' '%s' loaded!", | ||
181 | ie->file, ie->key ? ie->key : ""); | ||
182 | return EVAS_LOAD_ERROR_NONE; | ||
183 | } | ||
184 | } | ||
185 | #endif | ||
186 | if (stat(ie->file, &st) != 0 || S_ISDIR(st.st_mode)) | ||
187 | { | ||
188 | DBG("trying to open directory '%s' !", ie->file); | ||
189 | return EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
190 | } | ||
191 | |||
192 | len = strlen(ie->file); | ||
193 | end = ie->file + len; | ||
194 | for (i = 0; i < (sizeof (loaders) / sizeof(struct ext_loader_s)); i++) | ||
195 | { | ||
196 | int len2 = strlen(loaders[i].extension); | ||
197 | if (len2 > len) continue; | ||
198 | if (!strcasecmp(end - len2, loaders[i].extension)) | ||
199 | { | ||
200 | loader = loaders[i].loader; | ||
201 | DBG("known loader '%s' handles extension '%s' of file '%s'", | ||
202 | loader, end - len2, ie->file); | ||
203 | break; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | if (loader) | ||
208 | { | ||
209 | em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader); | ||
210 | if (em) | ||
211 | { | ||
212 | DBG("found image loader '%s' (%p)", loader, em); | ||
213 | if (evas_module_load(em)) | ||
214 | { | ||
215 | evas_module_use(em); | ||
216 | evas_image_load_func = em->functions; | ||
217 | ret = EVAS_LOAD_ERROR_NONE; | ||
218 | if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) | ||
219 | { | ||
220 | DBG("loaded file head using module '%s' (%p): %s", | ||
221 | loader, em, ie->file); | ||
222 | goto end; | ||
223 | } | ||
224 | evas_module_unload(em); | ||
225 | INF("failed to load file head using module '%s' (%p): " | ||
226 | "%s (%s)", | ||
227 | loader, em, ie->file, evas_load_error_str(ret)); | ||
228 | } | ||
229 | else | ||
230 | WRN("failed to load module '%s' (%p)", loader, em); | ||
231 | } | ||
232 | else | ||
233 | INF("image loader '%s' is not enabled or missing!", loader); | ||
234 | } | ||
235 | |||
236 | fdata.ie = ie; | ||
237 | fdata.error = &ret; | ||
238 | fdata.em = NULL; | ||
239 | ret = EVAS_LOAD_ERROR_NONE; | ||
240 | evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata); | ||
241 | em = fdata.em; | ||
242 | evas_image_load_func = em ? em->functions : NULL; | ||
243 | if (em) goto end; | ||
244 | |||
245 | /* This is our last chance, try all known image loader. */ | ||
246 | /* FIXME: We could use eina recursive module search ability. */ | ||
247 | for (i = 0; i < sizeof (loaders_name) / sizeof (char *); i++) | ||
248 | { | ||
249 | em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]); | ||
250 | if (em) | ||
251 | { | ||
252 | if (evas_module_load(em)) | ||
253 | { | ||
254 | evas_module_use(em); | ||
255 | evas_image_load_func = em->functions; | ||
256 | ret = EVAS_LOAD_ERROR_NONE; | ||
257 | if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret)) | ||
258 | { | ||
259 | DBG("brute force loader '%s' (%p) worked on %s", | ||
260 | loaders_name[i], em, ie->file); | ||
261 | goto end; | ||
262 | } | ||
263 | else | ||
264 | INF("brute force loader '%s' (%p) failed on %s (%s)", | ||
265 | loaders_name[i], em, ie->file, | ||
266 | evas_load_error_str(ret)); | ||
267 | |||
268 | evas_module_unload(em); | ||
269 | } | ||
270 | else | ||
271 | INF("failed to load module '%s' (%p)", loaders_name[i], em); | ||
272 | } | ||
273 | else | ||
274 | DBG("could not find module '%s'", loaders_name[i]); | ||
275 | } | ||
276 | |||
277 | INF("exhausted all means to load image '%s'", ie->file); | ||
278 | return EVAS_LOAD_ERROR_UNKNOWN_FORMAT; | ||
279 | |||
280 | end: | ||
281 | |||
282 | if (ret != EVAS_LOAD_ERROR_NONE) | ||
283 | { | ||
284 | const char *modname = NULL; | ||
285 | int modversion = -1; | ||
286 | if (em && em->definition) | ||
287 | { | ||
288 | modname = em->definition->name; | ||
289 | modversion = em->definition->version; | ||
290 | } | ||
291 | WRN("loader '%s' (version %d) " | ||
292 | "handled file '%s', key '%s' with errors: %s", | ||
293 | modname ? modname : "<UNKNOWN>", modversion, | ||
294 | ie->file, ie->key ? ie->key : "", | ||
295 | evas_load_error_str(ret)); | ||
296 | goto end; | ||
297 | } | ||
298 | |||
299 | DBG("loader '%s' used for file %s", | ||
300 | (em && em->definition && em->definition->name) ? | ||
301 | em->definition->name : "<UNKNOWN>", | ||
302 | ie->file); | ||
303 | |||
304 | ie->info.module = (void*) em; | ||
305 | ie->info.loader = (void*) evas_image_load_func; | ||
306 | evas_module_ref((Evas_Module*) ie->info.module); | ||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | EAPI int | ||
311 | evas_common_load_rgba_image_data_from_file(Image_Entry *ie) | ||
312 | { | ||
313 | Evas_Image_Load_Func *evas_image_load_func = NULL; | ||
314 | int ret = EVAS_LOAD_ERROR_NONE; | ||
315 | |||
316 | if ((ie->flags.loaded) && (!ie->flags.animated)) return EVAS_LOAD_ERROR_GENERIC; | ||
317 | |||
318 | #ifdef EVAS_CSERVE | ||
319 | if (ie->data1) | ||
320 | { | ||
321 | if (evas_cserve_image_data_load(ie)) | ||
322 | { | ||
323 | RGBA_Image *im = (RGBA_Image *)ie; | ||
324 | Mem *mem = ie->data2; | ||
325 | if (mem) | ||
326 | { | ||
327 | im->image.data = (void*) (mem->data + mem->offset); | ||
328 | im->image.no_free = 1; | ||
329 | return EVAS_LOAD_ERROR_NONE; | ||
330 | } | ||
331 | } | ||
332 | return EVAS_LOAD_ERROR_GENERIC; | ||
333 | } | ||
334 | #endif | ||
335 | |||
336 | if (!ie->info.module) return EVAS_LOAD_ERROR_GENERIC; | ||
337 | |||
338 | // printf("load data [%p] %s %s\n", ie, ie->file, ie->key); | ||
339 | |||
340 | evas_image_load_func = ie->info.loader; | ||
341 | evas_module_use((Evas_Module*) ie->info.module); | ||
342 | if (!evas_image_load_func->file_data(ie, ie->file, ie->key, &ret)) | ||
343 | { | ||
344 | return ret; | ||
345 | } | ||
346 | |||
347 | // evas_module_unref((Evas_Module*) ie->info.module); | ||
348 | // ie->info.module = NULL; | ||
349 | |||
350 | return EVAS_LOAD_ERROR_NONE; | ||
351 | } | ||
352 | |||
353 | EAPI double | ||
354 | evas_common_load_rgba_image_frame_duration_from_file(Image_Entry *ie, const int start, const int frame_num) | ||
355 | { | ||
356 | Evas_Image_Load_Func *evas_image_load_func = NULL; | ||
357 | |||
358 | if (!ie->info.module) return -1; | ||
359 | |||
360 | evas_image_load_func = ie->info.loader; | ||
361 | evas_module_use((Evas_Module*) ie->info.module); | ||
362 | if (evas_image_load_func->frame_duration) | ||
363 | return evas_image_load_func->frame_duration(ie, ie->file, start, frame_num); | ||
364 | return -1; | ||
365 | } | ||
366 | |||
367 | EAPI Eina_Bool | ||
368 | evas_common_extension_can_load_get(const char *file) | ||
369 | { | ||
370 | unsigned int length; | ||
371 | unsigned int i; | ||
372 | |||
373 | length = eina_stringshare_strlen(file) + 1; | ||
374 | if (length < 5) return EINA_FALSE; | ||
375 | |||
376 | for (i = 0; i < sizeof (loaders) / sizeof (struct ext_loader_s); ++i) | ||
377 | { | ||
378 | if (loaders[i].length > length) continue; | ||
379 | |||
380 | if (!strcasecmp(loaders[i].extension, file + length - loaders[i].length)) | ||
381 | return EINA_TRUE; | ||
382 | } | ||
383 | |||
384 | return EINA_FALSE; | ||
385 | } | ||