2003.07.30 21:53 "[Tiff] writing tiles to tiff file", by Pushkar Pradhan

Hi,

I'm new to libtiff programming. I've looked at some examples on the web but can't write out a tiled img. correctly.

I'm trying to read in a 3 band tiled img. into 3 buffers and write it out. (I use tiffinfo to verify it's a tiled, band separate img.)

I got the img width, length and tile width, length of the i/p img. using TIFFGetField and the other params. like planarconfig, samplesperpixel etc. Similarly I use TIFFSetField to set up the o/p img. info.

    bufR = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));
    bufG = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));
    bufB = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));

    for(y = 0; y < imageLength; y += tileLength) {
      for(x = 0; x < imageWidth; x += tileWidth) {
        size = TIFFReadTile(tif, bufR, x, y, 0, 0);
        printf("read %d bytes\n", size);
        size = TIFFReadTile(tif, bufG, x, y, 0, 1);
        printf("read %d bytes\n", size);
        size = TIFFReadTile(tif, bufB, x, y, 0, 2);
        printf("read %d bytes\n", size);
        printf("width %d bytes\n", x);
        printf("length %d bytes\n", y);

        /* RGBTOLHS */
        /*Rgb2Lhs(&bufR, &bufG, &bufB, &L, &H, &S, tileLength, tileWidth);*/
        size = TIFFWriteTile(wtif, bufR, x, y, 0, 0);
        printf("written %d bytes\n", size);
        TIFFWriteTile(wtif, bufG, x, y, 0, 1);
        printf("written %d bytes\n", size);
        TIFFWriteTile(wtif, bufB, x, y, 0, 2);
        printf("written %d bytes\n", size);
      }
    }

Problem: It's not writing the no. of bytes it read, thus the o/p img. is invalid:

Sample Output:
read 16384 bytes
read 16384 bytes
read 16384 bytes
width 384 bytes
length 384 bytes
written 2048 bytes
written 2048 bytes
written 2048 bytes

Can anyone tell what's wrong? Thanks,

Pushkar Pradhan