2004.10.25 17:17 "[Tiff] Read a compressed tiff with G4", by Elzumba Sefue

2004.10.25 20:33 "Re: [Tiff] Read a compressed tiff with G4", by Elzumba Sefue

How did you read the image? TIFFReadEncodedStrip() function should return the decode data in the buffer.

Hello, for first, thanks for your answer. Yes, I read with TIFFReadEncodedStrip, but the buffer of result not have the same pixels that the image have (height x width).

And when, later, I TIFFWriteEncodedStrip, I get an "exception" in memory.

The code is below (is short).

I check the file "fax2tiff.c" but I don't know to implement, I don't understand the code good. I need help, is very important for my progress in my job.

Thanks.

int CC(char *strFileName) {
TIFF* tif = TIFFOpen(strFileName, "r");
TIFF* tif2 = TIFFOpen("C:\\2.tif", "w");
if (tif) {
char* buf;
tstrip_t strip;
uint32* bc,c,w,p,h,bps,photo,spp,*rps,ru;
uint32 stripsize;
unsigned long i;

TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &bc);
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);

TIFFSetField(tif2, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(tif2, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(tif2, TIFFTAG_COMPRESSION, 4);
TIFFSetField(tif2, TIFFTAG_PHOTOMETRIC,
PHOTOMETRIC_MINISWHITE);
TIFFSetField(tif2, TIFFTAG_FILLORDER,
FILLORDER_MSB2LSB);
TIFFSetField(tif2, TIFFTAG_PLANARCONFIG, 1);

stripsize = bc[0];
buf = (char*) malloc(stripsize);
for (strip = 0; strip < TIFFNumberOfStrips(tif);
strip++) {
    if (bc[strip] > stripsize) {
        buf = (char*) realloc(buf, bc[strip]);
        stripsize = bc[strip];
    }
    TIFFReadRawStrip(tif, strip, buf, bc[strip]);
}
TIFFWriteRawStrip(tif2, strip, buf, bc[strip]);
//EXCEPTION
/* the line code above write the strip, that is
   1, isn't an error, I try too with a for that
   go trought the strips, but is equivalent. */
free(buf);
TIFFClose(tif);
TIFFClose(tif2);
}