[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=f520a57

The following commit has been merged in the master branch:
commit f520a571a6c608b042cdf00619ccc3710629ac18
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Wed Mar 31 12:03:02 2004 +0000

    Avoid opening the image twice on read and write
---
 src/exif.cpp  | 23 +++++++++--------------
 src/image.cpp | 24 ++++++++++++++++--------
 src/image.hpp | 31 ++++++++++++++++++++++++++-----
 3 files changed, 51 insertions(+), 27 deletions(-)

diff --git a/src/exif.cpp b/src/exif.cpp
index 1af64ec..56c07a9 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -20,14 +20,14 @@
  */
 /*
   File:      exif.cpp
-  Version:   $Name:  $ $Revision: 1.34 $
+  Version:   $Name:  $ $Revision: 1.35 $
   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.34 $ $RCSfile: exif.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.35 $ $RCSfile: exif.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -483,11 +483,8 @@ namespace Exif {
         std::ifstream file(path.c_str(), std::ios::binary);
         if (!file) return -1;
         Image* pImage = ImageFactory::instance().create(file);
-        file.close();
         if (pImage == 0) return -2;
-        // Todo: should we use file to read from? (and write isThisType so 
-        //       that it doesn't advance the stream)
-        int rc = pImage->readExifData(path);
+        int rc = pImage->readExifData(file);
         if (rc == 0) rc = read(pImage->exifData(), pImage->sizeExifData());
         delete pImage;
         return rc;
@@ -582,21 +579,19 @@ namespace Exif {
 
     int ExifData::write(const std::string& path) 
     {
+        std::ifstream is(path.c_str(), std::ios::binary);
+        if (!is) return -1;
+        Image* pImage = ImageFactory::instance().create(is);
+        if (pImage == 0) return -2;
+
         long size = this->size();
         char* buf = new char[size];
         long actualSize = copy(buf);
         assert(actualSize <= size);
 
-        std::ifstream file(path.c_str(), std::ios::binary);
-        if (!file) return -1;
-        Image* pImage = ImageFactory::instance().create(file);
-        file.close();
-        if (pImage == 0) return -2;
         pImage->setExifData(buf, actualSize);
         delete[] buf;
-        // Todo: Should this method take a path and stream arg?
-        //       Then we could reuse the file stream from above.
-        int rc = pImage->writeExifData(path);
+        int rc = pImage->writeExifData(path, is);
         delete pImage;
         return rc;
     } // ExifData::write
diff --git a/src/image.cpp b/src/image.cpp
index 3bc927a..e732054 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -20,14 +20,14 @@
  */
 /*
   File:      image.cpp
-  Version:   $Name:  $ $Revision: 1.5 $
+  Version:   $Name:  $ $Revision: 1.6 $
   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.5 $ $RCSfile: image.cpp,v $")
+EXIV2_RCSID("@(#) $Name:  $ $Revision: 1.6 $ $RCSfile: image.cpp,v $")
 
 // *****************************************************************************
 // included header files
@@ -153,6 +153,8 @@ namespace Exif {
             if (!is.good()) return 1;
             return 2;
         }
+        // isThisType does not advance the stream, so do this now
+        is.seekg(2, std::ios::cur);
 
         // Read and check section marker and size
         char tmpbuf[10];
@@ -182,16 +184,19 @@ namespace Exif {
     {
         std::ifstream infile(path.c_str(), std::ios::binary);
         if (!infile) return -1;
+        return writeExifData(path, infile);
+    } // JpegImage::writeExifData
 
+    int JpegImage::writeExifData(const std::string& path, std::istream& is) const
+    {
         // Write the output to a temporary file
         pid_t pid = getpid();
         std::string tmpname = path + toString(pid);
-        std::ofstream outfile(tmpname.c_str(), std::ios::binary);
-        if (!outfile) return -3;
+        std::ofstream os(tmpname.c_str(), std::ios::binary);
+        if (!os) return -3;
 
-        int rc = writeExifData(outfile, infile);
-        infile.close();
-        outfile.close();
+        int rc = writeExifData(os, is);
+        os.close();
         if (rc == 0) {
             // rename temporary file
             if (rename(tmpname.c_str(), path.c_str()) == -1) rc = -4;
@@ -212,6 +217,8 @@ namespace Exif {
             if (!is.good()) return 1;
             return 2;
         }
+        // isThisType does not advance the stream, so do this now
+        is.seekg(2, std::ios::cur);
 
         // Read and check section marker and size
         char tmpbuf[12];
@@ -268,9 +275,10 @@ namespace Exif {
         is.get(c);
         if (!is.good()) return false;
         if (static_cast<char>(soi_ & 0x00ff) != c) {
-            is.unget();
+            is.seekg(-2, std::ios::cur);
             return false;
         }
+        is.seekg(-2, std::ios::cur);
         return true;
     }
 
diff --git a/src/image.hpp b/src/image.hpp
index 1f140de..8a09e6e 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.5 $
+  @version $Name:  $ $Revision: 1.6 $
   @author  Andreas Huggel (ahu)
            <a href="mailto:ahuggel at gmx.net">ahuggel at gmx.net</a>
   @date    09-Jan-04, ahu: created
@@ -104,6 +104,15 @@ namespace Exif {
          */
         virtual int writeExifData(const std::string& path) const =0;
         /*!
+          @brief Add the %Exif data to the image provided in the input
+                 stream is and write the combined result to file path.
+          @param path Path to the file.
+          @param is Input stream with the image to add the %Exif data to.
+          @return 0 if successful.
+         */
+        virtual int writeExifData(const std::string& path, 
+                                  std::istream& is) 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.
@@ -264,9 +273,9 @@ namespace Exif {
           @brief  Determine if the content of the stream is a JPEG image. 
           @param  is Input stream to test.
           @return true if the input stream starts with the JPEG SOI marker.
-                  The stream is advanced by two characters in this case.<br>
+                  The stream is not advanced in this case.<BR>
                   false if the input stream does not begin with the JPEG SOI
-                  marker. The stream is not advanced in this case.<br>
+                  marker. The stream is not advanced.<BR>
                   false if reading the first two bytes from the stream fails.
                   Consult the stream state for more information. In this case,
                   the stream may or may not have been advanced by 1 or 2 
@@ -280,14 +289,26 @@ namespace Exif {
           @param path Path to the file.
           @return 0 if successful;<br>
                  -1 if the input file cannot be opened;<br>
+                 the return code of 
+                    writeExifData(const std::string& path, std::istream& is) const
+                    if the call to this function fails.
+         */
+        int writeExifData(const std::string& path) const;
+        /*!
+          @brief Add the %Exif data to the JPEG image provided in the input
+                 stream is and write the combined result to file path.  If an
+                 %Exif APP1 section exists in input stream, it is
+                 replaced. Otherwise, an %Exif data section is created.
+          @param path Path to the file.
+          @param is Input stream with the JPEG image to add the %Exif data to.
+          @return 0 if successful;<br>
                  -3 if the temporary file cannot be opened;<br>
                  -4 if renaming the temporary file fails; or<br>
                  the return code of 
                     writeExifData(std::ostream& os, std::istream& is) const
                     if the call to this function fails.
-
          */
-        int writeExifData(const std::string& path) const;
+        int writeExifData(const std::string& path, std::istream& is) const;
         /*!
           @brief Copy %Exif data into the JPEG image is, write the resulting
                  image to the output stream os. If an %Exif APP1 section exists

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list