mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
This commit is contained in:
parent
b11bf3e157
commit
2a6b7e4e02
@ -26,10 +26,92 @@ public:
|
|||||||
/* virtual */ void PaletteAnimate(uint start, uint count);
|
/* virtual */ void PaletteAnimate(uint start, uint count);
|
||||||
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
|
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
|
||||||
|
|
||||||
static inline uint32 LookupColourInPalette(uint8 index) {
|
/**
|
||||||
#define ARGB(a, r, g, b) ((((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF))
|
* Compose a colour based on RGB values.
|
||||||
if (index == 0) return 0x00000000;
|
*/
|
||||||
return ARGB(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
|
static inline uint ComposeColour(uint a, uint r, uint g, uint b)
|
||||||
|
{
|
||||||
|
return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look up the colour in the current palette.
|
||||||
|
**/
|
||||||
|
static inline uint32 LookupColourInPalette(uint8 index)
|
||||||
|
{
|
||||||
|
if (index == 0) return 0x00000000; // Full transparent pixel */
|
||||||
|
return ComposeColour(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose a colour based on RGBA values and the current pixel value.
|
||||||
|
*/
|
||||||
|
static inline uint ComposeColourRGBA(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 ComposeColour(0xFF,
|
||||||
|
(r * a + cr * (255 - a)) / 255,
|
||||||
|
(g * a + cg * (255 - a)) / 255,
|
||||||
|
(b * a + cb * (255 - a)) / 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose a colour based on Pixel value, alpha value, and the current pixel value.
|
||||||
|
*/
|
||||||
|
static inline uint ComposeColourPA(uint colour, uint a, uint current)
|
||||||
|
{
|
||||||
|
uint r, g, b, cr, cg, cb;
|
||||||
|
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);
|
||||||
|
|
||||||
|
return ComposeColour(0xFF,
|
||||||
|
(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 colour the colour already on the screen.
|
||||||
|
* @param amount the amount of transparency, times 100.
|
||||||
|
* @return the new colour for the screen.
|
||||||
|
*/
|
||||||
|
static inline uint MakeTransparent(uint colour, uint amount)
|
||||||
|
{
|
||||||
|
uint r, g, b;
|
||||||
|
r = GB(colour, 16, 8);
|
||||||
|
g = GB(colour, 8, 8);
|
||||||
|
b = GB(colour, 0, 8);
|
||||||
|
|
||||||
|
return ComposeColour(0xFF, r * amount / 100, g * amount / 100, b * amount / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a colour grey-based.
|
||||||
|
* @param colour the colour to make grey.
|
||||||
|
* @return the new colour, now grey.
|
||||||
|
*/
|
||||||
|
static inline uint MakeGrey(uint colour)
|
||||||
|
{
|
||||||
|
uint r, g, b;
|
||||||
|
r = GB(colour, 16, 8);
|
||||||
|
g = GB(colour, 8, 8);
|
||||||
|
b = GB(colour, 0, 8);
|
||||||
|
|
||||||
|
/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
|
||||||
|
* divide by it to normalize the value to a byte again. See heightmap.cpp for
|
||||||
|
* information about the formula. */
|
||||||
|
colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
|
||||||
|
|
||||||
|
return ComposeColour(0xFF, colour, colour, colour);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,83 +7,6 @@
|
|||||||
|
|
||||||
static FBlitter_32bppSimple iFBlitter_32bppSimple;
|
static FBlitter_32bppSimple iFBlitter_32bppSimple;
|
||||||
|
|
||||||
/**
|
|
||||||
* Compose a color based on RGB values.
|
|
||||||
*/
|
|
||||||
static inline uint ComposeColor(uint r, uint g, uint b)
|
|
||||||
{
|
|
||||||
return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF) << 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
* @return the new color for the screen.
|
|
||||||
*/
|
|
||||||
static inline uint MakeTransparent(uint color, uint amount)
|
|
||||||
{
|
|
||||||
uint r, g, b;
|
|
||||||
r = GB(color, 16, 8);
|
|
||||||
g = GB(color, 8, 8);
|
|
||||||
b = GB(color, 0, 8);
|
|
||||||
|
|
||||||
return ComposeColor(r * amount / 100, g * amount / 100, b * amount / 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make a color grey-based.
|
|
||||||
* @param color the color to make grey.
|
|
||||||
* @return the new color, now grey.
|
|
||||||
*/
|
|
||||||
static inline uint MakeGrey(uint color)
|
|
||||||
{
|
|
||||||
uint r, g, b;
|
|
||||||
r = GB(color, 16, 8);
|
|
||||||
g = GB(color, 8, 8);
|
|
||||||
b = GB(color, 0, 8);
|
|
||||||
|
|
||||||
/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
|
|
||||||
* divide by it to normalize the value to a byte again. See heightmap.cpp for
|
|
||||||
* information about the formula. */
|
|
||||||
color = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
|
|
||||||
|
|
||||||
return ComposeColor(color, color, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
const SpriteLoader::CommonPixel *src, *src_line;
|
const SpriteLoader::CommonPixel *src, *src_line;
|
||||||
@ -105,9 +28,9 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
|
|||||||
case BM_COLOUR_REMAP:
|
case BM_COLOUR_REMAP:
|
||||||
/* In case the m-channel is zero, do not remap this pixel in any way */
|
/* In case the m-channel is zero, do not remap this pixel in any way */
|
||||||
if (src->m == 0) {
|
if (src->m == 0) {
|
||||||
if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
||||||
} else {
|
} else {
|
||||||
if (bp->remap[src->m] != 0) *dst = ComposeColorPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
|
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -121,7 +44,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dst++;
|
dst++;
|
||||||
|
Loading…
Reference in New Issue
Block a user