From b4e226714d0e73aba69e6bfbfa91993a27213e05 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 15 Aug 2017 23:05:12 +0300 Subject: [PATCH 01/11] Faster ImagingUnpackRGB --- libImaging/Imaging.h | 1 - libImaging/Unpack.c | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index c2c640f0b..6bcd2401b 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -467,7 +467,6 @@ typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels); /* Public shufflers */ extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels); extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels); -extern void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels); diff --git a/libImaging/Unpack.c b/libImaging/Unpack.c index dfc8a4d7e..86a2d9737 100644 --- a/libImaging/Unpack.c +++ b/libImaging/Unpack.c @@ -463,19 +463,30 @@ 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 -ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels) +ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) { - int i; + int i = 0; + UINT32* out = (UINT32*) _out; /* RGB triplets */ - for (i = 0; i < pixels; i++) { - out[R] = in[0]; - out[G] = in[1]; - out[B] = in[2]; - out[A] = 255; - out += 4; in += 3; + for (; i < pixels-1; i++) { + out[i] = CHANNEL_4_MASK | *(UINT32*)&in[0]; + in += 3; + } + for (; i < pixels; i++) { + out[i] = MAKE_UINT32(in[0], in[1], in[2], 255); + in += 3; } } From 762b09cdb5b5ee24a38ae7e60cf2c7ff2863041f Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 18 Aug 2017 01:13:50 +0300 Subject: [PATCH 02/11] unroll ImagingPackRGB --- libImaging/Pack.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libImaging/Pack.c b/libImaging/Pack.c index 621936351..b624f1956 100644 --- a/libImaging/Pack.c +++ b/libImaging/Pack.c @@ -227,13 +227,17 @@ packLAL(UINT8* out, const UINT8* in, int pixels) void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) { - int i; + int i = 0; /* RGB triplets */ - for (i = 0; i < pixels; i++) { - out[0] = in[R]; - out[1] = in[G]; - out[2] = in[B]; - out += 3; in += 4; + for (; i < pixels-1; i++) { + ((UINT32*)out)[0] = ((UINT32*)in)[i]; + out += 3; + } + for (; i < pixels; i++) { + out[0] = in[i*4+R]; + out[1] = in[i*4+G]; + out[2] = in[i*4+B]; + out += 3; } } From 00b65ce1c3f9578d8067518eacc38a0b32c0c120 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Aug 2017 15:27:39 +0300 Subject: [PATCH 03/11] unused --- libImaging/Imaging.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 6bcd2401b..0a8bff32c 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -465,12 +465,9 @@ extern int ImagingZipEncodeCleanup(ImagingCodecState state); typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels); /* Public shufflers */ -extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels); extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels); -extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels); -extern void ImagingUnpackYCbCr(UINT8* out, const UINT8* in, int pixels); extern void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels); extern void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels); From 58542fdfb90883d551b847fe110acef74a8c4526 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Aug 2017 15:30:41 +0300 Subject: [PATCH 04/11] 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++) { From d64f163760c0790c1a468cbb80087dd42dbc5458 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Aug 2017 15:47:04 +0300 Subject: [PATCH 05/11] Move MULDIV255 and SHIFTFORDIV255 to ImagingUtils.h --- libImaging/AlphaComposite.c | 3 --- libImaging/Convert.c | 4 ---- libImaging/Draw.c | 4 ---- libImaging/ImagingUtils.h | 10 +++++++++- libImaging/Pack.c | 3 --- libImaging/Paste.c | 13 ++----------- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/libImaging/AlphaComposite.c b/libImaging/AlphaComposite.c index 7e99c59ce..00d28f956 100644 --- a/libImaging/AlphaComposite.c +++ b/libImaging/AlphaComposite.c @@ -77,9 +77,6 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) UINT16 coef1 = src->a * 255 * 255 * 128 / outa255; UINT16 coef2 = 255 * 128 - coef1; - #define SHIFTFORDIV255(a)\ - ((((a) >> 8) + a) >> 8) - tmpr = src->r * coef1 + dst->r * coef2 + (0x80 << 7); out->r = SHIFTFORDIV255(tmpr) >> 7; tmpg = src->g * coef1 + dst->g * coef2 + (0x80 << 7); diff --git a/libImaging/Convert.c b/libImaging/Convert.c index f4253bda4..f820b1f6d 100644 --- a/libImaging/Convert.c +++ b/libImaging/Convert.c @@ -41,10 +41,6 @@ #define CLIP(v) ((v) <= 0 ? 0 : (v) >= 255 ? 255 : (v)) #define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v)) -/* like (a * b + 127) / 255), but much faster on most platforms */ -#define MULDIV255(a, b, tmp)\ - (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) - /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ #define L(rgb)\ ((INT32) (rgb)[0]*299 + (INT32) (rgb)[1]*587 + (INT32) (rgb)[2]*114) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index 65ab34a66..a4d24133c 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -42,10 +42,6 @@ #define INK8(ink) (*(UINT8*)ink) #define INK32(ink) (*(INT32*)ink) -/* like (a * b + 127) / 255), but much faster on most platforms */ -#define MULDIV255(a, b, tmp)\ - (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) - #define BLEND(mask, in1, in2, tmp1, tmp2)\ (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) diff --git a/libImaging/ImagingUtils.h b/libImaging/ImagingUtils.h index d2a8f98a6..bb4ada311 100644 --- a/libImaging/ImagingUtils.h +++ b/libImaging/ImagingUtils.h @@ -10,4 +10,12 @@ #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 +#endif + + +#define SHIFTFORDIV255(a)\ + ((((a) >> 8) + a) >> 8) + +/* like (a * b + 127) / 255), but much faster on most platforms */ +#define MULDIV255(a, b, tmp)\ + (tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp)) diff --git a/libImaging/Pack.c b/libImaging/Pack.c index b624f1956..47086e091 100644 --- a/libImaging/Pack.c +++ b/libImaging/Pack.c @@ -72,9 +72,6 @@ #define C64L C64N #endif -/* like (a * b + 127) / 255), but much faster on most platforms */ -#define MULDIV255(a, b, tmp)\ - (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) static void pack1(UINT8* out, const UINT8* in, int pixels) diff --git a/libImaging/Paste.c b/libImaging/Paste.c index a18e5d6f2..402beff92 100644 --- a/libImaging/Paste.c +++ b/libImaging/Paste.c @@ -23,20 +23,11 @@ #include "Imaging.h" -/* like (a * b + 127) / 255), but much faster on most platforms */ -#define MULDIV255NEW(a, tmp)\ - (tmp = (a) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) - -#define MULDIV255OLD(a, tmp)\ - (((a) + 127) / 255) - -#define MULDIV255 MULDIV255NEW - #define BLEND(mask, in1, in2, tmp1)\ - MULDIV255(in1 * (255 - mask) + in2 * mask, tmp1) + (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp1)) #define PREBLEND(mask, in1, in2, tmp1)\ - (MULDIV255(in1 * (255 - mask), tmp1) + in2) + (MULDIV255(in1, (255 - mask), tmp1) + in2) static inline void paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy, From fc40ef0c1ea3018fc8c72d5aaf52446537add385 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 19 Aug 2017 15:58:23 +0300 Subject: [PATCH 06/11] Move PREBLEND and BLEND to ImagingUtils.h --- libImaging/Draw.c | 3 --- libImaging/ImagingUtils.h | 6 ++++++ libImaging/Paste.c | 41 +++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index a4d24133c..ef8a4db64 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -42,9 +42,6 @@ #define INK8(ink) (*(UINT8*)ink) #define INK32(ink) (*(INT32*)ink) -#define BLEND(mask, in1, in2, tmp1, tmp2)\ - (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) - /* * Rounds around zero (up=away from zero, down=torwards zero) * This guarantees that ROUND_UP|DOWN(f) == -ROUND_UP|DOWN(-f) diff --git a/libImaging/ImagingUtils.h b/libImaging/ImagingUtils.h index bb4ada311..231142735 100644 --- a/libImaging/ImagingUtils.h +++ b/libImaging/ImagingUtils.h @@ -19,3 +19,9 @@ /* like (a * b + 127) / 255), but much faster on most platforms */ #define MULDIV255(a, b, tmp)\ (tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp)) + +#define BLEND(mask, in1, in2, tmp1, tmp2)\ + (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) + +#define PREBLEND(mask, in1, in2, tmp1)\ + (MULDIV255(in1, (255 - mask), tmp1) + in2) diff --git a/libImaging/Paste.c b/libImaging/Paste.c index 402beff92..8c62f9ed3 100644 --- a/libImaging/Paste.c +++ b/libImaging/Paste.c @@ -23,11 +23,6 @@ #include "Imaging.h" -#define BLEND(mask, in1, in2, tmp1)\ - (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp1)) - -#define PREBLEND(mask, in1, in2, tmp1)\ - (MULDIV255(in1, (255 - mask), tmp1) + in2) static inline void paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy, @@ -91,7 +86,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, /* paste with mode "L" matte */ int x, y; - unsigned int tmp1; + unsigned int tmp1, tmp2; if (imOut->image8) { @@ -100,7 +95,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, *in, tmp1); + *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++, mask++; } } @@ -113,10 +108,10 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* mask = (UINT8*) (imMask->image8[y+sy] + sx); for (x = 0; x < xsize; x++) { UINT8 a = mask[0]; - out[0] = BLEND(a, out[0], in[0], tmp1); - out[1] = BLEND(a, out[1], in[1], tmp1); - out[2] = BLEND(a, out[2], in[2], tmp1); - out[3] = BLEND(a, out[3], in[3], tmp1); + out[0] = BLEND(a, out[0], in[0], tmp1, tmp2); + out[1] = BLEND(a, out[1], in[1], tmp1, tmp2); + out[2] = BLEND(a, out[2], in[2], tmp1, tmp2); + out[3] = BLEND(a, out[3], in[3], tmp1, tmp2); out += 4; in += 4; mask ++; } } @@ -131,7 +126,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, /* paste with mode "RGBA" matte */ int x, y; - unsigned int tmp1; + unsigned int tmp1, tmp2; if (imOut->image8) { @@ -140,7 +135,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, *in, tmp1); + *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++, mask += 4; } } @@ -153,10 +148,10 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* mask = (UINT8*) (imMask->image32[y+sy] + sx); for (x = 0; x < xsize; x++) { UINT8 a = mask[3]; - out[0] = BLEND(a, out[0], in[0], tmp1); - out[1] = BLEND(a, out[1], in[1], tmp1); - out[2] = BLEND(a, out[2], in[2], tmp1); - out[3] = BLEND(a, out[3], in[3], tmp1); + out[0] = BLEND(a, out[0], in[0], tmp1, tmp2); + out[1] = BLEND(a, out[1], in[1], tmp1, tmp2); + out[2] = BLEND(a, out[2], in[2], tmp1, tmp2); + out[3] = BLEND(a, out[3], in[3], tmp1, tmp2); out += 4; in += 4; mask += 4; } } @@ -364,7 +359,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, /* fill with mode "L" matte */ int x, y, i; - unsigned int tmp1; + unsigned int tmp1, tmp2; if (imOut->image8) { @@ -372,7 +367,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, ink[0], tmp1); + *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); out++, mask++; } } @@ -384,7 +379,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { - *out = BLEND(*mask, *out, ink[i], tmp1); + *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); out++; } mask++; @@ -401,7 +396,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, /* fill with mode "RGBA" matte */ int x, y, i; - unsigned int tmp1; + unsigned int tmp1, tmp2; if (imOut->image8) { @@ -410,7 +405,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, ink[0], tmp1); + *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); out++, mask += 4; } } @@ -424,7 +419,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { - *out = BLEND(*mask, *out, ink[i], tmp1); + *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); out++; } mask += 4; From 40d30f678bdfe22677404b2c6f9f5e1cbcfd5010 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 22 Aug 2017 00:00:17 +0300 Subject: [PATCH 07/11] Use MAKE_UINT32 when possible for unpacking --- libImaging/Unpack.c | 203 +++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 118 deletions(-) diff --git a/libImaging/Unpack.c b/libImaging/Unpack.c index c294287a6..53b9d3d04 100644 --- a/libImaging/Unpack.c +++ b/libImaging/Unpack.c @@ -313,26 +313,25 @@ unpackL4IR(UINT8* out, const UINT8* in, int pixels) } static void -unpackLA(UINT8* out, const UINT8* in, int pixels) +unpackLA(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* LA, pixel interleaved */ for (i = 0; i < pixels; i++) { - out[R] = out[G] = out[B] = in[0]; - out[A] = in[1]; - in += 2; out += 4; + out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]); + in += 2; } } static void -unpackLAL(UINT8* out, const UINT8* in, int pixels) +unpackLAL(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* LA, line interleaved */ for (i = 0; i < pixels; i++) { - out[R] = out[G] = out[B] = in[i]; - out[A] = in[i+pixels]; - out += 4; + out[i] = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]); } } @@ -483,58 +482,50 @@ ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels) } void -unpackRGB16B(UINT8* out, const UINT8* in, int pixels) +unpackRGB16B(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* 16-bit RGB triplets, big-endian order */ for (i = 0; i < pixels; i++) { - out[R] = in[0]; - out[G] = in[2]; - out[B] = in[4]; - out[A] = 255; - out += 4; in += 6; + out[i] = MAKE_UINT32(in[0], in[2], in[4], 255); + in += 6; } } static void -unpackRGBL(UINT8* out, const UINT8* in, int pixels) +unpackRGBL(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, line interleaved */ for (i = 0; i < pixels; i++) { - out[R] = in[i]; - out[G] = in[i+pixels]; - out[B] = in[i+pixels+pixels]; - out[A] = 255; - out += 4; + out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255); } } static void -unpackRGBR(UINT8* out, const UINT8* in, int pixels) +unpackRGBR(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, bit reversed */ for (i = 0; i < pixels; i++) { - out[R] = BITFLIP[in[0]]; - out[G] = BITFLIP[in[1]]; - out[B] = BITFLIP[in[2]]; - out[A] = 255; - out += 4; in += 3; + out[i] = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]], + BITFLIP[in[2]], 255); + in += 3; } } void -ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels) +ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, reversed bytes */ for (i = 0; i < pixels; i++) { - out[R] = in[2]; - out[G] = in[1]; - out[B] = in[0]; - out[A] = 255; - out += 4; in += 3; + out[i] = MAKE_UINT32(in[2], in[1], in[0], 255); + in += 3; } } @@ -659,118 +650,106 @@ ImagingUnpackRGBA4B(UINT8* out, const UINT8* in, int pixels) } static void -ImagingUnpackBGRX(UINT8* out, const UINT8* in, int pixels) +ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, reversed bytes with padding */ for (i = 0; i < pixels; i++) { - out[R] = in[2]; - out[G] = in[1]; - out[B] = in[0]; - out[A] = 255; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[2], in[1], in[0], 255); + in += 4; } } static void -ImagingUnpackXRGB(UINT8* out, const UINT8* in, int pixels) +ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, leading pad */ for (i = 0; i < pixels; i++) { - out[R] = in[1]; - out[G] = in[2]; - out[B] = in[3]; - out[A] = 255; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[1], in[2], in[3], 255); + in += 4; } } static void -ImagingUnpackXBGR(UINT8* out, const UINT8* in, int pixels) +ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGB, reversed bytes, leading pad */ for (i = 0; i < pixels; i++) { - out[R] = in[3]; - out[G] = in[2]; - out[B] = in[1]; - out[A] = 255; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[3], in[2], in[1], 255); + in += 4; } } /* Unpack to "RGBA" image */ static void -unpackRGBALA(UINT8* out, const UINT8* in, int pixels) +unpackRGBALA(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* greyscale with alpha */ for (i = 0; i < pixels; i++) { - out[R] = out[G] = out[B] = in[0]; - out[A] = in[1]; - out += 4; in += 2; + out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]); + in += 2; } } static void -unpackRGBALA16B(UINT8* out, const UINT8* in, int pixels) +unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* 16-bit greyscale with alpha, big-endian */ for (i = 0; i < pixels; i++) { - out[R] = out[G] = out[B] = in[0]; - out[A] = in[2]; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[0], in[0], in[0], in[2]); + in += 4; } } static void -unpackRGBa(UINT8* out, const UINT8* in, int pixels) +unpackRGBa(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* premultiplied RGBA */ for (i = 0; i < pixels; i++) { int a = in[3]; - if (!a) - out[R] = out[G] = out[B] = out[A] = 0; + if ( ! a) + out[i] = 0; else if (a == 255) { - out[R] = in[0]; - out[G] = in[1]; - out[B] = in[2]; - out[A] = a; + out[i] = MAKE_UINT32(in[0], in[1], in[2], a); } else { - out[R] = CLIP(in[0] * 255 / a); - out[G] = CLIP(in[1] * 255 / a); - out[B] = CLIP(in[2] * 255 / a); - out[A] = a; + out[i] = MAKE_UINT32(CLIP(in[0] * 255 / a), + CLIP(in[1] * 255 / a), + CLIP(in[2] * 255 / a), a); } - out += 4; in += 4; + in += 4; } } static void -unpackBGRa(UINT8* out, const UINT8* in, int pixels) +unpackBGRa(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* premultiplied BGRA */ for (i = 0; i < pixels; i++) { int a = in[3]; if (!a) - out[R] = out[G] = out[B] = out[A] = 0; + out[i] = 0; else if (a == 255) { - out[R] = in[2]; - out[G] = in[1]; - out[B] = in[0]; - out[A] = a; + out[i] = MAKE_UINT32(in[2], in[1], in[0], a); } else { - out[R] = CLIP(in[2] * 255 / a); - out[G] = CLIP(in[1] * 255 / a); - out[B] = CLIP(in[0] * 255 / a); - out[A] = a; + out[i] = MAKE_UINT32(CLIP(in[2] * 255 / a), + CLIP(in[1] * 255 / a), + CLIP(in[0] * 255 / a), a); } - out += 4; in += 4; + in += 4; } } @@ -789,73 +768,62 @@ unpackRGBAI(UINT8* out, const UINT8* in, int pixels) } static void -unpackRGBAL(UINT8* out, const UINT8* in, int pixels) +unpackRGBAL(UINT8* _out, const UINT8* in, int pixels) { int i; - + UINT32* out = (UINT32*) _out; /* RGBA, line interleaved */ for (i = 0; i < pixels; i++) { - out[R] = in[i]; - out[G] = in[i+pixels]; - out[B] = in[i+pixels+pixels]; - out[A] = in[i+pixels+pixels+pixels]; - out += 4; + out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], + in[i+pixels+pixels+pixels]); } } void -unpackRGBA16B(UINT8* out, const UINT8* in, int pixels) +unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* 16-bit RGBA, big-endian order */ for (i = 0; i < pixels; i++) { - out[R] = in[0]; - out[G] = in[2]; - out[B] = in[4]; - out[A] = in[6]; - out += 4; in += 8; + out[i] = MAKE_UINT32(in[0], in[2], in[4], in[6]); + in += 8; } } static void -unpackARGB(UINT8* out, const UINT8* in, int pixels) +unpackARGB(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGBA, leading pad */ for (i = 0; i < pixels; i++) { - out[R] = in[1]; - out[G] = in[2]; - out[B] = in[3]; - out[A] = in[0]; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[1], in[2], in[3], in[0]); + in += 4; } } static void -unpackABGR(UINT8* out, const UINT8* in, int pixels) +unpackABGR(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGBA, reversed bytes */ for (i = 0; i < pixels; i++) { - out[R] = in[3]; - out[G] = in[2]; - out[B] = in[1]; - out[A] = in[0]; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[3], in[2], in[1], in[0]); + in += 4; } } static void -unpackBGRA(UINT8* out, const UINT8* in, int pixels) +unpackBGRA(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* RGBA, reversed bytes */ for (i = 0; i < pixels; i++) { - out[R] = in[2]; - out[G] = in[1]; - out[B] = in[0]; - out[A] = in[3]; - out += 4; in += 4; + out[i] = MAKE_UINT32(in[2], in[1], in[0], in[3]); + in += 4; } } @@ -863,16 +831,14 @@ unpackBGRA(UINT8* out, const UINT8* in, int pixels) /* Unpack to "CMYK" image */ static void -unpackCMYKI(UINT8* out, const UINT8* in, int pixels) +unpackCMYKI(UINT8* _out, const UINT8* in, int pixels) { int i; + UINT32* out = (UINT32*) _out; /* CMYK, inverted bytes (Photoshop 2.5) */ for (i = 0; i < pixels; i++) { - out[C] = ~in[0]; - out[M] = ~in[1]; - out[Y] = ~in[2]; - out[K] = ~in[3]; - out += 4; in += 4; + out[i] = ~MAKE_UINT32(in[0], in[1], in[2], in[3]); + in += 4; } } @@ -893,6 +859,7 @@ ImagingUnpackLAB(UINT8* out, const UINT8* in, int pixels) int i; /* LAB triplets */ for (i = 0; i < pixels; i++) { + /* signed in outside world */ out[0] = in[0]; out[1] = in[1] ^ 128; /* signed in outside world */ out[2] = in[2] ^ 128; From 6d65123c10533289f2206d54addff1b31dc2b20c Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 22 Aug 2017 00:50:42 +0300 Subject: [PATCH 08/11] Add some tests --- Tests/test_lib_pack.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index 83872c5d1..dbd5501fc 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -122,6 +122,7 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack("RGB", "BGRX", 4), (3, 2, 1)) self.assertEqual(unpack("RGB", "XRGB", 4), (2, 3, 4)) self.assertEqual(unpack("RGB", "XBGR", 4), (4, 3, 2)) + self.assertEqual(unpack("RGB", "RGBX;L", 4), (1, 2, 3)) self.assertEqual(unpack("RGBA", "RGBA", 4), (1, 2, 3, 4)) self.assertEqual(unpack("RGBA", "RGBa", 4), (63, 127, 191, 4)) @@ -132,6 +133,8 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack("RGBA", "RGBA;15", 2), (8, 131, 0, 0)) self.assertEqual(unpack("RGBA", "BGRA;15", 2), (0, 131, 8, 0)) self.assertEqual(unpack("RGBA", "RGBA;4B", 2), (17, 0, 34, 0)) + self.assertEqual(unpack("RGBA", "LA;16B", 4), (1, 1, 1, 3)) + self.assertEqual(unpack("RGBA", "RGBA;16B", 8), (1, 3, 5, 7)) self.assertEqual(unpack("RGBa", "RGBa", 4), (1, 2, 3, 4)) self.assertEqual(unpack("RGBa", "BGRa", 4), (3, 2, 1, 4)) From ad2c9526976d64c1172e3938753be06afac7f13b Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 22 Aug 2017 00:52:42 +0300 Subject: [PATCH 09/11] Add more tests --- Tests/test_lib_pack.py | 18 ++++++++++++++++++ libImaging/Unpack.c | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index dbd5501fc..a1118a6d9 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -96,6 +96,17 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack_1("1", "1;R", 170), (0, X, 0, X, 0, X, 0, X)) self.assertEqual(unpack_1("1", "1;IR", 170), (X, 0, X, 0, X, 0, X, 0)) + self.assertEqual(unpack("P", "P;1", 1), 0) + self.assertEqual(unpack("P", "P;2", 2), 0) + self.assertEqual(unpack("P", "P;2L", 2), 0) + self.assertEqual(unpack("P", "P;4", 4), 0) + self.assertEqual(unpack("P", "P;4L", 4), 0) + self.assertEqual(unpack("P", "P", 8), 1) + self.assertEqual(unpack("P", "P;R", 8), 128) + + self.assertEqual(unpack("PA", "PA", 16), (1, 2)) + self.assertEqual(unpack("PA", "PA;L", 16), (1, 2)) + self.assertEqual(unpack("L", "L;2", 1), 0) self.assertEqual(unpack("L", "L;4", 1), 0) self.assertEqual(unpack("L", "L", 1), 1) @@ -133,6 +144,8 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack("RGBA", "RGBA;15", 2), (8, 131, 0, 0)) self.assertEqual(unpack("RGBA", "BGRA;15", 2), (0, 131, 8, 0)) self.assertEqual(unpack("RGBA", "RGBA;4B", 2), (17, 0, 34, 0)) + self.assertEqual(unpack("RGBA", "RGBA;L", 4), (1, 2, 3, 4)) + self.assertEqual(unpack("RGBA", "LA", 2), (1, 1, 1, 2)) self.assertEqual(unpack("RGBA", "LA;16B", 4), (1, 1, 1, 3)) self.assertEqual(unpack("RGBA", "RGBA;16B", 8), (1, 3, 5, 7)) @@ -152,6 +165,11 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack("CMYK", "CMYK", 4), (1, 2, 3, 4)) self.assertEqual(unpack("CMYK", "CMYK;I", 4), (254, 253, 252, 251)) + self.assertEqual(unpack("CMYK", "C;I", 1), (254, 0, 0, 0)) + self.assertEqual(unpack("CMYK", "M;I", 1), (0, 254, 0, 0)) + self.assertEqual(unpack("CMYK", "Y;I", 1), (0, 0, 254, 0)) + self.assertEqual(unpack("CMYK", "K;I", 1), (0, 0, 0, 254)) + self.assertRaises(ValueError, lambda: unpack("L", "L", 0)) self.assertRaises(ValueError, lambda: unpack("RGB", "RGB", 2)) self.assertRaises(ValueError, lambda: unpack("CMYK", "CMYK", 2)) diff --git a/libImaging/Unpack.c b/libImaging/Unpack.c index 53b9d3d04..30740d259 100644 --- a/libImaging/Unpack.c +++ b/libImaging/Unpack.c @@ -859,7 +859,6 @@ ImagingUnpackLAB(UINT8* out, const UINT8* in, int pixels) int i; /* LAB triplets */ for (i = 0; i < pixels; i++) { - /* signed in outside world */ out[0] = in[0]; out[1] = in[1] ^ 128; /* signed in outside world */ out[2] = in[2] ^ 128; From eeeafa2651df4323ae38874e26257a061ca2cc54 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 22 Aug 2017 22:30:20 +0300 Subject: [PATCH 10/11] One more tests --- Tests/test_lib_pack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index a1118a6d9..bc4c75ddf 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -145,6 +145,7 @@ class TestLibPack(PillowTestCase): self.assertEqual(unpack("RGBA", "BGRA;15", 2), (0, 131, 8, 0)) self.assertEqual(unpack("RGBA", "RGBA;4B", 2), (17, 0, 34, 0)) self.assertEqual(unpack("RGBA", "RGBA;L", 4), (1, 2, 3, 4)) + self.assertEqual(unpack("RGBA", "RGBA;I", 4), (254, 253, 252, 4)) self.assertEqual(unpack("RGBA", "LA", 2), (1, 1, 1, 2)) self.assertEqual(unpack("RGBA", "LA;16B", 4), (1, 1, 1, 3)) self.assertEqual(unpack("RGBA", "RGBA;16B", 8), (1, 3, 5, 7)) From b705df3b648f63119958796685d5ac0274d0c53f Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 27 Aug 2017 12:40:53 +0300 Subject: [PATCH 11/11] one div for blending --- libImaging/Draw.c | 16 ++++++++-------- libImaging/ImagingUtils.h | 9 ++++++--- libImaging/Paste.c | 36 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index ef8a4db64..3fae3d931 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -81,14 +81,14 @@ point32(Imaging im, int x, int y, int ink) static inline void point32rgba(Imaging im, int x, int y, int ink) { - unsigned int tmp1, tmp2; + unsigned int tmp1; if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) { UINT8* out = (UINT8*) im->image[y]+x*4; UINT8* in = (UINT8*) &ink; - out[0] = BLEND(in[3], out[0], in[0], tmp1, tmp2); - out[1] = BLEND(in[3], out[1], in[1], tmp1, tmp2); - out[2] = BLEND(in[3], out[2], in[2], tmp1, tmp2); + out[0] = BLEND(in[3], out[0], in[0], tmp1); + out[1] = BLEND(in[3], out[1], in[1], tmp1); + out[2] = BLEND(in[3], out[2], in[2], tmp1); } } @@ -140,7 +140,7 @@ static inline void hline32rgba(Imaging im, int x0, int y0, int x1, int ink) { int tmp; - unsigned int tmp1, tmp2; + unsigned int tmp1; if (y0 >= 0 && y0 < im->ysize) { if (x0 > x1) @@ -157,9 +157,9 @@ hline32rgba(Imaging im, int x0, int y0, int x1, int ink) UINT8* out = (UINT8*) im->image[y0]+x0*4; UINT8* in = (UINT8*) &ink; while (x0 <= x1) { - out[0] = BLEND(in[3], out[0], in[0], tmp1, tmp2); - out[1] = BLEND(in[3], out[1], in[1], tmp1, tmp2); - out[2] = BLEND(in[3], out[2], in[2], tmp1, tmp2); + out[0] = BLEND(in[3], out[0], in[0], tmp1); + out[1] = BLEND(in[3], out[1], in[1], tmp1); + out[2] = BLEND(in[3], out[2], in[2], tmp1); x0++; out += 4; } } diff --git a/libImaging/ImagingUtils.h b/libImaging/ImagingUtils.h index 231142735..5541fec30 100644 --- a/libImaging/ImagingUtils.h +++ b/libImaging/ImagingUtils.h @@ -20,8 +20,11 @@ #define MULDIV255(a, b, tmp)\ (tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp)) -#define BLEND(mask, in1, in2, tmp1, tmp2)\ - (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) +#define DIV255(a, tmp)\ + (tmp = (a) + 128, SHIFTFORDIV255(tmp)) + +#define BLEND(mask, in1, in2, tmp1)\ + DIV255(in1 * (255 - mask) + in2 * mask, tmp1) #define PREBLEND(mask, in1, in2, tmp1)\ - (MULDIV255(in1, (255 - mask), tmp1) + in2) + (MULDIV255(in1, (255 - mask), tmp1) + in2) diff --git a/libImaging/Paste.c b/libImaging/Paste.c index 8c62f9ed3..0bda25739 100644 --- a/libImaging/Paste.c +++ b/libImaging/Paste.c @@ -86,7 +86,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, /* paste with mode "L" matte */ int x, y; - unsigned int tmp1, tmp2; + unsigned int tmp1; if (imOut->image8) { @@ -95,7 +95,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, *in, tmp1, tmp2); + *out = BLEND(*mask, *out, *in, tmp1); out++, in++, mask++; } } @@ -108,10 +108,10 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* mask = (UINT8*) (imMask->image8[y+sy] + sx); for (x = 0; x < xsize; x++) { UINT8 a = mask[0]; - out[0] = BLEND(a, out[0], in[0], tmp1, tmp2); - out[1] = BLEND(a, out[1], in[1], tmp1, tmp2); - out[2] = BLEND(a, out[2], in[2], tmp1, tmp2); - out[3] = BLEND(a, out[3], in[3], tmp1, tmp2); + out[0] = BLEND(a, out[0], in[0], tmp1); + out[1] = BLEND(a, out[1], in[1], tmp1); + out[2] = BLEND(a, out[2], in[2], tmp1); + out[3] = BLEND(a, out[3], in[3], tmp1); out += 4; in += 4; mask ++; } } @@ -126,7 +126,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, /* paste with mode "RGBA" matte */ int x, y; - unsigned int tmp1, tmp2; + unsigned int tmp1; if (imOut->image8) { @@ -135,7 +135,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, *in, tmp1, tmp2); + *out = BLEND(*mask, *out, *in, tmp1); out++, in++, mask += 4; } } @@ -148,10 +148,10 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, UINT8* mask = (UINT8*) (imMask->image32[y+sy] + sx); for (x = 0; x < xsize; x++) { UINT8 a = mask[3]; - out[0] = BLEND(a, out[0], in[0], tmp1, tmp2); - out[1] = BLEND(a, out[1], in[1], tmp1, tmp2); - out[2] = BLEND(a, out[2], in[2], tmp1, tmp2); - out[3] = BLEND(a, out[3], in[3], tmp1, tmp2); + out[0] = BLEND(a, out[0], in[0], tmp1); + out[1] = BLEND(a, out[1], in[1], tmp1); + out[2] = BLEND(a, out[2], in[2], tmp1); + out[3] = BLEND(a, out[3], in[3], tmp1); out += 4; in += 4; mask += 4; } } @@ -359,7 +359,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, /* fill with mode "L" matte */ int x, y, i; - unsigned int tmp1, tmp2; + unsigned int tmp1; if (imOut->image8) { @@ -367,7 +367,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); + *out = BLEND(*mask, *out, ink[0], tmp1); out++, mask++; } } @@ -379,7 +379,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { - *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); + *out = BLEND(*mask, *out, ink[i], tmp1); out++; } mask++; @@ -396,7 +396,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, /* fill with mode "RGBA" matte */ int x, y, i; - unsigned int tmp1, tmp2; + unsigned int tmp1; if (imOut->image8) { @@ -405,7 +405,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { - *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); + *out = BLEND(*mask, *out, ink[0], tmp1); out++, mask += 4; } } @@ -419,7 +419,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { - *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); + *out = BLEND(*mask, *out, ink[i], tmp1); out++; } mask += 4;