Implementing TIFF Comments and Tags

Initially, only TIFF files supported TIFF tags. But the TIFF tags are so flexible and well documented that other formats added mechanisms for including TIFF tags:

In other words, TIFF tags are supported in file formats other than TIFF. You can use the L_TagsSupported function to determine whether a certain file format supports tags.

For these formats, the comments are simply TIFF tags saved with certain characteristics (fixed tag type, count and number of elements). To specify a comment to be saved, use the L_SetComment and L_GetComment functions to build the list of the comments you wish to save, then call one of the save functions. The output file will contains all these comments in addition to the image data.

To read a comment from an existing file, you can use L_ReadFileComment or L_ReadFileCommentMemory. To read a comment from a file at a specified location, use the L_ReadFileCommentOffset function.

To read all comments from an existing file, use L_ReadFileComments. L_ReadFileComments allocates a buffer large enough all the comments. The user is responsible for freing this buffer by calling L_FreeFileComments.

To write comments to an existing file, use L_WriteFileComment or L_WriteFileCommentExt (TIFF only). To check whether a file format supports comment fields, use L_CommentsSupported. You can use the L_DeleteComment function to delete a comment field from a file (TIFF only).

Note: If an error occurred in reading all file comments using the L_ReadFileComments function, then no comments will be returned, and the user is responsible to find the valid metadata in the file.

For a list of possible comments, refer to TIFF File Comments. The files that support Exif metadata can save the exif comments in addition to the TIFF comments. See Exif File comments for the full list.

If the comments do not meet your needs, you can define your own tag for saving additional non-raster data in a TIFF file. For example, you may want to define a tag to save annotations.

The TIFF 6.0 Specification sets aside a range of private tags that developers can define. To avoid conflicts with files created by other developers, you can register your tag by contacting Adobe Developer Relations. (The E-Mail address posted on The Unofficial TIFF Home Page is gapdevsup@adobe.com.)

To define a tag and to specify the data to save in the tag, you can use the L_SetTag and L_GetTag functions. To load the tagged data from a file, you can use L_ReadFileTag or L_ReadFileTagMemory .To read all tags from an existing file, use L_ReadFileTags. When the data allocated by calling the L_ReadFileTags function are no longer needed it must be freed by calling L_FreeFileTags. To write tags to an existing file, or to change existing tags in a file, use L_WriteFileTag (TIFF only). To check whether a file format supports tags, use L_TagsSupported.

Note: To write tags to an existing TIFF file, use L_WriteFileTag or L_WriteFileTagMemory instead of using L_SetTag followed by L_SaveFile or L_SaveFileMemory.

LEADTOOLS uses an additional private tag to store extra information in the TIFF file (region, LUT for 12/16-bit grayscale bitmaps, etc). This is done automatically, without any action required on your part.

Help Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

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