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 df7c427 commit 676aac1
Show file tree
Hide file tree
Showing 5 changed files with 9 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
3 changes: 2 additions & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

// + standard includes
#include <bit>
#include <cinttypes>
#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -92,7 +93,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
11 changes: 2 additions & 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,8 @@ 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
3 changes: 2 additions & 1 deletion src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <algorithm>
#include <array>
#include <bit>
#include <iostream>

namespace Exiv2 {
Expand Down Expand Up @@ -101,7 +102,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
4 changes: 3 additions & 1 deletion src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "futils.hpp"
#include "image.hpp"

#include <bit>
#include <iostream>

// Signature from front of PGF file
Expand Down Expand Up @@ -54,7 +55,8 @@ 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 676aac1

Please sign in to comment.