Skip to content

Commit

Permalink
better handling of alpha blending - patch from cdestigter - closes #674
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Dec 21, 2010
1 parent 5646dc3 commit 2ee9c3b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions include/mapnik/graphics.hpp
Expand Up @@ -384,10 +384,14 @@ namespace mapnik
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
Expand All @@ -407,10 +411,14 @@ namespace mapnik
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
Expand Down

0 comments on commit 2ee9c3b

Please sign in to comment.