使用 libTIFF 将标签的字节数组写入 tiff 文件

Writing a byte array of tags to tiff file using libTIFF

我想知道,有没有什么方法可以使用 libTIFF 将字节数组作为整个数据块(许多标签)写入 .tiff 文件?

据我所知,由于随机数据块 (IFD) 的位置,.tiff 文件无法流式传输。但是,正如我所假设的那样,该块内的数据是按照预定义的顺序写入的。我想要完成的是将整个 exif 属性字节块从 jpeg 文件写入我的 tiff 中的 "Exif IFD"。

那么,是否有类似 TIFFSetField() 的函数填充整个数据块 (IFD)?

显然不是。 documentation states:

The TIFF specification requires that all information except an 8-byte header can be placed anywhere in a file. In particular, it is perfectly legitimate for directory information to be written after the image data itself. Consequently TIFF is inherently not suitable for passing through a stream-oriented mechanism such as UNIX pipes. Software that require that data be organized in a file in a particular order (e.g. directory information before image data) does not correctly support TIFF. libtiff provides no mechanism for controlling the placement of data in a file; image data is typically written before directory information.

您可以编写自己的 TIFF 数据块,在该块内,数据采用 "private" 格式(如果没记错的话,RichTIFFIPTC 就是这种情况)。您不能 做的是将多个标签发送到 TIFF 对象并期望它们以任何特定顺序结束。

我相信 Photoshop 和其他软件总是将固定长度的数据对象写入单个标签,然后随意重写其内部结构。

由于 EXIF 集合和 TIFF 标签集合重叠,您不能这样做并让 libTIFF 读取您的标签,但是:

[tag1],[tag2],[tag3] ---> [privateTiffLongObject] --> not re-readable
[tag1],[tag2],[tag3] ---> [Tiff2],[Tiff3],[Tiff1] --> re-readable

也就是说,您想要完成什么?要简单地将标签从 JPEG 文件转移到 TIFF 文件,我敢说 exiftool 就足够了。我经常采用如下工作流程:

(image) --> exiftool --> XML --> XML parsers -->
--> exiftool --> (new image)

当然,如果需要对大批量的图片进行此操作,性能可能会成为问题。不过,使用 RAM 磁盘和 SSD 设备可以更轻松地解决这个问题。

"Hacking" TIFF 格式可能会给您留下可以高效编写并由您现在拥有的软件工具正确处理的文件,但不会与其他地方的某些其他工具兼容——这可能是在您完成 的工作后发现。