Codechange: Move colour brightness methods to palette code.

This allows reuse outside of blitters.
This commit is contained in:
Peter Nelson
2025-01-15 17:36:31 +00:00
committed by Peter Nelson
parent 83e9ee00f0
commit c5d3ac7a71
12 changed files with 93 additions and 82 deletions
-30
View File
@@ -150,36 +150,6 @@ void Blitter_32bppBase::PaletteAnimate(const Palette &)
/* By default, 32bpp doesn't have palette animation */
}
Colour Blitter_32bppBase::ReallyAdjustBrightness(Colour colour, uint8_t brightness)
{
assert(DEFAULT_BRIGHTNESS == 1 << 7);
uint64_t combined = (((uint64_t) colour.r) << 32) | (((uint64_t) colour.g) << 16) | ((uint64_t) colour.b);
combined *= brightness;
uint16_t r = GB(combined, 39, 9);
uint16_t g = GB(combined, 23, 9);
uint16_t b = GB(combined, 7, 9);
if ((combined & 0x800080008000L) == 0L) {
return Colour(r, g, b, colour.a);
}
uint16_t ob = 0;
/* Sum overbright */
if (r > 255) ob += r - 255;
if (g > 255) ob += g - 255;
if (b > 255) ob += b - 255;
/* Reduce overbright strength */
ob /= 2;
return Colour(
r >= 255 ? 255 : std::min(r + ob * (255 - r) / 256, 255),
g >= 255 ? 255 : std::min(g + ob * (255 - g) / 256, 255),
b >= 255 ? 255 : std::min(b + ob * (255 - b) / 256, 255),
colour.a);
}
Blitter::PaletteAnimation Blitter_32bppBase::UsePaletteAnimation()
{
return Blitter::PALETTE_ANIMATION_NONE;