summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_image_load.c
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-05-08 15:37:37 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-05-08 18:17:00 +0900
commitd8332441009f2f34c92140ce7b61460402d5fe96 (patch)
treefeb264ed9d08008f9c71716f25048a1b682000c2 /src/lib/evas/common/evas_image_load.c
parentba46068c0977ec773822ba8b790ab1e9f9b6c2ba (diff)
evas: add infrastructure to open from Eina_File.
Diffstat (limited to 'src/lib/evas/common/evas_image_load.c')
-rw-r--r--src/lib/evas/common/evas_image_load.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/lib/evas/common/evas_image_load.c b/src/lib/evas/common/evas_image_load.c
index a505bc99f6..cb03c7ab76 100644
--- a/src/lib/evas/common/evas_image_load.c
+++ b/src/lib/evas/common/evas_image_load.c
@@ -150,8 +150,17 @@ _evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
150 if (evas_image_load_func) 150 if (evas_image_load_func)
151 { 151 {
152 Evas_Image_Property property; 152 Evas_Image_Property property;
153 const char *file;
153 154
154 if (!ie->f) ie->f = eina_file_open(ie->file, EINA_FALSE); 155 if (!ie->f)
156 {
157 ie->f = eina_file_open(ie->file, EINA_FALSE);
158 file = ie->file;
159 }
160 else
161 {
162 file = eina_file_filename_get(ie->f);
163 }
155 if (!ie->f) 164 if (!ie->f)
156 { 165 {
157 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; 166 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
@@ -173,7 +182,7 @@ _evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
173 (*error == EVAS_LOAD_ERROR_NONE)) 182 (*error == EVAS_LOAD_ERROR_NONE))
174 { 183 {
175 DBG("loaded file head using module '%s' (%p): %s", 184 DBG("loaded file head using module '%s' (%p): %s",
176 em->definition->name, em, ie->file); 185 em->definition->name, em, file);
177 186
178 ie->w = property.w; 187 ie->w = property.w;
179 ie->h = property.h; 188 ie->h = property.h;
@@ -189,7 +198,7 @@ _evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
189 evas_module_unload(em); 198 evas_module_unload(em);
190 INF("failed to load file head using module '%s' (%p): " 199 INF("failed to load file head using module '%s' (%p): "
191 "%s (%s)", 200 "%s (%s)",
192 em->definition->name, em, ie->file, evas_load_error_str(*error)); 201 em->definition->name, em, file, evas_load_error_str(*error));
193 } 202 }
194 } 203 }
195 else 204 else
@@ -221,8 +230,8 @@ EAPI int
221evas_common_load_rgba_image_module_from_file(Image_Entry *ie) 230evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
222{ 231{
223 const char *loader = NULL, *end; 232 const char *loader = NULL, *end;
233 const char *file;
224 Evas_Module *em; 234 Evas_Module *em;
225 struct stat st;
226 unsigned int i; 235 unsigned int i;
227 int len, ret = EVAS_LOAD_ERROR_NONE; 236 int len, ret = EVAS_LOAD_ERROR_NONE;
228 struct evas_image_foreach_loader_data fdata; 237 struct evas_image_foreach_loader_data fdata;
@@ -240,14 +249,27 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
240 // } 249 // }
241 } 250 }
242#endif 251#endif
243 if (stat(ie->file, &st) != 0 || S_ISDIR(st.st_mode)) 252 if (ie->f)
244 { 253 {
245 DBG("trying to open directory '%s' !", ie->file); 254 len = strlen(eina_file_filename_get(ie->f));
246 return EVAS_LOAD_ERROR_DOES_NOT_EXIST; 255 end = eina_file_filename_get(ie->f) + len;
256 file = eina_file_filename_get(ie->f);
257 }
258 else
259 {
260 struct stat st;
261
262 if (stat(ie->file, &st) != 0 || S_ISDIR(st.st_mode))
263 {
264 DBG("trying to open directory '%s' !", ie->file);
265 return EVAS_LOAD_ERROR_DOES_NOT_EXIST;
266 }
267
268 len = strlen(ie->file);
269 end = ie->file + len;
270 file = ie->file;
247 } 271 }
248 272
249 len = strlen(ie->file);
250 end = ie->file + len;
251 for (i = 0; i < (sizeof (loaders) / sizeof(struct ext_loader_s)); i++) 273 for (i = 0; i < (sizeof (loaders) / sizeof(struct ext_loader_s)); i++)
252 { 274 {
253 int len2 = strlen(loaders[i].extension); 275 int len2 = strlen(loaders[i].extension);
@@ -256,7 +278,7 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
256 { 278 {
257 loader = loaders[i].loader; 279 loader = loaders[i].loader;
258 DBG("known loader '%s' handles extension '%s' of file '%s'", 280 DBG("known loader '%s' handles extension '%s' of file '%s'",
259 loader, end - len2, ie->file); 281 loader, end - len2, file);
260 break; 282 break;
261 } 283 }
262 } 284 }
@@ -296,10 +318,10 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
296 DBG("could not find module '%s'", loaders_name[i]); 318 DBG("could not find module '%s'", loaders_name[i]);
297 } 319 }
298 320
299 INF("exhausted all means to load image '%s'", ie->file); 321 INF("exhausted all means to load image '%s'", file);
300 return EVAS_LOAD_ERROR_UNKNOWN_FORMAT; 322 return EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
301 323
302 end: 324 end:
303 325
304 if (ret != EVAS_LOAD_ERROR_NONE) 326 if (ret != EVAS_LOAD_ERROR_NONE)
305 { 327 {
@@ -313,7 +335,7 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
313 WRN("loader '%s' (version %d) " 335 WRN("loader '%s' (version %d) "
314 "handled file '%s', key '%s' with errors: %s", 336 "handled file '%s', key '%s' with errors: %s",
315 modname ? modname : "<UNKNOWN>", modversion, 337 modname ? modname : "<UNKNOWN>", modversion,
316 ie->file, ie->key ? ie->key : "", 338 file, ie->key ? ie->key : "",
317 evas_load_error_str(ret)); 339 evas_load_error_str(ret));
318 goto end; 340 goto end;
319 } 341 }
@@ -321,7 +343,7 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
321 DBG("loader '%s' used for file %s", 343 DBG("loader '%s' used for file %s",
322 (em && em->definition && em->definition->name) ? 344 (em && em->definition && em->definition->name) ?
323 em->definition->name : "<UNKNOWN>", 345 em->definition->name : "<UNKNOWN>",
324 ie->file); 346 file);
325 347
326 ie->info.module = (void*) em; 348 ie->info.module = (void*) em;
327 ie->info.loader = (void*) em ? em->functions : NULL; 349 ie->info.loader = (void*) em ? em->functions : NULL;