mirror of https://github.com/OpenRCT2/OpenRCT2.git
Improve colour blending
This commit is contained in:
parent
579c578777
commit
4213a66069
|
@ -66,14 +66,14 @@ void colours_init_maps()
|
||||||
#ifndef NO_TTF
|
#ifndef NO_TTF
|
||||||
static uint8 BlendColourMap[PALETTE_COUNT][PALETTE_COUNT] = {0};
|
static uint8 BlendColourMap[PALETTE_COUNT][PALETTE_COUNT] = {0};
|
||||||
|
|
||||||
static uint8 findClosestIndex(uint8 red, uint8 green, uint8 blue)
|
static uint8 findClosestPaletteIndex(uint8 red, uint8 green, uint8 blue)
|
||||||
{
|
{
|
||||||
sint16 closest = -1;
|
sint16 closest = -1;
|
||||||
sint32 closestDistance = INT32_MAX;
|
sint32 closestDistance = INT32_MAX;
|
||||||
|
|
||||||
for (int i = PALETTE_INDEX_0; i < PALETTE_INDEX_230; i++)
|
for (int i = PALETTE_INDEX_0; i < PALETTE_INDEX_230; i++)
|
||||||
{
|
{
|
||||||
const int distance =
|
const sint32 distance =
|
||||||
pow(gPalette[i].red - red, 2) + pow(gPalette[i].green - green, 2) + pow(gPalette[i].blue - blue, 2);
|
pow(gPalette[i].red - red, 2) + pow(gPalette[i].green - green, 2) + pow(gPalette[i].blue - blue, 2);
|
||||||
|
|
||||||
if (distance < closestDistance)
|
if (distance < closestDistance)
|
||||||
|
@ -86,23 +86,21 @@ static uint8 findClosestIndex(uint8 red, uint8 green, uint8 blue)
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 blend(const uint8 base, const uint8 layer)
|
uint8 blend(const uint8 paletteIndex1, const uint8 paletteIndex2)
|
||||||
{
|
{
|
||||||
const uint8 cMin = min(base, layer);
|
const uint8 cMin = min(paletteIndex1, paletteIndex2);
|
||||||
const uint8 cMax = max(base, layer);
|
const uint8 cMax = max(paletteIndex1, paletteIndex2);
|
||||||
|
|
||||||
if (BlendColourMap[cMin][cMax] != 0)
|
if (BlendColourMap[cMin][cMax] != 0)
|
||||||
{
|
{
|
||||||
return BlendColourMap[cMin][cMax];
|
return BlendColourMap[cMin][cMax];
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info("Blending colours %d and %d", cMin, cMax);
|
|
||||||
|
|
||||||
uint8 red = (gPalette[cMin].red + gPalette[cMax].red) / 2;
|
uint8 red = (gPalette[cMin].red + gPalette[cMax].red) / 2;
|
||||||
uint8 green = (gPalette[cMin].green + gPalette[cMax].green) / 2;
|
uint8 green = (gPalette[cMin].green + gPalette[cMax].green) / 2;
|
||||||
uint8 blue = (gPalette[cMin].blue + gPalette[cMax].blue) / 2;
|
uint8 blue = (gPalette[cMin].blue + gPalette[cMax].blue) / 2;
|
||||||
|
|
||||||
BlendColourMap[cMin][cMax] = findClosestIndex(red, green, blue);
|
BlendColourMap[cMin][cMax] = findClosestPaletteIndex(red, green, blue);
|
||||||
return BlendColourMap[cMin][cMax];
|
return BlendColourMap[cMin][cMax];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -152,7 +152,7 @@ extern rct_colour_map ColourMapA[COLOUR_COUNT];
|
||||||
void colours_init_maps();
|
void colours_init_maps();
|
||||||
|
|
||||||
#ifndef NO_TTF
|
#ifndef NO_TTF
|
||||||
uint8 blend(const uint8 base, const uint8 layer);
|
uint8 blend(const uint8 paletteIndex1, const uint8 paletteIndex2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue