LibTIFF:从TIFF图像中提取所有标签 [英] LibTIFF: Extract all tags from a TIFF image

查看:603
本文介绍了LibTIFF:从TIFF图像中提取所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个项目,该项目需要我将TIFF图像拆分为包含所有标签的文件和包含所有图像数据的文件,并从这些文件中重建TIFF图像.唯一的问题是,似乎LibTIFF没有提供简单的方法来获取图像中的所有标签.我尝试过使用TIFFGetTagListCount然后使用TIFFGetField来检索标签,但这只会返回标签的一小部分.我已经开始发布自己的版本,但是我只想仔细检查并确保我不会忽略某些内容,因为这似乎是应该包含在库中的非常明显的功能.

I'm currently working on a project which requires me to split a TIFF image into a file containing all tags and a file containing all image data and to reconstruct a TIFF image from these files. The only problem is that it seems that LibTIFF provides no easy way to grab all tags from an image. I've tried using TIFFGetTagListCount and then TIFFGetField to retrieve the tag, but this only returns a small subset of the tags. I've started rolling my own version, but I just want to double check and make sure I'm not overlooking something as this seems like a pretty obvious feature that should be included in the library.

推荐答案

以下是关闭所有标签可以获取的关闭页面:

Here is the closes you can get for scanning all tags:

 #include "LibTIFF/tif_dir.h"
 ...

 TIFFDirectory *td = &tif->tif_dir;

 for (int fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
    const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];

    // test if tag value is set
    // (lifted directly form LibTiff _TIFFWriteDirectory)

        if( fip->field_bit == FIELD_CUSTOM ) {
            int ci, is_set = FALSE;

            for( ci = 0; ci < td->td_customValueCount; ci++ )
                is_set |= (td->td_customValues[ci].info == fip);

            if( !is_set )
                continue;
        } else if(!TIFFFieldSet(tif, fip->field_bit))
            continue;

        // else: process the fip->field_tag


    }

请注意,您必须考虑到某些标签会出现两次(LONG和SHORT版本),但其中只有一个才有价值.可以在附带的标头(TIFFDirectory结构)中查找要使用的正确类型.

Note that you will have to take into account that some tags will appear twice (LONG and SHORT version), but only one of these will have value. The correct type to use can be looked up in the included header (the TIFFDirectory struct).

还有其他有关如何读取标签的注意事项,但这至少会使您遍历所有标签(标准标签).如果卡住,请参阅tif_dirinfo.c中的指针.

There also other catches on how to read the tags, but this at least will make you loop over all of them (the standard ones). See tif_dirinfo.c for pointers if you get stuck.

这篇关于LibTIFF:从TIFF图像中提取所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆