AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2007.03.15 12:34 "[Tiff] tiff 32bit float writer", by Giuseppe Rota
2007.03.15 13:54 "Re: [Tiff] tiff 32bit float writer", by Kai-Uwe Behrmann
2007.03.15 17:25 "Re: [Tiff] tiff 32bit float writer", by Giuseppe Rota

2007.03.15 12:34 "[Tiff] tiff 32bit float writer", by Giuseppe Rota

Hi All,

I am using libtiff 3.7.4, and I have a strange problem with a 32bit float (not logluv) tiff writer. (I didn't find the solution on the ML archive) The problem is that the resulting file size seems to be "height" times more than expected.

I.e. if I am saving a 100x74 image I expect a size roughly close to: 100*74 px * 3 chan/px * 4 byte/chan = 88800 bytes.

Instead I get a file size of 8880732. (100 times more).

If I reduce the image to 10x7 pixels i get a file size of 8596 B, rather than the expected 840B.

Here's the code:
//R,G,B are arrays of float wrapped in a class.
    width=R->getWidth();
    height=R->getHeight();
    tif = TIFFOpen(filename, "w");

    TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
    TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
    TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 3);
    TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, 1);
    TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
    TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
    TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 32);
    tsize_t strip_size = TIFFStripSize (tif);

    tstrip_t strips_num = TIFFNumberOfStrips (tif);
    float* strip_buf=(float*)_TIFFmalloc(strip_size); //enough space for a
strip
    for (unsigned int s=0; s<strips_num; s++) {
        for (unsigned int col=0; col<width; col++) {

            strip_buf[3*col+0]=(*R)(col,s);
            strip_buf[3*col+1]=(*G)(col,s);
            strip_buf[3*col+2]=(*B)(col,s);
            if (TIFFWriteEncodedStrip (tif, s, strip_buf, strip_size) == 0)

{
               //deal with error
            }
        }
    }
    _TIFFfree(strip_buf);
    TIFFClose(tif);

I also tried to use all the rows as a single strip but it didn't change the outcome.

Thanks in advance,
Giuseppe