move around - flatter.
[profile/ivi/evas.git] / src / lib / engines / common / evas_image_load.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #include "evas_common.h"
6 #include "evas_private.h"
7
8 extern Evas_List *evas_modules;
9
10 struct ext_loader_s {
11    const char*  extention;
12    const char*  loader;
13 };
14
15 static struct ext_loader_s      loaders[] = {
16    { "png", "png" },
17    { "jpg", "jpeg" },
18    { "jpeg", "jpeg" },
19    { "jfif", "jpeg" },
20    { "eet", "eet" },
21    { "edj", "eet" },
22    { "eap", "eet" },
23    { "edb", "edb" },
24    { "xpm", "xpm" },
25    { "tiff", "tiff" },
26    { "tif", "tiff" },
27    { "svg", "svg" },
28    { "svgz", "svg" },
29    { "gif", "gif" },
30    { "pbm", "pmaps" },
31    { "pgm", "pmaps" },
32    { "ppm", "pmaps" },
33    { "pnm", "pmaps" }
34 };
35
36 int
37 evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
38 {
39    Evas_Image_Load_Func *evas_image_load_func = NULL;
40    const char           *loader = NULL;
41    Evas_List            *l;
42    Evas_Module          *em;
43    char                 *dot;
44    int                   i;
45
46    dot = strrchr (ie->file, '.');
47    if (dot)
48      {
49         for (i = 0, ++dot; i < (sizeof (loaders) / sizeof (struct ext_loader_s)); ++i)
50           {
51              if (!strcasecmp (dot, loaders[i].extention))
52                {
53                   loader = loaders[i].loader;
54                   break;
55                }
56           }
57      }
58
59    if (loader)
60      {
61         em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
62         if (em)
63           {
64              if (evas_module_load(em))
65                {
66                   evas_module_use(em);
67                   evas_image_load_func = em->functions;
68                   if (evas_image_load_func->file_head(ie, ie->file, ie->key))
69                     goto ok;
70                }
71           }
72      }
73
74    for (l = evas_modules; l; l = l->next)
75      {
76         em = l->data;
77         if (em->type != EVAS_MODULE_TYPE_IMAGE_LOADER) continue;
78         if (!evas_module_load(em)) continue;
79         evas_image_load_func = em->functions;
80         evas_module_use(em);
81         if (evas_image_load_func->file_head(ie, ie->file, ie->key))
82           {
83              if (evas_modules != l)
84                {
85                   evas_modules = evas_list_promote_list(evas_modules, l);
86                }
87              goto ok;
88           }
89      }
90
91    return -1;
92
93   ok:
94    ie->info.module = (void*) em;
95    ie->info.loader = (void*) evas_image_load_func;
96    evas_module_ref((Evas_Module*) ie->info.module);
97    return 0;
98 }
99
100 int
101 evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
102 {
103    Evas_Image_Load_Func *evas_image_load_func = NULL;
104
105    if (!ie->info.module) return -1;
106    if (ie->flags.loaded) return -1;
107
108    evas_image_load_func = ie->info.loader;
109    evas_module_use((Evas_Module*) ie->info.module);
110    if (!evas_image_load_func->file_data(ie, ie->file, ie->key))
111      return -1;
112
113    evas_module_unref((Evas_Module*) ie->info.module);
114    ie->info.module = NULL;
115
116    return 0;
117 }