mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-03 04:43:12 +00:00
(svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
-Fix: ComposeColourXXX could work a tiny bit faster when using 256, not 255 as value to divide with; downside is that it can give alpha errors (frosch)
This commit is contained in:
parent
38ff181ebf
commit
89bdfaacd9
@ -59,7 +59,7 @@ void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
|
||||
|
||||
/* Make the current color a bit more black, so it looks like this image is transparent */
|
||||
if (src->a != 0) {
|
||||
*dst = MakeTransparent(*dst, 75);
|
||||
*dst = MakeTransparent(*dst, 192);
|
||||
*anim = bp->remap[*anim];
|
||||
}
|
||||
break;
|
||||
@ -90,7 +90,7 @@ void Blitter_32bppAnim::DrawColorMappingRect(void *dst, int width, int height, i
|
||||
if (pal == PALETTE_TO_TRANSPARENT) {
|
||||
do {
|
||||
for (int i = 0; i != width; i++) {
|
||||
*udst = MakeTransparent(*udst, 60);
|
||||
*udst = MakeTransparent(*udst, 154);
|
||||
*anim = 0;
|
||||
udst++;
|
||||
anim++;
|
||||
|
@ -48,15 +48,19 @@ public:
|
||||
*/
|
||||
static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current)
|
||||
{
|
||||
if (a == 0) return current;
|
||||
if (a >= 255) return ComposeColour(0xFF, r, g, b);
|
||||
|
||||
uint cr, cg, cb;
|
||||
cr = GB(current, 16, 8);
|
||||
cg = GB(current, 8, 8);
|
||||
cb = GB(current, 0, 8);
|
||||
|
||||
/* The 256 is wrong, it should be 255, but 256 is much faster... */
|
||||
return ComposeColour(0xFF,
|
||||
(r * a + cr * (255 - a)) / 255,
|
||||
(g * a + cg * (255 - a)) / 255,
|
||||
(b * a + cb * (255 - a)) / 255);
|
||||
(r * a + cr * (256 - a)) / 256,
|
||||
(g * a + cg * (256 - a)) / 256,
|
||||
(b * a + cb * (256 - a)) / 256);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,24 +68,28 @@ public:
|
||||
*/
|
||||
static inline uint ComposeColourPA(uint colour, uint a, uint current)
|
||||
{
|
||||
if (a == 0) return current;
|
||||
if (a >= 255) return (colour | 0xFF000000);
|
||||
|
||||
uint r, g, b, cr, cg, cb;
|
||||
r = GB(colour, 16, 8);
|
||||
g = GB(colour, 8, 8);
|
||||
b = GB(colour, 0, 8);
|
||||
r = GB(colour, 16, 8);
|
||||
g = GB(colour, 8, 8);
|
||||
b = GB(colour, 0, 8);
|
||||
cr = GB(current, 16, 8);
|
||||
cg = GB(current, 8, 8);
|
||||
cb = GB(current, 0, 8);
|
||||
|
||||
/* The 256 is wrong, it should be 255, but 256 is much faster... */
|
||||
return ComposeColour(0xFF,
|
||||
(r * a + cr * (255 - a)) / 255,
|
||||
(g * a + cg * (255 - a)) / 255,
|
||||
(b * a + cb * (255 - a)) / 255);
|
||||
(r * a + cr * (256 - a)) / 256,
|
||||
(g * a + cg * (256 - a)) / 256,
|
||||
(b * a + cb * (256 - a)) / 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a pixel looks like it is transparent.
|
||||
* @param colour the colour already on the screen.
|
||||
* @param amount the amount of transparency, times 100.
|
||||
* @param amount the amount of transparency, times 256.
|
||||
* @return the new colour for the screen.
|
||||
*/
|
||||
static inline uint MakeTransparent(uint colour, uint amount)
|
||||
@ -91,7 +99,7 @@ public:
|
||||
g = GB(colour, 8, 8);
|
||||
b = GB(colour, 0, 8);
|
||||
|
||||
return ComposeColour(0xFF, r * amount / 100, g * amount / 100, b * amount / 100);
|
||||
return ComposeColour(0xFF, r * amount / 256, g * amount / 256, b * amount / 256);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
|
||||
* we produce a result the newgrf maker didn't expect ;) */
|
||||
|
||||
/* Make the current color a bit more black, so it looks like this image is transparent */
|
||||
if (src->a != 0) *dst = MakeTransparent(*dst, 75);
|
||||
if (src->a != 0) *dst = MakeTransparent(*dst, 192);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -60,7 +60,7 @@ void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height,
|
||||
if (pal == PALETTE_TO_TRANSPARENT) {
|
||||
do {
|
||||
for (int i = 0; i != width; i++) {
|
||||
*udst = MakeTransparent(*udst, 60);
|
||||
*udst = MakeTransparent(*udst, 154);
|
||||
udst++;
|
||||
}
|
||||
udst = udst - width + _screen.pitch;
|
||||
|
Loading…
Reference in New Issue
Block a user