summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-06-16 12:29:54 +0200
committerTor Andersson <tor@ghostscript.com>2010-06-16 12:29:54 +0200
commit5795eaee9455031dead3dff50d1ab2d06c5f9915 (patch)
treebd5f9f2e8c29c4fa24c90f5f9d1ff6d25714dd2b
parentef055a22a6ad0c28f57dc9f783124b51903f3106 (diff)
downloadmupdf-5795eaee9455031dead3dff50d1ab2d06c5f9915.tar.xz
Do runtime endianness test instead of relying on unreliable preprocessor macros.
-rw-r--r--apps/x11_image.c11
-rw-r--r--draw/imageunpack.c12
-rw-r--r--fitz/base_cpudep.c6
-rw-r--r--fitz/fitz_base.h2
4 files changed, 20 insertions, 11 deletions
diff --git a/apps/x11_image.c b/apps/x11_image.c
index 90116026..f38de236 100644
--- a/apps/x11_image.c
+++ b/apps/x11_image.c
@@ -10,7 +10,7 @@
# define _XOPEN_SOURCE 1
#endif
-#include <fitz.h>
+#include "fitz.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -205,11 +205,10 @@ select_mode(void)
unsigned long rs, gs, bs;
byteorder = ImageByteOrder(info.display);
-#if BYTE_ORDER == BIG_ENDIAN
- byterev = byteorder != MSBFirst;
-#else
- byterev = byteorder != LSBFirst;
-#endif
+ if (fz_isbigendian())
+ byterev = byteorder != MSBFirst;
+ else
+ byterev = byteorder != LSBFirst;
rm = info.visual.red_mask;
gm = info.visual.green_mask;
diff --git a/draw/imageunpack.c b/draw/imageunpack.c
index 6e4e7f85..536e43d1 100644
--- a/draw/imageunpack.c
+++ b/draw/imageunpack.c
@@ -31,6 +31,12 @@ static void decodetile(fz_pixmap *pix, int skip, float *decode)
justinvert &= min[i] == 255 && max[i] == 0 && sub[i] == -255;
}
+ unsigned mask;
+ if (fz_isbigendian())
+ mask = 0x00ff00ff;
+ else
+ mask = 0xff00ff00;
+
if (!needed)
return;
@@ -51,11 +57,7 @@ static void decodetile(fz_pixmap *pix, int skip, float *decode)
wh = wh - 2 * hwh;
while(hwh--) {
unsigned in = *wp;
-#if BYTE_ORDER == LITTLE_ENDIAN
- unsigned out = in ^ 0xff00ff00;
-#else
- unsigned out = in ^ 0x00ff00ff;
-#endif
+ unsigned out = in ^ mask;
*wp++ = out;
}
p = (byte *)wp;
diff --git a/fitz/base_cpudep.c b/fitz/base_cpudep.c
index 980bc9d8..f17d6a25 100644
--- a/fitz/base_cpudep.c
+++ b/fitz/base_cpudep.c
@@ -10,6 +10,12 @@ Glenn Kennard <d98gk@efd.lth.se>
/* global run-time constant */
unsigned fz_cpuflags = 0;
+int fz_isbigendian(void)
+{
+ static const int one = 1;
+ return *(char*)&one == 0;
+}
+
#ifndef HAVE_CPUDEP
void fz_cpudetect(void)
diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h
index b6ca40c4..94197a1a 100644
--- a/fitz/fitz_base.h
+++ b/fitz/fitz_base.h
@@ -86,6 +86,8 @@ extern void fz_cpudetect(void);
/* treat as constant! */
extern unsigned fz_cpuflags;
+int fz_isbigendian(void);
+
/*
* Base Fitz runtime.
*/