LibGfx: Mask alpha values when setting pixels on non-alpha bitmaps

This is not technically necessary, presumably the bitmap type does not
offer any guarantees about what values are stored in the alpha component
for non-alpha pixel formats.

But the previous behavior meant that `set_pixel()` would produce
different values in the alpha component depending on whether the bitmap
format was RGBx or BGRx (i.e. `color.alpha()` vs. 0x00), which can be a
bit confusing.
This commit is contained in:
InvalidUsernameException
2025-11-23 13:07:41 +01:00
committed by Jelle Raaijmakers
parent 88c4814de6
commit 6847185d9a
Notes: github-actions[bot] 2025-11-28 17:34:33 +00:00

View File

@@ -249,15 +249,17 @@ ALWAYS_INLINE Color Bitmap::get_pixel(int x, int y) const
ALWAYS_INLINE void Bitmap::set_pixel(int x, int y, Color color)
{
switch (m_format) {
case BitmapFormat::BGRx8888:
case BitmapFormat::BGRA8888:
scanline(y)[x] = color.value();
return;
case BitmapFormat::BGRx8888:
scanline(y)[x] = color.value() | (0xFF << 24);
return;
case BitmapFormat::RGBA8888:
scanline(y)[x] = (color.alpha() << 24) | (color.blue() << 16) | (color.green() << 8) | color.red();
return;
case BitmapFormat::RGBx8888:
scanline(y)[x] = (color.blue() << 16) | (color.green() << 8) | color.red();
scanline(y)[x] = (0xFF << 24) | (color.blue() << 16) | (color.green() << 8) | color.red();
return;
case BitmapFormat::Invalid:
VERIFY_NOT_REACHED();