efl/legacy/evas/src/lib/engines/common/evas_image_load.c

110 lines
2.4 KiB
C
Raw Normal View History

2002-11-08 00:02:15 -08:00
#include "evas_common.h"
#include "evas_private.h"
extern Evas_List *evas_modules;
2005-05-21 19:49:50 -07:00
static Evas_Image_Load_Func *evas_image_load_func = NULL;
2002-11-08 00:02:15 -08:00
RGBA_Image *
evas_common_load_image_from_file(const char *file, const char *key)
2002-11-08 00:02:15 -08:00
{
Evas_List *l;
2002-11-08 00:02:15 -08:00
RGBA_Image *im;
char *p;
char *loader = NULL;
2004-09-21 00:45:13 -07:00
if (file == NULL)
return NULL;
2005-05-21 19:49:50 -07:00
im = evas_common_image_find(file, key, 0);
2002-11-08 00:02:15 -08:00
if (im)
{
evas_common_image_ref(im);
2002-11-08 00:02:15 -08:00
return im;
}
im = evas_common_image_new();
2003-02-04 20:19:16 -08:00
if (!im)
{
return NULL;
}
p = strrchr(file, '.');
if (p)
{
p++;
if (!strcasecmp(p, "png"))
loader = "png";
if ((!strcasecmp(p, "jpg")) || (!strcasecmp(p, "jpeg")) ||
(!strcasecmp(p, "jfif")))
loader = "jpeg";
if ((!strcasecmp(p, "eet")) || (!strcasecmp(p, "edj")) ||
2006-01-14 20:49:46 -08:00
(!strcasecmp(p, "eap")))
loader = "eet";
if (!strcasecmp(p, "edb"))
loader = "edb";
}
if (loader)
{
Evas_Module *em;
em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
if (em)
{
if (evas_module_load(em))
{
evas_image_load_func = em->functions;
if (evas_image_load_func->file_head(im, file, key))
goto ok;
}
}
}
for (l = evas_modules; l; l = l->next)
2003-01-09 18:05:37 -08:00
{
Evas_Module *em;
em = l->data;
if (em->type != EVAS_MODULE_TYPE_IMAGE_LOADER) continue;
if (!evas_module_load(em)) continue;
evas_image_load_func = em->functions;
if (evas_image_load_func->file_head(im, file, key))
{
if (evas_modules != l)
{
evas_modules = evas_list_remove_list(evas_modules, l);
evas_modules = evas_list_prepend(evas_modules, em);
}
goto ok;
}
2003-02-04 20:19:16 -08:00
}
evas_common_image_free(im);
return NULL;
ok:
im->info.file = (char *)evas_stringshare_add(file);
if (key) im->info.key = (char *)evas_stringshare_add(key);
evas_common_image_ref(im);
2002-11-08 00:02:15 -08:00
return im;
}
void
evas_common_load_image_data_from_file(RGBA_Image *im)
2002-11-08 00:02:15 -08:00
{
if (im->image->data) return;
if (!evas_image_load_func->file_data(im, im->info.file, im->info.key))
2002-11-08 00:02:15 -08:00
{
evas_common_image_surface_alloc(im->image);
2002-11-08 00:02:15 -08:00
if (!im->image->data)
{
const DATA32 pixel = 0xffffffff;
2005-05-21 19:49:50 -07:00
2002-11-08 00:02:15 -08:00
im->image->w = 1;
im->image->h = 1;
im->image->data = (DATA32 *)&pixel;
im->image->no_free = 1;
}
}
}