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.
LFile::GetInfo will report the IFD of a TIFF page by filling FILEINFO.IFD.
To get LFile::GetInfo 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:
void CMainFrame::OnFileinfo()
{
// We will assume that "mtif.tif" has over
42 pages.
// The error checks
// are not performed to simplify the example get info
for page 40
LOADFILEOPTION LoadFileOption;
FILEINFO FileInfo;
memset(&FileInfo, 0, sizeof(FILEINFO));
// get the info and IFD for page 40
memset(&LoadFileOption, 0, sizeof(LOADFILEOPTION));
LoadFileOption.PageNumber = 40;
LFile MyFile;
MyFile.SetFileName(TEXT("d:\\work\\images\\mtif.tif"));
MyFile.GetInfo(&FileInfo, FILEINFO_TOTALPAGES, &LoadFileOption);
// get the info and IFD for page 41.
LoadFileOption.PageNumber = 2;
LoadFileOption.IFD = FileInfo.IFD;
LoadFileOption.Flags = ELO_USEIFD;
MyFile.GetInfo(&FileInfo, FILEINFO_TOTALPAGES, &LoadFileOption);
}
The example above gets the info for page 41 on the second call. The second call is lightning-quick because we don’t have to skip over the first 40 pages to get the information about page 41. Instead, we skip only page 40, because the IFD provided in LOADFILEOPTION allowed us to jump directly to page 40.
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 LoadXXX 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 a SaveXXX 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 LFile::Compact 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.