AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2003.07.30 21:53 "[Tiff] writing tiles to tiff file", by Pushkar Pradhan
2003.08.01 20:02 "[Tiff] problems using tiffwritetile", by Pushkar Pradhan
2003.08.03 01:52 "[Tiff] problems using tiffwritetile", by Frank Warmerdam
2003.08.03 02:41 "[Tiff] problems using tiffwritetile", by Pushkar Pradhan
2003.08.04 02:57 "[Tiff] Configure ZIP, JPEG, PIXARLOG", by Robin Rowe
2003.08.04 05:14 "[Tiff] Configure ZIP, JPEG, PIXARLOG", by Andrey Kiselev
2003.08.04 16:16 "[Tiff] Configure ZIP, JPEG, PIXARLOG", by Frank Warmerdam
2003.09.12 16:04 "[Tiff] writing out custom tags", by Chris Padwick
2003.09.15 07:45 "[Tiff] writing out custom tags", by Andrey Kiselev
2003.09.18 09:53 "[Tiff] color changes only with Windows Imaging (again)", by Takuya SATO
2003.09.18 12:26 "[Tiff] color changes only with Windows Imaging (again)", by Frank Warmerdam
2003.09.17 22:14 "[Tiff] is image tiled or striped?", by Pushkar Pradhan
2003.09.17 22:39 "[Tiff] is image tiled or striped?", by Frank Warmerdam

2003.08.03 02:41 "[Tiff] problems using tiffwritetile", by Pushkar Pradhan

Franks,
Here's the code and thanks for your interest!

int main(int argc, char **argv)
{
  TIFF* tif = TIFFOpen(argv[1], "r");
  TIFF* wtif = TIFFOpen(argv[2], "w");
  if(tif && wtif) {

    uint16 compress;
    uint16 config;
    uint16 samplesPerPixel;
    uint32 imageWidth, imageLength;
    uint32 tileWidth, tileLength;
    uint32 sample;
    uint32 row, col;

int count = 0;

    unsigned char *bufR, *bufG, *bufB;

tdata_t buf;
float *L, *H, *S;

ttile_t tile;
tstrip_t strip;
tsize_t size;

/*buf = _TIFFmalloc(TIFFStripSize(tif)); for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) TIFFReadEncodedStrip(tif, strip, buf, (tsize_t) - 1);*/

TIFFGetField(tif, TIFFTAG_COMPRESSION, &compress);

    TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imageWidth);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imageLength);
    TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth);
    TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileLength);

TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel);

TIFFSetField(wtif, TIFFTAG_COMPRESSION, compress);

TIFFSetField(wtif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);

    TIFFSetField(wtif, TIFFTAG_IMAGEWIDTH, imageWidth);
    TIFFSetField(wtif, TIFFTAG_IMAGELENGTH, imageLength);
    TIFFSetField(wtif, TIFFTAG_TILEWIDTH, tileWidth);
    TIFFSetField(wtif, TIFFTAG_TILELENGTH, tileLength);

TIFFSetField(wtif, TIFFTAG_SAMPLESPERPIXEL, samplesPerPixel);

    buf =_TIFFmalloc(TIFFTileSize(tif));
    bufR = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));
    if(bufR == NULL)
      return -1;
    bufG = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));
    if(bufR == NULL)
      return -1;
    bufB = (unsigned char*)_TIFFmalloc(TIFFTileSize(tif));
    if(bufR == NULL)
      return -1;
    L = (float*)_TIFFmalloc(TIFFTileSize(tif)*sizeof(float));

if(L == NULL)
  return -1;
H = (float*)_TIFFmalloc(TIFFTileSize(tif)*sizeof(float));
if(H == NULL)
  return -1;
S = (float*)_TIFFmalloc(TIFFTileSize(tif)*sizeof(float));
if(S == NULL)
  return -1;

printf("config: %d\n", config);

printf("samples per pixel: %d\n", samplesPerPixel); printf("tilesize: %d\n", TIFFTileSize(tif)); for(row = 0; row < imageLength; row += tileLength) {

      for(col = 0; col < imageWidth; col += tileWidth) {
        size = TIFFReadTile(tif, bufR, col, row, 0, 0);
        printf("read %d bytes\n", size);
        size = TIFFReadTile(tif, bufG, col, row, 0, 1);
        printf("read %d bytes\n", size);
        size = TIFFReadTile(tif, bufB, col, row, 0, 2);
        printf("read %d bytes\n", size);

    printf("width %d bytes\n", row);
    printf("length %d bytes\n", col);

    count++;
    printf("tile: %d\n", count);

    printf("val: %d\n", (unsigned int)bufG[127]);

    /* RGBTOLHS - not important at this time! */
    Rgb2Lhs(bufR, bufG, bufB, L, H, S, tileLength, tileWidth);

    size = TIFFWriteTile(wtif, bufR, col, row, 0, 0);
    printf("written %d bytes\n", size);
    size = TIFFWriteTile(wtif, bufG, col, row, 0, 1);
    printf("written %d bytes\n", size);
    size = TIFFWriteTile(wtif, bufB, col, row, 0, 2);
    printf("written %d bytes\n", size);
  }
}

_TIFFfree(bufR);
_TIFFfree(bufG);
_TIFFfree(bufB);
TIFFClose(tif);
TIFFClose(wtif);

}

} /* main */

Pushkar Pradhan

----- Original Message -----
From: "Frank Warmerdam" <warmerdam@pobox.com>
To: "Pushkar Pradhan" <pushkar@GRI.MsState.Edu>
Cc: <tiff@remotesensing.org>
Sent: Saturday, August 02, 2003 8:52 PM
Subject: Re: [Tiff] problems using tiffwritetile

I'm not able to write a tiled tiff file. The problem is TIFFWriteTile is not writing the amount of data being read by TIFFReadTile TIFFReadTile reads in 16384 bytes but TIFFWriteTile writes out only 2048 bytes.

Can anyone tell what's going wrong? (it's a single band img. and I set the tags also).

Code:
    for(y = 0; y < imageLength; y += tileLength) {

for(x = 0; x < imageWidth; x += tileWidth) {

        size = TIFFReadTile(tif, buf, x, y, 0, 0);

printf("read %d bytes\n", size);

        count++;
        printf("tile: %d\n", count);

/* RGBTOLHS */

        /*Rgb2Lhs(&bufR, &bufG, &bufB, &L, &H, &S, tileLength, tileWidth);*/

        size = TIFFWriteTile(wtif, buf, x, y, 0, 0);

printf("written %d bytes\n", size);

printf("width %d bytes\n", x);

        printf("length %d bytes\n", y }
    }

I think we would need to see more of your program to know what is going wrong. It seems likely that the configuration of the output file is different from the input file. For instance, number of samples per pixel, bits per sample, or planar configuration. These would all result in writing a different amount of data than was read.

> ---------------------------------------+----------------------------------
----