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

This commit is contained in:
Dane Springmeyer 2010-12-21 18:59:51 +00:00
parent 5646dc3e33
commit 2ee9c3b5f3

View file

@ -384,10 +384,14 @@ namespace mapnik
unsigned g0 = (rgba0 >> 16 ) & 0xff; unsigned g0 = (rgba0 >> 16 ) & 0xff;
unsigned b0 = (rgba0 >> 8) & 0xff; unsigned b0 = (rgba0 >> 8) & 0xff;
r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8); unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8); if (atmp)
b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8); {
a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8)); 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) ; row_to[x] = (a0)| (b0 << 8) | (g0 << 16) | (r0 << 24) ;
#else #else
@ -407,10 +411,14 @@ namespace mapnik
unsigned g0 = (rgba0 >> 8 ) & 0xff; unsigned g0 = (rgba0 >> 8 ) & 0xff;
unsigned b0 = (rgba0 >> 16) & 0xff; unsigned b0 = (rgba0 >> 16) & 0xff;
r0 = byte(((r1 - r0) * a1 + (r0 << 8)) >> 8); unsigned atmp = a1 + a0 - ((a1 * a0 + 255) >> 8);
g0 = byte(((g1 - g0) * a1 + (g0 << 8)) >> 8); if (atmp)
b0 = byte(((b1 - b0) * a1 + (b0 << 8)) >> 8); {
a0 = byte((a1 + a0) - ((a1 * a0 + 255) >> 8)); 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) ; row_to[x] = (a0 << 24)| (b0 << 16) | (g0 << 8) | (r0) ;
#endif #endif