diff --git a/src/m_swap.h b/src/m_swap.h
index 2d42f6138efda6115d1d0527877ddb55a983d79a..4318ce7be9ee1321ada7a0517f0e5c3beccdd4a0 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))
+#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 SHORT(x) ((INT16)(x))
-#define LONG(x)	((INT32)(x))
+	#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 485de3c40c60162f4a9025abf805c15362fe2541..172a61da5863b9e76b71d7fc5c373f87b9543e39 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