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
This commit is contained in:
James Zern 2014-06-28 12:27:17 -07:00
parent ee70a90187
commit 380cca4f2c
5 changed files with 16 additions and 8 deletions

View File

@ -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])

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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