From b6e79357de3cd436a017ba29938f8526d951279a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Walenciak?= Date: Wed, 20 Sep 2017 21:23:35 +0200 Subject: [PATCH] Adding 8-byte swap functions + consts --- include/exiv2/image.hpp | 10 ++++++---- src/image.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 47e31f14..1d7c4c25 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -353,10 +353,12 @@ namespace Exiv2 { bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option); bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option); - uint32_t byteSwap(uint32_t value,bool bSwap); - uint16_t byteSwap(uint16_t value,bool bSwap); - uint16_t byteSwap2(DataBuf& buf,size_t offset,bool bSwap); - uint32_t byteSwap4(DataBuf& buf,size_t offset,bool bSwap); + uint64_t byteSwap(uint64_t value,bool bSwap) const; + uint32_t byteSwap(uint32_t value,bool bSwap) const; + uint16_t byteSwap(uint16_t value,bool bSwap) const; + uint16_t byteSwap2(const DataBuf& buf,size_t offset,bool bSwap) const; + uint32_t byteSwap4(const DataBuf& buf,size_t offset,bool bSwap) const; + uint64_t byteSwap8(const DataBuf& buf,size_t offset,bool bSwap) const; //@} diff --git a/src/image.cpp b/src/image.cpp index c8259708..ea78911b 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -244,7 +244,19 @@ namespace Exiv2 { } bool Image::isLittleEndianPlatform() { return !isBigEndianPlatform(); } - uint32_t Image::byteSwap(uint32_t value,bool bSwap) + uint64_t Image::byteSwap(uint64_t value,bool bSwap) const + { + uint64_t result = 0; + byte* source_value = reinterpret_cast(&value); + byte* destination_value = reinterpret_cast(&result); + + for (int i = 0; i < 8; i++) + destination_value[i] = source_value[8 - i - 1]; + + return bSwap ? result : value; + } + + uint32_t Image::byteSwap(uint32_t value,bool bSwap) const { uint32_t result = 0; result |= (value & 0x000000FF) << 24; @@ -254,7 +266,7 @@ namespace Exiv2 { return bSwap ? result : value; } - uint16_t Image::byteSwap(uint16_t value,bool bSwap) + uint16_t Image::byteSwap(uint16_t value,bool bSwap) const { uint16_t result = 0; result |= (value & 0x00FF) << 8; @@ -262,7 +274,7 @@ namespace Exiv2 { return bSwap ? result : value; } - uint16_t Image::byteSwap2(DataBuf& buf,size_t offset,bool bSwap) + uint16_t Image::byteSwap2(const DataBuf& buf,size_t offset,bool bSwap) const { uint16_t v; char* p = (char*) &v; @@ -271,7 +283,7 @@ namespace Exiv2 { return Image::byteSwap(v,bSwap); } - uint32_t Image::byteSwap4(DataBuf& buf,size_t offset,bool bSwap) + uint32_t Image::byteSwap4(const DataBuf& buf,size_t offset,bool bSwap) const { uint32_t v; char* p = (char*) &v; @@ -282,6 +294,17 @@ namespace Exiv2 { return Image::byteSwap(v,bSwap); } + uint64_t Image::byteSwap8(const DataBuf& buf,size_t offset,bool bSwap) const + { + uint64_t v; + byte* p = reinterpret_cast(&v); + + for(int i = 0; i < 8; i++) + p[i] = buf.pData_[offset + i]; + + return Image::byteSwap(v,bSwap); + } + const char* Image::typeName(uint16_t tag) const { //! List of TIFF image tags