From 21eb0cec4ff61b472834fc19cae018780f81caa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Sat, 19 Feb 2022 18:34:34 +0100 Subject: [PATCH] Fix build when EXIV2_BUILD_MESSAGES is ON --- src/crwimage.cpp | 3 --- src/crwimage_int.cpp | 1 + src/tiffimage_int.cpp | 2 ++ src/webpimage.cpp | 52 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 165f096b..5aa57a60 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -147,9 +147,6 @@ namespace Exiv2 { // Parse the image, starting with a CIFF header component CiffHeader header; header.read(pData, size); -#ifdef EXIV2_DEBUG_MESSAGES - header.print(std::cerr); -#endif header.decode(*pCrwImage); // a hack to get absolute offset of preview image inside CRW structure diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 018f2d00..9b4afafa 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -27,6 +27,7 @@ #include #include +#include // ***************************************************************************** // local declarations diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 36849be7..e4cb602f 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -26,6 +26,8 @@ #include "tiffvisitor_int.hpp" #include "i18n.h" // NLS support. +#include + // Shortcuts for the newTiffBinaryArray templates. #define EXV_BINARY_ARRAY(arrayCfg, arrayDef) (newTiffBinaryArray0<&arrayCfg, EXV_COUNTOF(arrayDef), arrayDef>) #define EXV_SIMPLE_BINARY_ARRAY(arrayCfg) (newTiffBinaryArray1<&arrayCfg>) diff --git a/src/webpimage.cpp b/src/webpimage.cpp index f881c3f7..6562010f 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -50,6 +50,54 @@ #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) +namespace { + [[maybe_unused]] std::string binaryToHex(const uint8_t* data, size_t size) + { + std::stringstream hexOutput; + + auto tl = size_t(size / 16) * 16; + auto tl_offset = size_t(size) - tl; + + for (size_t loop = 0; loop < size; loop++) { + if (data[loop] < 16) { + hexOutput << "0"; + } + hexOutput << std::hex << static_cast(data[loop]); + if ((loop % 8) == 7) { + hexOutput << " "; + } + if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) { + int max = 15; + if (loop >= tl) { + max = int(tl_offset) - 1; + for (int offset = 0; offset < int(16 - tl_offset); offset++) { + if ((offset % 8) == 7) { + hexOutput << " "; + } + hexOutput << " "; + } + } + hexOutput << " "; + for (int offset = max; offset >= 0; offset--) { + if (offset == (max - 8)) { + hexOutput << " "; + } + uint8_t c = '.'; + if (data[loop - offset] >= 0x20 && data[loop - offset] <= 0x7E) { + c = data[loop - offset]; + } + hexOutput << static_cast(c); + } + hexOutput << std::endl; + } + } + + hexOutput << std::endl << std::endl << std::endl; + + return hexOutput.str(); + } +} // namespace + // ***************************************************************************** // class member definitions namespace Exiv2 { @@ -688,7 +736,7 @@ namespace Exiv2 { #ifdef EXIV2_DEBUG_MESSAGES std::cout << "Display Hex Dump [size:" << static_cast(sizePayload) << "]" << std::endl; - std::cout << Internal::binaryToHex(rawExifData.c_data(), sizePayload); + std::cout << binaryToHex(rawExifData.c_data(), sizePayload); #endif if (pos != -1) { @@ -716,7 +764,7 @@ namespace Exiv2 { #ifdef EXIV2_DEBUG_MESSAGES std::cout << "Display Hex Dump [size:" << static_cast(payload.size()) << "]" << std::endl; - std::cout << Internal::binaryToHex(payload.c_data(), payload.size()); + std::cout << binaryToHex(payload.c_data(), payload.size()); #endif } } else {