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

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:41:09 UTC 2017


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

The following commit has been merged in the master branch:
commit 6c0ecf66fb40becad093396e41030ed79f748dac
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Fri Feb 12 15:37:28 2010 +0000

    #662: Added new option -n and action fixcom to exiv2 utility.
---
 src/actions.cpp          | 103 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/actions.hpp          |  18 +++++++++
 src/exiv2.cpp            |   2 +-
 src/value.cpp            |   2 +-
 test/data/exiv2-test.out |   4 ++
 5 files changed, 125 insertions(+), 4 deletions(-)

diff --git a/src/actions.cpp b/src/actions.cpp
index 849003c..72a0b78 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -218,6 +218,7 @@ namespace Action {
         registerTask(insert,  Task::AutoPtr(new Insert));
         registerTask(modify,  Task::AutoPtr(new Modify));
         registerTask(fixiso,  Task::AutoPtr(new FixIso));
+        registerTask(fixcom,  Task::AutoPtr(new FixCom));
     } // TaskFactory c'tor
 
     Task::AutoPtr TaskFactory::create(TaskType type)
@@ -695,7 +696,19 @@ namespace Action {
                 std::cout << _("(Binary value suppressed)") << std::endl;
                 return;
             }
-            std::cout << std::dec << md.value();
+            bool done = false;
+            if (0 == strcmp(md.key().c_str(), "Exif.Photo.UserComment")) {
+                const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(&md.value());
+                if (pcv) {
+                    Exiv2::CommentValue::CharsetId csId = pcv->charsetId();
+                    if (csId != Exiv2::CommentValue::undefined) {
+                        std::cout << "charset=\"" << Exiv2::CommentValue::CharsetInfo::name(csId) << "\" ";
+                    }
+                    std::cout << pcv->comment(Params::instance().charset_.c_str());
+                    done = true;
+                }
+            }
+            if (!done) std::cout << std::dec << md.value();
         }
         if (Params::instance().printItems_ & Params::prTrans) {
             if (!first) std::cout << "  ";
@@ -708,7 +721,15 @@ namespace Action {
                 std::cout << _("(Binary value suppressed)") << std::endl;
                 return;
             }
-            std::cout << std::dec << md.print(&pImage->exifData());
+            bool done = false;
+            if (0 == strcmp(md.key().c_str(), "Exif.Photo.UserComment")) {
+                const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(&md.value());
+                if (pcv) {
+                    std::cout << pcv->comment(Params::instance().charset_.c_str());
+                    done = true;
+                }
+            }
+            if (!done) std::cout << std::dec << md.print(&pImage->exifData());
         }
         if (Params::instance().printItems_ & Params::prHex) {
             if (!first) std::cout << std::endl;
@@ -1685,6 +1706,84 @@ namespace Action {
         return new FixIso(*this);
     }
 
+    FixCom::~FixCom()
+    {
+    }
+
+    int FixCom::run(const std::string& path)
+    {
+    try {
+        if (!Exiv2::fileExists(path, true)) {
+            std::cerr << path
+                      << ": " <<_("Failed to open the file
");
+            return -1;
+        }
+        Timestamp ts;
+        if (Params::instance().preserve_) {
+            ts.read(path);
+        }
+        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
+        assert(image.get() != 0);
+        image->readMetadata();
+        Exiv2::ExifData& exifData = image->exifData();
+        if (exifData.empty()) {
+            std::cerr << path
+                      << ": " << _("No Exif data found in the file
");
+            return -3;
+        }
+        Exiv2::ExifData::iterator pos = exifData.findKey(Exiv2::ExifKey("Exif.Photo.UserComment"));
+        if (pos == exifData.end()) {
+            if (Params::instance().verbose_) {
+                std::cout << _("No Exif user comment found") << "
";
+            }
+            return 0;
+        }
+        Exiv2::Value::AutoPtr v = pos->getValue();
+        const Exiv2::CommentValue* pcv = dynamic_cast<const Exiv2::CommentValue*>(v.get());
+        if (!pcv) {
+            if (Params::instance().verbose_) {
+                std::cout << _("Found Exif user comment with unexpected value type") << "
";
+            }
+            return 0;
+        }
+        Exiv2::CommentValue::CharsetId csId = pcv->charsetId();
+        if (csId != Exiv2::CommentValue::unicode) {
+            if (Params::instance().verbose_) {
+                std::cout << _("No Exif UNICODE user comment found") << "
";
+            }
+            return 0;
+        }
+        std::string comment = pcv->comment(Params::instance().charset_.c_str());
+        if (Params::instance().verbose_) {
+            std::cout << _("Setting Exif UNICODE user comment to") << " \"" << comment << "\"
";
+        }
+        comment = std::string("charset=\"") + Exiv2::CommentValue::CharsetInfo::name(csId) + "\" " + comment;
+        // Remove BOM and convert value from source charset to UCS-2, but keep byte order
+        pos->setValue(comment);
+        image->writeMetadata();
+        if (Params::instance().preserve_) {
+            ts.touch(path);
+        }
+        return 0;
+    }
+    catch(const Exiv2::AnyError& e)
+    {
+        std::cerr << "Exiv2 exception in fixcom action for file " << path
+                  << ":
" << e << "
";
+        return 1;
+    }
+    } // FixCom::run
+
+    FixCom::AutoPtr FixCom::clone() const
+    {
+        return AutoPtr(clone_());
+    }
+
+    FixCom* FixCom::clone_() const
+    {
+        return new FixCom(*this);
+    }
+
 }                                       // namespace Action
 
 // *****************************************************************************
diff --git a/src/actions.hpp b/src/actions.hpp
index 08fa057..5093db5 100644
--- a/src/actions.hpp
+++ b/src/actions.hpp
@@ -390,6 +390,24 @@ namespace Action {
 
     }; // class FixIso
 
+    /*!
+      @brief Fix the character encoding of Exif UNICODE user comments.
+             Decodes the comment using the auto-detected or specified
+             character encoding and writes it back in UCS-2.
+     */
+    class FixCom : public Task {
+    public:
+        virtual ~FixCom();
+        virtual int run(const std::string& path);
+        typedef std::auto_ptr<FixCom> AutoPtr;
+        AutoPtr clone() const;
+
+    private:
+        virtual FixCom* clone_() const;
+        std::string path_;
+
+    }; // class FixCom
+
 }                                       // namespace Action
 
 #endif                                  // #ifndef ACTIONS_HPP_
diff --git a/src/exiv2.cpp b/src/exiv2.cpp
index 30df50a..2145034 100644
--- a/src/exiv2.cpp
+++ b/src/exiv2.cpp
@@ -744,7 +744,7 @@ int Params::nonoption(const std::string& argv)
             action = true;
             action_ = Action::fixiso;
         }
-        if (argv == "fc" || argv == "fixcom") {
+        if (argv == "fc" || argv == "fixcom" || argv == "fixcomment") {
             if (action_ != Action::none && action_ != Action::fixcom) {
                 std::cerr << progname() << ": "
                           << _("Action fixcom is not compatible with the given options
");
diff --git a/src/value.cpp b/src/value.cpp
index 293792c..4102a69 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -527,7 +527,7 @@ namespace Exiv2 {
         }
         c = value_.substr(8);
         if (charsetId() == unicode) {
-            const char* from = encoding == 0 ? detectCharset(c) : encoding;
+            const char* from = encoding == 0 || *encoding == '

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list