From 2ab82c4bc9e8cfdbef2c3fa706df807b92ece203 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Wed, 20 Dec 2006 10:22:32 +0000 Subject: [PATCH] Fixed and tweaked IPTC decoding code for bug #502. --- src/tiffvisitor.cpp | 51 ++++++++++++++++++++++++--------------------- src/tiffvisitor.hpp | 13 ++++++++++++ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp index d53e237f..989a24f8 100644 --- a/src/tiffvisitor.cpp +++ b/src/tiffvisitor.cpp @@ -186,6 +186,27 @@ namespace Exiv2 { } } + void TiffMetadataDecoder::getObjData(byte const*& pData, + long& size, + uint16_t tag, + uint16_t group, + const TiffEntryBase* object) + { + if (object && object->tag() == tag && object->group() == group) { + pData = object->pData(); + size = object->size(); + return; + } + TiffFinder finder(tag, group); + pRoot_->accept(finder); + TiffEntryBase const* te = dynamic_cast(finder.result()); + if (te) { + pData = te->pData(); + size = te->size(); + return; + } + } + void TiffMetadataDecoder::decodeIptc(const TiffEntryBase* object) { // add Exif tag anyway @@ -200,19 +221,7 @@ namespace Exiv2 { // 1st choice: IPTCNAA byte const* pData = 0; long size = 0; - if (object->tag() == 0x83bb) { - pData = object->pData(); - size = object->size(); - } - if (pData == 0) { - TiffFinder finder(0x83bb, Group::ifd0); - pRoot_->accept(finder); - TiffEntryBase* te = dynamic_cast(finder.result()); - if (te) { - pData = te->pData(); - size = te->size(); - } - } + getObjData(pData, size, 0x83bb, Group::ifd0, object); if (pData) { if (0 == pImage_->iptcData().load(pData, size)) { return; @@ -227,20 +236,14 @@ namespace Exiv2 { // 2nd choice if no IPTCNAA record found or failed to decode it: // ImageResources - TiffEntryBase const* te = 0; - if (object->tag() == 0x8649) { - te = object; - } - else { - TiffFinder finder(0x83bb, Group::ifd0); - pRoot_->accept(finder); - te = dynamic_cast(finder.result()); - } - if (te) { + pData = 0; + size = 0; + getObjData(pData, size, 0x8649, Group::ifd0, object); + if (pData) { byte const* record = 0; uint32_t sizeHdr = 0; uint32_t sizeData = 0; - if (0 != Photoshop::locateIptcIrb(te->pData(), te->size(), + if (0 != Photoshop::locateIptcIrb(pData, size, &record, &sizeHdr, &sizeData)) { return; } diff --git a/src/tiffvisitor.hpp b/src/tiffvisitor.hpp index c9c348ad..fa425f76 100644 --- a/src/tiffvisitor.hpp +++ b/src/tiffvisitor.hpp @@ -251,6 +251,19 @@ namespace Exiv2 { private: //! Set an Exif tag in the image. Overwrites existing tags void setExifTag(const ExifKey& key, const Value* pValue); + /*! + @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 + in the hierarchy. + + Populates \em pData and \em size with the result. If no matching + element is found the function leaves both of these parameters unchanged. + */ + void getObjData(byte const*& pData, + long& size, + uint16_t tag, + uint16_t group, + const TiffEntryBase* object); // DATA Image* pImage_; //!< Pointer to the image to which the metadata is added