Improve colour blending

This commit is contained in:
Marijn van der Werf 2017-10-13 22:12:09 +02:00
parent 579c578777
commit 4213a66069
2 changed files with 7 additions and 9 deletions

View File

@ -66,14 +66,14 @@ void colours_init_maps()
#ifndef NO_TTF
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;
sint32 closestDistance = INT32_MAX;
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);
if (distance < closestDistance)
@ -86,23 +86,21 @@ static uint8 findClosestIndex(uint8 red, uint8 green, uint8 blue)
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 cMax = max(base, layer);
const uint8 cMin = min(paletteIndex1, paletteIndex2);
const uint8 cMax = max(paletteIndex1, paletteIndex2);
if (BlendColourMap[cMin][cMax] != 0)
{
return BlendColourMap[cMin][cMax];
}
log_info("Blending colours %d and %d", cMin, cMax);
uint8 red = (gPalette[cMin].red + gPalette[cMax].red) / 2;
uint8 green = (gPalette[cMin].green + gPalette[cMax].green) / 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];
}
#endif

View File

@ -152,7 +152,7 @@ extern rct_colour_map ColourMapA[COLOUR_COUNT];
void colours_init_maps();
#ifndef NO_TTF
uint8 blend(const uint8 base, const uint8 layer);
uint8 blend(const uint8 paletteIndex1, const uint8 paletteIndex2);
#endif
#ifdef __cplusplus