2012.07.16 15:55 "[Tiff] CCITTFaxDecode with EncodedByteAlign. How to create a TIFF from that.", by Sergius Bobrovsky

2012.07.16 15:55 "[Tiff] CCITTFaxDecode with EncodedByteAlign. How to create a TIFF from that.", by Sergius Bobrovsky

Hello!

I am trying to extract a CCITTFaxDecode encoded image from a PDF as TIFF and the code that works just fine with many other similar images fails.

The image in PDF is specified as following
<<
/Type /XObject
/Subtype /Image
/Name /Im1
/Filter [ /CCITTFaxDecode ]
/Width 3504 /Height 2480 /BitsPerComponent 1
/ColorSpace /DeviceGray
/Length 2 0 R
/DecodeParms [ <</K 0 /Columns 3504 /Rows 2480 /EncodedByteAlign true
/EndOfBlock false>> ]
>>

So, it looks like it's a CCITT Group 3 fax image with two extra options: /EncodedByteAlign true /EndOfBlock false.

I tried to create a TIFF from it using following code TIFF* image = TIFFOpen("out.tiff", "w"); TIFFSetField(image, TIFFTAG_IMAGEWIDTH, 3504);

TIFFSetField(image, TIFFTAG_IMAGELENGTH, 2480);

TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);

TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);

TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 2480);

TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);

TIFFSetField(image, TIFFTAG_T4OPTIONS, GROUP3OPT_FILLBITS);

TIFFSetField(image, TIFFTAG_FAXMODE, FAXMODE_BYTEALIGN | FAXMODE_CLASSF);

TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);

FILE* raw = fopen("out.raw", "r");
unsigned char* rawBuf = new unsigned char[78808];
fread(rawBuf, 1, 78808, raw);
fclose(raw);

TIFFWriteRawStrip(image, 0, rawBuf, 78808);
TIFFClose(image);
delete rawBuf;
return 0;

But the output TIFF displays as a black rectangle in Windows Photo Viewer and tiff2rgba utility can not decode the image also. The utility issues multiple warnings about line length mismatch and premature EOL and basically that's all.

fax2tiff utility with following options
-A -X 3504 out.raw
produce basically the same.

How am I supposed to create a valid TIFF from the data described above? Is it supported by libtiff at all?

out.raw can be downloaded using following link: https://dl.dropbox.com/u/3070948/out.raw.zip

--
Sergius Bobrovsky