[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:41 UTC 2017


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

The following commit has been merged in the master branch:
commit 58f7d669dc759e487c4bb17f4499fc3b11bf2467
Author: brad <chickb at gmail.com>
Date:   Fri Oct 29 06:30:59 2004 +0000

    open image files on demand rather than keeping them open: bug #393
---
 src/actions.cpp  |   2 -
 src/image.cpp    | 208 ++++++++++++++++++++++++-------------------------------
 src/image.hpp    |  59 ++++------------
 src/metacopy.cpp |   1 -
 src/types.hpp    |  24 +++++++
 5 files changed, 128 insertions(+), 166 deletions(-)

diff --git a/src/actions.cpp b/src/actions.cpp
index 07ce666..a08fa04 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -566,7 +566,6 @@ namespace Action {
             return -2;
         }
         int rc = image->readMetadata();
-        image->detach();
         if (rc) {
             std::cerr << path_
                       << ": Could not read metadata
";
@@ -975,7 +974,6 @@ namespace {
             return -2;
         }
         int rc = sourceImage->readMetadata();
-        sourceImage->detach();
         if (rc) {
             std::cerr << source
                       << ": Could not read metadata
";
diff --git a/src/image.cpp b/src/image.cpp
index 888323d..82c7950 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -72,7 +72,7 @@ namespace Exiv2 {
              Caller owns the returned object and the auto-pointer ensures that 
              it will be deleted.
      */
-    Image::AutoPtr newExvInstance(const std::string& path, FILE* fp);
+    Image::AutoPtr newExvInstance(const std::string& path, bool create);
     //! Check if the file ifp is an EXV file.
     bool isExvType(FILE* ifp, bool advance);
     /*!
@@ -80,7 +80,7 @@ namespace Exiv2 {
              Caller owns the returned object and the auto-pointer ensures that 
              it will be deleted.
      */
-    Image::AutoPtr newJpegInstance(const std::string& path, FILE* fp);
+    Image::AutoPtr newJpegInstance(const std::string& path, bool create);
     //! Check if the file ifp is a JPEG image.
     bool isJpegType(FILE* ifp, bool advance);
 
@@ -110,35 +110,34 @@ namespace Exiv2 {
 
     Image::Type ImageFactory::getType(const std::string& path) const
     {
-        FILE* ifp = fopen(path.c_str(), "rb");
-        if (!ifp) return Image::none;
+        FileCloser closer(fopen(path.c_str(), "rb"));
+        if (!closer.fp_) return Image::none;
 
         Image::Type type = Image::none;
         Registry::const_iterator b = registry_.begin();
         Registry::const_iterator e = registry_.end();
         for (Registry::const_iterator i = b; i != e; ++i)
         {
-            if (i->second.isThisType(ifp, false)) {
+            if (i->second.isThisType(closer.fp_, false)) {
                 type = i->first;
                 break;
             }
         }
-        fclose(ifp);
         return type;
     } // ImageFactory::getType
 
     Image::AutoPtr ImageFactory::open(const std::string& path) const
     {
         Image::AutoPtr image;
-        FILE* ifp = fopen(path.c_str(), "rb");
-        if (!ifp) return image;
+        FileCloser closer(fopen(path.c_str(), "rb"));
+        if (!closer.fp_) return image;
 
         Registry::const_iterator b = registry_.begin();
         Registry::const_iterator e = registry_.end();
         for (Registry::const_iterator i = b; i != e; ++i)
         {
-            if (i->second.isThisType(ifp, false)) {
-                image = Image::AutoPtr(i->second.newInstance(path, ifp));
+            if (i->second.isThisType(closer.fp_, false)) {
+                image = Image::AutoPtr(i->second.newInstance(path, false));
                 break;
             }
         }
@@ -150,10 +149,9 @@ namespace Exiv2 {
     {
         Registry::const_iterator i = registry_.find(type);
         if (i != registry_.end()) {
-            return i->second.newInstance(path, 0);
+            return i->second.newInstance(path, true);
         }
-        Image::AutoPtr p;
-        return p;
+        return Image::AutoPtr();
     } // ImageFactory::create
 
 
@@ -171,33 +169,22 @@ namespace Exiv2 {
 
     JpegBase::JpegBase(const std::string& path, bool create, 
                        const byte initData[], size_t dataSize) 
-        : fp_(0), path_(path), 
-          sizeExifData_(0), pExifData_(0), sizeIptcData_(0), pIptcData_(0)
+        : path_(path), sizeExifData_(0), pExifData_(0),
+          sizeIptcData_(0), pIptcData_(0)
     {
         if (create) {
-            fp_ = fopen(path.c_str(), "w+b");
-            if (fp_) initFile(initData, dataSize);
-        }
-        else {
-            fp_ = fopen(path.c_str(), "rb");
+            FILE* fp = fopen(path.c_str(), "w+b");
+            if (fp) {
+                initFile(fp, initData, dataSize);
+                fclose(fp);
+            }
         }
     }
-    
-    JpegBase::JpegBase(const std::string& path, FILE* fp)
-        : fp_(fp), path_(path), sizeExifData_(0), 
-         pExifData_(0), sizeIptcData_(0), pIptcData_(0)
-    {
-        assert(fp_);
-    }
 
-    int JpegBase::initFile(const byte initData[], size_t dataSize)
+    int JpegBase::initFile(FILE* fp, const byte initData[], size_t dataSize)
     {
-        if (!fp_ || ferror(fp_)) return 4;
-        if (fwrite(initData, 1, dataSize, fp_) != dataSize) {
-            return 4;
-        }
-        fseek(fp_, 0, SEEK_SET);
-        if (ferror(fp_)) {
+        if (!fp || ferror(fp)) return 4;
+        if (fwrite(initData, 1, dataSize, fp) != dataSize) {
             return 4;
         }
         return 0;
@@ -205,23 +192,15 @@ namespace Exiv2 {
 
     JpegBase::~JpegBase()
     {
-        if (fp_) fclose(fp_);
         delete[] pExifData_;
         delete[] pIptcData_;
     }
 
-    int JpegBase::detach()
-    {
-        if (fp_) fclose(fp_); 
-        fp_ = 0; 
-        return 0; 
-    }
-
     bool JpegBase::good() const
     {
-        if (fp_ == 0) return false;
-        rewind(fp_);
-        return isThisType(fp_, false);
+        FileCloser closer(fopen(path_.c_str(), "rb"));
+        if (closer.fp_ == 0 ) return false;
+        return isThisType(closer.fp_, false);
     }
 
     void JpegBase::clearMetadata()
@@ -282,16 +261,16 @@ namespace Exiv2 {
         setComment(image.comment());
     }
 
-    int JpegBase::advanceToMarker() const
+    int JpegBase::advanceToMarker(FILE *fp) const
     {
         int c = -1;
         // Skips potential padding between markers
-        while ((c=fgetc(fp_)) != 0xff) {
+        while ((c=fgetc(fp)) != 0xff) {
             if (c == EOF) return -1;
         }
             
         // Markers can start with any number of 0xff
-        while ((c=fgetc(fp_)) == 0xff) {
+        while ((c=fgetc(fp)) == 0xff) {
             if (c == EOF) return -1;
         }
         return c;
@@ -299,12 +278,12 @@ namespace Exiv2 {
 
     int JpegBase::readMetadata()
     {
-        if (!fp_) return 1;
-        rewind(fp_);
+        FileCloser closer(fopen(path_.c_str(), "rb"));
+        if (!closer.fp_) return 1;
 
         // Ensure that this is the correct image type
-        if (!isThisType(fp_, true)) {
-            if (ferror(fp_) || feof(fp_)) return 1;
+        if (!isThisType(closer.fp_, true)) {
+            if (ferror(closer.fp_) || feof(closer.fp_)) return 1;
             return 2;
         }
         clearMetadata();
@@ -314,23 +293,23 @@ namespace Exiv2 {
         DataBuf buf(bufMinSize);
 
         // Read section marker
-        int marker = advanceToMarker();
+        int marker = advanceToMarker(closer.fp_);
         if (marker < 0) return 2;
         
         while (marker != sos_ && marker != eoi_ && search > 0) {
             // Read size and signature (ok if this hits EOF)
-            bufRead = (long)fread(buf.pData_, 1, bufMinSize, fp_);
-            if (ferror(fp_)) return 1;
+            bufRead = (long)fread(buf.pData_, 1, bufMinSize, closer.fp_);
+            if (ferror(closer.fp_)) return 1;
             uint16_t size = getUShort(buf.pData_, bigEndian);
 
             if (marker == app1_ && memcmp(buf.pData_ + 2, exifId_, 6) == 0) {
                 if (size < 8) return 2;
                 // Seek to begining and read the Exif data
-                fseek(fp_, 8-bufRead, SEEK_CUR); 
+                fseek(closer.fp_, 8-bufRead, SEEK_CUR); 
                 long sizeExifData = size - 8;
                 pExifData_ = new byte[sizeExifData];
-                fread(pExifData_, 1, sizeExifData, fp_);
-                if (ferror(fp_) || feof(fp_)) {
+                fread(pExifData_, 1, sizeExifData, closer.fp_);
+                if (ferror(closer.fp_) || feof(closer.fp_)) {
                     delete[] pExifData_;
                     pExifData_ = 0;
                     return 1;
@@ -342,10 +321,10 @@ namespace Exiv2 {
             else if (marker == app13_ && memcmp(buf.pData_ + 2, ps3Id_, 14) == 0) {
                 if (size < 16) return 2;
                 // Read the rest of the APP13 segment
-                // needed if bufMinSize!=16: fseek(fp_, 16-bufRead, SEEK_CUR);
+                // needed if bufMinSize!=16: fseek(closer.fp_, 16-bufRead, SEEK_CUR);
                 DataBuf psData(size - 16);
-                fread(psData.pData_, 1, psData.size_, fp_);
-                if (ferror(fp_) || feof(fp_)) return 1;
+                fread(psData.pData_, 1, psData.size_, closer.fp_);
+                if (ferror(closer.fp_) || feof(closer.fp_)) return 1;
                 const byte *record = 0;
                 uint16_t sizeIptc = 0;
                 uint16_t sizeHdr = 0;
@@ -365,10 +344,10 @@ namespace Exiv2 {
                 // Jpegs can have multiple comments, but for now only read
                 // the first one (most jpegs only have one anyway). Comments
                 // are simple single byte ISO-8859-1 strings.
-                fseek(fp_, 2-bufRead, SEEK_CUR);
+                fseek(closer.fp_, 2-bufRead, SEEK_CUR);
                 buf.alloc(size-2);
-                fread(buf.pData_, 1, size-2, fp_);
-                if (ferror(fp_) || feof(fp_)) return 1;
+                fread(buf.pData_, 1, size-2, closer.fp_);
+                if (ferror(closer.fp_) || feof(closer.fp_)) return 1;
                 comment_.assign(reinterpret_cast<char*>(buf.pData_), size-2);
                 while (   comment_.length()
                        && comment_.at(comment_.length()-1) == '

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list