2004.07.26 12:23 "[Tiff] Saving multiple images to a tiff file...", by Sanjay Gupta

2004.07.26 12:23 "[Tiff] Saving multiple images to a tiff file...", by Sanjay Gupta

Hi List,

I have a set of pixel data, which i want to store in a tiff file. All the elements from set of pixel data needs to be saved in the same file, thereby creating a tiff file with multiple images.

I have the following code,

for (k = 0; k < frameCount; k++) {
                data = image->frameDimensionList [j].frames [k];
        TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, data.Width);
        TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, data.Height);
        TIFFSetField (tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

        TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

        TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
        TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 4); /* Hardcoded 32bbps*/
        TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);

        linebytes =  data.Stride;
        TIFFSetField (tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize (tiff, linebytes));

        /*write data*/
        for (i = 0; i < data.Height; i++) {
                if (TIFFWriteScanline (tiff, data.Scan0 + i * data.Stride, i, 0) < 0) /*Scan0 points to the char * for pixels*/
                        break;
        }

        TIFFWriteDirectory (tiff);
}

Now when i try to reload the image from my program, the saved file is not recognized as a valid tiff file. The problem what i am seeing is, my program is not saving the correct dircount for the tiff file, and while reading the tiff image, some junk value is read, because of which loading of image doesnt work. What else needs to be done in my above code, to make it work properly. The above piece of code works fine it there is only 1 image which needs to go in a tiff file.

Any pointers, suggestions or help will be greatly appreciated.

Thanx,
Sanjay