diff --git a/samples/exifprint.cpp b/samples/exifprint.cpp index 1ac4e3f9..72c2244b 100644 --- a/samples/exifprint.cpp +++ b/samples/exifprint.cpp @@ -28,7 +28,9 @@ try { } Exiv2::ExifData::const_iterator end = exifData.end(); for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { - std::cout << std::setw(44) << std::setfill(' ') << std::left + std::cout << std::setw(3) << std::right + << i->idx() << " " + << std::setw(44) << std::setfill(' ') << std::left << i->key() << " " << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " diff --git a/src/tiffcomposite.cpp b/src/tiffcomposite.cpp index e6bb765b..4bdb83a4 100644 --- a/src/tiffcomposite.cpp +++ b/src/tiffcomposite.cpp @@ -1402,7 +1402,8 @@ namespace Exiv2 { { assert(lhs != 0); assert(rhs != 0); - return lhs->tag() < rhs->tag(); + if (lhs->tag() != rhs->tag()) return lhs->tag() < rhs->tag(); + return lhs->idx() < rhs->idx(); } TiffComponent::AutoPtr newTiffDirectory(uint16_t tag, diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index 6b98829f..b4ccf711 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -245,6 +245,12 @@ namespace Exiv2 { their implementation of writeImage(). */ uint32_t sizeImage() const; + /*! + @brief Return the unique id of the entry in the image. + */ + // Todo: This is only implemented in TiffEntryBase. It is needed here so that + // we can sort components by tag and idx. Something is not quite right. + virtual int idx() const { return 0; } //@} protected: @@ -426,7 +432,7 @@ namespace Exiv2 { /*! @brief Return the unique id of the entry in the image */ - int idx() const { return idx_; } + virtual int idx() const { return idx_; } /*! @brief Return a pointer to the binary representation of the value of this component. diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp index bdd0426c..20f90a22 100644 --- a/src/tiffvisitor.cpp +++ b/src/tiffvisitor.cpp @@ -646,6 +646,11 @@ namespace Exiv2 { ed = &(*pos); } } + else { + // For intrusive writing, the index is used to preserve the order of + // duplicate tags + object->idx_ = ed->idx(); + } if (ed) { const EncoderFct fct = findEncoderFct_(make_, object->tag(), object->group()); if (fct) {