Adobe XMP SDK项目应用(续2)

本文讲述了作者尝试在图像exif属性中添加SoftWare属性时遇到的困难,详细解析了在SDK中ExportTIFF_StandardMappings函数的调试过程,揭示了如何处理XMP和EXIF信息同步的问题。
摘要由CSDN通过智能技术生成

今日我想给给图像的exif属性里面增加一个SoftWare属性,毋庸置疑,最终是失败而告终。在SDk上面纠缠了半日,直奔核心代码而去,最终无功而返。问题的症结其实跟前几日差不多,修改xmp信息可以,但是修改exif信息,就得付出惨痛的代价,不断的调试...跟踪...调试...跟踪,问题点是跟踪出来了,在函数ExportTIFF_StandardMappings里面

static void
ExportTIFF_StandardMappings ( XMP_Uns8 ifd, TIFF_Manager * tiff, const SXMPMeta & xmp )
{
	const bool nativeEndian = tiff->IsNativeEndian();
	TIFF_Manager::TagInfo tagInfo;
	std::string xmpValue;
	XMP_OptionBits xmpForm;

	const TIFF_MappingToXMP * mappings = 0;

	if ( ifd == kTIFF_PrimaryIFD ) {
		mappings = sPrimaryIFDMappings;
	} else if ( ifd == kTIFF_ExifIFD ) {
		mappings = sExifIFDMappings;
	} else if ( ifd == kTIFF_GPSInfoIFD ) {
		mappings = sGPSInfoIFDMappings;
	} else {
		XMP_Throw ( "Invalid IFD for standard mappings", kXMPErr_InternalFailure );
	}

	for ( size_t i = 0; mappings[i].id != 0xFFFF; ++i ) {

		try {	// Don't let errors with one stop the others.

			const TIFF_MappingToXMP & mapInfo =  mappings[i];

			if ( mapInfo.exportMode == kExport_Never ) continue;
			if ( mapInfo.name[0] == 0 ) continue;	// Skip special mappings, handled higher up.

			bool haveTIFF = tiff->GetTag ( ifd, mapInfo.id, &tagInfo );
			if ( haveTIFF && (mapInfo.exportMode == kExport_InjectOnly) ) continue;
			
            {
				bool haveXMP = xmp.GetProperty(mapInfo.ns, mapInfo.name, &xmpValue, &xmpForm);
				if (!haveXMP) {

					if (haveTIFF && (mapInfo.exportMode == kExport_Always)) tiff->DeleteTag(ifd, mapInfo.id);

				}
				else {

					XMP_Assert(tagInfo.type != kTIFF_UndefinedType);	// These must have a special mapping.
					if (tagInfo.type == kTIFF_UndefinedType) continue;

					const bool mapSingle = ((mapInfo.count == 1) || (mapInfo.type == kTIFF_ASCIIType));
					if (mapSingle) {
						if (!XMP_PropIsSimple(xmpForm)) continue;	// ? Notify client?
						ExportSingleTIFF(tiff, ifd, mapInfo, nativeEndian, xmpValue);
					}
    				else {
						if (!XMP_PropIsArray(xmpForm)) continue;	// ? Notify client?
						ExportArrayTIFF(tiff, ifd, mapInfo, nativeEndian, xmp, mapInfo.ns, mapInfo.name);
					}
				}
			}

		} catch ( ... ) {

			// Do nothing, let other imports proceed.
			// ? Notify client?

		}

	}

}	// ExportTIFF_StandardMappings

程序首先已经从tag里面获取到了tagInfo(里面包含了exif:SoftWare信息),紧跟着就从xmp中去获取属性信息,导致的结果就是从tag获取的信息实际上没有用到。修改方案如下(红色部分为新增加内容):

static void
ExportTIFF_StandardMappings ( XMP_Uns8 ifd, TIFF_Manager * tiff, const SXMPMeta & xmp )
{
    const bool nativeEndian = tiff->IsNativeEndian();
    TIFF_Manager::TagInfo tagInfo;
    std::string xmpValue;
    XMP_OptionBits xmpForm;

    const TIFF_MappingToXMP * mappings = 0;

    if ( ifd == kTIFF_PrimaryIFD ) {
        mappings = sPrimaryIFDMappings;
    } else if ( ifd == kTIFF_ExifIFD ) {
        mappings = sExifIFDMappings;
    } else if ( ifd == kTIFF_GPSInfoIFD ) {
        mappings = sGPSInfoIFDMappings;
    } else {
        XMP_Throw ( "Invalid IFD for standard mappings", kXMPErr_InternalFailure );
    }

    for ( size_t i = 0; mappings[i].id != 0xFFFF; ++i ) {

        try {    // Don't let errors with one stop the others.

            const TIFF_MappingToXMP & mapInfo =  mappings[i];

            if ( mapInfo.exportMode == kExport_Never ) continue;
            if ( mapInfo.name[0] == 0 ) continue;    // Skip special mappings, handled higher up.

            bool haveTIFF = tiff->GetTag ( ifd, mapInfo.id, &tagInfo );
            if ( haveTIFF && (mapInfo.exportMode == kExport_InjectOnly) ) continue;
            
            if (haveTIFF){
                XMP_Assert(tagInfo.type != kTIFF_UndefinedType);    // These must have a special mapping.
                if (tagInfo.type == kTIFF_UndefinedType) continue;
                if (tagInfo.type == kTIFF_ASCIIType)
                    xmpValue = (const char*)tagInfo.dataPtr;

                ExportSingleTIFF(tiff, ifd, mapInfo, nativeEndian, xmpValue);
            }

            else {
                bool haveXMP = xmp.GetProperty(mapInfo.ns, mapInfo.name, &xmpValue, &xmpForm);
                if (!haveXMP) {

                    if (haveTIFF && (mapInfo.exportMode == kExport_Always)) tiff->DeleteTag(ifd, mapInfo.id);

                }
                else {

                    XMP_Assert(tagInfo.type != kTIFF_UndefinedType);    // These must have a special mapping.
                    if (tagInfo.type == kTIFF_UndefinedType) continue;

                    const bool mapSingle = ((mapInfo.count == 1) || (mapInfo.type == kTIFF_ASCIIType));
                    if (mapSingle) {
                        if (!XMP_PropIsSimple(xmpForm)) continue;    // ? Notify client?
                        ExportSingleTIFF(tiff, ifd, mapInfo, nativeEndian, xmpValue);
                    }
                    else {
                        if (!XMP_PropIsArray(xmpForm)) continue;    // ? Notify client?
                        ExportArrayTIFF(tiff, ifd, mapInfo, nativeEndian, xmp, mapInfo.ns, mapInfo.name);
                    }
                }
            }

        } catch ( ... ) {

            // Do nothing, let other imports proceed.
            // ? Notify client?

        }

    }

}    // ExportTIFF_StandardMappings

也许是我对这套SDK还没研究透彻,或许在设置tag子初已经有更为简单有效的方式 ,总之我没发现,暂且先这么改完凑合用着吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值