better handling of alpha blending - patch from cdestigter - closes #674

This commit is contained in:
Dane Springmeyer 2010-12-10 19:31:57 +00:00
parent 0791b039d5
commit fc6227afda

View file

@ -396,10 +396,14 @@ public:
unsigned g0 = (rgba0 >> 16 ) & 0xff;
unsigned b0 = (rgba0 >> 8) & 0xff;
r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8);
g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8);
b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8);
a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8));
unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
if (atmp)
{
r0 = byte((r1 * a1 + (r0 * a0) - ((r0 * a0 * a1 + 255) >> 8)) / atmp);
g0 = byte((g1 * a1 + (g0 * a0) - ((g0 * a0 * a1 + 255) >> 8)) / atmp);
b0 = byte((b1 * a1 + (b0 * a0) - ((b0 * a0 * a1 + 255) >> 8)) / atmp);
}
a0 = byte(atmp);
row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ;
#else
@ -418,11 +422,15 @@ public:
unsigned r0 = rgba0 & 0xff ;
unsigned g0 = (rgba0 >> 8 ) & 0xff;
unsigned b0 = (rgba0 >> 16) & 0xff;
r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8);
g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8);
b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8);
a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8));
unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
if (atmp)
{
r0 = byte((r1 * a1 + (r0 * a0) - ((r0 * a0 * a1 + 255) >> 8)) / atmp);
g0 = byte((g1 * a1 + (g0 * a0) - ((g0 * a0 * a1 + 255) >> 8)) / atmp);
b0 = byte((b1 * a1 + (b0 * a0) - ((b0 * a0 * a1 + 255) >> 8)) / atmp);
}
a0 = byte(atmp);
row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
#endif