40const uint PALETTE_BITS_MASK = ((1U <<
PALETTE_BITS) - 1) << PALETTE_SHIFT;
41const uint PALETTE_BITS_OR = (1U << (PALETTE_SHIFT - 1));
44using PaletteLookup = std::array<uint8_t, 1U << (
PALETTE_BITS * 3)>;
45static PaletteLookup _palette_lookup{};
59 return (c & PALETTE_BITS_MASK) | PALETTE_BITS_OR;
73 int r = (int)col1.r - (
int)r2;
74 int g = (int)col1.g - (
int)g2;
75 int b = (int)col1.
b - (
int)b2;
77 int avgr = (col1.r + r2) / 2;
78 return ((2 + (avgr / 256.0)) * r * r) + (4 * g * g) + ((2 + ((255 - avgr) / 256.0)) * b * b);
101 uint best_distance = UINT32_MAX;
106 best_distance = distance;
113 best_distance = distance;
129 uint32_t key = (r >> PALETTE_SHIFT) | (g >> PALETTE_SHIFT) <<
PALETTE_BITS | (b >> PALETTE_SHIFT) << (
PALETTE_BITS * 2);
131 return _palette_lookup[key];
134void DoPaletteAnimations();
136void GfxInitPalettes()
140 DoPaletteAnimations();
169#define EXTR(p, q) (((uint16_t)(palette_animation_counter * (p)) * (q)) >> 16)
170#define EXTR2(p, q) (((uint16_t)(~palette_animation_counter * (p)) * (q)) >> 16)
172void DoPaletteAnimations()
177 static int palette_animation_counter = 0;
178 palette_animation_counter += 8;
184 const uint old_tc = palette_animation_counter;
188 palette_animation_counter = 0;
194 memcpy(old_val, palette_pos,
sizeof(old_val));
200 *palette_pos++ = s[j];
209 *palette_pos++ = s[j];
216 uint8_t i = (palette_animation_counter >> 1) & 0x7F;
221 }
else if (i < 0x4A || i >= 0x75) {
234 }
else if (i < 0x4A || i >= 0x75) {
249 *palette_pos++ = s[j];
258 *palette_pos++ = s[j];
267 *palette_pos++ = s[j];
273 palette_animation_counter = old_tc;
292 uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.
b * c.
b * 114;
294 return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
303 using ColourGradient = std::array<uint8_t, SHADE_END>;
305 static inline std::array<ColourGradient, COLOUR_END> gradient{};
316 return ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END];
327 assert(colour < COLOUR_END);
328 assert(shade < SHADE_END);
329 ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END] = palette_index;
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
@ PALETTE_ANIMATION_NONE
No palette animation.
Factory to 'query' all available blitters.
Functions for Standard In/Out file operations.
Types related to the graphics and/or input devices.
static constexpr uint8_t PALETTE_ANIM_SIZE
number of animated colours
static constexpr uint8_t PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Types related to the landscape.
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
const uint8_t PALETTE_INDEX_END
Palette index of end of defined palette.
const uint8_t PALETTE_INDEX_CC_END
Palette index of end of company colour remap area.
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
uint CrunchColour(uint c)
Reduce bits per channel to PALETTE_BITS, and place value in the middle of the reduced range.
static std::recursive_mutex _palette_mutex
To coordinate access to _cur_palette.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
static uint CalculateColourDistance(const Colour &col1, int r2, int g2, int b2)
Calculate distance between two colours.
const uint8_t PALETTE_INDEX_CC_START
Palette index of start of company colour remap area.
const uint PALETTE_BITS
PALETTE_BITS reduces the bits-per-channel of 32bpp graphics data to allow faster palette lookups from...
TextColour GetContrastColour(uint8_t background, uint8_t threshold)
Determine a contrasty text colour for a coloured background.
const uint8_t PALETTE_INDEX_START
Palette index of start of defined palette.
Palette _cur_palette
Current palette.
static uint8_t FindNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Find nearest colour palette index for a 32bpp pixel.
uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Get nearest colour palette index from an RGB colour.
Functions related to palettes.
The colour translation of the GRF palettes.
static const Palette _palette
Colour palette (DOS)
static const uint EPV_CYCLES_DARK_WATER
Description of the length of the palette cycle animations.
static const uint EPV_CYCLES_OIL_REFINERY
length of the oil refinery's fire animation
static const uint EPV_CYCLES_LIGHTHOUSE
length of the lighthouse/stadium animation
static const uint EPV_CYCLES_GLITTER_WATER
length of the glittery water animation
static const ExtraPaletteValues _extra_palette_values
Actual palette animation tables.
static const uint EPV_CYCLES_FIZZY_DRINK
length of the fizzy drinks animation
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
Lookup table of colour shades for all 16 colour gradients.
uint8_t landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
Information about the currently used palette.
int first_dirty
The first dirty element.
int count_dirty
The number of dirty elements.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
uint8_t b
colour channels in BE order
std::mutex lock
synchronization for playback status fields