From 380cca4f2caf14437f7b41825d54128634a5b949 Mon Sep 17 00:00:00 2001 From: James Zern Date: Sat, 28 Jun 2014 12:27:17 -0700 Subject: [PATCH] configure.ac: add AC_C_BIGENDIAN this defines WORDS_BIGENDIAN, replacing uses of __BIG_ENDIAN__/__BYTE_ORDER__ with it + fixes lossless BGRA output with big-endian toolchains that do not define __BIG_ENDIAN__ (codesourcery mips gcc) Change-Id: Ieaccd623292d235343b5e34b7a720fc251c432d7 --- configure.ac | 3 +++ examples/tiffdec.c | 2 +- src/dsp/lossless.c | 4 ++-- src/utils/bit_reader_inl.h | 4 ++-- src/utils/endian_inl.h | 11 ++++++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index c764473f..665647d4 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,9 @@ AM_PROG_CC_C_O dnl === Enable less verbose output when building. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) +dnl == test endianness +AC_C_BIGENDIAN + dnl === SET_IF_UNSET(shell_var, value) dnl === Set the shell variable 'shell_var' to 'value' if it is unset. AC_DEFUN([SET_IF_UNSET], [test "${$1+set}" = "set" || $1=$2]) diff --git a/examples/tiffdec.c b/examples/tiffdec.c index 449d3b94..88e19fdb 100644 --- a/examples/tiffdec.c +++ b/examples/tiffdec.c @@ -97,7 +97,7 @@ int ReadTIFF(const char* const filename, pic->width = width; pic->height = height; // TIFF data is ABGR -#ifdef __BIG_ENDIAN__ +#ifdef WORDS_BIGENDIAN TIFFSwabArrayOfLong(raster, width * height); #endif pic->use_argb = 1; diff --git a/src/dsp/lossless.c b/src/dsp/lossless.c index d0d605d8..84e20784 100644 --- a/src/dsp/lossless.c +++ b/src/dsp/lossless.c @@ -1360,7 +1360,7 @@ static void CopyOrSwap(const uint32_t* src, int num_pixels, uint8_t* dst, while (src < src_end) { const uint32_t argb = *src++; -#if !defined(__BIG_ENDIAN__) +#if !defined(WORDS_BIGENDIAN) #if !defined(WEBP_REFERENCE_IMPLEMENTATION) *(uint32_t*)dst = BSwap32(argb); #else // WEBP_REFERENCE_IMPLEMENTATION @@ -1369,7 +1369,7 @@ static void CopyOrSwap(const uint32_t* src, int num_pixels, uint8_t* dst, dst[2] = (argb >> 8) & 0xff; dst[3] = (argb >> 0) & 0xff; #endif -#else // __BIG_ENDIAN__ +#else // WORDS_BIGENDIAN dst[0] = (argb >> 0) & 0xff; dst[1] = (argb >> 8) & 0xff; dst[2] = (argb >> 16) & 0xff; diff --git a/src/utils/bit_reader_inl.h b/src/utils/bit_reader_inl.h index de8c91ab..24a375bc 100644 --- a/src/utils/bit_reader_inl.h +++ b/src/utils/bit_reader_inl.h @@ -70,7 +70,7 @@ static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) { const lbit_t in_bits = *(const lbit_t*)br->buf_; #endif br->buf_ += BITS >> 3; -#if !defined(__BIG_ENDIAN__) +#if !defined(WORDS_BIGENDIAN) #if (BITS > 32) bits = BSwap64(in_bits); bits >>= 64 - BITS; @@ -83,7 +83,7 @@ static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) { #else // BITS == 8 bits = (bit_t)in_bits; #endif // BITS > 32 -#else // BIG_ENDIAN +#else // WORDS_BIGENDIAN bits = (bit_t)in_bits; if (BITS != 8 * sizeof(bit_t)) bits >>= (8 * sizeof(bit_t) - BITS); #endif diff --git a/src/utils/endian_inl.h b/src/utils/endian_inl.h index 9cff9e73..c3fbd3a7 100644 --- a/src/utils/endian_inl.h +++ b/src/utils/endian_inl.h @@ -12,12 +12,17 @@ #ifndef WEBP_UTILS_ENDIAN_INL_H_ #define WEBP_UTILS_ENDIAN_INL_H_ +#ifdef HAVE_CONFIG_H +#include "../webp/config.h" +#endif + #include "../webp/types.h" // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__) -#if !defined(__BIG_ENDIAN__) && defined(__BYTE_ORDER__) && \ - (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -#define __BIG_ENDIAN__ +#if !defined(WORDS_BIGENDIAN) && \ + (defined(__BIG_ENDIAN__) || \ + (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) +#define WORDS_BIGENDIAN #endif // endian-specific htoleXX() definition