L_CompactFile

Summary

Compacts TIFF / BigTIFF files, Exif metadata in PNG and Exif JPEG files. Can also compact Exif metadata in PNG or Exif JPEG files.

Note: 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.

Syntax

#include "l_bitmap.h"

L_LTFIL_API L_INT L_CompactFile(pszSrcFile, pszDstFile, uPages, pLoadFileOption, pSaveFileOption)

Parameters

L_TCHAR* pszSrcFile

Character string containing the name of the file being compacted. All of the pages will be read from this file.

L_TCHAR* pszDstFile

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.

L_UINT uPages

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.

pLOADFILEOPTION pLoadFileOption

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.

pSAVEFILEOPTION pSaveFileOption

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.

Returns

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.

Comments

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:

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:

Flags: can be used to specify one or more options:

Flags2: Can be used to specify one or more of the following options:

If the source file is PNG or Exif JPEG, this function will compact and regenerate the Exif metadata to save space. This is particularly useful for JPEG files, since the exif metadata is limited to 64K in size. Consequently, compacting the Exif metadata can make the difference between being able to add comments, tags or stamps to a Exif JPEG file and failing.

Also, if the source file is Exif JPEG or PNG, the settings regarding pages, IFD, should be used carefully because you might not get the results you expect. The only useful values for uPages are 0 or 1 because exif metadata has at most 2 IFDs: one describing the main image and the second containing an optional stamp. The side effect is that calling L_CompactFile for a PNG or Exif JPEG file and passing a 1 for the number of pages, discards the stamp.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

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 Version 22.0.2023.7.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.