From ff7773a8da615e4dc91320636beb4e6877777a01 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 31 Jul 2006 20:34:14 +0200 Subject: initial tiff write support --- src/DataImage.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/DataImage.cxx') diff --git a/src/DataImage.cxx b/src/DataImage.cxx index f7968b2..2f1ad80 100644 --- a/src/DataImage.cxx +++ b/src/DataImage.cxx @@ -25,6 +25,7 @@ #include extern "C" { #include +#include } #include @@ -161,3 +162,34 @@ DataImage::write_jpeg(const char *file, int quality) { return 0; } + +int +DataImage::write_tiff(const char *file) { + TIFF *output; + uint32 width, height; + char *raster; + + // Open the output image + if((output = TIFFOpen(file, "w")) == NULL){ + fprintf(stderr, "can't open %s\n", file); + return 1; + } + + // Write the tiff tags to the file + TIFFSetField(output, TIFFTAG_IMAGEWIDTH, w()); + TIFFSetField(output, TIFFTAG_IMAGELENGTH, h()); + TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE); + TIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, 3); + + // Actually write the image + if(TIFFWriteEncodedStrip(output, 0, data, w() * h() * 3) == 0){ + fprintf(stderr, "Could not write image\n"); + return 2; + } + + TIFFClose(output); + return 0; +} -- cgit v1.2.3