From 71fd0ae96ecd2a78d3ace4605f8fdeedc75e6f89 Mon Sep 17 00:00:00 2001 From: draekko Date: Fri, 12 Aug 2016 11:46:51 +0000 Subject: [PATCH] #1199 (as was discussed) moved WebPImage::debugPrintHex to Internal::binaryToHex --- src/image.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/image_int.hpp | 5 +++++ src/webpimage.cpp | 44 ++++------------------------------------- 3 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 4a086395..b7906e68 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -648,6 +648,56 @@ namespace Exiv2 { return binaryToString(buf.pData_,size,start); } + std::string binaryToHex(const byte *data, size_t size) + { + std::stringstream hexOutput; + + unsigned long tl = (unsigned long)(size / 16) * 16; + unsigned long tl_offset = size - tl; + + hexOutput << "Display Hex Dump [size:" << (unsigned long)size << "]" << std::endl; + + for (unsigned long loop = 0; loop < (unsigned long)size; loop++) { + if (data[loop] < 16) { + hexOutput << "0"; + } + hexOutput << std::hex << (int)data[loop]; + if ((loop % 8) == 7) { + hexOutput << " "; + } + if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) { + int max = 15; + if (loop >= tl) { + max = tl_offset - 1; + hexOutput << " "; + for (long offset = 0; offset < (16 - tl_offset); offset++) { + if ((offset % 8) == 7) { + hexOutput << " "; + } + hexOutput << " "; + } + } + hexOutput << " "; + for (unsigned long offset = max; offset >= 0; offset--) { + if (offset == (max - 8)) { + hexOutput << " "; + } + if ((data[loop - offset]) >= 0x20 && + (data[loop - offset]) <= 0x7E) { + hexOutput << data[loop - offset]; + } else { + hexOutput << "."; + } + } + hexOutput << std::endl; + } + } + + hexOutput << std::endl << std::endl << std::endl; + + return hexOutput.str(); + } + std::string indent(int32_t d) { std::string result ; diff --git a/src/image_int.hpp b/src/image_int.hpp index 7e515eed..62a845c8 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -65,6 +65,11 @@ namespace Exiv2 { */ std::string binaryToString(const byte* buff, size_t size, size_t start /*=0*/); + /*! + @brief format binary for display of raw data . + */ + std::string binaryToHex(const byte *data, size_t size); + /*! @brief indent output for kpsRecursive in \em printStructure() \em . */ diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 75fec6ea..f597da66 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -43,16 +43,14 @@ #include "tiffimage_int.hpp" #include "exiv2/convert.hpp" #include -#include #include #include #include #include +#include #include #include -#include // To uncompress or compress text chunk - #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) // ***************************************************************************** @@ -60,7 +58,6 @@ namespace Exiv2 { namespace Internal { - }} // namespace Internal, Exiv2 namespace Exiv2 { @@ -668,8 +665,9 @@ namespace Exiv2 { memcpy(rawExifData + offset, payload.pData_, (long)payload.size_); #ifdef DEBUG - debugPrintHex(rawExifData, size); + std::cout << Internal::binaryToHex(rawExifData, size); #endif + if (pos != -1) { XmpData xmpData; ByteOrder bo = ExifParser::decode(exifData_, @@ -696,7 +694,7 @@ namespace Exiv2 { #endif } else { #ifdef DEBUG - debugPrintHex(xmpData_, xmpData_.size()); + std::cout << Internal::binaryToHex(xmpData_, xmpData_.size()); #endif #ifdef __USE_IPTC__ copyXmpToIptc(xmpData_, iptcData_); @@ -831,38 +829,4 @@ namespace Exiv2 { return pos; } - void WebPImage::debugPrintHex(byte *data, long size) { - std::cout << "Display Hex Dump [size:" << size << "]" << std::endl; - long tl = (long)(size / 16) * 16; - long tl_offset = size - tl; - for (long loop = 0; loop < size; loop++) { - if (data[loop] < 16) std::cout << "0"; - std::cout << std::hex << (int)data[loop] << " "; - if ((loop % 8) == 7) std::cout << " "; - if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) { - int max = 15; - if (loop >= tl) { - max = tl_offset - 1; - std::cout << " "; - for (long offset = 0; offset < (16 - tl_offset); offset++) { - if ((offset % 8) == 7) std::cout << " "; - std::cout << " "; - } - } - std::cout << " "; - for (long offset = max; offset >= 0; offset--) { - if (offset == (max - 8)) std::cout << " "; - if ((data[loop - offset]) >= 0x20 && - (data[loop - offset]) <= 0x7E) { - std::cout << data[loop - offset]; - } else { - std::cout << "."; - } - } - std::cout << std::endl; - } - } - std::cout << std::dec << std::endl << std::endl; - } - } // namespace Exiv2