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

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:42:28 UTC 2017


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

The following commit has been merged in the master branch:
commit 3342822ad7d9c8209bd8240de711158162ee9d8f
Author: vog <vog at notjusthosting.com>
Date:   Mon Jun 27 16:38:53 2011 +0000

    Provide generic mechanism for native previews
---
 src/image.cpp   |   5 +++
 src/image.hpp   |  15 +++++++++
 src/preview.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)

diff --git a/src/image.cpp b/src/image.cpp
index 56d128d..b23fcdb 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -320,6 +320,11 @@ namespace Exiv2 {
         return writeXmpFromPacket_;
     }
 
+    const NativePreviewList& Image::nativePreviews() const
+    {
+        return nativePreviews_;
+    }
+
     bool Image::good() const
     {
         if (io_->open() != 0) return false;
diff --git a/src/image.hpp b/src/image.hpp
index 7737afa..896696e 100644
--- a/src/image.hpp
+++ b/src/image.hpp
@@ -58,6 +58,18 @@ namespace Exiv2 {
         const int none = 0;         //!< Not an image
     }
 
+    //! Native preview information. This is meant to be used only by the PreviewManager.
+    struct NativePreview {
+        long position_;
+        uint32_t size_;
+        uint32_t width_;
+        uint32_t height_;
+        std::string mimeType_;
+    };
+
+    //! List of native previews. This is meant to be used only by the PreviewManager.
+    typedef std::vector<NativePreview> NativePreviewList;
+
     /*!
       @brief Abstract base class defining the interface for an image. This is
          the top-level interface to the Exiv2 library.
@@ -385,6 +397,8 @@ namespace Exiv2 {
         bool supportsMetadata(MetadataId metadataId) const;
         //! Return the flag indicating the source when writing XMP metadata.
         bool writeXmpFromPacket() const;
+        //! Return list of native previews. This is meant to be used only by the PreviewManager.
+        const NativePreviewList& nativePreviews() const;
         //@}
 
     protected:
@@ -397,6 +411,7 @@ namespace Exiv2 {
         std::string       xmpPacket_;         //!< XMP packet
         int               pixelWidth_;        //!< image pixel width
         int               pixelHeight_;       //!< image pixel height
+        NativePreviewList nativePreviews_;    //!< list of native previews
 
     private:
         //! @name NOT implemented
diff --git a/src/preview.cpp b/src/preview.cpp
index 1b3cbf8..9d16997 100644
--- a/src/preview.cpp
+++ b/src/preview.cpp
@@ -138,6 +138,29 @@ namespace {
         bool valid_;
     };
 
+    //! Loader for native previews
+    class LoaderNative : public Loader {
+    public:
+        //! Constructor
+        LoaderNative(PreviewId id, const Image &image, int parIdx);
+
+        //! Get properties of a preview image with given params
+        virtual PreviewProperties getProperties() const;
+
+        //! Get a buffer that contains the preview image
+        virtual DataBuf getData() const;
+
+        //! Read preview image dimensions
+        virtual bool readDimensions();
+
+    protected:
+        //! Native preview information
+        NativePreview nativePreview_;
+    };
+
+    //! Function to create new LoaderNative
+    Loader::AutoPtr createLoaderNative(PreviewId id, const Image &image, int parIdx);
+
     //! Loader for Jpeg previews that are not read into ExifData directly
     class LoaderExifJpeg : public Loader {
     public:
@@ -269,6 +292,10 @@ namespace {
 // class member definitions
 
     const Loader::LoaderList Loader::loaderList_[] = {
+        { 0,                       createLoaderNative,       0 },
+        { 0,                       createLoaderNative,       1 },
+        { 0,                       createLoaderNative,       2 },
+        { 0,                       createLoaderNative,       3 },
         { 0,                       createLoaderExifDataJpeg, 0 },
         { 0,                       createLoaderExifDataJpeg, 1 },
         { 0,                       createLoaderExifDataJpeg, 2 },
@@ -371,6 +398,82 @@ namespace {
         return (PreviewId)EXV_COUNTOF(loaderList_);
     }
 
+    LoaderNative::LoaderNative(PreviewId id, const Image &image, int parIdx)
+        : Loader(id, image)
+    {
+        if (!(0 <= parIdx && static_cast<size_t>(parIdx) < image.nativePreviews().size())) return;
+        nativePreview_ = image.nativePreviews()[parIdx];
+        size_ = nativePreview_.size_;
+        width_ = nativePreview_.width_;
+        height_ = nativePreview_.height_;
+        valid_ = true;
+    }
+
+    Loader::AutoPtr createLoaderNative(PreviewId id, const Image &image, int parIdx)
+    {
+        return Loader::AutoPtr(new LoaderNative(id, image, parIdx));
+    }
+
+    PreviewProperties LoaderNative::getProperties() const
+    {
+        PreviewProperties prop = Loader::getProperties();
+        prop.mimeType_ = nativePreview_.mimeType_;
+        if (nativePreview_.mimeType_ == "image/jpeg") {
+            prop.extension_ = ".jpg";
+        } else {
+#ifndef SUPPRESS_WARNINGS
+            EXV_WARNING << "Unknown native preview format: " << nativePreview_.mimeType_ << "
";
+#endif
+            prop.extension_ = ".dat";
+        }
+#ifdef EXV_UNICODE_PATH
+        prop.wextension_ = s2ws(prop.extension_);
+#endif
+        return prop;
+    }
+
+    DataBuf LoaderNative::getData() const
+    {
+        if (!valid()) return DataBuf();
+
+        BasicIo &io = image_.io();
+        if (io.open() != 0) {
+            throw Error(9, io.path(), strError());
+        }
+        IoCloser closer(io);
+        const Exiv2::byte* data = io.mmap();
+        if (io.size() < nativePreview_.position_ + static_cast<long>(nativePreview_.size_)) {
+#ifndef SUPPRESS_WARNINGS
+            EXV_WARNING << "Invalid native preview position or size.
";
+#endif
+            return DataBuf();
+        }
+        return DataBuf(data + nativePreview_.position_, nativePreview_.size_);
+    }
+
+    bool LoaderNative::readDimensions()
+    {
+        if (!valid()) return false;
+        if (width_ != 0 || height_ != 0) return true;
+
+        const DataBuf data = getData();
+        if (data.size_ == 0) return false;
+        try {
+            Image::AutoPtr image = ImageFactory::open(data.pData_, data.size_);
+            if (image.get() == 0) return false;
+            image->readMetadata();
+
+            width_ = image->pixelWidth();
+            height_ = image->pixelHeight();
+        } catch (const AnyError& /* error */) {
+#ifndef SUPPRESS_WARNINGS
+            EXV_WARNING << "Unable to determine dimensions of native preview image.
";
+#endif
+            return false;
+        }
+        return true;
+    }
+
     LoaderExifJpeg::LoaderExifJpeg(PreviewId id, const Image &image, int parIdx)
         : Loader(id, image)
     {

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list