From 6c37576bc095aad0d958c909f260bed55876eedf Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Thu, 12 Sep 2019 16:03:44 -0300 Subject: [PATCH] Moved this macro --- src/m_swap.h | 42 ++++++++++++++++++++++++++---------------- src/r_data.c | 15 ++------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/m_swap.h b/src/m_swap.h index 2d42f6138..4318ce7be 100644 --- a/src/m_swap.h +++ b/src/m_swap.h @@ -14,29 +14,39 @@ #ifndef __M_SWAP__ #define __M_SWAP__ -#include "endian.h" - // Endianess handling. // WAD files are stored little endian. +#include "endian.h" + +// Little to big endian #ifdef SRB2_BIG_ENDIAN -#define SHORT(x) ((INT16)(\ -(((UINT16)(x) & (UINT16)0x00ffU) << 8) \ -| \ -(((UINT16)(x) & (UINT16)0xff00U) >> 8))) \ + #define SHORT(x) ((INT16)(\ + (((UINT16)(x) & (UINT16)0x00ffU) << 8) \ + | \ + (((UINT16)(x) & (UINT16)0xff00U) >> 8))) \ -#define LONG(x) ((INT32)(\ -(((UINT32)(x) & (UINT32)0x000000ffUL) << 24) \ -| \ -(((UINT32)(x) & (UINT32)0x0000ff00UL) << 8) \ -| \ -(((UINT32)(x) & (UINT32)0x00ff0000UL) >> 8) \ -| \ -(((UINT32)(x) & (UINT32)0xff000000UL) >> 24))) + #define LONG(x) ((INT32)(\ + (((UINT32)(x) & (UINT32)0x000000ffUL) << 24) \ + | \ + (((UINT32)(x) & (UINT32)0x0000ff00UL) << 8) \ + | \ + (((UINT32)(x) & (UINT32)0x00ff0000UL) >> 8) \ + | \ + (((UINT32)(x) & (UINT32)0xff000000UL) >> 24))) #else -#define SHORT(x) ((INT16)(x)) -#define LONG(x) ((INT32)(x)) + #define SHORT(x) ((INT16)(x)) + #define LONG(x) ((INT32)(x)) +#endif + +// Big to little endian +#ifdef SRB2_LITTLE_ENDIAN + #define BIGENDIAN_LONG(x) ((INT32)((x>>24)&0xff)|((x<<8)&0xff0000)|((x>>8)&0xff00)|((x<<24)&0xff000000)) + #define BIGENDIAN_SHORT(x) ((INT16)((x>>8)|(x<<8))) +#else + #define BIGENDIAN_LONG(x) ((INT32)(x)) + #define BIGENDIAN_SHORT(x) ((INT16)(x)) #endif #endif diff --git a/src/r_data.c b/src/r_data.c index 485de3c40..172a61da5 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -2747,24 +2747,13 @@ static png_bytep *PNG_Read(UINT8 *png, UINT16 *w, UINT16 *h, INT16 *topoffset, I if ((topoffset || leftoffset) && (chunk.data != NULL)) { INT32 *offsets = (INT32 *)chunk.data; - - // The grAb chunk stores offsets as big-endian numbers. - #ifdef SRB2_BIG_ENDIAN - #define ENDIANESS(x) (x) - #else - #define ENDIANESS(x) ((x>>24)&0xff)|((x<<8)&0xff0000)|((x>>8)&0xff00)|((x<<24)&0xff000000) - #endif - // read left offset if (leftoffset != NULL) - *leftoffset = (INT16)ENDIANESS(*offsets); + *leftoffset = (INT16)BIGENDIAN_LONG(*offsets); offsets++; - // read top offset if (topoffset != NULL) - *topoffset = (INT16)ENDIANESS(*offsets); - - #undef ENDIANESS + *topoffset = (INT16)BIGENDIAN_LONG(*offsets); } // bye