Skip to content

Commit

Permalink
remove endian handling
Browse files Browse the repository at this point in the history
There's std::endian now.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jul 12, 2023
1 parent 029b68a commit 7aa28d2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 26 deletions.
14 changes: 0 additions & 14 deletions include/exiv2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
#endif
#endif

#ifndef __LITTLE_ENDIAN__
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
#endif
#endif

#ifndef __LITTLE_ENDIAN__
#if defined(_WIN32) || defined(__CYGWIN__)
#define __LITTLE_ENDIAN__ 1
#endif
#endif

/*
If you're using Solaris and the Solaris Studio compiler
you must -library=stdcxx4 along with these inclusions below
Expand Down
2 changes: 1 addition & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::string BmffImage::toAscii(uint32_t n) {
return '_'; // show 0 as _
return '.'; // others .
});
if (!isBigEndianPlatform())
if (std::endian::native == std::endian::little)
std::reverse(result.begin(), result.end());
return result;
}
Expand Down
10 changes: 1 addition & 9 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@ bool Image::isPrintICC(uint16_t type, Exiv2::PrintStructureOption option) {
return type == 0x8773 && option == kpsIccProfile;
}

bool Image::isBigEndianPlatform() {
return std::endian::native == std::endian::big;
}

bool Image::isLittleEndianPlatform() {
return std::endian::native == std::endian::little;
}

uint64_t Image::byteSwap(uint64_t value, bool bSwap) {
uint64_t result = 0;
auto source_value = reinterpret_cast<byte*>(&value);
Expand Down Expand Up @@ -509,7 +501,7 @@ void Image::printTiffStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruc
// read header (we already know for certain that we have a Tiff file)
io.readOrThrow(dir.data(), 8, ErrorCode::kerCorruptedMetadata);
auto c = dir.read_uint8(0);
bool bSwap = (c == 'M' && isLittleEndianPlatform()) || (c == 'I' && isBigEndianPlatform());
bool bSwap = (c == 'M' && std::endian::native == std::endian::little || (c == 'I' && std::endian::native == std::endian::big));
size_t start = byteSwap4(dir, 4, bSwap);
printIFDStructure(io, out, option, start + offset, bSwap, c, depth);
}
Expand Down
2 changes: 1 addition & 1 deletion src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, m
std::string Jp2Image::toAscii(uint32_t n) {
const auto p = reinterpret_cast<const char*>(&n);
std::string result(p, p + 4);
if (!isBigEndianPlatform())
if (std::endian::native == std::endian::little)
std::reverse(result.begin(), result.end());
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static uint32_t byteSwap_(Exiv2::DataBuf& buf, size_t offset, bool bSwap) {
}

PgfImage::PgfImage(BasicIo::UniquePtr io, bool create) :
Image(ImageType::pgf, mdExif | mdIptc | mdXmp | mdComment, std::move(io)), bSwap_(isBigEndianPlatform()) {
Image(ImageType::pgf, mdExif | mdIptc | mdXmp | mdComment, std::move(io)), bSwap_(std::endian::native == std::endian::big) {
if (create && io_->open() == 0) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n";
Expand Down

0 comments on commit 7aa28d2

Please sign in to comment.