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

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


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

The following commit has been merged in the master branch:
commit 40ffba603368a96fb2dbbd6cb1545050a9680baf
Author: Robin Mills <robin at clanmills.com>
Date:   Mon Apr 27 20:07:14 2015 +0000

    #922  -pS and -pX support for TIFF.  Added formatters to Image class and use them from {jpg/png/tiff}image.cpp
---
 include/exiv2/image.hpp |  10 ++
 src/image.cpp           |  41 ++++++
 src/jpgimage.cpp        | 101 +++++++--------
 src/pngimage.cpp        |  36 +++---
 src/tiffimage.cpp       | 335 ++++++++++++++++++++++++------------------------
 5 files changed, 282 insertions(+), 241 deletions(-)

diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp
index 31f41d6..9f96d3c 100644
--- a/include/exiv2/image.hpp
+++ b/include/exiv2/image.hpp
@@ -412,6 +412,16 @@ namespace Exiv2 {
         bool writeXmpFromPacket() const;
         //! Return list of native previews. This is meant to be used only by the PreviewManager.
         const NativePreviewList& nativePreviews() const;
+        /*!
+          @brief format a string in the pattern of \em sprintf \em .
+        */
+        std::string stringFormat(const std::string fmt, ...) const;
+
+        /*!
+          @brief format binary for display in \em printStructure() \em .
+        */
+        std::string binaryToString(DataBuf& buf,size_t size,size_t start=0) const;
+
         //@}
 
     protected:
diff --git a/src/image.cpp b/src/image.cpp
index bead82b..620f190 100644
--- a/src/image.cpp
+++ b/src/image.cpp
@@ -351,6 +351,47 @@ namespace Exiv2 {
         return ImageFactory::checkMode(imageType_, metadataId);
     }
 
+    std::string Image::stringFormat(const std::string fmt, ...) const
+    {
+        std::string result;
+
+        int     need = fmt.size()*4;             // initial guess
+        char*   buffer = new char[need];         // allocate a buffer
+        va_list ap;                              // variable arg list
+
+        va_start(ap, fmt);
+        need=vsnprintf(buffer, need, fmt.c_str(), ap);
+        va_end(ap);
+
+        if (need < 0) {                          // make buffer bigger
+            delete[] buffer;
+            buffer = new char[need+2];
+            va_start(ap, fmt);
+            need=vsnprintf(buffer, need, fmt.c_str(), ap);
+            va_end(ap);
+        }
+
+        if ( need > 0 ) result = std::string(buffer) ;
+
+        delete[] buffer;                         // free buffer
+        return result;
+    }
+
+    std::string Image::binaryToString(DataBuf& buf,size_t size,size_t start /* = 0 */) const
+    {
+        std::string result = "";
+        byte* buff = buf.pData_;
+
+        size += start;
+
+        while (start < size) {
+            int c = (int) buff[start++] ;
+            if (c < ' ' || c > 127) c = '.' ;
+            result +=  (char) c ;
+        }
+        return result;
+    }
+
     AccessMode ImageFactory::checkMode(int type, MetadataId metadataId)
     {
         const Registry* r = find(registry, type);
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
index 4fe3741..7c7fb80 100644
--- a/src/jpgimage.cpp
+++ b/src/jpgimage.cpp
@@ -509,13 +509,13 @@ namespace Exiv2 {
 
     bool isBlank(std::string& s)
     {
-    	for ( std::size_t i = 0 ; i < s.length() ; i++ )
-    		if ( s[i] != ' ' )
-    			return false ;
-    	return true ;
+        for ( std::size_t i = 0 ; i < s.length() ; i++ )
+            if ( s[i] != ' ' )
+                return false ;
+        return true ;
     }
 
-#define REPORT_MARKER if ( option == kpsBasic ) {  	sprintf(sbuff,"%8ld | %#02x %-5s",io_->tell(), marker,nm[marker].c_str());   out << sbuff; }
+#define REPORT_MARKER if ( option == kpsBasic ) out << stringFormat("%8ld | %#02x %-5s",io_->tell(), marker,nm[marker].c_str())
 
     void JpegBase::printStructure(std::ostream& out,printStructureOption_e option)
     {
@@ -527,9 +527,8 @@ namespace Exiv2 {
         }
 
         if ( option == kpsBasic || option == kpsXMP ) {
-            char sbuff[80];
 
-            // nemonic for markers
+            // nmonic for markers
             std::string nm[256] ;
             nm[0xd8]="SOI"  ;
             nm[0xd9]="EOI"  ;
@@ -554,9 +553,8 @@ namespace Exiv2 {
             // Container for the signature
             bool        bExtXMP    = false;
             long        bufRead    =  0;
-            long        startSig   =  0;
             const long  bufMinSize = 36;
-            DataBuf buf(bufMinSize);
+            DataBuf     buf(bufMinSize);
 
             // Read section marker
             int marker = advanceToMarker();
@@ -566,12 +564,12 @@ namespace Exiv2 {
             bool    first= true;
             while (!done) {
                 // print marker bytes
-            	if ( first && option == kpsBasic ) {
+                if ( first && option == kpsBasic ) {
                     out << "STRUCTURE OF JPEG FILE: " << io_->path() << std::endl;
-                    out << " address | marker     | length  | signature" << std::endl ;
-            		REPORT_MARKER;
-            	}
-        		first = false;
+                    out << " address | marker     | length  | data" << std::endl ;
+                    REPORT_MARKER;
+                }
+                first = false;
 
                 // Read size and signature
                 std::memset(buf.pData_, 0x0, buf.size_);
@@ -579,7 +577,6 @@ namespace Exiv2 {
                 if (io_->error()) throw Error(14);
                 if (bufRead < 2) throw Error(15);
                 uint16_t size = 0;
-                sbuff[0]=0;
 
                 // not all markers have size field.
                 if( ( marker >= sof0_ && marker <= sof15_)
@@ -591,16 +588,15 @@ namespace Exiv2 {
                 ||    marker == sos_
                 ){
                     size = getUShort(buf.pData_, bigEndian);
-                    sprintf(sbuff," | %7d ", size);
                 }
-                if ( option == kpsBasic ) out << sbuff ;
+                if ( option == kpsBasic ) out << stringFormat(" | %7d ", size);
 
                 // only print the signature for appn
                 if (marker >= app0_ && marker <= (app0_ | 0x0F)) {
                     char http[5];
                     http[4]=0;
                     memcpy(http,buf.pData_+2,4);
-                    if ( option == kpsXMP && strncmp(http,"http",4) == 0 ) {
+                    if ( option == kpsXMP && std::strcmp(http,"http") == 0 ) {
                         // http://ns.adobe.com/xap/1.0/
                         if ( size > 0 ) {
                             io_->seek(-bufRead , BasicIo::cur);
@@ -613,53 +609,46 @@ namespace Exiv2 {
                             // the first extended block is a copy of the Standard block.
                             // a robust implementation enables extended blocks to be out of sequence
                             if ( ! bExtXMP ) {
-                            	while (xmp[start]) start++; start++;
-                            	if ( ::strstr((char*)xmp+start,"HasExtendedXMP") ) {
-                            		start  = size ; // ignore this packet, we'll get on the next time around
-	                           		bExtXMP = true;
-                            	}
+                                while (xmp[start]) start++; start++;
+                                if ( ::strstr((char*)xmp+start,"HasExtendedXMP") ) {
+                                    start  = size ; // ignore this packet, we'll get on the next time around
+                                    bExtXMP = true;
+                                }
                             } else {
-                            	start = 2+35+32+4+4; // Adobe Spec, p19
+                                start = 2+35+32+4+4; // Adobe Spec, p19
                             }
                             xmp[size]=0;
 
-							// #922:  Remove blank lines.
+#if 1
+                            out << xmp + start; // this is all we need to output without the blank line dance.
+#else
+                            // #922:  Remove blank lines.
                             // cut the xmp into (non blank) lines
-                            // out << xmp + start; // this is all we need to output without the blank line dance.
                             std::vector<std::string> lines ;
                             std::string s((char*)xmp+start);
                             char nl      = '
';
 
                             while( s.length() )
-							{
-								std::size_t end = s.find(nl);
-								if ( end != std::string::npos )
-								{
-									std::string line = s.substr(0,end);
-									if ( !isBlank(line) )
-										lines.push_back(line+nl);
-									s = s.substr(end+1,std::string::npos);
-								} else {
-									lines.push_back(s);
-									s="";
-								}
-							}
-							for ( size_t l = 0 ; l < lines.size() ; l++  ) out << lines[l];
-
+                            {
+                                std::size_t end = s.find(nl);
+                                if ( end != std::string::npos )
+                                {
+                                    std::string line = s.substr(0,end);
+                                    if ( !isBlank(line) )
+                                        lines.push_back(line+nl);
+                                    s = s.substr(end+1,std::string::npos);
+                                } else {
+                                    lines.push_back(s);
+                                    s="";
+                                }
+                            }
+                            for ( size_t l = 0 ; l < lines.size() ; l++  ) out << lines[l];
+#endif
                             delete [] xmp;
                             bufRead = size;
                         }
                     } else if ( option == kpsBasic ) {
-                        startSig = size>0?2:0;
-                        int endSig = size?size:bufRead;
-                        if (endSig > 32) endSig = 32 ;
-                        out << "| ";
-                        while (startSig++ < endSig ) {
-                            byte c = buf.pData_[startSig-1] ;
-                            c      = (' '<=c && c<128) ? c : '.' ;
-                            out << (char) c ;
-                            // else     endSig = startSig;
-                        }
+                        out << "| " << binaryToString(buf,32,size>0?2:0);
                     }
                 }
 
@@ -670,14 +659,14 @@ namespace Exiv2 {
 
                 if (marker == sos_)
                     // sos_ is immediately followed by entropy-coded data & eoi_
-                	done = true;
+                    done = true;
                 else {
-                	// Read the beginning of the next segment
-                	marker = advanceToMarker();
-            		REPORT_MARKER;
+                    // Read the beginning of the next segment
+                    marker = advanceToMarker();
+                    REPORT_MARKER;
                     if ( marker == eoi_ ) {
                         if ( option == kpsBasic ) out << std::endl;
-                    	done = true;
+                        done = true;
                     }
                 }
             }
diff --git a/src/pngimage.cpp b/src/pngimage.cpp
index a1c424d..95431d0 100644
--- a/src/pngimage.cpp
+++ b/src/pngimage.cpp
@@ -109,13 +109,18 @@ namespace Exiv2 {
 
         if ( option == kpsBasic || option == kpsXMP ) {
 
-            if ( option == kpsBasic ) out << "index | chunk_type | length | data" << std::endl;
+            if ( option == kpsBasic ) {
+                out << "STRUCTURE OF PNG FILE: " << io_->path() << std::endl;
+                out << " address | index | chunk_type |  length | data" << std::endl;
+            }
 
             long       index   = 0;
             const long imgSize = io_->size();
             DataBuf    cheaderBuf(8);
 
             while( !io_->eof() && ::strcmp(chType,"IEND") ) {
+                size_t address = io_->tell();
+
                 std::memset(cheaderBuf.pData_, 0x0, cheaderBuf.size_);
                 long bufRead = io_->read(cheaderBuf.pData_, cheaderBuf.size_);
                 if (io_->error()) throw Error(14);
@@ -132,31 +137,24 @@ namespace Exiv2 {
                     chType[i-4]=cheaderBuf.pData_[i];
                 }
 
-                byte   buff[32];
-                size_t blen  = sizeof(buff)-1;
-                buff  [blen] = 0;
-                buff  [   0] = 0;
-
-                size_t     dOff = dataOffset;
+                size_t      blen = 32   ;
+                size_t      dOff = dataOffset;
+                std::string dataString ;
 
                 if ( dataOffset > blen ) {
-                    io_->read(buff,blen);
+                    DataBuf buff(blen+1);
+                    io_->read(buff.pData_,blen);
                     dataOffset -=  blen ;
-                    for ( size_t i = 0 ; i < blen ; i++ ) {
-                        int c = buff[i] ;
-                        buff[i] = (' '<=c && c<128) ? c : '.' ;
-                    }
+                    dataString  = binaryToString(buff,blen);
                 }
 
-                char sbuff[80];
-                sprintf(sbuff,"%5ld %12s %8lu   %s
", index++,chType,dOff,buff);
-                if ( option == kpsBasic ) out << sbuff;
+                if ( option == kpsBasic ) out << stringFormat("%8llu | %5ld | %10s |%8lu | ",address, index++,chType,dOff) << dataString << std::endl;
 
                 // for XMP, back up and read the whole block
                 const char* key = "XML:com.adobe.xmp" ;
                 int       start = ::strlen(key);
-                buff[start] = 0;
-                if ( option == kpsXMP && ::strcmp((const char*)buff,key) == 0 ) {
+
+                if ( option == kpsXMP && dataString.find(key)==0 ) {
 #if defined(_MSC_VER)
                     io_->seek(-static_cast<int64_t>(blen) , BasicIo::cur);
 #else
@@ -166,8 +164,8 @@ namespace Exiv2 {
                     byte* xmp  = new byte[dataOffset+5];
                     io_->read(xmp,dataOffset+4);
                     xmp[dataOffset]=0;
-                    while ( xmp[start] == 0 ) start++;
-                    out << xmp+start << std::endl;
+                    while ( xmp[start] == 0 ) start++; // crawl over the '

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list