mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 19:43:06 +01:00
Move blending code to colour.c.
This commit is contained in:
committed by
Marijn van der Werf
parent
d6349d0095
commit
d4c5218ba2
@@ -717,48 +717,6 @@ static void ttf_draw_string_raw_sprite(rct_drawpixelinfo *dpi, const utf8 *text,
|
||||
|
||||
#ifndef NO_TTF
|
||||
|
||||
static uint8 colormap[256][256] = {0};
|
||||
|
||||
uint8 findClosestIndex(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
sint16 closest = -1;
|
||||
sint32 closestDistance = INT32_MAX;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
const int distance =
|
||||
pow(gPalette[i].red - red, 2) + pow(gPalette[i].green - green, 2) + pow(gPalette[i].blue - blue, 2);
|
||||
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closest = i;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
uint8 blend(const uint8 base, const uint8 layer)
|
||||
{
|
||||
const uint8 cMin = min(base, layer);
|
||||
const uint8 cMax = max(base, layer);
|
||||
|
||||
if (colormap[cMin][cMax] != 0)
|
||||
{
|
||||
return colormap[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;
|
||||
|
||||
colormap[cMin][cMax] = findClosestIndex(red, green, blue);
|
||||
return colormap[cMin][cMax];
|
||||
}
|
||||
|
||||
static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, text_draw_info *info)
|
||||
{
|
||||
if (!ttf_initialise())
|
||||
|
||||
@@ -62,3 +62,47 @@ void colours_init_maps()
|
||||
ColourMapA[i].colour_11 = g1Element->offset[INDEX_COLOUR_11];
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_TTF
|
||||
static uint8 BlendColourMap[PALETTE_COUNT][PALETTE_COUNT] = {0};
|
||||
|
||||
static uint8 findClosestIndex(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
sint16 closest = -1;
|
||||
sint32 closestDistance = INT32_MAX;
|
||||
|
||||
for (int i = 0; i < PALETTE_COUNT; i++)
|
||||
{
|
||||
const int distance =
|
||||
pow(gPalette[i].red - red, 2) + pow(gPalette[i].green - green, 2) + pow(gPalette[i].blue - blue, 2);
|
||||
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closest = i;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
uint8 blend(const uint8 base, const uint8 layer)
|
||||
{
|
||||
const uint8 cMin = min(base, layer);
|
||||
const uint8 cMax = max(base, layer);
|
||||
|
||||
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);
|
||||
return BlendColourMap[cMin][cMax];
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -111,6 +111,8 @@ enum
|
||||
PALETTE_INDEX_209 = 209, // Bright Pink (light)
|
||||
PALETTE_INDEX_222 = 222, //
|
||||
PALETTE_INDEX_245 = 245, //
|
||||
|
||||
PALETTE_COUNT = 256,
|
||||
};
|
||||
|
||||
#define TEXT_COLOUR_254 (254)
|
||||
@@ -148,6 +150,10 @@ extern rct_colour_map ColourMapA[COLOUR_COUNT];
|
||||
|
||||
void colours_init_maps();
|
||||
|
||||
#ifndef NO_TTF
|
||||
uint8 blend(const uint8 base, const uint8 layer);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user