1
0
Fork 0

Codechange: Support RGB colours in pixel/line drawing.

pull/11634/head
Peter Nelson 2025-07-25 08:56:47 +01:00
parent 36d14669c5
commit 79a2af5d44
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
5 changed files with 40 additions and 15 deletions

View File

@ -323,7 +323,7 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height,
void Blitter_32bppAnim::SetPixel(void *video, int x, int y, PixelColour colour) void Blitter_32bppAnim::SetPixel(void *video, int x, int y, PixelColour colour)
{ {
*((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour.p); *((Colour *)video + x + y * _screen.pitch) = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
/* Set the colour in the anim-buffer too, if we are rendering to the screen */ /* Set the colour in the anim-buffer too, if we are rendering to the screen */
if (_screen_disable_anim) return; if (_screen_disable_anim) return;
@ -333,7 +333,7 @@ void Blitter_32bppAnim::SetPixel(void *video, int x, int y, PixelColour colour)
void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash)
{ {
const Colour c = LookupColourInPalette(colour.p); const Colour c = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
if (_screen_disable_anim) { if (_screen_disable_anim) {
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](int x, int y) { this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](int x, int y) {
@ -357,7 +357,7 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, PixelColour
return; return;
} }
Colour colour32 = LookupColourInPalette(colour.p); Colour colour32 = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->anim_buf; uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->anim_buf;
do { do {

View File

@ -20,12 +20,13 @@ void *Blitter_32bppBase::MoveTo(void *video, int x, int y)
void Blitter_32bppBase::SetPixel(void *video, int x, int y, PixelColour colour) void Blitter_32bppBase::SetPixel(void *video, int x, int y, PixelColour colour)
{ {
*((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour.p); const Colour c = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
*((Colour *)video + x + y * _screen.pitch) = c;
} }
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash)
{ {
const Colour c = LookupColourInPalette(colour.p); const Colour c = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) { this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
*((Colour *)video + x + y * _screen.pitch) = c; *((Colour *)video + x + y * _screen.pitch) = c;
}); });
@ -33,7 +34,7 @@ void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int
void Blitter_32bppBase::DrawRect(void *video, int width, int height, PixelColour colour) void Blitter_32bppBase::DrawRect(void *video, int width, int height, PixelColour colour)
{ {
Colour colour32 = LookupColourInPalette(colour.p); Colour colour32 = colour.HasRGB() ? colour.ToColour() : LookupColourInPalette(colour.p);
do { do {
Colour *dst = (Colour *)video; Colour *dst = (Colour *)video;

View File

@ -32,10 +32,14 @@ void Blitter_40bppAnim::SetPixel(void *video, int x, int y, PixelColour colour)
if (_screen_disable_anim) { if (_screen_disable_anim) {
Blitter_32bppOptimized::SetPixel(video, x, y, colour); Blitter_32bppOptimized::SetPixel(video, x, y, colour);
} else { } else {
size_t y_offset = static_cast<size_t>(y) * _screen.pitch; bool has_rgb = colour.HasRGB();
*((Colour *)video + x + y_offset) = _black_colour; const Colour colour32 = has_rgb ? colour.ToColour() : _black_colour;
const uint8_t colour8 = has_rgb ? 0 : colour.p;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = colour.p; size_t y_offset = static_cast<size_t>(y) * _screen.pitch;
*((Colour *)video + x + y_offset) = colour32;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = colour8;
} }
} }
@ -47,6 +51,10 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, PixelColour
return; return;
} }
bool has_rgb = colour.HasRGB();
const Colour colour32 = has_rgb ? colour.ToColour() : _black_colour;
const uint8_t colour8 = has_rgb ? 0 : colour.p;
assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr); assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr);
uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer(); uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
@ -55,8 +63,8 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, PixelColour
uint8_t *anim = anim_line; uint8_t *anim = anim_line;
for (int i = width; i > 0; i--) { for (int i = width; i > 0; i--) {
*dst = _black_colour; *dst = colour32;
*anim = colour.p; *anim = colour8;
dst++; dst++;
anim++; anim++;
} }
@ -73,12 +81,16 @@ void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int
return; return;
} }
bool has_rgb = colour.HasRGB();
const Colour colour32 = has_rgb ? colour.ToColour() : _black_colour;
const uint8_t colour8 = has_rgb ? 0 : colour.p;
assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr); assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr);
uint8_t *anim = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer(); uint8_t *anim = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) { this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
*((Colour *)video + x + y * _screen.pitch) = _black_colour; *((Colour *)video + x + y * _screen.pitch) = colour32;
*(anim + x + y * _screen.pitch) = colour.p; *(anim + x + y * _screen.pitch) = colour8;
}); });
} }

View File

@ -404,11 +404,18 @@ DECLARE_ENUM_AS_BIT_SET(StringAlignment)
/** Colour for pixel/line drawing. */ /** Colour for pixel/line drawing. */
struct PixelColour { struct PixelColour {
uint8_t p; ///< Palette index. uint8_t p = 0; ///< Palette index.
uint8_t r = 0; ///< Red component.
uint8_t g = 0; ///< Green component.
uint8_t b = 0; ///< Blue component.
constexpr PixelColour() : p(0) {} constexpr PixelColour() {}
explicit constexpr PixelColour(uint8_t p) : p(p) {} explicit constexpr PixelColour(uint8_t p) : p(p) {}
constexpr PixelColour(uint8_t p, Colour colour) : p(p), r(colour.r), g(colour.g), b(colour.b) {}
PixelColour(Colour colour);
constexpr inline bool HasRGB() const { return (this->r | this->g | this->b) != 0; }
constexpr inline Colour ToColour() const { return {this->r, this->g, this->b}; }
constexpr inline TextColour ToTextColour() const { return static_cast<TextColour>(this->p) | TC_IS_PALETTE_COLOUR; } constexpr inline TextColour ToTextColour() const { return static_cast<TextColour>(this->p) | TC_IS_PALETTE_COLOUR; }
}; };

View File

@ -402,3 +402,8 @@ void SetColourGradient(Colours colour, ColourShade shade, PixelColour palette_in
assert(shade < SHADE_END); assert(shade < SHADE_END);
ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END] = palette_index; ColourGradients::gradient[colour % COLOUR_END][shade % SHADE_END] = palette_index;
} }
PixelColour::PixelColour(Colour colour) : r(colour.r), g(colour.g), b(colour.b)
{
this->p = GetNearestColourIndex(colour);
}