diff options
author | truelight <truelight@openttd.org> | 2007-06-13 16:04:35 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2007-06-13 16:04:35 +0000 |
commit | 4185c4afcdd58d49c33e64c6d53a7eb71d44bd1e (patch) | |
tree | 9fefeb9b430522a88904a9f51a8c545f49404328 | |
parent | 5f1791bfb169a99205fef1f8c8984730f3b38857 (diff) | |
download | openttd-4185c4afcdd58d49c33e64c6d53a7eb71d44bd1e.tar.xz |
(svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
-rw-r--r-- | src/blitter/32bpp_simple.cpp | 40 | ||||
-rw-r--r-- | src/fontcache.cpp | 2 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp index 15a5e926c..c858736cf 100644 --- a/src/blitter/32bpp_simple.cpp +++ b/src/blitter/32bpp_simple.cpp @@ -17,6 +17,39 @@ static inline uint ComposeColor(uint r, uint g, uint b) } /** + * Compose a color based on RGBA values and the current pixel value. + */ +static inline uint ComposeColorRGBA(uint r, uint g, uint b, uint a, uint current) +{ + uint cr, cg, cb; + cr = GB(current, 16, 8); + cg = GB(current, 8, 8); + cb = GB(current, 0, 8); + + return ComposeColor((r * a + cr * (255 - a)) / 255, + (g * a + cg * (255 - a)) / 255, + (b * a + cb * (255 - a)) / 255); +} + +/** + * Compose a color based on Pixel value, alpha value, and the current pixel value. + */ +static inline uint ComposeColorPA(uint color, uint a, uint current) +{ + uint r, g, b, cr, cg, cb; + r = GB(color, 16, 8); + g = GB(color, 8, 8); + b = GB(color, 0, 8); + cr = GB(current, 16, 8); + cg = GB(current, 8, 8); + cb = GB(current, 0, 8); + + return ComposeColor((r * a + cr * (255 - a)) / 255, + (g * a + cg * (255 - a)) / 255, + (b * a + cb * (255 - a)) / 255); +} + +/** * Make a pixel looks like it is transparent. * @param color the color already on the screen. * @param amount the amount of transparency, times 100. @@ -69,14 +102,13 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo src_line += bp->sprite_width * ScaleByZoom(1, zoom); for (int x = 0; x < bp->width; x++) { - switch (mode) { case BM_COLOUR_REMAP: /* In case the m-channel is zero, do not remap this pixel in any way */ if (src->m == 0) { - if (src->a != 0) *dst = ComposeColor(src->r, src->g, src->b); + if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst); } else { - if (bp->remap[src->m] != 0) *dst = Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]); + if (bp->remap[src->m] != 0) *dst = ComposeColorPA(Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]), src->a, *dst); } break; @@ -90,7 +122,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo break; default: - if (src->a != 0) *dst = ComposeColor(src->r, src->g, src->b); + if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst); break; } dst++; diff --git a/src/fontcache.cpp b/src/fontcache.cpp index ded1ffe72..a04936aec 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -419,6 +419,7 @@ const Sprite *GetGlyph(FontSize size, WChar key) for (x = 0; x < slot->bitmap.width; x++) { if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR; + sprite.data[1 + x + (1 + y) * sprite.width].a = 0xFF; } } } @@ -428,6 +429,7 @@ const Sprite *GetGlyph(FontSize size, WChar key) for (x = 0; x < slot->bitmap.width; x++) { if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) { sprite.data[x + y * sprite.width].m = FACE_COLOUR; + sprite.data[x + y * sprite.width].a = 0xFF; } } } |