2006-10-27 20:02:23 -07:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2006-04-08 05:22:18 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <gif_lib.h>
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool evas_image_load_file_head_gif(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_gif(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
2006-04-08 05:22:18 -07:00
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Image_Load_Func evas_image_load_gif_func =
|
2006-04-08 05:22:18 -07:00
|
|
|
{
|
2009-12-24 05:15:34 -08:00
|
|
|
EINA_TRUE,
|
2006-04-08 05:22:18 -07:00
|
|
|
evas_image_load_file_head_gif,
|
|
|
|
evas_image_load_file_data_gif
|
|
|
|
};
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_head_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2006-04-08 05:22:18 -07:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
GifFileType *gif;
|
|
|
|
GifRecordType rec;
|
|
|
|
int done;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int alpha;
|
|
|
|
|
|
|
|
done = 0;
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
|
|
|
alpha = -1;
|
|
|
|
|
|
|
|
#ifndef __EMX__
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
#else
|
|
|
|
fd = open(file, O_RDONLY | O_BINARY);
|
|
|
|
#endif
|
|
|
|
if (fd < 0)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 05:22:18 -07:00
|
|
|
|
|
|
|
gif = DGifOpenFileHandle(fd);
|
|
|
|
if (!gif)
|
|
|
|
{
|
|
|
|
close(fd);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (DGifGetRecordType(gif, &rec) == GIF_ERROR)
|
|
|
|
{
|
|
|
|
/* PrintGifError(); */
|
|
|
|
rec = TERMINATE_RECORD_TYPE;
|
|
|
|
}
|
|
|
|
if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done))
|
|
|
|
{
|
|
|
|
if (DGifGetImageDesc(gif) == GIF_ERROR)
|
|
|
|
{
|
|
|
|
/* PrintGifError(); */
|
|
|
|
rec = TERMINATE_RECORD_TYPE;
|
|
|
|
}
|
|
|
|
w = gif->Image.Width;
|
|
|
|
h = gif->Image.Height;
|
2009-09-16 02:48:05 -07:00
|
|
|
if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
|
|
|
|
IMG_TOO_BIG(w, h))
|
2006-11-04 21:07:53 -08:00
|
|
|
{
|
|
|
|
DGifCloseFile(gif);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (IMG_TOO_BIG(w, h))
|
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
else
|
|
|
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
|
|
|
return EINA_FALSE;
|
2006-11-04 21:07:53 -08:00
|
|
|
}
|
|
|
|
done = 1;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
else if (rec == EXTENSION_RECORD_TYPE)
|
|
|
|
{
|
|
|
|
int ext_code;
|
|
|
|
GifByteType *ext;
|
2009-12-22 15:11:57 -08:00
|
|
|
|
2006-04-08 05:22:18 -07:00
|
|
|
ext = NULL;
|
|
|
|
DGifGetExtension(gif, &ext_code, &ext);
|
|
|
|
while (ext)
|
|
|
|
{
|
|
|
|
if ((ext_code == 0xf9) && (ext[1] & 1) && (alpha < 0))
|
|
|
|
{
|
|
|
|
alpha = (int)ext[4];
|
|
|
|
}
|
|
|
|
ext = NULL;
|
|
|
|
DGifGetExtensionNext(gif, &ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (rec != TERMINATE_RECORD_TYPE);
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
if (alpha >= 0) ie->flags.alpha = 1;
|
|
|
|
ie->w = w;
|
|
|
|
ie->h = h;
|
2006-04-08 05:22:18 -07:00
|
|
|
|
|
|
|
DGifCloseFile(gif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_data_gif(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2006-04-08 05:22:18 -07:00
|
|
|
{
|
|
|
|
int intoffset[] = { 0, 4, 2, 1 };
|
|
|
|
int intjump[] = { 8, 8, 4, 2 };
|
|
|
|
double per;
|
|
|
|
double per_inc;
|
|
|
|
int fd;
|
|
|
|
GifFileType *gif;
|
|
|
|
GifRecordType rec;
|
|
|
|
GifRowType *rows;
|
|
|
|
ColorMapObject *cmap;
|
|
|
|
DATA32 *ptr;
|
|
|
|
int done;
|
|
|
|
int last_y;
|
|
|
|
int last_per;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int alpha;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int bg;
|
|
|
|
int r;
|
|
|
|
int g;
|
|
|
|
int b;
|
|
|
|
|
|
|
|
rows = NULL;
|
|
|
|
per = 0.0;
|
|
|
|
done = 0;
|
|
|
|
last_y = 0;
|
|
|
|
last_per = 0;
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
|
|
|
alpha = -1;
|
|
|
|
|
|
|
|
#ifndef __EMX__
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
#else
|
|
|
|
fd = open(file, O_RDONLY | O_BINARY);
|
|
|
|
#endif
|
|
|
|
if (fd < 0)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 05:22:18 -07:00
|
|
|
|
|
|
|
gif = DGifOpenFileHandle(fd);
|
|
|
|
if (!gif)
|
|
|
|
{
|
|
|
|
close(fd);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (DGifGetRecordType(gif, &rec) == GIF_ERROR)
|
|
|
|
{
|
|
|
|
/* PrintGifError(); */
|
|
|
|
rec = TERMINATE_RECORD_TYPE;
|
|
|
|
}
|
|
|
|
if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done))
|
|
|
|
{
|
|
|
|
if (DGifGetImageDesc(gif) == GIF_ERROR)
|
|
|
|
{
|
|
|
|
/* PrintGifError(); */
|
|
|
|
rec = TERMINATE_RECORD_TYPE;
|
|
|
|
}
|
|
|
|
w = gif->Image.Width;
|
|
|
|
h = gif->Image.Height;
|
|
|
|
rows = malloc(h * sizeof(GifRowType *));
|
|
|
|
if (!rows)
|
|
|
|
{
|
|
|
|
DGifCloseFile(gif);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
rows[i] = NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
rows[i] = malloc(w * sizeof(GifPixelType));
|
|
|
|
if (!rows[i])
|
|
|
|
{
|
|
|
|
DGifCloseFile(gif);
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
if (rows[i])
|
|
|
|
{
|
|
|
|
free(rows[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(rows);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gif->Image.Interlace)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
for (j = intoffset[i]; j < h; j += intjump[i])
|
|
|
|
{
|
|
|
|
DGifGetLine(gif, rows[j], w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
DGifGetLine(gif, rows[i], w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
else if (rec == EXTENSION_RECORD_TYPE)
|
|
|
|
{
|
|
|
|
int ext_code;
|
|
|
|
GifByteType *ext;
|
|
|
|
|
|
|
|
ext = NULL;
|
|
|
|
DGifGetExtension(gif, &ext_code, &ext);
|
|
|
|
while (ext)
|
|
|
|
{
|
|
|
|
if ((ext_code == 0xf9) && (ext[1] & 1) && (alpha < 0))
|
|
|
|
{
|
|
|
|
alpha = (int)ext[4];
|
|
|
|
}
|
|
|
|
ext = NULL;
|
|
|
|
DGifGetExtensionNext(gif, &ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (rec != TERMINATE_RECORD_TYPE);
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
if (alpha >= 0) ie->flags.alpha = 1;
|
|
|
|
evas_cache_image_surface_alloc(ie, w, h);
|
|
|
|
if (!evas_cache_image_pixels(ie))
|
2006-04-08 05:22:18 -07:00
|
|
|
{
|
|
|
|
DGifCloseFile(gif);
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
free(rows[i]);
|
|
|
|
}
|
|
|
|
free(rows);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bg = gif->SBackGroundColor;
|
|
|
|
cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap);
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
ptr = evas_cache_image_pixels(ie);
|
2006-04-08 05:22:18 -07:00
|
|
|
per_inc = 100.0 / (((double)w) * h);
|
|
|
|
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < w; j++)
|
|
|
|
{
|
|
|
|
if (rows[i][j] == alpha)
|
|
|
|
{
|
|
|
|
r = cmap->Colors[bg].Red;
|
|
|
|
g = cmap->Colors[bg].Green;
|
|
|
|
b = cmap->Colors[bg].Blue;
|
2010-06-07 22:39:46 -07:00
|
|
|
*ptr++ = 0x00ffffff & RGB_JOIN(r, g, b);
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = cmap->Colors[rows[i][j]].Red;
|
|
|
|
g = cmap->Colors[rows[i][j]].Green;
|
|
|
|
b = cmap->Colors[rows[i][j]].Blue;
|
2010-06-07 22:39:46 -07:00
|
|
|
*ptr++ = ARGB_JOIN(0xff, r, g, b);
|
2006-04-08 05:22:18 -07:00
|
|
|
}
|
|
|
|
per += per_inc;
|
|
|
|
}
|
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_common_image_premul(ie);
|
2006-04-08 05:22:18 -07:00
|
|
|
DGifCloseFile(gif);
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
|
|
|
free(rows[i]);
|
|
|
|
}
|
|
|
|
free(rows);
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2006-04-08 05:22:18 -07: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-04-08 05:22:18 -07:00
|
|
|
{
|
|
|
|
if (!em) return 0;
|
|
|
|
em->functions = (void *)(&evas_image_load_gif_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-04-08 05:22:18 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Module_Api evas_modapi =
|
2006-04-08 05:22:18 -07:00
|
|
|
{
|
2009-06-16 06:01:36 -07:00
|
|
|
EVAS_MODULE_API_VERSION,
|
|
|
|
"gif",
|
|
|
|
"none",
|
|
|
|
{
|
|
|
|
module_open,
|
|
|
|
module_close
|
|
|
|
}
|
2006-04-08 05:22:18 -07:00
|
|
|
};
|
2009-06-16 06:01:36 -07:00
|
|
|
|
|
|
|
EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, gif);
|
|
|
|
|
|
|
|
#ifndef EVAS_STATIC_BUILD_GIF
|
|
|
|
EVAS_EINA_MODULE_DEFINE(image_loader, gif);
|
|
|
|
#endif
|