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 <rosenp@gmail.com>
  • Loading branch information
neheb committed Jul 19, 2023
1 parent 273364e commit 21cbd59
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 37 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
10 changes: 0 additions & 10 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,6 @@ class EXIV2API Image {
void printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start, bool bSwap,
char c, size_t depth);

/*!
@brief is the host platform bigEndian
*/
static bool isBigEndianPlatform();

/*!
@brief is the host platform littleEndian
*/
static bool isLittleEndianPlatform();

static bool isStringType(uint16_t type);
static bool isShortType(uint16_t type);
static bool isLongType(uint16_t type);
Expand Down
2 changes: 1 addition & 1 deletion src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
std::copy_n(bytes + DWORD, WORD, reinterpret_cast<uint8_t*>(&data2_));
std::copy_n(bytes + DWORD + WORD, WORD, reinterpret_cast<uint8_t*>(&data3_));
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
if (isBigEndianPlatform()) {
if (std::endian::native == std::endian::big) {
data1_ = byteSwap(data1_, true);
data2_ = byteSwap(data2_, true);
data3_ = byteSwap(data3_, true);
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 @@ -85,7 +86,7 @@ BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */) :
std::string BmffImage::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());
// show 0 as _
std::replace(result.begin(), result.end(), '\0', '_');
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) {
#ifdef __cpp_lib_byteswap
return bSwap ? std::byteswap(value) : value;
Expand Down Expand Up @@ -521,7 +513,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 @@ -100,7 +101,7 @@ Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, m
// Obtains the ascii version from the box.type
std::string Jp2Image::toAscii(uint32_t n) {
const auto p = reinterpret_cast<const char*>(&n);
if (isBigEndianPlatform())
if (std::endian::native == std::endian::big)
return std::string(p, p + 4);
std::string result(p, p + 4);
std::reverse(result.begin(), result.end());
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 21cbd59

Please sign in to comment.