From 6e19d043efcf8425fdd08cd8a856d1c46528cf10 Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Thu, 17 Mar 2016 22:14:21 +0000 Subject: [PATCH] #1108 Added IPTC parser for tiff. --- src/image.cpp | 9 ++++++--- src/image_int.hpp | 5 +++++ src/tiffimage.cpp | 25 ++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 9e8ddf40..38ffc28d 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -609,11 +609,9 @@ namespace Exiv2 { return result; } - std::string binaryToString(DataBuf& buf, size_t size, size_t start /*=0*/) + std::string binaryToString(const byte* buff, size_t size, size_t start /*=0*/) { std::string result = ""; - byte* buff = buf.pData_; - size += start; while (start < size) { @@ -627,4 +625,9 @@ namespace Exiv2 { return result; } + std::string binaryToString(DataBuf& buf, size_t size, size_t start /*=0*/) + { + return binaryToString(buf.pData_,size,start); + } + }} // namespace Internal, Exiv2 diff --git a/src/image_int.hpp b/src/image_int.hpp index 00f1a304..a96445d1 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -60,6 +60,11 @@ namespace Exiv2 { */ std::string binaryToString(DataBuf& buf, size_t size, size_t start =0); + /*! + @brief format binary for display in \em printStructure() \em . + */ + std::string binaryToString(const byte* buff, size_t size, size_t start /*=0*/); + }} // namespace Internal, Exiv2 #endif // #ifndef IMAGE_INT_HPP_ diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index d41934b4..8efcb74b 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -574,12 +574,31 @@ namespace Exiv2 { sp = kount == count ? "" : " ..."; out << sp << std::endl; - if ( option == kpsRecursive - && (tag == 0x8769 /* ExifTag */ /* || tag == 0x927c MakerNote */) - ){ + if ( option == kpsRecursive && tag == 0x8769 /* ExifTag */ ) { size_t restore = io.tell(); printIFDStructure(io,out,option,Offset,bSwap,c,depth); io.seek(restore,BasicIo::beg); + } else if ( option == kpsRecursive && tag == 0x83bb /* IPTCNAA */ ) { + size_t restore = io.tell(); // save + io.seek(offset,BasicIo::beg); // position + byte* bytes=new byte[count] ; // allocate memory + io.read(bytes,count) ; // read + io.seek(restore,BasicIo::beg); // restore + + uint32_t i = 0 ; + while ( i < count-3 && bytes[i] != 0x1c ) i++; + out << " Record | DataSet | Name | Length | Data" << std::endl; + while ( bytes[i] == 0x1c && i < size-3 ) { + char buff[100]; + uint16_t record = bytes[i+1]; + uint16_t dataset = bytes[i+2]; + uint16_t len = getUShort(bytes+i+3,bigEndian); + sprintf(buff," %6d | %7d | %-24s | %6d | ",record,dataset, Exiv2::IptcDataSets::dataSetName(dataset,record).c_str(), len); + + out << buff << Internal::binaryToString(bytes,(len>40?40:len),i+5) << (len>40?"...":"") << std::endl; + i += 5 + len; + } + delete[] bytes; } }