TIFF files use 32-bit offsets, so they are limited to 4GB. A newer version of this file format, BigTIFF, uses 64-bit offsets and can create files larger than 4GB. In other aspects BigTIFF files are the same as TIFF files. For the rest of this topic, the generic term "TIFF file" will be used for both TIFF and BigTIFF files.
TIFF files can contain large numbers of pages. This can make loading and saving them very time-consuming. Using an IFD (Image File Directory) speeds up loading, saving, and getting information about very large TIFF files. The IFD is essentially an offset within the TIFF file where a page starts.
Several structures contain an IFD member that contains the offset of the desired page within the TIFF file. These structures include FILEINFO, SAVEFILEOPTION, and LOADFILEOPTION. For 32-bit applications, the same structures also contain an IFD64 member that contains the 64-bit offset of the desired page within a BigTIFF file.
For 32-bit applications, L_FileInfo will report the IFD of a TIFF page by filling FILEINFO.IFD. For 32-bit applications. L_FileInfo will also report a 64-bit version of the IFD from a BigTIFF page by filling FILEINFO.IFD64.
To get L_FileInfo to use an IFD, set LOADFILEOPTION.IFD to the IFD and set ELO_USEIFD in LOADFILEOPTION.uFlags to signal that the IFD field is valid. For 32-bit applications, it is best to set LOADFILEOPTION.IFD64 to the IFD and set ELO2_USEIFD64 in LOADFILEOPTION.Flags2 to signal that the 64-bit bersion of the IFD should be used instead. The 64-bit version of the IFD is useful when dealing with BigTIFF files larger than 4 GB. For 64-bit applications, LOADFILEOPTION.IFD is a 64-bit value, so LOADFILEINFO.IFD can be used for both TIFF and BigTIFF files.
Caution should be taken when using the IFD, since incorrect values can have unexpected consequences. Also note that page numbering is different if the IFD is used: page 1 is the page whose IFD is indicated in LOADFILEOPTION, page 2 is the page after the page whose IFD is indicated, etc.
Example:
/* Assume that "test.tif" has over 1002 pages. Error checks
are not performed to simplify the example */
// get info for page 1000
LOADFILEOPTION LoadFileOption;
FILEINFO FileInfo;
// get the info and IFD for page 1000
memset(&LoadFileOption, 0, sizeof(LOADFILEOPTION));
LoadFileOption.PageNumber = 1000;
FileInfo.uStructSize = sizeof(FileInfo);
L_FileInfo(TEXT("test.tif"), &FileInfo, sizeof(FILEINFO), 0, &LoadFileOption);
// get the info and IFD for page 1001.
LoadFileOption.PageNumber = 2;
#if !defined(FOR_X64)
LoadFileOption.IFD64 = FileInfo.IFD64;
LoadFileOption.Flags2 = ELO2_USEIFD64;
#else
LoadFileOption.IFD = FileInfo.IFD;
LoadFileOption.Flags = ELO_USEIFD;
#endif // #if !defined(FOR_X64)
L_FileInfo(TEXT("test.tif"), &FileInfo, sizeof(FILEINFO), 0, &LoadFileOption);
The example above gets the information for page 1001 on the second call. The second call is lightning-quick because we don't have to skip over the first 1000 pages to get the information about page 1001. Instead, we only have to skip page 1000, because the IFD provided in LOADFILEOPTION allowed us to jump directly to page 1000.
FILEINFO.IFD will be filled whenever retrieving information about a TIFF file. The IFD field is valid if Fileinfo.uFlags has the FILEINFO_IFDVALID flag set. Also, the IFD value cannot be less that 8 for TIFF (values of 7 and below are invalid) or 16 for BigTIFF.
FILEINFO.IFD can be used for faster load by setting it in LOADFILEOPTION.IFD as explained above.
When loading a page from a TIFF file, setting the LOADFILEOPTION.IFD parameter of L_LoadFile function tells LEADTOOLS to treat the page beginning at the specified offset as page 1. Therefore, LEADTOOLS does not have to go through all pages from the beginning of the file prior to loading the desired page.
Similarly, when saving a page to a TIFF file, setting the SAVEFILEOPTION parameter of the L_SaveFile function tells the control to treat the page beginning at the specified offset as page 1. Pages after this offset can be appended more quickly, since the control does not have to go through all pages from the beginning of the file.
The L_CompactFile function lets you compact TIFF files. It also lets you copy or extract one or more pages from a TIFF file and copy them without recompression to another TIFF file.
NOTE: To save a region inside a TIFF file, you must have an unlocked Document or Medical Imaging license.
For technical reasons, the following restrictions apply when you pass an IFD offset by setting the IFD member of the SAVEFILEOPTION structure if you set PageNumber to 1:
You cannot add tags, comments or GeoKeys to this IFD. You can only update existing tags, comments or GeoKeys in this IFD.
You cannot replace the TIFF page indicated by this IFD.
You cannot add a page before this IFD.
You cannot delete the page indicated by this IFD.
You can, however, add tags, comments or GeoKeys to a IFD that follows the specified IFD (for example, if PageNumber is >= 2). You can also replace or delete a page that follows the specified IFD and you can insert a page after this IFD.
NOTE: To speed up the handling of file formats other than TIFF / BigTIFF, use the filter data mechanism described in the Using Filter Data to Speed up Loading Large Files topic.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document