使用各种回调函数 /事件听众自定义libtiff

发布于 2024-10-29 08:19:38 字数 658 浏览 3 评论 0原文

通过阅读 LibTIFF 源代码,在我看来,自定义 LibTIFF 的主要方法是定义新标签并实施新编解码器。此外,由于 LibTIFF 是开源的并且拥有自由许可证,因此需要出于各种目的对其进行调整的用户可以直接对其进行修改。

但是,有一种自定义似乎不适合这两种扩展方法:我想安装各种类型的事件侦听器(回调函数),以便我可以检测现有编解码器内发生的各种条件。

示例 #1:我希望能够替换 LibTIFF 的错误/警告消息处理程序,以便它是线程安全的并将消息发送到调用者设置的回调函数。

示例#2:某些 TIFF 图像可能缺少一些标签,LibTIFF 尝试通过猜测它们的值来弥补它们。有时某些标签明显错误,LibTIFF 会尝试纠正它们。但是,我希望有一个回调函数,每当 LibTIFF 更改标签的值时都会通知该函数,以便我可以记录该函数并生成有关图像是否符合标准的报告。

示例 #3:我需要将多页 TIFF 的多个页面连接在一起。这些页面具有相同的尺寸和压缩参数。如果我可以访问压缩数据,那么我可以通过将压缩数据逐字复制到新 TIFF 图像的条带中来更有效地完成此操作。

在不使其架构复杂化的情况下,向 LibTIFF 添加回调函数/事件侦听器的推荐方法是什么?

From reading the LibTIFF source code, it appears to me that the main approach to customizing LibTIFF is to define new Tags and to implement new Codecs. Also, since LibTIFF is open-source and has a liberal license, users who need to tweak it for various purposes can modify it directly.

However, there is a kind of customization which doesn't seem to fit into the two approaches to extension: I want to install various kinds of event listeners (callback functions) so that I can detect various conditions that happen inside the existing codecs.

Example #1: I want to be able to replace the error / warning message handlers of LibTIFF so that it is thread-safe and sends the messages to a callback function set by the caller.

Example #2: Some TIFF images may be missing some tags, and LibTIFF tries to make them up by guessing their values. Sometimes some tags are obviously wrong and LibTIFF tries to correct them. However, I would like to have a callback function which is notified whenever LibTIFF changes the tag's value, so that I can log this and generate a report about the image's conformance to the standard.

Example #3: I need to concatenate several pages of a multi-page TIFF together. The pages have the same dimensions and compression parameters. If I have access to the compressed data, then I can do this more efficiently by copying the compressed data verbatim into the strips of a new TIFF image.

What is the recommended way of adding callback functions / event listeners to LibTIFF, without complicating its architecture?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文