tiff saver and more checks

SVN revision: 21997
This commit is contained in:
doursse 2006-04-10 07:27:54 +00:00 committed by doursse
parent 34b43317af
commit ed9ce5b051
7 changed files with 176 additions and 2 deletions

View File

@ -1817,6 +1817,7 @@ src/modules/savers/edb/Makefile
src/modules/savers/eet/Makefile
src/modules/savers/jpeg/Makefile
src/modules/savers/png/Makefile
src/modules/savers/tiff/Makefile
src/lib/include/Makefile
proj/Makefile
proj/win32_gdi/Makefile

View File

@ -16,4 +16,8 @@ if BUILD_LOADER_PNG
png_subdir = png
endif
SUBDIRS = $(edb_subdir) $(eet_subdir) $(jpeg_subdir) $(png_subdir)
if BUILD_LOADER_TIFF
tiff_subdir = tiff
endif
SUBDIRS = $(edb_subdir) $(eet_subdir) $(jpeg_subdir) $(png_subdir) $(tiff_subdir)

View File

@ -17,6 +17,9 @@ evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int
Eet_File *ef;
int alpha = 0, lossy = 0, ok = 0;
if (!im || !im->image || !im->image->data || !file)
return 0;
ef = eet_open((char *)file, EET_FILE_MODE_READ_WRITE);
if (!ef) ef = eet_open((char *)file, EET_FILE_MODE_WRITE);
if (!ef) return 0;

View File

@ -63,6 +63,9 @@ save_image_jpeg(RGBA_Image *im, const char *file, int quality)
JSAMPROW *jbuf;
int y = 0;
int i, j;
if (!im || !im->image || !im->image->data || !file)
return 0;
buf = alloca(im->image->w * 3 * sizeof(DATA8));
f = fopen(file, "wb");

View File

@ -22,7 +22,10 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
int x, y, j;
png_bytep row_ptr, data = NULL;
png_color_8 sig_bit;
int quality = 75, compression = 3, num_passes = 1, pass;
int num_passes = 1, pass;
if (!im || !im->image || !im->image->data || !file)
return 0;
f = fopen(file, "wb");
if (!f) return 0;

View File

@ -0,0 +1,24 @@
## Process this file with automake to produce Makefile.in
AUTOMAKE_OPTIONS = 1.4 foreign
# A list of all the files in the current directory which can be regenerated
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = -I. \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/lib/include \
@FREETYPE_CFLAGS@ @tiff_cflags@
pkgdir = $(libdir)/evas/modules/savers/tiff/$(MODULE_ARCH)
pkg_LTLIBRARIES = module.la
module_la_SOURCES = evas_image_save_tiff.c
module_la_LIBADD = @tiff_libs@ $(top_builddir)/src/lib/libevas.la
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
module_la_DEPENDENCIES = $(top_builddir)/config.h
EXTRA_DIST = evas_image_save_tiff.c

View File

@ -0,0 +1,136 @@
#include <tiffio.h>
#include "evas_common.h"
#include "evas_private.h"
int evas_image_save_file_tiff(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
Evas_Image_Save_Func evas_image_save_tiff_func =
{
evas_image_save_file_tiff
};
static int
save_image_tiff(RGBA_Image *im, const char *file, int compress, int interlace)
{
TIFF *tif = NULL;
uint8 *buf = NULL;
DATA32 pixel;
DATA32 *data;
double alpha_factor;
uint32 x, y;
uint8 r, g, b, a = 0;
int i = 0;
int has_alpha;
if (!im || !im->image || !im->image->data || !file)
return 0;
has_alpha = im->flags & RGBA_IMAGE_HAS_ALPHA;
data = im->image->data;
tif = TIFFOpen(file, "w");
if (!tif)
return 0;
/* None of the TIFFSetFields are checked for errors, but since they */
/* shouldn't fail, this shouldn't be a problem */
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->image->h);
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->image->w);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
/* By default uses patent-free use COMPRESSION_DEFLATE,
* another lossless compression technique */
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
if (has_alpha)
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA);
}
else
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
}
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
buf = (uint8 *) _TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
{
TIFFClose(tif);
return 0;
}
for (y = 0; y < im->image->h; y++)
{
i = 0;
for (x = 0; x < im->image->w; x++)
{
pixel = data[(y * im->image->w) + x];
r = (pixel >> 16) & 0xff;
g = (pixel >> 8) & 0xff;
b = pixel & 0xff;
if (has_alpha)
{
/* TIFF makes you pre-mutiply the rgb components by alpha */
a = (pixel >> 24) & 0xff;
alpha_factor = ((double)a / 255.0);
r *= alpha_factor;
g *= alpha_factor;
b *= alpha_factor;
}
/* This might be endian dependent */
buf[i++] = r;
buf[i++] = g;
buf[i++] = b;
if (has_alpha)
buf[i++] = a;
}
if (!TIFFWriteScanline(tif, buf, y, 0))
{
_TIFFfree(buf);
TIFFClose(tif);
return 0;
}
}
_TIFFfree(buf);
TIFFClose(tif);
return 1;
}
int evas_image_save_file_tiff(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
{
return save_image_tiff(im, file, compress, 0);
}
int module_open(Evas_Module *em)
{
if (!em) return 0;
em->functions = (void *)(&evas_image_save_tiff_func);
return 1;
}
void module_close(void)
{
}
Evas_Module_Api evas_modapi =
{
EVAS_MODULE_API_VERSION,
EVAS_MODULE_TYPE_IMAGE_SAVER,
"tiff",
"none"
};