LEADTOOLS Raster Imaging C DLL Help > LEADTOOLS Raster Imaging Features > Loading and Saving Images > Loading and Saving Large TIFF Files |
TIFF files can contain large numbers of pages. This can make loading and saving these TIFF files very time consuming. Using an IFD (Image File Directory) speeds up loading, saving and getting information from 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.
L_FileInfo will report the IFD of a TIFF page by filling FILEINFO.IFD.
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. Caution should be taken in using the IFD, since incorrect values could have unexpected consequences. Also note that the 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:
/* We will assume that "test.tif" has over 1002 pages. The 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;
LoadFileOption.IFD = FileInfo.IFD;
LoadFileOption.Flags = ELO_USEIFD;
L_FileInfo(TEXT("test.tif"), &FileInfo, sizeof(FILEINFO), 0, &LoadFileOption);
The example above gets the info 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 TIF file. The IFD field is valid if Fileinfo.uFlags has the FILEINFO_IFDVALID flag set. Also, the IFD value cannot be less that 8 (values of 7 and below are invalid).
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 Vector, 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 the 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.