今日我想給給圖像的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子初已經有更為簡單有效的方式 ,總之我沒發現,暫且先這麼改完湊合用着吧。