#include "l_bitmap.h"
L_LTFIL_API L_INT L_CompactFile(pszSrcFile, pszDstFile, uPages, pLoadFileOption, pSaveFileOption)
Compacts TIFF / BigTIFF files. It can also be used to copy or extract one or more pages from a TIFF / BigTIFF file and copy them without recompression to another TIFF / BigTIFF file.
Character string containing the name of the file being compacted. All of the pages will be read from this file.
Character string containing the name of the file to which all the pages will be written. This cannot be NULL. If this is NULL, the function will return an error. The pages can be added to this file using the pSaveFileOption
parameter.
Value that represents the number of pages to copy. Use 0 to copy all of the pages. If uPages is > 0, only uPages will be copied to pszDstFile
.
Optional pointer to the LOADFILEOPTION structure, which can be used to specify a starting page. You can speed up access to the starting page by using the IFD. Passing NULL is equivalent to starting from the first page and to use the default load options.
Optional pointer to the SAVEFILEOPTION structure, which can be used to specify where to save the data or how to modify an existing file. You can modify whether the new pages should appended, inserted, or replace existing pages. Pass NULL to use the default save options.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
ERROR_COMPACT_ABORTED | The function encountered an error while reading a page from the source file. Not all of the pages have been copied to the destination file. |
ERROR_TAG_VALUE_TOO_BIG | This error can occur while converting BigTIFF files to regular TIFF files when the source file contains a 64-bit integer value that cannot be converted into a 32-bit integer value due to overflow. This error can occur because TIFF files do not support 64-bit integer values. |
< 1 | An error occurred. Refer to Return Codes. |
This function can also be used to convert a TIFF file to BigTIFF and vice versa (BigTIFF -> TIFF).
The following members of the LOADFILEOPTION structure are important for this function:
PageNumber: specifies the start page. Page 0 is the first page, page 1 is the second page, etc. The pages will be read starting with this page.
Flags: specifies whether to use the IFD.
IFD: used only if Flags contains the ELO_USEIFD flag. If ELO_USEIFD is not set, the PageNumber references the beginning of the file.
(32-bit only) IFD64: used only if Flags2 contains the ELO2_USEIFD64. If ELO_USEIFD64 is not set, the PageNumber references the beginning of the file.
If pSaveFileOption
is NULL and if pszDstFile
exists, pszDstFile will be overwritten regardless of its format. Also, defaults will be used when saving the file (it will be saved in Intel format). Refer to the SAVEFILEOPTION documentation. TIFF files can be saved either in Intel or Motorola byte order (see SAVEFILEOPTIONS.Flags and the ESO_MOTOROLAORDER flag.)
NOTE: To save a region inside a TIFF file, you must have an unlocked Document or Medical Imaging license.
If pSaveFileOption is not NULL, the following members of the SAVEFILEOPTION structure are important for this function:
PageNumber: specifies the starting page. This parameter is used as follows:
If ESO_INSERTPAGE is set in Flags, all pages are inserted before this page.
If ESO_REPLACEPAGE is set in Flags, this page and the remaining uPages
1 will be replaced.
If none of the above parameters are set, then:
If PageNumber is 0, the file will be overwritten.
If PageNumber is <> 0, the pages will be appended to the end of the file.
IFD: can be used to speed up file access for TIFF files having many pages. Used only if ESO_USEIFD is set in Flags.
(32-bit only) IFD64: can be used to speed up file access for TIFF files having many pages. Used only if ESO2_USEIFD64 is set in Flags.
Flags: can be used to specify one or more options:
ESO_NOSUBFILETYPE if this flag is set, the TGSUBFILETYPE tag will be stripped from all the pages.
ESO_REPLACEPAGE if this is set, the pages in pszDstFile are replaced starting with page PageNumber.
ESO_INSERTPAGE - if this is set, all pages are inserted before page PageNumber.
ESO_USEIFD if this is set, the first page in pszDstFile is at offset IFD. All pages will be relative to that page. (Note that this might not be the first physical page in the file). This is a common technique for manipulating files with thousands of pages.
ESO_MOTOROLAORDER if this is set and a new file is being created, the pages will be saved in Motorola byte order. If the flag is not set, the pages will be saved in Intel byte order. If you are modifying an existing file, this flag has no meaning: the pages will be saved in the same byte order that the file uses.
Flags2: Can be used to specify one or more of the following options:
ESO2_BIGTIFF: if set, the destination file will be BigTIFF instead of regular TIFF. BigTIFF files are similar to TIFF files, but are somewhat non-standard and not supported by all readers. But BigTIFF files use 64-bit file offsets so they can be greater than 4GB.
(32-bit only) If ESO2_USEIFD64 is set, then the first page in pszDstFile
is at offset IFD64. All pages are relative to that page. Useful only with BigTIFF files.
IFD64 offsets are useful only when processing BigTIFF files in 32-bit applications. For such files, the IFD pointer can be a 64-bit value > 0xFFFFFFFF. Because IFD is already a 64-bit value in 64-bit applications, IFD64 is not defined in 64-bit applications. In addition, regular TIFF files cannot use 64-bit pointers, so it is not necessary to use IFD64 with TIFF files.
Required DLLs and Libraries
Win32, x64, Linux.
The first example will compact all the pages in a TIFF file. It will create a new file called dstfile.tif.
The second example will compact all the pages in a TIFF file. It will append all the pages to an existing file called dstfile.tif.
L_INT CompactFileFirstExample(L_VOID)
{
L_INT nRet;
nRet = L_CompactFile(MAKE_IMAGE_PATH(TEXT("clean.tif")),MAKE_IMAGE_PATH(TEXT("dstfile.tif")), 0, NULL, NULL);
if(nRet != SUCCESS)
{
MessageBox(NULL, TEXT("Error compacting file!"), TEXT("ERROR"), MB_OK);
return nRet;
}
return SUCCESS;
}
L_INT CompactFileSecondExample(L_VOID)
{
L_INT nRet;
SAVEFILEOPTION SaveFileOption;
nRet = L_GetDefaultSaveFileOption(&SaveFileOption, sizeof(SaveFileOption));
if(nRet != SUCCESS)
return nRet;
SaveFileOption.PageNumber = 2;
nRet = L_CompactFile(MAKE_IMAGE_PATH(TEXT("clean.tif")),MAKE_IMAGE_PATH(TEXT("dstfile.tif")), 0, NULL, &SaveFileOption);
if(nRet != SUCCESS)
{
MessageBox(NULL, TEXT("Error compacting file!"), TEXT("ERROR"), MB_OK);
return nRet;
}
return SUCCESS;
}
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