From 89518c4f013c75721197791aac4e7ead528cb8bb Mon Sep 17 00:00:00 2001 From: gitlost Date: Tue, 23 Mar 2021 15:37:18 +0000 Subject: [PATCH] tif.c: fix endianness detection, props Schaich Alonso --- backend/tif.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/tif.c b/backend/tif.c index f0000efb..a950e122 100644 --- a/backend/tif.c +++ b/backend/tif.c @@ -45,13 +45,6 @@ #include #endif -#if !defined(_WIN32) && !defined(__APPLE__) -#include -# if __BYTE_ORDER == __BIG_ENDIAN -#define TIF_BIG_ENDIAN -#endif -#endif - /* PhotometricInterpretation */ #define TIF_PMI_WHITEISZERO 0 #define TIF_PMI_BLACKISZERO 1 @@ -85,6 +78,10 @@ static void to_cmyk(unsigned char rgb[3], unsigned char alpha, unsigned char *cm } +static int is_big_endian() { + return (*((const uint16_t *)"\x11\x22") == 0x1122); +} + INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { unsigned char fg[4], bg[4]; int i; @@ -351,11 +348,11 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) } /* Header */ -#ifdef TIF_BIG_ENDIAN - header.byte_order = 0x4D4D; // "MM" big-endian -#else - header.byte_order = 0x4949; // "II" little-endian -#endif + if (is_big_endian()) { + header.byte_order = 0x4D4D; // "MM" big-endian + } else { + header.byte_order = 0x4949; // "II" little-endian + } header.identity = 42; header.offset = free_memory;