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

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


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

The following commit has been merged in the master branch:
commit 214a00b8428ad49098f41900844f6b2f9979a479
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Thu Feb 5 03:45:20 2004 +0000

    Added thumbnail type none, added ifd and TIFF header to thumbnail
---
 src/exif.cpp | 148 +++++++++++++++++++++++++++++++++++++----------------------
 src/exif.hpp |  27 ++++++++---
 2 files changed, 114 insertions(+), 61 deletions(-)

diff --git a/src/exif.cpp b/src/exif.cpp
index 925a650..b008693 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -20,13 +20,13 @@
  */
 /*
   File:      exif.cpp
-  Version:   $Name:  $ $Revision: 1.15 $
+  Version:   $Name:  $ $Revision: 1.16 $
   Author(s): Andreas Huggel (ahu) <ahuggel at gmx.net>
   History:   26-Jan-04, ahu: created
  */
 // *****************************************************************************
 #include "rcsid.hpp"
-EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.15 $ $RCSfile: exif.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.16 $ $RCSfile: exif.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -543,7 +543,7 @@ namespace Exif {
     }
 
     int Ifd::readSubIfd(
-        Ifd& dest, char* buf, ByteOrder byteOrder, uint16 tag
+        Ifd& dest, const char* buf, ByteOrder byteOrder, uint16 tag
     ) const
     {
         int rc = 0;
@@ -744,6 +744,48 @@ namespace Exif {
 
     } // Ifd::print
 
+    Thumbnail::Thumbnail()
+        : type_(none), size_(0), image_(0), ifd_(ifd1, false)
+    {
+    }
+
+    Thumbnail::~Thumbnail()
+    {
+        delete[] image_;
+    }
+
+    Thumbnail::Thumbnail(const Thumbnail& rhs)
+        : type_(rhs.type_), size_(rhs.size_), image_(0), ifd_(ifd1, false)
+    {
+        if (rhs.image_ > 0 && rhs.size_ > 0) {
+            image_ = new char[rhs.size_];
+            memcpy(image_, rhs.image_, rhs.size_);
+        }
+        if (image_ && type_ == tiff) {
+            tiffHeader_.read(image_);
+            ifd_.read(image_ + tiffHeader_.offset(),
+                      tiffHeader_.byteOrder(), tiffHeader_.offset());
+        }
+    }
+
+    Thumbnail& Thumbnail::operator=(const Thumbnail& rhs)
+    {
+        type_ = rhs.type_;
+        size_ = rhs.size_;
+        delete[] image_;
+        image_ = 0;
+        if (rhs.image_ > 0 && rhs.size_ > 0) {
+            image_ = new char[rhs.size_];
+            memcpy(image_, rhs.image_, rhs.size_);
+        }
+        if (image_ && type_ == tiff) {
+            tiffHeader_.read(image_);
+            ifd_.read(image_ + tiffHeader_.offset(), 
+                      tiffHeader_.byteOrder(), tiffHeader_.offset());
+        }
+        return *this;
+    }
+
     int Thumbnail::read(const char* buf,
                         const ExifData& exifData,
                         ByteOrder byteOrder)
@@ -772,8 +814,10 @@ namespace Exif {
         pos = exifData.findKey(key);
         if (pos == exifData.end()) return 1;
         long size = pos->toLong();
-        image_ = std::string(buf + offset, size);
-        type_ = JPEG;
+        image_ = new char[size];
+        memcpy(image_, buf + offset, size);
+        size_ = size;
+        type_ = jpeg;
         return 0;
     } // Thumbnail::readJpegImage
 
@@ -826,9 +870,14 @@ namespace Exif {
         ifd1.sortByTag();
         ifd1.copy(data + ifdOffset, tiffHeader.byteOrder(), ifdOffset);
 
-        image_ = std::string(data, len);
+        image_ = new char[len];
+        memcpy(image_, data, len);
+        size_ = len;
+        tiffHeader_.read(image_);
+        ifd_.read(image_ + tiffHeader_.offset(), 
+                  tiffHeader_.byteOrder(), tiffHeader_.offset());
+        type_ = tiff;
         delete[] data;
-        type_ = TIFF;
 
         return 0;
     } // Thumbnail::readTiffImage
@@ -837,16 +886,19 @@ namespace Exif {
     {
         std::string p;
         switch (type_) {
-        case JPEG: 
+        case jpeg: 
             p = path + ".jpg";
             break;
-        case TIFF:
+        case tiff:
             p = path + ".tif";
             break;
+        case none:
+            return 1;
+            break;
         }
         std::ofstream file(p.c_str(), std::ios::binary | std::ios::out);
         if (!file) return 1;
-        file.write(image_.data(), image_.size());
+        file.write(image_, size_);
         if (!file.good()) return 2;
         return 0;
     } // Thumbnail::write
@@ -857,12 +909,15 @@ namespace Exif {
         //       i.e., synch all relevant metadata
 
         switch (type_) {
-        case JPEG: 
+        case jpeg: 
             updateJpegImage(exifData);
             break;
-        case TIFF:
+        case tiff:
             updateTiffImage(exifData);
             break;
+        case none:
+            /* do nothing */
+            break;
         }
 
     } // Thumbnail::update
@@ -887,29 +942,21 @@ namespace Exif {
             delete value;            
             pos = exifData.findKey(key);
         }
-        std::ostringstream os;
-        os << image_.size();
-        pos->setValue(os.str());
+        pos->setValue(toString(size_));
 
     } // Thumbnail::updateJpegImage
 
     void Thumbnail::updateTiffImage(ExifData& exifData) const
     {
-        TiffHeader tiffHeader;
-        tiffHeader.read(image_.data());
-        long offset = tiffHeader.offset();
-        Ifd ifd1(ifd1);
-        ifd1.read(image_.data() + offset, tiffHeader.byteOrder(), offset);
-
         // Create metadata from the StripOffsets and StripByteCounts entries
         // and add these to the Exif data, replacing existing entries
-        Ifd::const_iterator pos = ifd1.findTag(0x0111);
-        if (pos == ifd1.end()) throw Error("Bad thumbnail (0x0111)");
-        exifData.add(Metadatum(*pos, tiffHeader.byteOrder()));
+        Ifd::const_iterator pos = ifd_.findTag(0x0111);
+        if (pos == ifd_.end()) throw Error("Bad thumbnail (0x0111)");
+        exifData.add(Metadatum(*pos, tiffHeader_.byteOrder()));
 
-        pos = ifd1.findTag(0x0117);
-        if (pos == ifd1.end()) throw Error("Bad thumbnail (0x0117)");
-        exifData.add(Metadatum(*pos, tiffHeader.byteOrder()));
+        pos = ifd_.findTag(0x0117);
+        if (pos == ifd_.end()) throw Error("Bad thumbnail (0x0117)");
+        exifData.add(Metadatum(*pos, tiffHeader_.byteOrder()));
 
     } // Thumbnail::updateTiffImage
 
@@ -917,47 +964,45 @@ namespace Exif {
     {
         long ret = 0;
         switch (type_) {
-        case JPEG: 
+        case jpeg: 
             ret = copyJpegImage(buf);
             break;
-        case TIFF:
+        case tiff:
             ret = copyTiffImage(buf);
             break;
+        case none:
+            ret = 0;
+            break;
         }
         return ret;
     }
 
     long Thumbnail::copyJpegImage(char* buf) const
     {
-        memcpy(buf, image_.data(), image_.size());
-        return image_.size();
+        memcpy(buf, image_, size_);
+        return size_;
     }
 
     long Thumbnail::copyTiffImage(char* buf) const
     {
-        // Read the TIFF header and IFD from the thumbnail image
-        TiffHeader tiffHeader;
-        tiffHeader.read(image_.data());
-        long offset = tiffHeader.offset();
-        Ifd thumbIfd(ifd1);
-        thumbIfd.read(image_.data() + offset, tiffHeader.byteOrder(), offset);
-
-
-        offset = thumbIfd.offset() + thumbIfd.size() + thumbIfd.dataSize();
-        long size = image_.size() - offset;
-        memcpy(buf, image_.data() + offset, size);
+        long offset = ifd_.offset() + ifd_.size() + ifd_.dataSize();
+        long size = size_ - offset;
+        memcpy(buf, image_ + offset, size);
         return size;
     }
 
     void Thumbnail::setOffsets(Ifd& ifd1, ByteOrder byteOrder) const
     {
         switch (type_) {
-        case JPEG: 
+        case jpeg: 
             setJpegImageOffsets(ifd1, byteOrder);
             break;
-        case TIFF:
+        case tiff:
             setTiffImageOffsets(ifd1, byteOrder);
             break;
+        case none:
+            /* do nothing */
+            break;
         }        
     }
 
@@ -970,20 +1015,13 @@ namespace Exif {
 
     void Thumbnail::setTiffImageOffsets(Ifd& ifd1, ByteOrder byteOrder) const
     {
-        // Read the TIFF header and IFD from the thumbnail image
-        TiffHeader tiffHeader;
-        tiffHeader.read(image_.data());
-        long offset = tiffHeader.offset();
-        Ifd thumbIfd(ifd1);
-        thumbIfd.read(image_.data() + offset, tiffHeader.byteOrder(), offset);
-
         // Adjust the StripOffsets, assuming that the existing TIFF strips
         // start immediately after the thumbnail IFD
         long shift = ifd1.offset() + ifd1.size() + ifd1.dataSize() 
-            - thumbIfd.offset() - thumbIfd.size() - thumbIfd.dataSize();
-        Ifd::const_iterator pos = thumbIfd.findTag(0x0111);
-        if (pos == thumbIfd.end()) throw Error("Bad thumbnail (0x0111)");
-        Metadatum offsets(*pos, tiffHeader.byteOrder());
+            - ifd_.offset() - ifd_.size() - ifd_.dataSize();
+        Ifd::const_iterator pos = ifd_.findTag(0x0111);
+        if (pos == ifd_.end()) throw Error("Bad thumbnail (0x0111)");
+        Metadatum offsets(*pos, tiffHeader_.byteOrder());
         std::ostringstream os;
         for (long k = 0; k < offsets.count(); ++k) {
             os << offsets.toLong(k) + shift << " ";
diff --git a/src/exif.hpp b/src/exif.hpp
index 5e92e90..167391a 100644
--- a/src/exif.hpp
+++ b/src/exif.hpp
@@ -21,7 +21,7 @@
 /*!
   @file    exif.hpp
   @brief   Encoding and decoding of %Exif data
-  @version $Name:  $ $Revision: 1.14 $
+  @version $Name:  $ $Revision: 1.15 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    09-Jan-04, ahu: created
@@ -838,7 +838,7 @@ namespace Exif {
           @return 0 if successful
         */
         int readSubIfd(
-            Ifd& dest, char* buf, ByteOrder byteOrder, uint16 tag
+            Ifd& dest, const char* buf, ByteOrder byteOrder, uint16 tag
         ) const;
         /*!
           @brief Copy the IFD to a data array, return the number of bytes
@@ -903,8 +903,16 @@ namespace Exif {
     //! %Thumbnail data Todo: add, create, rotate, delete
     class Thumbnail {
     public:
+        //! Default constructor
+        Thumbnail();
+        //! Destructor
+        ~Thumbnail();
+        //! Copy constructor
+        Thumbnail(const Thumbnail& rhs);
+        //! Assignment operator
+        Thumbnail& operator=(const Thumbnail& rhs);
         //! %Thumbnail image types
-        enum Type { JPEG, TIFF };
+        enum Type { none, jpeg, tiff };
         /*!
           @brief Read the thumbnail from the data buffer buf, using %Exif
                  metadata exifData. Return 0 if successful. 
@@ -924,7 +932,10 @@ namespace Exif {
         int read(const char* buf, 
                  const ExifData& exifData,
                  ByteOrder byteOrder =littleEndian);
-        //! Write thumbnail to file path, return 0 if successful
+        /*!
+          @brief Write thumbnail to file path, return 0 if successful, -1 if 
+                 there is no thumbnail image to write.
+         */
         int write(const std::string& path) const;
         /*!
           @brief Copy the thumbnail image data (without the IFD, if any) to the
@@ -976,8 +987,12 @@ namespace Exif {
         //! Update the offsets to the TIFF thumbnail image in the IFD
         void setTiffImageOffsets(Ifd& ifd1, ByteOrder byteOrder) const;
 
-        std::string image_;
-        Type type_;
+        Type type_;              // Type of thumbnail image
+        long size_;              // Size of the image data
+        char* image_;            // Thumbnail image data
+        TiffHeader tiffHeader_;  // Thumbnail TIFF Header, only for TIFF thumbs
+        Ifd ifd_;                // Thumbnail IFD, only for TIFF thumbnails
+       
     }; // class Thumbnail
 
     /*!

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list