From 58542fdfb90883d551b847fe110acef74a8c4526 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Aug 2017 15:30:41 +0300 Subject: [PATCH] Move WORDS_BIGENDIAN to ImagingUtils.h --- libImaging/Bands.c | 7 ------- libImaging/Imaging.h | 4 ++++ libImaging/ImagingUtils.h | 13 +++++++++++++ libImaging/Resample.c | 6 ------ libImaging/Unpack.c | 10 +--------- 5 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 libImaging/ImagingUtils.h diff --git a/libImaging/Bands.c b/libImaging/Bands.c index 758734b52..89cfd33db 100644 --- a/libImaging/Bands.c +++ b/libImaging/Bands.c @@ -22,13 +22,6 @@ #define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255) -#ifdef WORDS_BIGENDIAN - #define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24)) -#else - #define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24)) -#endif - - Imaging ImagingGetBand(Imaging imIn, int band) { diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 0a8bff32c..2031442b2 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -509,6 +509,10 @@ extern Py_ssize_t _imaging_tell_pyFd(PyObject *fd); #define IMAGING_CODEC_CONFIG -8 #define IMAGING_CODEC_MEMORY -9 + + +#include "ImagingUtils.h" + #if defined(__cplusplus) } #endif diff --git a/libImaging/ImagingUtils.h b/libImaging/ImagingUtils.h new file mode 100644 index 000000000..d2a8f98a6 --- /dev/null +++ b/libImaging/ImagingUtils.h @@ -0,0 +1,13 @@ +#ifdef WORDS_BIGENDIAN + #define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24)) + #define MASK_UINT32_CHANNEL_0 0xff000000 + #define MASK_UINT32_CHANNEL_1 0x00ff0000 + #define MASK_UINT32_CHANNEL_2 0x0000ff00 + #define MASK_UINT32_CHANNEL_3 0x000000ff +#else + #define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24)) + #define MASK_UINT32_CHANNEL_0 0x000000ff + #define MASK_UINT32_CHANNEL_1 0x0000ff00 + #define MASK_UINT32_CHANNEL_2 0x00ff0000 + #define MASK_UINT32_CHANNEL_3 0xff000000 +#endif \ No newline at end of file diff --git a/libImaging/Resample.c b/libImaging/Resample.c index afd045f7a..ff56c535b 100644 --- a/libImaging/Resample.c +++ b/libImaging/Resample.c @@ -5,12 +5,6 @@ #define ROUND_UP(f) ((int) ((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) -#ifdef WORDS_BIGENDIAN - #define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24)) -#else - #define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24)) -#endif - struct filter { double (*filter)(double x); diff --git a/libImaging/Unpack.c b/libImaging/Unpack.c index 86a2d9737..c294287a6 100644 --- a/libImaging/Unpack.c +++ b/libImaging/Unpack.c @@ -464,14 +464,6 @@ unpackP4L(UINT8* out, const UINT8* in, int pixels) } -#ifdef WORDS_BIGENDIAN - #define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24)) - #define CHANNEL_4_MASK 0x000000ff -#else - #define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24)) - #define CHANNEL_4_MASK 0xff000000 -#endif - /* Unpack to "RGB" image */ void @@ -481,7 +473,7 @@ ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) UINT32* out = (UINT32*) _out; /* RGB triplets */ for (; i < pixels-1; i++) { - out[i] = CHANNEL_4_MASK | *(UINT32*)&in[0]; + out[i] = MASK_UINT32_CHANNEL_3 | *(UINT32*)&in[0]; in += 3; } for (; i < pixels; i++) {