Adding 8-byte swap functions + consts

v0.27.3
Michał Walenciak 8 years ago
parent f96d84ba8c
commit b6e79357de

@ -353,10 +353,12 @@ namespace Exiv2 {
bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option); bool isPrintXMP(uint16_t type, Exiv2::PrintStructureOption option);
bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option); bool isPrintICC(uint16_t type, Exiv2::PrintStructureOption option);
uint32_t byteSwap(uint32_t value,bool bSwap); uint64_t byteSwap(uint64_t value,bool bSwap) const;
uint16_t byteSwap(uint16_t value,bool bSwap); uint32_t byteSwap(uint32_t value,bool bSwap) const;
uint16_t byteSwap2(DataBuf& buf,size_t offset,bool bSwap); uint16_t byteSwap(uint16_t value,bool bSwap) const;
uint32_t byteSwap4(DataBuf& buf,size_t offset,bool bSwap); 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;
//@} //@}

@ -244,7 +244,19 @@ namespace Exiv2 {
} }
bool Image::isLittleEndianPlatform() { return !isBigEndianPlatform(); } 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<byte *>(&value);
byte* destination_value = reinterpret_cast<byte *>(&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; uint32_t result = 0;
result |= (value & 0x000000FF) << 24; result |= (value & 0x000000FF) << 24;
@ -254,7 +266,7 @@ namespace Exiv2 {
return bSwap ? result : value; 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; uint16_t result = 0;
result |= (value & 0x00FF) << 8; result |= (value & 0x00FF) << 8;
@ -262,7 +274,7 @@ namespace Exiv2 {
return bSwap ? result : value; 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; uint16_t v;
char* p = (char*) &v; char* p = (char*) &v;
@ -271,7 +283,7 @@ namespace Exiv2 {
return Image::byteSwap(v,bSwap); 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; uint32_t v;
char* p = (char*) &v; char* p = (char*) &v;
@ -282,6 +294,17 @@ namespace Exiv2 {
return Image::byteSwap(v,bSwap); 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<byte *>(&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 const char* Image::typeName(uint16_t tag) const
{ {
//! List of TIFF image tags //! List of TIFF image tags

Loading…
Cancel
Save