2004.12.30 08:42 "[Tiff] Search samples of using COMPRESSION_CCITTFAX4, LSB2MSB", by Jamel BEL HADJ BRAHIM
Is there someone who can give me a complete sample
using TIFFTAG_COMPRESSION = COMPRESSION_CCITTFAX4
And TIFFTAG_FAXMODE = FAXMODE_CLASSF
And TIFFTAG_FILLORDER = FILLORDER_LSB2MSB
The source file is bmp or tiff
The output file should be like this:
SubFileType (1 Long): Zero
ImageWidth (1 Short): 1728
ImageLength (1 Short): 2156
BitsPerSample (1 Short): 1
Compression (1 Short): Group 4 Fax (aka CCITT FAX4)
Photometric (1 Short): MinIsWhite
FillOrder (1 Short): Lsb2Msb
StripOffsets (1 Long): 324
Orientation (1 Short): TopLeft
SamplesPerPixel (1 Short): 1
RowsPerStrip (1 Short): 2156
StripByteCounts (1 Long): 45832
XResolution (1 Rational): 204
YResolution (1 Rational): 196
PlanarConfig (1 Short): Contig
Group3Options (1 Long): 0
Group4Options (1 Long): 0
ResolutionUnit (1 Short): Inch
PageNumber (2 Short): 0, 1
Software (22 ASCII): AAAAA
DateTime (20 ASCII): 2004:12:23 10:17:19
I use this code but I usually obtain a black image with nothing else, where is the error?
(If I use FILLORDER_MSB2LSB I obtain a correct image but usually inversed Even with PHOTOMETRIC_MINISBLACK or PHOTOMETRIC_MINISWHITE)
HBITMAP hImage = (HBITMAP)LoadImage(NULL, "C:\\test001.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE|LR_CREATEDIBSECTION);
CBitmap* m_Bitmap = CBitmap::FromHandle(hImage);
BYTE* buffer=(BYTE*)GlobalAlloc(GPTR, XSIZE * YSIZE);
DWORD ret = m_Bitmap->GetBitmapBits(XSIZE * YSIZE , buffer);
out = TIFFOpen("C:\\out.tif", "w");
if (!out) return;
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, XSIZE);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, YSIZE);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, YSIZE);
TIFFSetField(out, TIFFTAG_SUBFILETYPE, 0);
TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
TIFFSetField(out, TIFFTAG_GROUP4OPTIONS, 0);
TIFFSetField(out, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(out, TIFFTAG_XRESOLUTION, 204.0);
TIFFSetField(out, TIFFTAG_YRESOLUTION, 196.0);
TIFFSetField(out, TIFFTAG_DATETIME, "2004:12:23 10:17:19");
TIFFSetField(out, TIFFTAG_SOFTWARE, "Jamel");
TIFFSetField(out, TIFFTAG_PAGENUMBER, 0, 1);
uint32 ret = TIFFWriteEncodedStrip(out, 0, buffer, XSIZE * YSIZE);
TIFFClose(out);
GlobalFree(buffer);