2008-11-05 09:21:04 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2011-01-16 00:08:13 -08:00
|
|
|
#include <sys/types.h>
|
2006-10-27 20:02:23 -07:00
|
|
|
#include <stdio.h>
|
2011-01-16 00:08:13 -08:00
|
|
|
#include <unistd.h>
|
2006-10-27 20:02:23 -07:00
|
|
|
#include <tiffio.h>
|
|
|
|
|
2008-11-05 09:21:04 -08:00
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2010-04-08 15:55:54 -07:00
|
|
|
static int _evas_loader_tiff_log_dom = -1;
|
2010-04-08 10:39:01 -07:00
|
|
|
|
|
|
|
#ifdef ERR
|
|
|
|
# undef ERR
|
|
|
|
#endif
|
|
|
|
#define ERR(...) EINA_LOG_DOM_ERR(_evas_loader_tiff_log_dom, __VA_ARGS__)
|
|
|
|
|
|
|
|
#ifdef INF
|
|
|
|
# undef INF
|
|
|
|
#endif
|
|
|
|
#define INF(...) EINA_LOG_DOM_INFO(_evas_loader_tiff_log_dom, __VA_ARGS__)
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool evas_image_load_file_head_tiff(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_tiff(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Image_Load_Func evas_image_load_tiff_func =
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
2009-12-24 05:15:34 -08:00
|
|
|
EINA_TRUE,
|
2006-04-08 17:10:47 -07:00
|
|
|
evas_image_load_file_head_tiff,
|
2011-08-10 23:04:08 -07:00
|
|
|
evas_image_load_file_data_tiff,
|
2011-12-13 08:58:20 -08:00
|
|
|
NULL,
|
|
|
|
EINA_FALSE
|
2006-04-08 17:10:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
|
|
|
|
|
|
|
|
struct TIFFRGBAImage_Extra {
|
|
|
|
TIFFRGBAImage rgba;
|
2008-06-03 02:09:39 -07:00
|
|
|
Image_Entry *image;
|
2006-04-08 17:10:47 -07:00
|
|
|
char pper;
|
|
|
|
uint32 num_pixels;
|
|
|
|
uint32 py;
|
|
|
|
};
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_head_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
|
|
|
char txt[1024];
|
|
|
|
TIFFRGBAImage tiff_image;
|
|
|
|
TIFF *tif = NULL;
|
|
|
|
FILE *ffile;
|
|
|
|
int fd;
|
|
|
|
uint16 magic_number;
|
|
|
|
|
|
|
|
ffile = fopen(file, "rb");
|
|
|
|
if (!ffile)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2007-10-28 03:08:32 -07:00
|
|
|
if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1)
|
|
|
|
{
|
|
|
|
fclose(ffile);
|
2010-09-18 18:14:56 -07:00
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2007-10-28 03:08:32 -07:00
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
/* Apparently rewind(f) isn't sufficient */
|
2010-09-18 18:14:56 -07:00
|
|
|
fseek(ffile, 0, SEEK_SET);
|
2006-04-08 17:10:47 -07:00
|
|
|
|
|
|
|
if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
|
|
|
|
&& (magic_number != TIFF_LITTLEENDIAN))
|
|
|
|
{
|
|
|
|
fclose(ffile);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fd = fileno(ffile);
|
|
|
|
fd = dup(fd);
|
|
|
|
lseek(fd, (long)0, SEEK_SET);
|
|
|
|
fclose(ffile);
|
|
|
|
|
|
|
|
tif = TIFFFdOpen(fd, file, "r");
|
|
|
|
if (!tif)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2006-05-27 23:22:10 -07:00
|
|
|
strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
|
2006-04-08 17:10:47 -07:00
|
|
|
if (!TIFFRGBAImageOK(tif, txt))
|
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
2006-05-27 23:22:10 -07:00
|
|
|
strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
|
2008-02-05 04:00:19 -08:00
|
|
|
if (!TIFFRGBAImageBegin(& tiff_image, tif, 1, txt))
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tiff_image.alpha != EXTRASAMPLE_UNSPECIFIED)
|
2008-06-03 02:09:39 -07:00
|
|
|
ie->flags.alpha = 1;
|
2006-11-04 21:07:53 -08:00
|
|
|
if ((tiff_image.width < 1) || (tiff_image.height < 1) ||
|
2009-09-16 02:48:05 -07:00
|
|
|
(tiff_image.width > IMG_MAX_SIZE) || (tiff_image.height > IMG_MAX_SIZE) ||
|
|
|
|
IMG_TOO_BIG(tiff_image.width, tiff_image.height))
|
2006-11-04 21:07:53 -08:00
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
if (IMG_TOO_BIG(tiff_image.width, tiff_image.height))
|
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
else
|
|
|
|
*error = EVAS_LOAD_ERROR_GENERIC;
|
|
|
|
return EINA_FALSE;
|
2006-11-04 21:07:53 -08:00
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
ie->w = tiff_image.width;
|
|
|
|
ie->h = tiff_image.height;
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2009-01-10 14:44:04 -08:00
|
|
|
TIFFRGBAImageEnd(&tiff_image);
|
2006-04-08 17:10:47 -07:00
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_data_tiff(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
|
|
|
char txt[1024];
|
|
|
|
TIFFRGBAImage_Extra rgba_image;
|
|
|
|
TIFF *tif = NULL;
|
|
|
|
FILE *ffile;
|
|
|
|
uint32 *rast = NULL;
|
|
|
|
uint32 num_pixels;
|
2011-04-11 23:20:38 -07:00
|
|
|
int fd, x, y;
|
2006-04-08 17:10:47 -07:00
|
|
|
uint16 magic_number;
|
2006-04-23 08:38:23 -07:00
|
|
|
|
2006-04-08 17:10:47 -07:00
|
|
|
ffile = fopen(file, "rb");
|
|
|
|
if (!ffile)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2010-09-18 16:39:30 -07:00
|
|
|
if (fread(&magic_number, sizeof(uint16), 1, ffile) != 1)
|
|
|
|
{
|
|
|
|
fclose(ffile);
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
/* Apparently rewind(f) isn't sufficient */
|
|
|
|
fseek(ffile, (long)0, SEEK_SET);
|
|
|
|
|
|
|
|
if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
|
|
|
|
&& (magic_number != TIFF_LITTLEENDIAN))
|
|
|
|
{
|
|
|
|
fclose(ffile);
|
2010-09-18 16:39:30 -07:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fd = fileno(ffile);
|
|
|
|
fd = dup(fd);
|
|
|
|
lseek(fd, (long)0, SEEK_SET);
|
|
|
|
fclose(ffile);
|
|
|
|
|
|
|
|
tif = TIFFFdOpen(fd, file, "r");
|
|
|
|
if (!tif)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2006-05-27 23:22:10 -07:00
|
|
|
strcpy(txt, "Evas Tiff loader: cannot be processed by libtiff");
|
2006-04-08 17:10:47 -07:00
|
|
|
if (!TIFFRGBAImageOK(tif, txt))
|
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
2006-05-27 23:22:10 -07:00
|
|
|
strcpy(txt, "Evas Tiff loader: cannot begin reading tiff");
|
2006-04-08 17:10:47 -07:00
|
|
|
if (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0, txt))
|
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
2008-06-03 02:09:39 -07:00
|
|
|
rgba_image.image = ie;
|
2006-04-08 17:10:47 -07:00
|
|
|
|
|
|
|
if (rgba_image.rgba.alpha != EXTRASAMPLE_UNSPECIFIED)
|
2008-06-03 02:09:39 -07:00
|
|
|
ie->flags.alpha = 1;
|
|
|
|
if ((rgba_image.rgba.width != ie->w) ||
|
|
|
|
(rgba_image.rgba.height != ie->h))
|
2006-11-04 21:07:53 -08:00
|
|
|
{
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2006-11-04 21:07:53 -08:00
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_cache_image_surface_alloc(ie, rgba_image.rgba.width, rgba_image.rgba.height);
|
|
|
|
if (!evas_cache_image_pixels(ie))
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
|
|
|
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
rgba_image.num_pixels = num_pixels = ie->w * ie->h;
|
2008-04-11 17:32:30 -07:00
|
|
|
|
2006-04-08 17:10:47 -07:00
|
|
|
rgba_image.pper = rgba_image.py = 0;
|
|
|
|
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
|
|
|
|
|
|
|
|
if (!rast)
|
|
|
|
{
|
2009-10-22 09:39:20 -07:00
|
|
|
ERR("Evas Tiff loader: out of memory");
|
2009-12-22 15:11:57 -08:00
|
|
|
|
2009-09-21 09:08:51 -07:00
|
|
|
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
if (rgba_image.rgba.bitspersample == 8)
|
|
|
|
{
|
2008-02-05 04:00:19 -08:00
|
|
|
if (!TIFFRGBAImageGet((TIFFRGBAImage *) &rgba_image, rast,
|
2006-04-08 17:10:47 -07:00
|
|
|
rgba_image.rgba.width, rgba_image.rgba.height))
|
|
|
|
{
|
|
|
|
_TIFFfree(rast);
|
|
|
|
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
|
|
|
|
TIFFClose(tif);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-22 09:39:20 -07:00
|
|
|
INF("channel bits == %i", (int)rgba_image.rgba.samplesperpixel);
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
2011-04-11 23:20:38 -07:00
|
|
|
/* process rast -> image rgba. really same as prior code anyway just simpler */
|
|
|
|
for (y = 0; y < (int)ie->h; y++)
|
|
|
|
{
|
|
|
|
DATA32 *pix, *pd;
|
|
|
|
uint32 *ps, pixel;
|
|
|
|
unsigned int a, r, g, b;
|
|
|
|
|
|
|
|
pix = evas_cache_image_pixels(ie);
|
|
|
|
pd = pix + ((ie->h - y - 1) * ie->w);
|
|
|
|
ps = rast + (y * ie->w);
|
|
|
|
for (x = 0; x < (int)ie->w; x++)
|
|
|
|
{
|
|
|
|
pixel = *ps;
|
|
|
|
a = TIFFGetA(pixel);
|
|
|
|
r = TIFFGetR(pixel);
|
|
|
|
g = TIFFGetG(pixel);
|
|
|
|
b = TIFFGetB(pixel);
|
|
|
|
if (!ie->flags.alpha) a = 255;
|
|
|
|
if ((rgba_image.rgba.alpha == EXTRASAMPLE_UNASSALPHA) &&
|
|
|
|
(a < 255))
|
|
|
|
{
|
|
|
|
r = (r * (a + 1)) >> 8;
|
|
|
|
g = (g * (a + 1)) >> 8;
|
|
|
|
b = (b * (a + 1)) >> 8;
|
|
|
|
}
|
|
|
|
*pd = ARGB_JOIN(a, r, g, b);
|
|
|
|
ps++;
|
|
|
|
pd++;
|
|
|
|
}
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
|
|
|
|
_TIFFfree(rast);
|
|
|
|
|
|
|
|
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
|
|
|
|
|
|
|
|
TIFFClose(tif);
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_common_image_set_alpha_sparse(ie);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2006-04-08 17:10:47 -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 17:10:47 -07:00
|
|
|
{
|
|
|
|
if (!em) return 0;
|
2010-10-07 16:46:42 -07:00
|
|
|
_evas_loader_tiff_log_dom = eina_log_domain_register
|
|
|
|
("evas-tiff", EVAS_DEFAULT_LOG_COLOR);
|
2010-04-08 10:39:01 -07:00
|
|
|
if (_evas_loader_tiff_log_dom < 0)
|
|
|
|
{
|
2010-10-07 16:46:42 -07:00
|
|
|
EINA_LOG_ERR("Can not create a module log domain.");
|
2010-04-08 10:39:01 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
em->functions = (void *)(&evas_image_load_tiff_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 17:10:47 -07:00
|
|
|
{
|
2010-04-08 10:39:01 -07:00
|
|
|
eina_log_domain_unregister(_evas_loader_tiff_log_dom);
|
2006-04-08 17:10:47 -07:00
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Module_Api evas_modapi =
|
2006-04-08 17:10:47 -07:00
|
|
|
{
|
|
|
|
EVAS_MODULE_API_VERSION,
|
2009-06-16 06:01:36 -07:00
|
|
|
"tiff",
|
|
|
|
"none",
|
|
|
|
{
|
|
|
|
module_open,
|
|
|
|
module_close
|
|
|
|
}
|
2006-04-08 17:10:47 -07:00
|
|
|
};
|
2009-06-16 06:01:36 -07:00
|
|
|
|
|
|
|
EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, tiff);
|
|
|
|
|
|
|
|
#ifndef EVAS_STATIC_BUILD_TIFF
|
|
|
|
EVAS_EINA_MODULE_DEFINE(image_loader, tiff);
|
|
|
|
#endif
|