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

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:38:43 UTC 2017


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

The following commit has been merged in the master branch:
commit c2b31e4f5fe4d682a5dd164d6d0f081406963de4
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Wed Sep 19 13:00:31 2007 +0000

    Utility: Implemented XMP delete and insert from *.xmp file actions. Library: Added logic to determine whether to write from XMP packet or parsed XMP data.
---
 src/actions.cpp  | 42 ++++++++++++++++++++++++++++++++++++------
 src/actions.hpp  | 12 +++++++++++-
 src/image.cpp    | 19 ++++++++++++++++++-
 src/image.hpp    | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/jpgimage.cpp | 30 +++++++++++++++---------------
 src/xmp.cpp      | 10 ++++++----
 6 files changed, 140 insertions(+), 29 deletions(-)

diff --git a/src/actions.cpp b/src/actions.cpp
index 76ba0de..f964688 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -925,10 +925,7 @@ namespace Action {
             rc = eraseComment(image.get());
         }
         if (0 == rc && Params::instance().target_ & Params::ctXmp) {
-            // Todo: Implement me!
-            if (!image->xmpData().empty()) {
-                std::cerr << "Deletion of XMP data not implemented yet.
";
-            }
+            rc = eraseXmpData(image.get());
         }
         if (0 == rc) {
             image->writeMetadata();
@@ -988,6 +985,15 @@ namespace Action {
         return 0;
     }
 
+    int Erase::eraseXmpData(Exiv2::Image* image) const
+    {
+        if (Params::instance().verbose_ && image->xmpData().count() > 0) {
+            std::cout << _("Erasing XMP data from the file") << std::endl;
+        }
+        image->clearXmpPacket();
+        return 0;
+    }
+
     Erase::AutoPtr Erase::clone() const
     {
         return AutoPtr(clone_());
@@ -1129,8 +1135,7 @@ namespace Action {
             rc = metacopy(exvPath, path, true);
         }
         if (0 == rc && Params::instance().target_ & Params::ctXmpPacket) {
-            // Todo: Implement me!
-            std::cerr << "Insertion of XMP packet from *.xmp file not implemented yet.
";
+            rc = insertXmpPacket(path);
         }
         if (Params::instance().preserve_) {
             ts.touch(path);
@@ -1144,6 +1149,31 @@ namespace Action {
         return 1;
     } // Insert::run
 
+    int Insert::insertXmpPacket(const std::string& path) const
+    {
+        std::string xmpPath = newFilePath(path, ".xmp");
+        if (!Exiv2::fileExists(xmpPath, true)) {
+            std::cerr << xmpPath
+                      << ": " << _("Failed to open the file
");
+            return -1;
+        }
+        if (!Exiv2::fileExists(path, true)) {
+            std::cerr << path
+                      << ": " << _("Failed to open the file
");
+            return -1;
+        }
+        Exiv2::DataBuf buf = Exiv2::readFile(xmpPath);
+        std::string xmpPacket;
+        xmpPacket.assign(reinterpret_cast<char*>(buf.pData_), buf.size_);
+        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
+        assert(image.get() != 0);
+        image->readMetadata();
+        image->setXmpPacket(xmpPacket);
+        image->writeMetadata();
+
+        return 0;
+    }
+
     int Insert::insertThumbnail(const std::string& path) const
     {
         std::string thumbPath = newFilePath(path, "-thumb.jpg");
diff --git a/src/actions.hpp b/src/actions.hpp
index ead9eae..7922cb1 100644
--- a/src/actions.hpp
+++ b/src/actions.hpp
@@ -246,6 +246,10 @@ namespace Action {
           @brief Erase Jpeg comment from the file.
          */
         int eraseComment(Exiv2::Image* image) const;
+        /*!
+          @brief Erase XMP packet from the file.
+         */
+        int eraseXmpData(Exiv2::Image* image) const;
 
     private:
         virtual Erase* clone_() const;
@@ -291,10 +295,16 @@ namespace Action {
 
         /*!
           @brief Insert a Jpeg thumbnail image from a file into file \em path.
-                 The filename of the thumbanail is expected to be the image
+                 The filename of the thumbnail is expected to be the image
                  filename (\em path) minus its suffix plus "-thumb.jpg".
          */
         int insertThumbnail(const std::string& path) const;
+        /*!
+          @brief Insert an XMP packet from a file into file \em path.
+                 The filename of the XMP packet is expected to be the image
+                 filename (\em path) minus its suffix plus ".xmp".
+         */
+        int insertXmpPacket(const std::string& path) const;
 
     private:
         virtual Insert* clone_() const;
diff --git a/src/image.cpp b/src/image.cpp
index e1b2431..838b975 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -101,7 +101,12 @@ namespace Exiv2 {
                  BasicIo::AutoPtr io)
         : io_(io),
           imageType_(imageType),
-          supportedMetadata_(supportedMetadata)
+          supportedMetadata_(supportedMetadata),
+#ifdef EXV_HAVE_XMP_TOOLKIT
+          writeXmpFromPacket_(false)
+#else 
+          writeXmpFromPacket_(true)
+#endif
     {
     }
 
@@ -118,6 +123,7 @@ namespace Exiv2 {
     {
         setExifData(image.exifData());
         setIptcData(image.iptcData());
+        setXmpPacket(image.xmpPacket());
         setXmpData(image.xmpData());
         setComment(image.comment());
     }
@@ -145,21 +151,32 @@ namespace Exiv2 {
     void Image::clearXmpPacket()
     {
         xmpPacket_.clear();
+        writeXmpFromPacket(true);
     }
 
     void Image::setXmpPacket(const std::string& xmpPacket)
     {
         xmpPacket_ = xmpPacket;
+        writeXmpFromPacket(true);
     }
 
     void Image::clearXmpData()
     {
         xmpData_.clear();
+        writeXmpFromPacket(false);
     }
 
     void Image::setXmpData(const XmpData& xmpData)
     {
         xmpData_ = xmpData;
+        writeXmpFromPacket(false);
+    }
+
+    void Image::writeXmpFromPacket(bool flag)
+    {
+#ifdef EXV_HAVE_XMP_TOOLKIT
+        writeXmpFromPacket_ = flag; 
+#endif
     }
 
     void Image::clearComment()
diff --git a/src/image.hpp b/src/image.hpp
index 20175d3..18eb414 100644
--- a/src/image.hpp
+++ b/src/image.hpp
@@ -145,22 +145,55 @@ namespace Exiv2 {
          */
         virtual void clearIptcData();
         /*!
-          @brief Set the raw XMP packet to \em xmpPacket.
+          @brief Assign a raw XMP packet. The new XMP packet is not written
+              to the image until the writeMetadata() method is called.
+
+          Subsequent calls to writeMetadata() write the XMP packet from 
+          the buffered raw XMP packet rather than from buffered parsed XMP 
+          data. In order to write from parsed XMP data again, use
+          either writeXmpFromPacket(false) or setXmpData().
+
+          @param xmpPacket A string containing the raw XMP packet.
          */
         virtual void setXmpPacket(const std::string& xmpPacket);
         /*!
-          @brief Set the raw XMP packet to \em xmpPacket.
+          @brief Erase the buffered XMP packet. XMP data is not removed from
+              the actual image until the writeMetadata() method is called.
+
+          This has the same effect as clearXmpData() but operates on the 
+          buffered raw XMP packet only, not the parsed XMP data.
+
+          Subsequent calls to writeMetadata() write the XMP packet from 
+          the buffered raw XMP packet rather than from buffered parsed XMP
+          data. In order to write from parsed XMP data again, use
+          either writeXmpFromPacket(false) or setXmpData().
          */
         virtual void clearXmpPacket();
         /*!
           @brief Assign new XMP data. The new XMP data is not written
               to the image until the writeMetadata() method is called.
+
+          Subsequent calls to writeMetadata() encode the XMP data to
+          a raw XMP packet and write the newly encoded packet to the image.
+          In the process, the buffered raw XMP packet is updated. 
+          In order to write directly from the raw XMP packet, use
+          writeXmpFromPacket(true) or setXmpPacket().
+
           @param xmpData An XmpData instance holding XMP data to be copied
          */
         virtual void setXmpData(const XmpData& xmpData);
         /*!
           @brief Erase any buffered XMP data. XMP data is not removed from
               the actual image until the writeMetadata() method is called.
+
+          This has the same effect as clearXmpPacket() but operates on the 
+          buffered parsed XMP data.
+
+          Subsequent calls to writeMetadata() encode the XMP data to
+          a raw XMP packet and write the newly encoded packet to the image.
+          In the process, the buffered raw XMP packet is updated.
+          In order to write directly from the raw XMP packet, use
+          writeXmpFromPacket(true) or setXmpPacket().
          */
         virtual void clearXmpData();
         /*!
@@ -226,6 +259,21 @@ namespace Exiv2 {
           @brief Return a modifiable reference to the raw XMP packet.
          */
         virtual std::string& xmpPacket() { return xmpPacket_; }
+        /*!
+          @brief Determine the source when writing XMP.
+
+          Depending on the setting of this flag, writeMetadata() writes
+          XMP from the buffered raw XMP packet or from parsed XMP data.
+          The default is to write from parsed XMP data. The switch is also
+          set by all functions to set and clear the buffered raw XMP packet
+          and parsed XMP data, so using this function should usually not be 
+          necessary.
+
+          If %Exiv2 was compiled without XMP support, the default for this 
+          flag is true and it will never be changed in order to preserve 
+          access to the raw XMP packet.
+         */
+        void writeXmpFromPacket(bool flag);
         //@}
 
         //! @name Accessors
@@ -318,6 +366,8 @@ namespace Exiv2 {
              This method is deprecated. Use checkMode() instead.
          */
         bool supportsMetadata(MetadataId metadataId) const;
+        //! Return the flag indicating the source when writing XMP metadata.
+        bool writeXmpFromPacket() const { return writeXmpFromPacket_; }
         //@}
 
     protected:
@@ -341,6 +391,8 @@ namespace Exiv2 {
         // DATA
         const int         imageType_;         //!< Image type
         const uint16_t    supportedMetadata_; //!< Bitmap with all supported metadata types
+        bool              writeXmpFromPacket_;//!< Determines the source when writing XMP
+
     }; // class Image
 
     //! Type for function pointer that creates new Image instances
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
index 89492a8..440c683 100644
--- a/src/jpgimage.cpp
+++ b/src/jpgimage.cpp
@@ -524,28 +524,28 @@ namespace Exiv2 {
                         --search;
                     }
                 }
-                if (xmpData_.count() > 0) {
+                if (writeXmpFromPacket() == false) {
                     if (XmpParser::encode(xmpPacket_, xmpData_)) {
 #ifndef SUPPRESS_WARNINGS
                         std::cerr << "Warning: Failed to encode XMP metadata.
";
 #endif
                     }
-                    if (xmpPacket_.size() > 0) {
-                        // Write APP1 marker, size of APP1 field, XMP id and XMP packet
-                        tmpBuf[0] = 0xff;
-                        tmpBuf[1] = app1_;
+                }
+                if (xmpPacket_.size() > 0) {
+                    // Write APP1 marker, size of APP1 field, XMP id and XMP packet
+                    tmpBuf[0] = 0xff;
+                    tmpBuf[1] = app1_;
 
-                        if (xmpPacket_.size() + 31 > 0xffff) throw Error(37, "XMP");
-                        us2Data(tmpBuf + 2, static_cast<uint16_t>(xmpPacket_.size() + 31), bigEndian);
-                        memcpy(tmpBuf + 4, xmpId_, 29);
-                        if (outIo.write(tmpBuf, 33) != 33) throw Error(21);
+                    if (xmpPacket_.size() + 31 > 0xffff) throw Error(37, "XMP");
+                    us2Data(tmpBuf + 2, static_cast<uint16_t>(xmpPacket_.size() + 31), bigEndian);
+                    memcpy(tmpBuf + 4, xmpId_, 29);
+                    if (outIo.write(tmpBuf, 33) != 33) throw Error(21);
 
-                        // Write new XMP packet
-                        if (   outIo.write(reinterpret_cast<const byte*>(xmpPacket_.data()), xmpPacket_.size())
-                            != static_cast<long>(xmpPacket_.size())) throw Error(21);
-                        if (outIo.error()) throw Error(21);
-                        --search;
-                    }
+                    // Write new XMP packet
+                    if (   outIo.write(reinterpret_cast<const byte*>(xmpPacket_.data()), xmpPacket_.size())
+                           != static_cast<long>(xmpPacket_.size())) throw Error(21);
+                    if (outIo.error()) throw Error(21);
+                    --search;
                 }
                 if (psData.size_ > 0 || iptcData_.count() > 0) {
                     // Set the new IPTC IRB, keeps existing IRBs but removes the
diff --git a/src/xmp.cpp b/src/xmp.cpp
index 903c2dc..8d80945 100644
--- a/src/xmp.cpp
+++ b/src/xmp.cpp
@@ -100,7 +100,6 @@ namespace {
 // class member definitions
 namespace Exiv2 {
 
-    //! @cond IGNORE
     //! Internal Pimpl structure of class Xmpdatum.
     struct Xmpdatum::Impl {
         Impl(const XmpKey& key, const Value* pValue);  //!< Constructor
@@ -111,7 +110,6 @@ namespace Exiv2 {
         XmpKey::AutoPtr key_;                          //!< Key
         Value::AutoPtr  value_;                        //!< Value
     };
-    //! @endcond
 
     Xmpdatum::Impl::Impl(const XmpKey& key, const Value* pValue)
         : key_(key.clone())
@@ -389,6 +387,7 @@ namespace Exiv2 {
                           const std::string& xmpPacket)
     { try {
         xmpData.clear();
+        if (xmpPacket.empty()) return 0;
 
         if (!initialize()) {
 #ifndef SUPPRESS_WARNINGS
@@ -524,6 +523,7 @@ namespace Exiv2 {
     int XmpParser::decode(      XmpData&     /*xmpData*/,
                           const std::string& xmpPacket)
     {
+        xmpData.clear();
         if (!xmpPacket.empty()) {
 #ifndef SUPPRESS_WARNINGS
             std::cerr << "Warning: XMP toolkit support not compiled in.
";
@@ -535,9 +535,10 @@ namespace Exiv2 {
 
 #ifdef EXV_HAVE_XMP_TOOLKIT
     int XmpParser::encode(      std::string& xmpPacket,
-                           const XmpData&     xmpData)
+                          const XmpData&     xmpData)
     { try {
         xmpPacket.clear();
+        if (xmpData.empty()) return 0;
 
         if (!initialize()) {
 #ifndef SUPPRESS_WARNINGS
@@ -604,9 +605,10 @@ namespace Exiv2 {
         return 3;
     }} // XmpParser::decode
 #else
-    void XmpParser::encode(      std::string& /*xmpPacket*/,
+    void XmpParser::encode(      std::string& xmpPacket,
                            const XmpData&     xmpData)
     {
+        xmpPacket.clear();
         if (!xmpData.empty()) {
 #ifndef SUPPRESS_WARNINGS
             std::cerr << "Warning: XMP toolkit support not compiled in.
";

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list