2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2023-01-01 04:58:01 -06:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-06-22 22:59:46 +02:00
|
|
|
#include "Colour.h"
|
|
|
|
|
|
2021-07-22 20:13:55 +03:00
|
|
|
#include "../core/EnumMap.hpp"
|
2018-01-05 21:17:33 +00:00
|
|
|
#include "../drawing/Drawing.h"
|
2016-11-11 09:46:14 +01:00
|
|
|
#include "../sprites.h"
|
2018-06-22 22:59:46 +02:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
2018-01-05 23:08:58 +00:00
|
|
|
|
2018-06-04 19:50:46 +02:00
|
|
|
rct_colour_map ColourMapA[COLOUR_COUNT] = {};
|
2016-11-11 09:46:14 +01:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
INDEX_COLOUR_0 = 243,
|
|
|
|
|
INDEX_COLOUR_1 = 245,
|
|
|
|
|
INDEX_DARKEST = 245,
|
|
|
|
|
INDEX_DARKER = 246,
|
|
|
|
|
INDEX_DARK = 247,
|
|
|
|
|
INDEX_MID_DARK = 248,
|
|
|
|
|
INDEX_MID_LIGHT = 249,
|
|
|
|
|
INDEX_LIGHT = 250,
|
|
|
|
|
INDEX_LIGHTER = 251,
|
|
|
|
|
INDEX_LIGHTEST = 252,
|
|
|
|
|
INDEX_COLOUR_10 = 253,
|
|
|
|
|
INDEX_COLOUR_11 = 254,
|
2016-11-11 09:46:14 +01:00
|
|
|
};
|
2015-11-08 18:55:32 +00:00
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
void ColoursInitMaps()
|
2015-11-08 18:55:32 +00:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Get colour maps from g1
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < COLOUR_COUNT; i++)
|
2017-10-05 15:55:39 +02:00
|
|
|
{
|
2023-01-16 18:52:17 +00:00
|
|
|
const rct_g1_element* g1 = GfxGetG1Element(SPR_PALETTE_2_START + i);
|
2018-01-07 21:43:07 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
ColourMapA[i].colour_0 = g1->offset[INDEX_COLOUR_0];
|
|
|
|
|
ColourMapA[i].colour_1 = g1->offset[INDEX_COLOUR_1];
|
|
|
|
|
ColourMapA[i].darkest = g1->offset[INDEX_DARKEST];
|
|
|
|
|
ColourMapA[i].darker = g1->offset[INDEX_DARKER];
|
|
|
|
|
ColourMapA[i].dark = g1->offset[INDEX_DARK];
|
|
|
|
|
ColourMapA[i].mid_dark = g1->offset[INDEX_MID_DARK];
|
|
|
|
|
ColourMapA[i].mid_light = g1->offset[INDEX_MID_LIGHT];
|
|
|
|
|
ColourMapA[i].light = g1->offset[INDEX_LIGHT];
|
|
|
|
|
ColourMapA[i].lighter = g1->offset[INDEX_LIGHTER];
|
|
|
|
|
ColourMapA[i].lightest = g1->offset[INDEX_LIGHTEST];
|
|
|
|
|
ColourMapA[i].colour_10 = g1->offset[INDEX_COLOUR_10];
|
|
|
|
|
ColourMapA[i].colour_11 = g1->offset[INDEX_COLOUR_11];
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-11-08 18:55:32 +00:00
|
|
|
}
|
2017-10-13 16:17:21 +02:00
|
|
|
|
2020-08-12 19:44:59 +01:00
|
|
|
namespace Colour
|
|
|
|
|
{
|
2021-07-22 20:13:55 +03:00
|
|
|
static const EnumMap<colour_t> LookupTable{
|
|
|
|
|
{ "black", COLOUR_BLACK },
|
|
|
|
|
{ "grey", COLOUR_GREY },
|
|
|
|
|
{ "white", COLOUR_WHITE },
|
|
|
|
|
{ "dark_purple", COLOUR_DARK_PURPLE },
|
|
|
|
|
{ "light_purple", COLOUR_LIGHT_PURPLE },
|
|
|
|
|
{ "bright_purple", COLOUR_BRIGHT_PURPLE },
|
|
|
|
|
{ "dark_blue", COLOUR_DARK_BLUE },
|
|
|
|
|
{ "light_blue", COLOUR_LIGHT_BLUE },
|
|
|
|
|
{ "icy_blue", COLOUR_ICY_BLUE },
|
|
|
|
|
{ "teal", COLOUR_TEAL },
|
|
|
|
|
{ "aquamarine", COLOUR_AQUAMARINE },
|
|
|
|
|
{ "saturated_green", COLOUR_SATURATED_GREEN },
|
|
|
|
|
{ "dark_green", COLOUR_DARK_GREEN },
|
|
|
|
|
{ "moss_green", COLOUR_MOSS_GREEN },
|
|
|
|
|
{ "bright_green", COLOUR_BRIGHT_GREEN },
|
|
|
|
|
{ "olive_green", COLOUR_OLIVE_GREEN },
|
|
|
|
|
{ "dark_olive_green", COLOUR_DARK_OLIVE_GREEN },
|
|
|
|
|
{ "bright_yellow", COLOUR_BRIGHT_YELLOW },
|
|
|
|
|
{ "yellow", COLOUR_YELLOW },
|
|
|
|
|
{ "dark_yellow", COLOUR_DARK_YELLOW },
|
|
|
|
|
{ "light_orange", COLOUR_LIGHT_ORANGE },
|
|
|
|
|
{ "dark_orange", COLOUR_DARK_ORANGE },
|
|
|
|
|
{ "light_brown", COLOUR_LIGHT_BROWN },
|
|
|
|
|
{ "saturated_brown", COLOUR_SATURATED_BROWN },
|
|
|
|
|
{ "dark_brown", COLOUR_DARK_BROWN },
|
|
|
|
|
{ "salmon_pink", COLOUR_SALMON_PINK },
|
|
|
|
|
{ "bordeaux_red", COLOUR_BORDEAUX_RED },
|
|
|
|
|
{ "saturated_red", COLOUR_SATURATED_RED },
|
|
|
|
|
{ "bright_red", COLOUR_BRIGHT_RED },
|
|
|
|
|
{ "dark_pink", COLOUR_DARK_PINK },
|
|
|
|
|
{ "bright_pink", COLOUR_BRIGHT_PINK },
|
|
|
|
|
{ "light_pink", COLOUR_LIGHT_PINK },
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-07 01:22:22 +09:00
|
|
|
colour_t FromString(std::string_view s, colour_t defaultValue)
|
2020-08-12 19:44:59 +01:00
|
|
|
{
|
|
|
|
|
auto result = LookupTable.find(s);
|
|
|
|
|
return (result != LookupTable.end()) ? result->second : defaultValue;
|
|
|
|
|
}
|
2021-07-22 20:13:55 +03:00
|
|
|
|
2020-08-12 19:44:59 +01:00
|
|
|
} // namespace Colour
|
|
|
|
|
|
2017-10-13 16:17:21 +02:00
|
|
|
#ifndef NO_TTF
|
2018-06-22 22:59:46 +02:00
|
|
|
static uint8_t BlendColourMap[PALETTE_COUNT][PALETTE_COUNT] = { 0 };
|
2017-10-13 16:17:21 +02:00
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
static uint8_t FindClosestPaletteIndex(uint8_t red, uint8_t green, uint8_t blue)
|
2017-10-13 16:17:21 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int16_t closest = -1;
|
|
|
|
|
int32_t closestDistance = INT32_MAX;
|
2017-10-13 16:17:21 +02:00
|
|
|
|
2017-10-13 22:13:58 +02:00
|
|
|
for (int i = PALETTE_INDEX_0; i < PALETTE_INDEX_230; i++)
|
2017-10-13 16:17:21 +02:00
|
|
|
{
|
2020-05-27 20:12:01 +01:00
|
|
|
const int32_t distance = std::pow(gPalette[i].Red - red, 2) + std::pow(gPalette[i].Green - green, 2)
|
|
|
|
|
+ std::pow(gPalette[i].Blue - blue, 2);
|
2017-10-13 16:17:21 +02:00
|
|
|
|
|
|
|
|
if (distance < closestDistance)
|
|
|
|
|
{
|
|
|
|
|
closest = i;
|
|
|
|
|
closestDistance = distance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
uint8_t BlendColours(const uint8_t paletteIndex1, const uint8_t paletteIndex2)
|
2017-10-13 16:17:21 +02:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
const uint8_t cMin = std::min(paletteIndex1, paletteIndex2);
|
|
|
|
|
const uint8_t cMax = std::max(paletteIndex1, paletteIndex2);
|
2017-10-13 16:17:21 +02:00
|
|
|
|
|
|
|
|
if (BlendColourMap[cMin][cMax] != 0)
|
|
|
|
|
{
|
|
|
|
|
return BlendColourMap[cMin][cMax];
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 20:12:01 +01:00
|
|
|
uint8_t red = (gPalette[cMin].Red + gPalette[cMax].Red) / 2;
|
|
|
|
|
uint8_t green = (gPalette[cMin].Green + gPalette[cMax].Green) / 2;
|
|
|
|
|
uint8_t blue = (gPalette[cMin].Blue + gPalette[cMax].Blue) / 2;
|
2017-10-13 16:17:21 +02:00
|
|
|
|
2023-01-16 21:14:50 +01:00
|
|
|
BlendColourMap[cMin][cMax] = FindClosestPaletteIndex(red, green, blue);
|
2017-10-13 16:17:21 +02:00
|
|
|
return BlendColourMap[cMin][cMax];
|
|
|
|
|
}
|
|
|
|
|
#endif
|