TIFF Group 4 Fax images written with a FillOrder tag of 0.
Hello everyone,
I have written a small program with WIC to read a Black and white TIFF image and write it in TIFF Group 4 Fax format. Sonehow, the FillOrder tag (IFD tag 266) in the output image are all set to zero.
This is strange because (1) ExifTool says the meaning of a FillOrder value of zero is unknown, and (2) Some programs cannot open these images.
To test this issue, I have used ExifTool to set this value back to 1. After this step, those programs can now open these images. If I now use WIC to read this modified image and write it back in TIFF Group 4 Fax again, however, the value is set to zero again. Please see the test code below.
It appears that this metadata value is generated by the image frame encoder, and cannot be written to by MetadataWriter or MetadataQueryWriter.
As a side note, the symptom matches the description on this page: http://www.eggheadcafe.com/software/aspnet/29999874/tiffbitmapencoder-bug.aspx,
This is my WIC version:
WindowsCodecs.dll:
6.0.5840.16388 (winmain(wmbla).061024-1209) size: 716,288 bytes
WindowsCodecsExt.dll:
6.0.5840.16388 (winmain(wmbla).061024-1209)
Is this the latest version available for Windows XP SP2? I know that the Windows 7 version fixes a lot of bugs. Will these fixed be available to XP SP2 users?
Has anybody meet the same problem?
Thanks!
Code Snippetvoid TestExecute(const wchar_t* lpszInputFile, const wchar_t* lpszOutputFile)
{
IWICImagingFactoryPtr pFactory;
IWICBitmapDecoderPtr pFileReader;
IWICBitmapFrameDecodePtr pFrameReader;
IWICBitmapSourcePtr pFrameImage;
IWICStreamPtr pOutStream;
IWICBitmapEncoderPtr pFileWriter;
WICBitmapEncoderCacheOption cacheOption = WICBitmapEncoderNoCache;
GUID encoderGuid = GUID_ContainerFormatTiff;
IWICBitmapFrameEncodePtr frameEncoder;
IPropertyBag2Ptr frameSettings;CoCreateInstance(CLSID_WICImagingFactory,
NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory,
(LPVOID*) &pFactory);pFactory->CreateDecoderFromFilename(
lpszInputFile,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnDemand,
&pFileReader);pFileReader->GetFrame(0, &pFrameReader);
pFrameImage = pFrameReader;pFactory->CreateStream(&pOutStream);
pOutStream->InitializeFromFilename(lpszOutputFile, GENERIC_WRITE);pFactory->CreateEncoder(encoderGuid, NULL, &pFileWriter);
pFileWriter->Initialize(pOutStream, cacheOption);
pFileWriter->CreateNewFrame(&frameEncoder, &frameSettings);CComVariant optValue((BYTE) WICTiffCompressionCCITT4);
PROPBAG2 optName = {0};
optName.pstrName = L"TiffCompressionMethod";
optName.dwType = PROPBAG2_TYPE_DATA;
optName.vt = VT_UI1;frameSettings->Write(1, &optName, &optValue);
frameEncoder->Initialize(frameSettings);
UINT imgWidth = 0;
UINT imgHeight = 0;
GUID pixelFormat = {0};
double DpiX = 300.0;
double DpiY = 300.0;pFrameImage->GetSize(&imgWidth, &imgHeight);
pFrameImage->GetPixelFormat(&pixelFormat);
pFrameImage->GetResolution(&DpiX, &DpiY);frameEncoder->SetSize(imgWidth, imgHeight);
frameEncoder->SetPixelFormat(&pixelFormat);
frameEncoder->SetResolution(DpiX, DpiY);IWICPalettePtr pPalette;
pFactory->CreatePalette(&pPalette);
pPalette->InitializePredefined(WICBitmapPaletteTypeFixedBW, FALSE);
frameEncoder->SetPalette(pPalette);frameEncoder->WriteSource(pFrameImage, 0);
frameEncoder->Commit();
pFileWriter->Commit();
}Output from WICExplorer:
Code Snippet\output_5.tif\Frame #0\Ifd Reader
Metadata Values
254 (UI2) 0 (UI4)
256 (UI2) 2960 (UI2)
257 (UI2) 1050 (UI2)
258 (UI2) 1 (UI2)
259 (UI2) 4 (UI2)
262 (UI2) 0 (UI2)
266 (UI2) 0 (UI2)
273 (UI2) 8 (UI4)
277 (UI2) 1 (UI2)
278 (UI2) 1050 (UI4)
279 (UI2) 25579 (UI4)
282 (UI2) 96000 / 1000 (96) (URATIONAL)
283 (UI2) 96000 / 1000 (96) (URATIONAL)
296 (UI2) 2 (UI2)Output from ExifTool:
Code SnippetExifTool Version Number : 7.45
File Name : output_5.tif
Directory : .
File Size : 25 kB
File Modification Date/Time : 2008:11:18 14:02:37-08:00
File Type : TIFF
MIME Type : image/tiff
Exif Byte Order : Little-endian (Intel, II)
Subfile Type : Full-resolution Image
Image Width : 2960
Image Height : 1050
Bits Per Sample : 1
Compression : T6/Group 4 Fax
Photometric Interpretation : WhiteIsZero
Fill Order : Unknown (0)
Strip Offsets : 8
Samples Per Pixel : 1
Rows Per Strip : 1050
Strip Byte Counts : 25579
X Resolution : 96
Y Resolution : 96
Resolution Unit : inches
Image Size : 2960x1050
All Replies
- I have the same issue with the TiffBitmapEncoder (uses WIC) when using CCITT4 compression. FillOrder should NOT be set to 0. 1 or 2 are the only values defined in the spec. Can someone provide some information on when this will be fixed?
- This has been fixed in the version of WIC in Win7.
- Is there a work around for Vista? This bug has stopped me dead in my tracks, and an upgrade to Win7 cannot happen anytime soon - I never upgrade before the 1st service pack. I need to use the TiffBitmapEncoder so I can set the compression. Is there another way to set the compression? I'm using VB.net 2008. Thanks AB
- I am combining multiple TIF files into a single fax using C# and the fax was getting corrupted during conversion by the Microsoft Shared Fax engine just prior to transmission. I added one line of code to set the resolution to 204 x 200 and problem solved...or so I thought.
Microsoft Shared Fax (MSF) requires the FillOrder [Id: 266] TIFF property tag to be populated. Bug in MSF?? Strange nonetheless, read on...using (Bitmap bitmap = (Bitmap)Image.FromFile(imageFiles[0])) { //Force all pages to have the same X,Y resolution. bitmap.SetResolution(204, 200); bitmap.Save(outStream, imageCodecInfo, encoderParameters); //... }
I FINALLY found the rest of the solution to this problem! During testing, I found that some combined, multipage TIFF files were still failing during submission to MSF via the FAXCOMEXLib COM library with no error other than returning zero (0) for object jobID = faxDocument.ConnectedSubmit(faxServer). The failures seemed to be mostly, if not all, single page TIFF files that I was combining. Combined TIFF image files where I started with a multipage TIFF seem to work (already multipage prior to Bitmap.SaveAdd()). I tried changing the resolution from 204x200 to 204x196 after reading another post and I was able to submit these same faxes but the MSF conversion prior to transmission was corrupting the multipage TIFF file (although I was able to submit to MSF) and transmitting blank pages. Closer examination of the combined TIFF files with AWare Systems AsTiffTagViewer showed 3 other differences in the combined TIFF image file and the original MSF [Fax] printer TIFF image files: SubFileType [Id: 255] (None or 0 instead of Page or 2) (depricated by NewSubfileType in TIFF 6.0 Spec.), FillOrder [Id: 266] (missing in my combined image files), and PageNumber [Id: 297] (all set to 0,0).
After much trial and error, I found that the required missing TIFF property tag was FillOrder which needed to be MSB2LSB (1) in my case (I tried LSB2MSB or 2 but faxes were still corrupted). I also set NewSubfileType to [Page] (2) as it was currently set to [Zero] (0) and I updated the PageNumber tags appropriately. Try as I might, I could not get any of the C# built in libraries to add/update FillOrder or NewSubfileType although I was able to update PageNumber. I tried with both System.Drawing.Imaging and System.Windows.Media.Imaging libraries. Although System.Windows.Media.Imaging TiffBitmapDecoder and TiffBitmapEncoder would add FillOrder by default, I could not get it to update the value from 0. After much more trial and error, I wrote a custom method to read the binary TIFF data from a MemoryStream object and iterate through the Image File Directories (IFD) to update the appropriate FillOrder tag with MSB2LSB (1), NewSubfileType with Page (2), and PageNumber with x,y [Page-1,Pages-1] using a BinaryWriter.
I found the TIFF Revision 6.0 Specification very useful during this project.
http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
I hope this post saves somone some time as I invested quite a bit figuring this one out.


