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