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

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


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

The following commit has been merged in the master branch:
commit 8b7d9b8ea2866a706582c0fa486b28744a120747
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Tue Mar 23 08:19:27 2004 +0000

    Introduced Image class hierarchy, but JpegImage remains the only impl for now
---
 src/image.cpp |  81 ++++++++++++++++++++++++++-
 src/image.hpp | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 242 insertions(+), 11 deletions(-)

diff --git a/src/image.cpp b/src/image.cpp
index d49baf6..063cdf7 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -20,14 +20,14 @@
  */
 /*
   File:      image.cpp
-  Version:   $Name:  $ $Revision: 1.3 $
+  Version:   $Name:  $ $Revision: 1.4 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   26-Jan-04, ahu: created
              11-Feb-04, ahu: isolated as a component
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.3 $ $RCSfile: image.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.4 $ $RCSfile: image.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -46,11 +46,73 @@ EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.3 $ $RCSfile: image.cpp,v $")
 // class member definitions
 namespace Exif {
 
+    ImageFactory* ImageFactory::pInstance_ = 0;
+
+    ImageFactory& ImageFactory::instance()
+    {
+        if (0 == pInstance_) {
+            pInstance_ = new ImageFactory;
+        }
+        return *pInstance_;
+    } // ImageFactory::instance
+
+    void ImageFactory::registerImage(Image::Type type, Image* pImage)
+    {
+        Registry::iterator i = registry_.find(type);
+        if (i != registry_.end()) {
+            delete i->second;
+        }
+        registry_[type] = pImage;
+    } // ImageFactory::registerImage
+
+    ImageFactory::ImageFactory()
+    {
+        // Register a prototype of each known image
+        registerImage(Image::none, 0);
+        registerImage(Image::jpeg, new JpegImage);
+    } // ImageFactory c'tor
+
+    Image* ImageFactory::create(Image::Type type)
+    {
+        Registry::const_iterator i = registry_.find(type);
+        if (i != registry_.end() && i->second != 0) {
+            Image* pImage = i->second;
+            return pImage->clone();
+        }
+        return 0;
+    } // ImageFactory::create
+
     JpegImage::JpegImage()
         : sizeExifData_(0), pExifData_(0)
     {
     }
 
+    JpegImage::JpegImage(const JpegImage& rhs)
+        : Image(rhs), sizeExifData_(0), pExifData_(0)
+    {
+        char* newExifData = 0;
+        if (rhs.sizeExifData_ > 0) {
+            char* newExifData = new char[rhs.sizeExifData_];
+            memcpy(newExifData, rhs.pExifData_, rhs.sizeExifData_);
+        }
+        pExifData_ = newExifData;
+        sizeExifData_ = rhs.sizeExifData_;
+    }
+
+    JpegImage& JpegImage::operator=(const JpegImage& rhs)
+    {
+        if (this == &rhs) return *this;
+        char* newExifData = 0;
+        if (rhs.sizeExifData_ > 0) {
+            char* newExifData = new char[rhs.sizeExifData_];
+            memcpy(newExifData, rhs.pExifData_, rhs.sizeExifData_);
+        }
+        Image::operator=(rhs);
+        pExifData_ = newExifData;
+        sizeExifData_ = rhs.sizeExifData_;
+        return *this;        
+    }
+
     JpegImage::~JpegImage()
     {
         delete[] pExifData_;
@@ -193,6 +255,21 @@ namespace Exif {
         memcpy(pExifData_, buf, size);
     }
 
+    Image* JpegImage::clone() const
+    {
+        return new JpegImage(*this);
+    }
+
+    int JpegImage::isThisType(const std::string& path) const
+    {
+        std::ifstream file(path.c_str(), std::ios::binary);
+        if (!file) return -1;          // Couldn't open file
+        if (!isJpeg(file)) {
+            return 1;                  // not a Jpeg image
+        }
+        return 0;                      // this is a Jpeg image
+    }
+
     TiffHeader::TiffHeader(ByteOrder byteOrder) 
         : byteOrder_(byteOrder), tag_(0x002a), offset_(0x00000008)
     {
diff --git a/src/image.hpp b/src/image.hpp
index cf6f514..57b6bdb 100644
--- a/src/image.hpp
+++ b/src/image.hpp
@@ -21,7 +21,7 @@
 /*!
   @file    image.hpp
   @brief   Class JpegImage to access JPEG images
-  @version $Name:  $ $Revision: 1.3 $
+  @version $Name:  $ $Revision: 1.4 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    09-Jan-04, ahu: created
@@ -37,6 +37,7 @@
 // + standard includes
 #include <string>
 #include <iosfwd>
+#include <map>
 
 // *****************************************************************************
 // namespace extensions
@@ -45,29 +46,175 @@ namespace Exif {
 // *****************************************************************************
 // class definitions
 
-    /*! 
-      @brief Helper class to access JPEG images
+    /*!
+      @brief Abstract base class defining the interface for an image.
      */
-    class JpegImage {
-        //! @name Not implemented
+    class Image {
+    public:
+        //! Supported image formats
+        enum Type { none, jpeg, exiv2 };
+
+        //! @name Creators
         //@{
-        //! Copying not allowed
-        JpegImage(const JpegImage& rhs);
-        //! Assignment not allowed
-        JpegImage& operator=(const JpegImage& rhs);
+        //! Default Constructor
+        Image() {}
+        //! Virtual Destructor
+        virtual ~Image() {}
+        //@}
+
+        //! @name Manipulators
+        //@{
+        /*!
+          @brief Read the %Exif data from the file path into the internal 
+                 data buffer.
+          @param path Path to the file.
+          @return 0 if successful.         
+         */
+        virtual int readExifData(const std::string& path) =0;
+        /*!
+          @brief Read the %Exif data from the stream into the internal 
+                 data buffer.
+          @param is Input stream to read from.
+          @return 0 if successful.
+         */
+        virtual int readExifData(std::istream& is) =0;
+        /*!
+          @brief Read the %Exif data from the buffer buf which has size bytes.
+          @param buf Pointer to the data buffer.
+          @param size Number of characters in the data buffer.
+         */
+        virtual void setExifData(const char* buf, long size) =0;
+        //@}
+
+        //! @name Accessors
+        //@{
+        //! Virtual copy construction
+        virtual Image* clone() const =0;
+        /*!
+          @brief Determine if the file path is of this type of image.
+          @return  0 if the type of the image matches that of this;<BR>
+                   1 if the type of the image is not that of this;<BR>
+                  -1 if the file cannot be opened.
+         */
+        virtual int isThisType(const std::string& path) const =0;
+        /*!
+          @brief Write the %Exif data to file path.
+          @param path Path to the file.
+          @return 0 if successful.
+         */
+        virtual int writeExifData(const std::string& path) const =0;
+        /*!
+          @brief Read from the image input stream is, add %Exif data to the
+                 image, replacing existing %Exif data, if there is any) and
+                 write the resulting image to the output stream os.
+          @param os Output stream to write to (e.g., a temporary file).
+          @param is Input stream with the image to which the %Exif data
+                 should be copied.
+          @return 0 if successful.
+         */
+        virtual int writeExifData(std::ostream& os, std::istream& is) const =0;
+        //! Return the size of the %Exif data in bytes.
+        virtual long sizeExifData() const =0;
+        /*!
+          @brief Return a read-only pointer to an %Exif data buffer. Do not
+                 attempt to write to this buffer.
+         */
+        virtual const char* exifData() const =0;
         //@}
 
+    protected:
+        /*!
+          @brief Assignment operator. Protected so that it can only be used
+                 by subclasses but not directly.
+         */
+        Image& operator=(const Image& rhs) { return *this; }
+
+    }; // class Image
+
+    /*!
+      @brief Image factory.
+
+      Creates an instance of the image of the requested type.  The factory is
+      implemented as a singleton, which can be accessed only through the static
+      member function instance().
+    */
+    class ImageFactory {
+    public:
+        /*!
+          @brief Get access to the image factory.
+
+          Clients access the image factory exclusively through
+          this method.
+        */
+        static ImageFactory& instance();
+
+        /*!
+          @brief  Create an %Image of the appropriate type, derived from path.
+
+          @param  path Path to an image file (which may or may not exist). The
+                  path is used to determine the image type to create.
+          @return A pointer that owns an %Image of the type derived from path. 
+                  If no image type could be determined, the pointer is 0.
+         */
+        Image* create(const std::string& path);
+
+        /*!
+          @brief  Create an %Image of the requested type.
+
+          @param  type Type of the image to be created.
+          @return A pointer that owns an %Image of the requested type.
+                  If the image type is not supported, the pointer is 0.
+         */
+        Image* create(Image::Type type);
+
+        /*!
+          @brief Register an image prototype together with its type.
+
+          The image factory creates new images by cloning their associated
+          prototypes. Additional images can be added by registering a prototype
+          and its type. If called for a type which already exists in the list,
+          the corresponding prototype is replaced.
+
+          @param type Image type.
+          @param pImage Pointer to the prototype. Ownership is transfered to the
+                 factory.
+        */
+        void registerImage(Image::Type type, Image* pImage);
+
+    private:
+        //! Prevent construction other than through instance().
+        ImageFactory();
+        //! Prevent copy construction: not implemented.
+        ImageFactory(const ImageFactory& rhs);
+
+        //! Pointer to the one and only instance of this class.
+        static ImageFactory* pInstance_;
+        //! Type used to store Image prototype classes
+        typedef std::map<Image::Type, Image*> Registry;
+        //! List of image types and corresponding prototypes.
+        Registry registry_;
+
+    }; // class ImageFactory
+
+    /*! 
+      @brief Helper class to access JPEG images
+     */
+    class JpegImage : public Image {
     public:
         //! @name Creators
         //@{
         //! Default constructor
         JpegImage();
+        //! Copy constructor
+        JpegImage(const JpegImage& rhs);
         //! Destructor
         ~JpegImage();
         //@}
 
         //! @name Manipulators
         //@{
+        //! Assignment operator
+        JpegImage& operator=(const JpegImage& rhs);
         /*!
           @brief Read the %Exif data from the file path into the internal 
                  data buffer.
@@ -101,6 +248,13 @@ namespace Exif {
 
         //! @name Accessors
         //@{
+        //! Virtual copy construction
+        Image* clone() const;
+        /*!
+          @brief Determine if the file path contains a JPEG file. Return true if it
+                 does, false if not or if path cannot be opened or accessed.
+         */
+        int isThisType(const std::string& path) const;
         /*!
           @brief Write the %Exif data to file path, which must contain a JPEG
                  image. If an %Exif APP1 section exists in the file, it is

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list