mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
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:
committed by
Jelle Raaijmakers
parent
88c4814de6
commit
6847185d9a
Notes:
github-actions[bot]
2025-11-28 17:34:33 +00:00
Author: https://github.com/InvalidUsernameException Commit: https://github.com/LadybirdBrowser/ladybird/commit/6847185d9ae Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6911 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/Psychpsyo Reviewed-by: https://github.com/gmta
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user