Fixed reading duplicate tags (barely tested).

v0.27.3
Andreas Huggel 17 years ago
parent 8489cec20c
commit a8aea29b5a

@ -52,6 +52,7 @@ EXIV2_RCSID("@(#) $Id$")
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cassert> #include <cassert>
#include <set>
// ***************************************************************************** // *****************************************************************************
// class member definitions // class member definitions
@ -340,7 +341,7 @@ namespace Exiv2 {
// Todo: ExifKey should have an appropriate c'tor, it should not be // Todo: ExifKey should have an appropriate c'tor, it should not be
// necessary to use groupName here // necessary to use groupName here
ExifKey key(object->tag(), tiffGroupName(Group::ifd0)); ExifKey key(object->tag(), tiffGroupName(Group::ifd0));
setExifTag(key, object->pValue()); setExifTag(key, object->pValue(), pvHigh);
} }
@ -365,22 +366,38 @@ namespace Exiv2 {
void TiffDecoder::decodeStdTiffEntry(const TiffEntryBase* object) void TiffDecoder::decodeStdTiffEntry(const TiffEntryBase* object)
{ {
assert(object !=0); assert(object !=0);
// "Normal" tag has low priority: only decode if it doesn't exist yet.
// Todo: This also filters duplicates (common in some makernotes)
// Todo: ExifKey should have an appropriate c'tor, it should not be // Todo: ExifKey should have an appropriate c'tor, it should not be
// necessary to use groupName here // necessary to use groupName here
ExifKey key(object->tag(), tiffGroupName(object->group())); ExifKey key(object->tag(), tiffGroupName(object->group()));
ExifData::iterator pos = exifData_.findKey(key); setExifTag(key, object->pValue(), pvNormal);
if (pos == exifData_.end()) {
exifData_.add(key, object->pValue());
}
} // TiffDecoder::decodeTiffEntry } // TiffDecoder::decodeTiffEntry
void TiffDecoder::setExifTag(const ExifKey& key, const Value* pValue) void TiffDecoder::setExifTag(const ExifKey& key, const Value* pValue, Prio prio)
{ {
typedef std::set<std::string> PriorityKeys;
static PriorityKeys priorityKeys;
bool isRegPrioTag = (priorityKeys.find(key.key()) != priorityKeys.end());
switch (prio) {
case pvNormal:
// If key is not registered as high prio tag, add it
if (!isRegPrioTag) exifData_.add(key, pValue);
break;
case pvHigh:
// Register the key as a high prio tag, erase low prio tags, add this
if (!isRegPrioTag) {
priorityKeys.insert(key.key());
ExifData::iterator pos = exifData_.findKey(key); ExifData::iterator pos = exifData_.findKey(key);
if (pos != exifData_.end()) exifData_.erase(pos); while (pos != exifData_.end()) {
exifData_.erase(pos);
pos = exifData_.findKey(key);
}
}
exifData_.add(key, pValue); exifData_.add(key, pValue);
break;
}
} // TiffDecoder::setExifTag } // TiffDecoder::setExifTag

@ -271,10 +271,13 @@ namespace Exiv2 {
//@} //@}
private: private:
//! Tag priorities
enum Prio { pvNormal, pvHigh };
//! @name Manipulators //! @name Manipulators
//@{ //@{
//! Set an Exif tag in the image. Overwrites existing tags //! Set an Exif tag in the image.
void setExifTag(const ExifKey& key, const Value* pValue); void setExifTag(const ExifKey& key, const Value* pValue, Prio prio);
/*! /*!
@brief Get the data for a \em tag and \em group, either from the @brief Get the data for a \em tag and \em group, either from the
\em object provided, if it matches or from the matching element \em object provided, if it matches or from the matching element

Loading…
Cancel
Save