40const uint PALETTE_BITS_MASK = ((1U <<
PALETTE_BITS) - 1) << PALETTE_SHIFT;
41const uint PALETTE_BITS_OR = (1U << (PALETTE_SHIFT - 1));
67 return (c & PALETTE_BITS_MASK) | PALETTE_BITS_OR;
81 int r = (int)col1.r - (
int)r2;
82 int g = (int)col1.g - (
int)g2;
83 int b = (int)col1.b - (
int)b2;
85 int avgr = (col1.r + r2) / 2;
86 return ((2 + (avgr / 256.0)) * r * r) + (4 * g * g) + ((2 + ((255 - avgr) / 256.0)) * b * b);
109 uint best_distance = UINT32_MAX;
114 best_distance = distance;
121 best_distance = distance;
137 uint best_distance = UINT32_MAX;
142 best_distance = distance;
158 uint32_t key = (r >> PALETTE_SHIFT) | (g >> PALETTE_SHIFT) <<
PALETTE_BITS | (b >> PALETTE_SHIFT) << (
PALETTE_BITS * 2);
171 uint32_t key = (b >> PALETTE_SHIFT);
184 if (brightness == DEFAULT_BRIGHTNESS)
return colour;
186 uint64_t combined = (
static_cast<uint64_t
>(colour.r) << 32) | (
static_cast<uint64_t
>(colour.g) << 16) |
static_cast<uint64_t
>(colour.b);
187 combined *= brightness;
189 uint16_t r =
GB(combined, 39, 9);
190 uint16_t g =
GB(combined, 23, 9);
191 uint16_t b =
GB(combined, 7, 9);
193 if ((combined & 0x800080008000L) == 0L) {
194 return Colour(r, g, b, colour.a);
199 if (r > 255) ob += r - 255;
200 if (g > 255) ob += g - 255;
201 if (b > 255) ob += b - 255;
206 r >= 255 ? 255 : std::min(r + ob * (255 - r) / 256, 255),
207 g >= 255 ? 255 : std::min(g + ob * (255 - g) / 256, 255),
208 b >= 255 ? 255 : std::min(b + ob * (255 - b) / 256, 255),
212void DoPaletteAnimations();
214void GfxInitPalettes()
218 DoPaletteAnimations();
234 if (!force_copy &&
_cur_palette.count_dirty == 0)
return false;
247#define EXTR(p, q) (((uint16_t)(palette_animation_counter * (p)) * (q)) >> 16)
248#define EXTR2(p, q) (((uint16_t)(~palette_animation_counter * (p)) * (q)) >> 16)
250void DoPaletteAnimations()
255 static int palette_animation_counter = 0;
256 palette_animation_counter += 8;
261 const uint old_tc = palette_animation_counter;
265 palette_animation_counter = 0;
271 std::array<Colour, PALETTE_ANIM_SIZE> original_palette;
272 std::ranges::copy(current_palette, original_palette.begin());
273 auto palette_pos = current_palette.begin();
279 *palette_pos++ = s[j];
288 *palette_pos++ = s[j];
295 uint8_t i = (palette_animation_counter >> 1) & 0x7F;
300 }
else if (i < 0x4A || i >= 0x75) {
313 }
else if (i < 0x4A || i >= 0x75) {
328 *palette_pos++ = s[j];
337 *palette_pos++ = s[j];
346 *palette_pos++ = s[j];
352 palette_animation_counter = old_tc;
353 }
else if (
_cur_palette.count_dirty == 0 && !std::ranges::equal(current_palette, original_palette)) {
371 uint sq1000_brightness = c.r * c.r * 299 + c.g * c.g * 587 + c.b * c.b * 114;
373 return sq1000_brightness < ((uint) threshold) * ((uint) threshold) * 1000 ? TC_WHITE : TC_BLACK;
382 using ColourGradient = std::array<PixelColour, SHADE_END>;
384 static inline std::array<ColourGradient, COLOUR_END> gradient{};
395 return ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END];
406 assert(colour < COLOUR_END);
407 assert(shade < SHADE_END);
408 ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END] = palette_index;
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
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.
@ None
No palette animation.
Factory to 'query' all available blitters.
Functions for standard in/out file operations.
Palette _cur_palette
Current palette.
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.
@ Toyland
Landscape with funky industries and vehicles.
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.
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.
static uint8_t FindNearestColourReshadeIndex(uint8_t b)
Find nearest company colour palette index for a brightness level.
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...
static ReshadeLookup _reshade_lookup
TextColour GetContrastColour(PixelColour background, uint8_t threshold)
Determine a contrasty text colour for a coloured background.
Colour ReallyAdjustBrightness(Colour colour, int brightness)
Adjust brightness of colour.
const uint8_t PALETTE_INDEX_START
Palette index of start of defined palette.
uint8_t GetNearestColourReshadeIndex(uint8_t b)
Get nearest colour palette index from a brightness level.
std::array< uint8_t, 1U<<(PALETTE_BITS *3)> PaletteLookup
void SetColourGradient(Colours colour, ColourShade shade, PixelColour palette_index)
Set colour gradient palette index.
static PaletteLookup _palette_lookup
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.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
std::array< uint8_t, 1U<< PALETTE_BITS > ReshadeLookup
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.
int first_dirty
The first dirty element.
int count_dirty
The number of dirty elements.
Colour for pixel/line drawing.
std::mutex lock
synchronization for playback status fields