1 #include "evas_common.h"
2 #include "evas_private.h"
6 int evas_image_save_file_tiff(RGBA_Image *im, const char *file, const char *key, int quality, int compress);
8 Evas_Image_Save_Func evas_image_save_tiff_func =
10 evas_image_save_file_tiff
14 save_image_tiff(RGBA_Image *im, const char *file, int compress, int interlace)
25 if (!im || !im->image.data || !file)
28 has_alpha = im->cache_entry.flags.alpha;
29 data = im->image.data;
31 tif = TIFFOpen(file, "w");
35 /* None of the TIFFSetFields are checked for errors, but since they */
36 /* shouldn't fail, this shouldn't be a problem */
38 TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->cache_entry.h);
39 TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->cache_entry.w);
40 TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
41 TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
42 TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
43 TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
45 /* By default uses patent-free use COMPRESSION_DEFLATE,
46 * another lossless compression technique */
47 TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
51 uint16 extras[] = { EXTRASAMPLE_ASSOCALPHA };
52 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
53 TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, extras);
57 TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
60 TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
61 TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
63 buf = (uint8 *) _TIFFmalloc(TIFFScanlineSize(tif));
70 for (y = 0; y < im->cache_entry.h; y++)
73 for (x = 0; x < im->cache_entry.w; x++)
75 pixel = data[(y * im->cache_entry.w) + x];
77 r = (pixel >> 16) & 0xff;
78 g = (pixel >> 8) & 0xff;
81 a = (pixel >> 24) & 0xff;
83 /* This might be endian dependent */
91 if (!TIFFWriteScanline(tif, buf, y, 0))
105 int evas_image_save_file_tiff(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
107 return save_image_tiff(im, file, compress, 0);
111 module_open(Evas_Module *em)
114 em->functions = (void *)(&evas_image_save_tiff_func);
124 EAPI Evas_Module_Api evas_modapi =
126 EVAS_MODULE_API_VERSION,
127 EVAS_MODULE_TYPE_IMAGE_SAVER,