1994.12.02 20:30 "Appending images to an existing file", by Venkatesh Narayanan

1994.12.02 21:40 "Re: Appending images to an existing file", by Sam Leffler

I'm trying to append some images to an existing TIFF file that already has an image in it. I'm not having much sucess doing this. Here is the sequence of calls I'm making:

        tiff = TIFFFOpen(filename, "r+"); //I've also tried "a" without success
        TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, xsize);
        TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, ysize);
        TIFFSetField(tiff, TIFFTAG_IMAGEDEPTH, 1);
        TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bpp);
        TIFFSetField(tiff, TIFFTAG_SAMPLEFORMAT, ttype);
        TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField(tiff, TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);
        TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, csize);
        TIFFSetField(tiff, TIFFTAG_TILEWIDTH, xPageSize);
        TIFFSetField(tiff, TIFFTAG_TILELENGTH, yPageSize);
        TIFFSetField(tiff, TIFFTAG_TILEDEPTH, 1);
        TIFFWriteDirectory(tiff);
        TIFFSetDirectory(tiff, 1); //this always fails and I get the message :
                                   //"Could not index into TIFF directory"
        While(..there are tiles to write..)
                TIFFWriteEncodedTile (tiff, tile, bufdata, bytecount);

Opening the file "r+" is not supported. If you want to append use "a". I'm not sure what will happen with the above code. My guess is that the TIFFWriteDirectory call will fail (though it should have generated a diagnostic) and then the TIFFSetDirectory call will fail because, presumably, you only have 1 IFD in the file.

Even if I take out the TIFFSetDirectory() call, what happens is that the existing file has been corrupted and can't be read at all. Anyone successfully appended images? The README file says that the append mode hasn't been tested.

Appending to a file works fine in v3.3beta021; you don't indicate what version you have.

    Sam