diff --git a/src/_imaging.c b/src/_imaging.c index 808917ad1..d9e6dff35 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -96,8 +96,6 @@ #undef VERBOSE -#define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255) - #define B16(p, i) ((((int)p[(i)]) << 8) + p[(i)+1]) #define L16(p, i) ((((int)p[(i)+1]) << 8) + p[(i)]) #define S16(v) ((v) < 32768 ? (v) : ((v) - 65536)) @@ -744,7 +742,7 @@ _prepare_lut_table(PyObject* table, Py_ssize_t table_size) prepared[i] = table_data[i] * (255 << PRECISION_BITS) + 0.5; } } - + #undef PRECISION_BITS free(table_data); return prepared; @@ -803,7 +801,7 @@ _color_lut_3d(ImagingObject* self, PyObject* args) return NULL; } - if ( ! ImagingColorLUT3D_linear(imOut, self->image, + if ( ! ImagingColorLUT3D_linear(imOut, self->image, table_channels, size1D, size2D, size3D, prepared_table)) { free(prepared_table); diff --git a/src/libImaging/Bands.c b/src/libImaging/Bands.c index 7f86d4973..58f4df1d9 100644 --- a/src/libImaging/Bands.c +++ b/src/libImaging/Bands.c @@ -19,9 +19,6 @@ #include "Imaging.h" -#define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255) - - Imaging ImagingGetBand(Imaging imIn, int band) { diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index b3e48e52b..582f9ca68 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -38,7 +38,6 @@ #define MAX(a, b) (a)>(b) ? (a) : (b) #define MIN(a, b) (a)<(b) ? (a) : (b) -#define CLIP(v) ((v) <= 0 ? 0 : (v) >= 255 ? 255 : (v)) #define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v)) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ diff --git a/src/libImaging/Effects.c b/src/libImaging/Effects.c index 6d25f4fff..1745302d9 100644 --- a/src/libImaging/Effects.c +++ b/src/libImaging/Effects.c @@ -79,7 +79,6 @@ ImagingEffectNoise(int xsize, int ysize, float sigma) Imaging imOut; int x, y; int nextok; - int d; double this, next; imOut = ImagingNewDirty("L", xsize, ysize); @@ -107,8 +106,7 @@ ImagingEffectNoise(int xsize, int ysize, float sigma) this = factor * v1; next = factor * v2; } - d = 128 + sigma * this; - out[x] = d<0 ? 0 : (d>UCHAR_MAX ? UCHAR_MAX : d); + out[x] = CLIP(128 + sigma * this); } } diff --git a/src/libImaging/ImagingUtils.h b/src/libImaging/ImagingUtils.h index a2f2aa8e2..ad29f0874 100644 --- a/src/libImaging/ImagingUtils.h +++ b/src/libImaging/ImagingUtils.h @@ -30,6 +30,8 @@ (MULDIV255(in1, (255 - mask), tmp1) + in2) +#define CLIP(v) ((v) <= 0 ? 0 : (v) < 256 ? (v) : 255) + /* This is to work around a bug in GCC prior 4.9 in 64 bit mode. GCC generates code with partial dependency which is 3 times slower. See: http://stackoverflow.com/a/26588074/253146 */ diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c index 0e7462c6e..dd849ce64 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -45,8 +45,6 @@ #define Y 2 #define K 3 -#define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255) - /* byte-swapping macros */ #define C16N\