Bug 488747 - Fix endian handling in qcms. r=joe
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 21 Apr 2009 22:22:29 -0400
changeset 27599 3c1e1b765d311287bc00462b5539eabfe9380423
parent 27598 2c04f555a23b5b49e58fd5a4a8e32980d82e563d
child 27601 f39413f3c16ba1719b07044837b57511776bc3eb
push id6639
push userjdrew@mozilla.com
push dateWed, 22 Apr 2009 02:23:11 +0000
treeherdermozilla-central@3c1e1b765d31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs488747
milestone1.9.2a1pre
Bug 488747 - Fix endian handling in qcms. r=joe
gfx/qcms/iccread.c
gfx/qcms/qcmstypes.h
--- a/gfx/qcms/iccread.c
+++ b/gfx/qcms/iccread.c
@@ -24,47 +24,43 @@
 #include <assert.h>
 #include <stdlib.h>
 #include "qcmsint.h"
 
 //XXX: use a better typename
 typedef uint32_t __be32;
 typedef uint16_t __be16;
 
-#if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
-#error Unknown endianess
-#endif
-
 #if 0
 not used yet
 /* __builtin_bswap isn't available in older gccs
  * so open code it for now */
 static __be32 cpu_to_be32(int32_t v)
 {
-#ifdef LITTLE_ENDIAN
+#ifdef IS_LITTLE_ENDIAN
 	return ((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24);
 	//return __builtin_bswap32(v);
 	return v;
 #endif
 }
 #endif
 
 static uint32_t be32_to_cpu(__be32 v)
 {
-#ifdef LITTLE_ENDIAN
+#ifdef IS_LITTLE_ENDIAN
 	return ((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24);
 	//return __builtin_bswap32(v);
 #else
 	return v;
 #endif
 }
 
 static uint32_t be16_to_cpu(__be16 v)
 {
-#ifdef LITTLE_ENDIAN
+#ifdef IS_LITTLE_ENDIAN
 	return ((v & 0xff) << 8) | ((v & 0xff00) >> 8);
 #else
 	return v;
 #endif
 }
 
 /* a wrapper around the memory that we are going to parse
  * into a qcms_profile */
--- a/gfx/qcms/qcmstypes.h
+++ b/gfx/qcms/qcmstypes.h
@@ -1,24 +1,16 @@
 #ifndef QCMS_TYPES_H
 #define QCMS_TYPES_H
 
 #ifdef MOZ_QCMS
 
 #include "prtypes.h"
 
-#if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
-#ifdef IS_LITTLE_ENDIAN
-#define LITTLE_ENDIAN
-#endif
-
-#ifdef IS_BIG_ENDIAN
-#define BIG_ENDIAN
-#endif
-#endif
+/* prtypes.h defines IS_LITTLE_ENDIAN and IS_BIG ENDIAN */
 
 #if defined (__SVR4) && defined (__sun)
 /* int_types.h gets included somehow, so avoid redefining the types differently */
 #include <sys/int_types.h>
 #else
 typedef PRInt8 int8_t;
 typedef PRUint8 uint8_t;
 typedef PRInt16 int16_t;
@@ -35,24 +27,34 @@ typedef PRUint64 uint64_t;
 /* FreeBSD typedefs uintptr_t in /usr/include/sys/types.h */
 #else
 typedef PRUptrdiff uintptr_t;
 #endif
 #endif
 
 #else // MOZ_QCMS
 
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define IS_LITTLE_ENDIAN
+#elif BYTE_ORDER == BIG_ENDIAN
+#define IS_BIG_ENDIAN
+#endif
+
 /* all of the platforms that we use _MSC_VER on are little endian
  * so this is sufficient for now */
 #ifdef _MSC_VER
-#define LITTLE_ENDIAN
+#define IS_LITTLE_ENDIAN
 #endif
 
 #ifdef __OS2__
-#define LITTLE_ENDIAN
+#define IS_LITTLE_ENDIAN
+#endif
+
+#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
+#error Unknown endianess
 #endif
 
 #if defined (_SVR4) || defined (SVR4) || defined (__OpenBSD__) || defined (_sgi) || defined (__sun) || defined (sun) || defined (__digital__)
 #  include <inttypes.h>
 #elif defined (_MSC_VER)
 typedef __int8 int8_t;
 typedef unsigned __int8 uint8_t;
 typedef __int16 int16_t;