今日我想给给图像的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子初已经有更为简单有效的方式 ,总之我没发现,暂且先这么改完凑合用着吧。