2008-03-14 09:49:49 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h" /* so that EAPI in Eet.h is correctly defined */
|
|
|
|
#endif
|
2006-01-14 12:03:42 -08:00
|
|
|
|
2006-10-27 20:02:23 -07:00
|
|
|
#include <Eet.h>
|
|
|
|
|
2008-03-14 09:49:49 -07:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2006-01-14 12:03:42 -08:00
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
|
|
static Eina_Bool evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
2006-01-14 12:03:42 -08:00
|
|
|
|
|
|
|
Evas_Image_Load_Func evas_image_load_eet_func =
|
|
|
|
{
|
2009-12-24 05:15:34 -08:00
|
|
|
EINA_TRUE,
|
2006-01-14 12:03:42 -08:00
|
|
|
evas_image_load_file_head_eet,
|
2011-08-10 23:04:08 -07:00
|
|
|
evas_image_load_file_data_eet,
|
2011-12-13 08:58:20 -08:00
|
|
|
NULL,
|
|
|
|
EINA_FALSE
|
2006-01-14 12:03:42 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_head_eet(Image_Entry *ie, const char *file, const char *key, int *error)
|
2006-01-14 12:03:42 -08:00
|
|
|
{
|
|
|
|
int alpha, compression, quality, lossy;
|
|
|
|
unsigned int w, h;
|
|
|
|
Eet_File *ef;
|
|
|
|
int ok;
|
2009-12-22 15:11:57 -08:00
|
|
|
Eina_Bool res = EINA_FALSE;
|
|
|
|
|
|
|
|
if (!key)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-01-14 12:03:42 -08:00
|
|
|
|
|
|
|
ef = eet_open((char *)file, EET_FILE_MODE_READ);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!ef)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
ok = eet_data_image_header_read(ef, key,
|
2006-01-14 12:03:42 -08:00
|
|
|
&w, &h, &alpha, &compression, &quality, &lossy);
|
2010-01-18 12:04:21 -08:00
|
|
|
if (!ok)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
2010-01-18 12:04:21 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
2009-12-22 15:11:57 -08:00
|
|
|
goto on_error;
|
|
|
|
}
|
2010-01-18 12:04:21 -08:00
|
|
|
if (IMG_TOO_BIG(w, h))
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
2010-01-18 12:04:21 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
2009-12-22 15:11:57 -08:00
|
|
|
goto on_error;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
if (alpha) ie->flags.alpha = 1;
|
|
|
|
ie->w = w;
|
|
|
|
ie->h = h;
|
2009-12-22 15:11:57 -08:00
|
|
|
res = EINA_TRUE;
|
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
2008-06-03 02:09:39 -07:00
|
|
|
|
|
|
|
on_error:
|
2006-01-14 12:03:42 -08:00
|
|
|
eet_close(ef);
|
2008-06-03 02:09:39 -07:00
|
|
|
return res;
|
2006-01-14 12:03:42 -08:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
Eina_Bool
|
|
|
|
evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error)
|
2006-01-14 12:03:42 -08:00
|
|
|
{
|
|
|
|
unsigned int w, h;
|
2008-06-03 02:09:39 -07:00
|
|
|
int alpha, compression, quality, lossy, ok;
|
2006-01-14 12:03:42 -08:00
|
|
|
Eet_File *ef;
|
2011-05-19 02:25:31 -07:00
|
|
|
DATA32 *body, *p, *end, *data;
|
2006-10-02 04:24:26 -07:00
|
|
|
DATA32 nas = 0;
|
2009-12-22 15:11:57 -08:00
|
|
|
Eina_Bool res = EINA_FALSE;
|
2006-01-14 12:03:42 -08:00
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!key)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
if (ie->flags.loaded)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
ef = eet_open(file, EET_FILE_MODE_READ);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!ef)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
ok = eet_data_image_header_read(ef, key,
|
|
|
|
&w, &h, &alpha, &compression, &quality, &lossy);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (IMG_TOO_BIG(w, h))
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
goto on_error;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_cache_image_surface_alloc(ie, w, h);
|
2011-05-19 02:25:31 -07:00
|
|
|
data = evas_cache_image_pixels(ie);
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
goto on_error;
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
ok = eet_data_image_read_to_surface(ef, key, 0, 0,
|
2011-05-19 02:25:31 -07:00
|
|
|
data, w, h, w * 4,
|
2008-06-03 02:09:39 -07:00
|
|
|
&alpha, &compression, &quality, &lossy);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
|
|
|
goto on_error;
|
|
|
|
}
|
2006-10-01 22:28:39 -07:00
|
|
|
if (alpha)
|
|
|
|
{
|
2008-06-03 02:09:39 -07:00
|
|
|
ie->flags.alpha = 1;
|
|
|
|
|
|
|
|
body = evas_cache_image_pixels(ie);
|
|
|
|
|
2006-10-01 22:28:39 -07:00
|
|
|
end = body +(w * h);
|
|
|
|
for (p = body; p < end; p++)
|
|
|
|
{
|
|
|
|
DATA32 r, g, b, a;
|
2008-06-03 02:09:39 -07:00
|
|
|
|
2006-10-01 22:28:39 -07:00
|
|
|
a = A_VAL(p);
|
|
|
|
r = R_VAL(p);
|
|
|
|
g = G_VAL(p);
|
|
|
|
b = B_VAL(p);
|
2006-10-02 04:24:26 -07:00
|
|
|
if ((a == 0) || (a == 255)) nas++;
|
2006-10-01 22:28:39 -07:00
|
|
|
if (r > a) r = a;
|
|
|
|
if (g > a) g = a;
|
|
|
|
if (b > a) b = a;
|
|
|
|
*p = ARGB_JOIN(a, r, g, b);
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
|
|
|
|
ie->flags.alpha_sparse = 1;
|
2006-10-01 22:28:39 -07:00
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
// result is already premultiplied now if u compile with edje
|
2006-09-30 03:18:37 -07:00
|
|
|
// evas_common_image_premul(im);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
res = EINA_TRUE;
|
2008-06-03 02:09:39 -07:00
|
|
|
|
|
|
|
on_error:
|
2006-01-14 12:03:42 -08:00
|
|
|
eet_close(ef);
|
2008-06-03 02:09:39 -07:00
|
|
|
return res;
|
2006-01-14 12:03:42 -08:00
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static int
|
2006-09-06 00:28:46 -07:00
|
|
|
module_open(Evas_Module *em)
|
2006-01-14 12:03:42 -08:00
|
|
|
{
|
|
|
|
if (!em) return 0;
|
|
|
|
em->functions = (void *)(&evas_image_load_eet_func);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static void
|
cleanup: fix some "unused" errors from -Wextra.
As we're heading for a release we better remove as much errors as
possible and as the first step I'm removing warnings due unused
parameters, variables and functions. These tend to pollute real errors
spotted by -Wall and clang/llvm.
This does not fixes all, just the clear that could be set to
__UNUSED__, particularly to do (and I'd like some help from the
authors):
* src/lib/engines/common/evas_font_{draw,query}.c (tasn):
intl_props is just used while doing BIDI, but also used in other
#ifdef blocks :-/
* evas_map_* (raster):
huge amount of warnings, code is quite confusing and thus I'm not
touching it. I have no idea whenever the commented blocks or extra
parameters are intended to be used or no.
* src/modules/engines/fbevas_fb_main.c (raster?):
is fb_setvt() to be used? If not do you mind removing it?
* src/modules/engines/gl_{common,x11} (raster):
huge amount of warnings, code is quite nested and full of #ifdefs
that does not help to give a clear picture of what's going on.
* src/bin/evas_cserve_main.c (raster):
I could have ignored most of the errors, but is the code correct? I
mean, there is no unload of images being applied. If you confirm
none of those warnings are harmful I can flag them as unused.
* src/lib/engines/common_8 (dottedmag):
lots of unused functions that were acquired from common_16, they
are unused and if they will not, then they should be removed.
SVN revision: 52421
2010-09-18 12:17:41 -07:00
|
|
|
module_close(Evas_Module *em __UNUSED__)
|
2006-01-14 12:03:42 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Module_Api evas_modapi =
|
2006-01-14 12:03:42 -08:00
|
|
|
{
|
|
|
|
EVAS_MODULE_API_VERSION,
|
2009-06-16 06:01:36 -07:00
|
|
|
"eet",
|
|
|
|
"none",
|
|
|
|
{
|
|
|
|
module_open,
|
|
|
|
module_close
|
|
|
|
}
|
2006-01-14 12:03:42 -08:00
|
|
|
};
|
2009-06-16 06:01:36 -07:00
|
|
|
|
|
|
|
EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, eet);
|
|
|
|
|
|
|
|
#ifndef EVAS_STATIC_BUILD_EET
|
|
|
|
EVAS_EINA_MODULE_DEFINE(image_loader, eet);
|
|
|
|
#endif
|