[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:37:40 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=c1a869d

The following commit has been merged in the master branch:
commit c1a869d33286f206698a6c5f45b6d2e134291761
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Sat May 27 09:08:56 2006 +0000

    Rearranged code and isolated a function to set a Photoshop IPTC IRB from the Jpeg write code into class Photoshop.
---
 src/iptc.cpp        |   4 +-
 src/iptc.hpp        |  14 ++---
 src/jpgimage.cpp    | 143 +++++++++++++++++++++++++++++-----------------------
 src/jpgimage.hpp    |  26 ++++++++--
 src/tiffvisitor.cpp |   8 +--
 5 files changed, 113 insertions(+), 82 deletions(-)

diff --git a/src/iptc.cpp b/src/iptc.cpp
index b96802b..41854de 100644
--- a/src/iptc.cpp
+++ b/src/iptc.cpp
@@ -186,7 +186,7 @@ namespace Exiv2 {
         return rc;
     }
 
-    DataBuf IptcData::copy()
+    DataBuf IptcData::copy() const
     {
         DataBuf buf(size());
         byte *pWrite = buf.pData_;
@@ -218,7 +218,7 @@ namespace Exiv2 {
         }
 
         return buf;
-    } // IptcData::updateBuffer
+    } // IptcData::copy
 
     long IptcData::size() const
     {
diff --git a/src/iptc.hpp b/src/iptc.hpp
index 3cbf5f9..ecf550d 100644
--- a/src/iptc.hpp
+++ b/src/iptc.hpp
@@ -298,13 +298,6 @@ namespace Exiv2 {
          */
         int load(const byte* buf, long len);
         /*!
-          @brief Write the Iptc data to a data buffer and return the data buffer.
-                 Caller owns this buffer. The copied data follows the IPTC IIM4
-                 standard.
-          @return Data buffer containing the Iptc data.
-         */
-        DataBuf copy();
-        /*!
           @brief Returns a reference to the %Iptcdatum that is associated with a
                  particular \em key. If %IptcData does not already contain such
                  an %Iptcdatum, operator[] adds object \em Iptcdatum(key).
@@ -370,6 +363,13 @@ namespace Exiv2 {
         //! End of the metadata
         const_iterator end() const { return iptcMetadata_.end(); }
         /*!
+          @brief Write the Iptc data to a data buffer and return the data buffer.
+                 Caller owns this buffer. The copied data follows the IPTC IIM4
+                 standard.
+          @return Data buffer containing the Iptc data.
+         */
+        DataBuf copy() const;
+        /*!
           @brief Find an Iptcdatum with the given key, return a const iterator
                  to it.  If multiple metadata with the same key exist it is
                  undefined which of the matching metadata is found.
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
index 763bad6..54f77a4 100644
--- a/src/jpgimage.cpp
+++ b/src/jpgimage.cpp
@@ -67,10 +67,10 @@ namespace Exiv2 {
     // Todo: Generalised from JpegBase::locateIptcData without really understanding
     //       the format (in particular the header). So it remains to be confirmed 
     //       if this also makes sense for psTag != Photoshop::iptc
-    int Photoshop::locateIrb(const byte *pPsData,
-                             long sizePsData,
-                             uint16_t psTag,
-                             const byte **record,
+    int Photoshop::locateIrb(const byte*     pPsData,
+                             long            sizePsData,
+                             uint16_t        psTag,
+                             const byte**    record,
                              uint16_t *const sizeHdr,
                              uint16_t *const sizeData)
     {
@@ -110,6 +110,59 @@ namespace Exiv2 {
         return 3;
     } // Photoshop::locateIrb
 
+    int Photoshop::locateIptcIrb(const byte*     pPsData,
+                                 long            sizePsData,
+                                 const byte**    record,
+                                 uint16_t *const sizeHdr,
+                                 uint16_t *const sizeData)
+    {
+        return locateIrb(pPsData, sizePsData, iptc_,
+                         record, sizeHdr, sizeData);
+    }
+
+    DataBuf Photoshop::setIptcIrb(const byte*     pPsData,
+                                  long            sizePsData,
+                                  const IptcData& iptcData)
+    {
+        const byte* record    = pPsData;
+        uint16_t    sizeIptc  = 0;
+        uint16_t    sizeHdr   = 0;
+        // Safe to call with zero psData.size_
+        Photoshop::locateIptcIrb(pPsData, sizePsData,
+                                 &record, &sizeHdr, &sizeIptc);
+
+        Blob psBlob;
+        // Data is rounded to be even
+        const int sizeOldData = sizeHdr + sizeIptc + (sizeIptc & 1);
+        if (sizePsData > sizeOldData || iptcData.count() > 0) {
+            const long sizeFront = static_cast<long>(record - pPsData);
+            const long sizeEnd = sizePsData - sizeFront - sizeOldData;
+
+            // Write data before old record.
+            if (sizePsData > 0) append(psBlob, pPsData, sizeFront);
+
+            // Write new iptc record if we have it
+            DataBuf rawIptc(iptcData.copy());
+            if (rawIptc.size_ > 0) {
+                byte tmpBuf[12];
+                memcpy(tmpBuf, Photoshop::bimId_, 4);
+                us2Data(tmpBuf + 4, iptc_, bigEndian);
+                tmpBuf[6] = 0;
+                tmpBuf[7] = 0;
+                ul2Data(tmpBuf + 8, rawIptc.size_, bigEndian);
+                append(psBlob, tmpBuf, 12);
+                append(psBlob, rawIptc.pData_, rawIptc.size_);
+                // Data is padded to be even (but not included in size)
+                if (rawIptc.size_ & 1) psBlob.push_back(0x00);
+            }
+
+            // Write existing stuff after record
+            if (sizePsData > 0) append(psBlob, record + sizeOldData, sizeEnd);
+        }
+        return DataBuf(&psBlob[0], psBlob.size());
+
+    } // Photoshop::setIptcIrb
+
     JpegBase::JpegBase(BasicIo::AutoPtr io, bool create,
                        const byte initData[], long dataSize)
         : Image(mdExif | mdIptc | mdComment), io_(io)
@@ -246,12 +299,8 @@ namespace Exiv2 {
                 uint16_t sizeIptc = 0;
                 uint16_t sizeHdr = 0;
                 // Find actual Iptc data within the APP13 segment
-                if (!Photoshop::locateIrb(psData.pData_, 
-                                          psData.size_,
-                                          Photoshop::iptc_,
-                                          &record,
-                                          &sizeHdr, 
-                                          &sizeIptc)) {
+                if (!Photoshop::locateIptcIrb(psData.pData_, psData.size_,
+                                          &record, &sizeHdr, &sizeIptc)) {
                     assert(sizeIptc);
                     if (iptcData_.load(record + sizeHdr, sizeIptc)) throw Error(36, "IPTC");
                 }
@@ -427,62 +476,29 @@ namespace Exiv2 {
                     if (outIo.error()) throw Error(21);
                     --search;
                 }
-
-                const byte *record = psData.pData_;
-                uint16_t sizeIptc = 0;
-                uint16_t sizeHdr = 0;
-                // Safe to call with zero psData.size_
-                Photoshop::locateIrb(psData.pData_, 
-                                     psData.size_, 
-                                     Photoshop::iptc_,
-                                     &record, 
-                                     &sizeHdr, 
-                                     &sizeIptc);
-
-                // Data is rounded to be even
-                const int sizeOldData = sizeHdr + sizeIptc + (sizeIptc & 1);
-                if (psData.size_ > sizeOldData || iptcData_.count() > 0) {
-                    // rawIptc may have size of zero.
-                    DataBuf rawIptc(iptcData_.copy());
-                    // write app13 marker, new size, and ps3Id
-                    tmpBuf[0] = 0xff;
-                    tmpBuf[1] = app13_;
-                    const int sizeNewData = rawIptc.size_ ?
-                            rawIptc.size_ + (rawIptc.size_ & 1) + 12 : 0;
-                    us2Data(tmpBuf + 2,
-                            static_cast<uint16_t>(psData.size_-sizeOldData+sizeNewData+16),
-                            bigEndian);
-                    memcpy(tmpBuf + 4, Photoshop::ps3Id_, 14);
-                    if (outIo.write(tmpBuf, 18) != 18) throw Error(21);
-                    if (outIo.error()) throw Error(21);
-
-                    const long sizeFront = (long)(record - psData.pData_);
-                    const long sizeEnd = psData.size_ - sizeFront - sizeOldData;
-                    // write data before old record.
-                    if (outIo.write(psData.pData_, sizeFront) != sizeFront) throw Error(21);
-
-                    // write new iptc record if we have it
-                    if (iptcData_.count() > 0) {
-                        memcpy(tmpBuf, Photoshop::bimId_, 4);
-                        us2Data(tmpBuf+4, Photoshop::iptc_, bigEndian);
-                        tmpBuf[6] = 0;
-                        tmpBuf[7] = 0;
-                        ul2Data(tmpBuf + 8, rawIptc.size_, bigEndian);
-                        if (outIo.write(tmpBuf, 12) != 12) throw Error(21);
-                        if (outIo.write(rawIptc.pData_, rawIptc.size_)
-                            != rawIptc.size_) throw Error(21);
-                        // data is padded to be even (but not included in size)
-                        if (rawIptc.size_ & 1) {
-                            if (outIo.putb(0)==EOF) throw Error(21);
-                        }
+                if (psData.size_ > 0 || iptcData_.count() > 0) {
+                    // Set the new IPTC IRB, keeps existing IRBs but removes the
+                    // IPTC block if there is no new IPTC data to write
+                    DataBuf newPsData = Photoshop::setIptcIrb(psData.pData_, 
+                                                              psData.size_, 
+                                                              iptcData_);
+                    if (newPsData.size_ > 0) {
+                        // Write APP13 marker, new size, and ps3Id
+                        tmpBuf[0] = 0xff;
+                        tmpBuf[1] = app13_;
+                        us2Data(tmpBuf + 2, newPsData.size_ + 16, bigEndian);
+                        memcpy(tmpBuf + 4, Photoshop::ps3Id_, 14);
+                        if (outIo.write(tmpBuf, 18) != 18) throw Error(21);
                         if (outIo.error()) throw Error(21);
+                        
+                        // Write new Photoshop IRB data buffer
+                        if (   outIo.write(newPsData.pData_, newPsData.size_)
+                               != newPsData.size_) throw Error(21);
+                        if (outIo.error()) throw Error(21);
+                    }
+                    if (iptcData_.count() > 0) {
                         --search;
                     }
-
-                    // write existing stuff after record
-                    if (outIo.write(record+sizeOldData, sizeEnd)
-                        != sizeEnd) throw Error(21);
-                    if (outIo.error()) throw Error(21);
                 }
             }
             if (marker == eoi_) {
@@ -519,7 +535,6 @@ namespace Exiv2 {
 
     } // JpegBase::doWriteMetadata
 
-
     const byte JpegImage::soi_ = 0xd8;
     const byte JpegImage::blank_[] = {
         0xFF,0xD8,0xFF,0xDB,0x00,0x84,0x00,0x10,0x0B,0x0B,0x0B,0x0C,0x0B,0x10,0x0C,0x0C,
diff --git a/src/jpgimage.hpp b/src/jpgimage.hpp
index a799e5b..e193487 100644
--- a/src/jpgimage.hpp
+++ b/src/jpgimage.hpp
@@ -67,12 +67,12 @@ namespace Exiv2 {
         static const uint16_t iptc_;    //!< %Photoshop IPTC marker
 
         /*!
-          @brief Locates the data for a Photoshop tag in a Photoshop formated memory
+          @brief Locates the data for a %Photoshop tag in a %Photoshop formated memory
               buffer. Operates on raw data to simplify reuse.
           @param pPsData Pointer to buffer containing entire payload of
-              Photoshop formated data, e.g., from APP13 Jpeg segment.
+              %Photoshop formated data, e.g., from APP13 Jpeg segment.
           @param sizePsData Size in bytes of pPsData.
-          @param psTag Tag number of the block to look for.
+          @param psTag %Tag number of the block to look for.
           @param record Output value that is set to the start of the
               data block within pPsData (may not be null).
           @param sizeHdr Output value that is set to the size of the header
@@ -89,6 +89,26 @@ namespace Exiv2 {
                              const byte **record,
                              uint16_t *const sizeHdr,
                              uint16_t *const sizeData);
+        /*!
+          @brief Forwards to locateIrb() with \em psTag = \em iptc_
+         */
+        static int locateIptcIrb(const byte *pPsData,
+                                 long sizePsData,
+                                 const byte **record,
+                                 uint16_t *const sizeHdr,
+                                 uint16_t *const sizeData);
+        /*!
+          @brief Set the new IPTC IRB, keeps existing IRBs but removes the
+                 IPTC block if there is no new IPTC data to write.
+
+          @param pPsData    Existing IRB buffer
+          @param sizePsData Size of the IRB buffer, may be 0
+          @param iptcData   Iptc data to embed, may be empty
+          @return A data buffer containing the new IRB buffer, may have 0 size
+        */ 
+        static DataBuf setIptcIrb(const byte*     pPsData,
+                                  long            sizePsData,
+                                  const IptcData& iptcData);
 
     }; // class Photoshop
 
diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp
index ab1fd19..91d86fc 100644
--- a/src/tiffvisitor.cpp
+++ b/src/tiffvisitor.cpp
@@ -205,12 +205,8 @@ namespace Exiv2 {
         byte const* record = 0;
         uint16_t sizeHdr = 0;
         uint16_t sizeData = 0;
-        if (0 != Photoshop::locateIrb(object->pData(), 
-                                      object->size(),
-                                      Photoshop::iptc_, 
-                                      &record,
-                                      &sizeHdr,
-                                      &sizeData)) {
+        if (0 != Photoshop::locateIptcIrb(object->pData(), object->size(),
+                                          &record, &sizeHdr, &sizeData)) {
             return;
         }
         if (0 != pImage_->iptcData().load(record + sizeHdr, sizeData)) {

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list