From a83ef0f0ed65961eace4869fcf6aa906576caed0 Mon Sep 17 00:00:00 2001 From: homm Date: Mon, 25 Mar 2013 09:49:35 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=E2=89=8820%=20faster,=202=20times=20more?= =?UTF-8?q?=20precisely=20(0.17%=20difference=20against=200.37%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libImaging/AlphaComposite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libImaging/AlphaComposite.c b/libImaging/AlphaComposite.c index 93afe2a95..86af8e940 100644 --- a/libImaging/AlphaComposite.c +++ b/libImaging/AlphaComposite.c @@ -74,7 +74,7 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) // There we use 7 bits for precision. // We could use more, but we go beyond 32 bits. UINT16 coef1 = src->a * 255 * 255 * 128 / outa255; - UINT16 coef2 = blend * 255 * 128 / outa255; + UINT16 coef2 = 255 * 128 - coef1; #define SHIFTFORDIV255(a)\ ((a >> 8) + a >> 8) From a511ef8b052db9d339caa2733c3145aef80a045f Mon Sep 17 00:00:00 2001 From: homm Date: Wed, 27 Mar 2013 23:18:10 +0400 Subject: [PATCH 2/3] move declarations to make ANSI compilers happy --- libImaging/AlphaComposite.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libImaging/AlphaComposite.c b/libImaging/AlphaComposite.c index 86af8e940..9876cda5f 100644 --- a/libImaging/AlphaComposite.c +++ b/libImaging/AlphaComposite.c @@ -69,6 +69,7 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) // almost equivalent to: // tmp = a + (2 << (n-1)), ((tmp >> n) + tmp) >> n + UINT32 tmpr, tmpg, tmpb; UINT16 blend = dst->a * (255 - src->a); UINT16 outa255 = src->a * 255 + blend; // There we use 7 bits for precision. @@ -79,11 +80,11 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) #define SHIFTFORDIV255(a)\ ((a >> 8) + a >> 8) - UINT32 tmpr = src->r * coef1 + dst->r * coef2 + (0x80 << 7); + tmpr = src->r * coef1 + dst->r * coef2 + (0x80 << 7); out->r = SHIFTFORDIV255(tmpr) >> 7; - UINT32 tmpg = src->g * coef1 + dst->g * coef2 + (0x80 << 7); + tmpg = src->g * coef1 + dst->g * coef2 + (0x80 << 7); out->g = SHIFTFORDIV255(tmpg) >> 7; - UINT32 tmpb = src->b * coef1 + dst->b * coef2 + (0x80 << 7); + tmpb = src->b * coef1 + dst->b * coef2 + (0x80 << 7); out->b = SHIFTFORDIV255(tmpb) >> 7; out->a = SHIFTFORDIV255(outa255 + 0x80); } From ebb9029fbe7cfb963a705f8126e806e9bd38929f Mon Sep 17 00:00:00 2001 From: homm Date: Wed, 27 Mar 2013 23:19:04 +0400 Subject: [PATCH 3/3] add parentheses to avoid warnings --- libImaging/AlphaComposite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libImaging/AlphaComposite.c b/libImaging/AlphaComposite.c index 9876cda5f..9433fae53 100644 --- a/libImaging/AlphaComposite.c +++ b/libImaging/AlphaComposite.c @@ -78,7 +78,7 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) UINT16 coef2 = 255 * 128 - coef1; #define SHIFTFORDIV255(a)\ - ((a >> 8) + a >> 8) + ((((a) >> 8) + a) >> 8) tmpr = src->r * coef1 + dst->r * coef2 + (0x80 << 7); out->r = SHIFTFORDIV255(tmpr) >> 7;