Skip to content

Commit f182a9e

Browse files
committed
fix icc header for big endian architectures
Test: ctest
1 parent 6f44e2f commit f182a9e

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

lib/include/ultrahdr/icc.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,21 @@
1313

1414
#include <memory>
1515

16-
#ifndef USE_BIG_ENDIAN_IN_ICC
17-
#define USE_BIG_ENDIAN_IN_ICC true
18-
#endif
16+
#include "ultrahdr/jpegr.h"
17+
#include "ultrahdr/gainmapmath.h"
18+
#include "ultrahdr/jpegrutils.h"
1919

2020
#undef Endian_SwapBE32
2121
#undef Endian_SwapBE16
22-
#if USE_BIG_ENDIAN_IN_ICC
23-
#define Endian_SwapBE32(n) EndianSwap32(n)
24-
#define Endian_SwapBE16(n) EndianSwap16(n)
25-
#else
22+
23+
#if UHDR_HOST_BIG_ENDIAN == true
2624
#define Endian_SwapBE32(n) (n)
2725
#define Endian_SwapBE16(n) (n)
26+
#else
27+
#define Endian_SwapBE32(n) EndianSwap32(n)
28+
#define Endian_SwapBE16(n) EndianSwap16(n)
2829
#endif
2930

30-
#include "ultrahdr/jpegr.h"
31-
#include "ultrahdr/gainmapmath.h"
32-
#include "ultrahdr/jpegrutils.h"
33-
3431
namespace ultrahdr {
3532

3633
typedef int32_t Fixed;

lib/include/ultrahdr/jpegrutils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313

1414
#include "ultrahdr/jpegr.h"
1515

16+
#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
17+
__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
18+
defined(_WIN32) || defined(_WIN64)
19+
#define UHDR_HOST_BIG_ENDIAN false
20+
#elif (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
21+
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
22+
defined(__BIG_ENDIAN__)
23+
#define UHDR_HOST_BIG_ENDIAN true
24+
#else
25+
#error "Unable to detect endianness."
26+
#endif
27+
1628
// TODO (dichenzhang): This is old version metadata, new version can be found in
1729
// https://drive.google.com/file/d/1yUGmjGytRuBa2vpr9eM5Uu8CVhyyddjp/view?resourcekey=0-HGzFrzPQzu5FNYLRAJXQBA
1830
// and in gainmapmetadata.h/.cpp

lib/include/ultrahdr/multipictureformat.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@
1313

1414
#include <memory>
1515

16+
#include "ultrahdr/jpegr.h"
17+
#include "ultrahdr/gainmapmath.h"
18+
#include "ultrahdr/jpegrutils.h"
19+
1620
#ifndef USE_BIG_ENDIAN_IN_MPF
1721
#define USE_BIG_ENDIAN_IN_MPF true
1822
#endif
1923

2024
#undef Endian_SwapBE32
2125
#undef Endian_SwapBE16
22-
#if USE_BIG_ENDIAN_IN_MPF
23-
#define Endian_SwapBE32(n) EndianSwap32(n)
24-
#define Endian_SwapBE16(n) EndianSwap16(n)
25-
#else
26+
27+
#if (USE_BIG_ENDIAN_IN_MPF == UHDR_HOST_BIG_ENDIAN)
2628
#define Endian_SwapBE32(n) (n)
2729
#define Endian_SwapBE16(n) (n)
30+
#else
31+
#define Endian_SwapBE32(n) EndianSwap32(n)
32+
#define Endian_SwapBE16(n) EndianSwap16(n)
2833
#endif
2934

30-
#include "ultrahdr/jpegr.h"
31-
#include "ultrahdr/gainmapmath.h"
32-
#include "ultrahdr/jpegrutils.h"
33-
3435
namespace ultrahdr {
3536

3637
constexpr size_t kNumPictures = 2;

0 commit comments

Comments
 (0)