mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-25 00:34:14 +03:00
Merge pull request #172 from homm/alpha-blending-enhancement
Fix compilation on windows and one more thing
This commit is contained in:
commit
9aff1c354b
|
@ -69,21 +69,22 @@ 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.
|
||||
// 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)
|
||||
((((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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user