mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibGfx: Unify bitmap set_pixel() using templates
This commit is contained in:
parent
24b68259b4
commit
6dfcdaa0d2
Notes:
github-actions[bot]
2024-12-12 22:14:39 +00:00
Author: https://github.com/shlyakpavel
Commit: 6dfcdaa0d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2734
Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 16 additions and 36 deletions
|
@ -263,40 +263,21 @@ ALWAYS_INLINE Color Bitmap::get_pixel(int x, int y) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<StorageFormat storage_format>
|
||||||
ALWAYS_INLINE void Bitmap::set_pixel<StorageFormat::BGRx8888>(int x, int y, Color color)
|
ALWAYS_INLINE void Bitmap::set_pixel(int x, int y, Color color)
|
||||||
{
|
{
|
||||||
VERIFY(x >= 0);
|
VERIFY(x >= 0);
|
||||||
VERIFY(x < width());
|
VERIFY(x < width());
|
||||||
scanline(y)[x] = color.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
if constexpr (storage_format == StorageFormat::BGRx8888 || storage_format == StorageFormat::BGRA8888) {
|
||||||
ALWAYS_INLINE void Bitmap::set_pixel<StorageFormat::BGRA8888>(int x, int y, Color color)
|
scanline(y)[x] = color.value();
|
||||||
{
|
} else if constexpr (storage_format == StorageFormat::RGBA8888) {
|
||||||
VERIFY(x >= 0);
|
scanline(y)[x] = (color.alpha() << 24) | (color.blue() << 16) | (color.green() << 8) | color.red();
|
||||||
VERIFY(x < width());
|
} else if constexpr (storage_format == StorageFormat::RGBx8888) {
|
||||||
scanline(y)[x] = color.value(); // drop alpha
|
scanline(y)[x] = (color.blue() << 16) | (color.green() << 8) | color.red();
|
||||||
}
|
} else {
|
||||||
|
static_assert(false, "There's a new storage format not in Bitmap::set_pixel");
|
||||||
template<>
|
}
|
||||||
ALWAYS_INLINE void Bitmap::set_pixel<StorageFormat::RGBA8888>(int x, int y, Color color)
|
|
||||||
{
|
|
||||||
VERIFY(x >= 0);
|
|
||||||
VERIFY(x < width());
|
|
||||||
// FIXME: There's a lot of inaccurately named functions in the Color class right now (RGBA vs BGRA),
|
|
||||||
// clear those up and then make this more convenient.
|
|
||||||
auto rgba = (color.alpha() << 24) | (color.blue() << 16) | (color.green() << 8) | color.red();
|
|
||||||
scanline(y)[x] = rgba;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
ALWAYS_INLINE void Bitmap::set_pixel<StorageFormat::RGBx8888>(int x, int y, Color color)
|
|
||||||
{
|
|
||||||
VERIFY(x >= 0);
|
|
||||||
VERIFY(x < width());
|
|
||||||
auto rgb = (color.blue() << 16) | (color.green() << 8) | color.red();
|
|
||||||
scanline(y)[x] = rgb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void Bitmap::set_pixel(int x, int y, Color color)
|
ALWAYS_INLINE void Bitmap::set_pixel(int x, int y, Color color)
|
||||||
|
@ -304,19 +285,18 @@ ALWAYS_INLINE void Bitmap::set_pixel(int x, int y, Color color)
|
||||||
switch (determine_storage_format(m_format)) {
|
switch (determine_storage_format(m_format)) {
|
||||||
case StorageFormat::BGRx8888:
|
case StorageFormat::BGRx8888:
|
||||||
set_pixel<StorageFormat::BGRx8888>(x, y, color);
|
set_pixel<StorageFormat::BGRx8888>(x, y, color);
|
||||||
break;
|
return;
|
||||||
case StorageFormat::BGRA8888:
|
case StorageFormat::BGRA8888:
|
||||||
set_pixel<StorageFormat::BGRA8888>(x, y, color);
|
set_pixel<StorageFormat::BGRA8888>(x, y, color);
|
||||||
break;
|
return;
|
||||||
case StorageFormat::RGBA8888:
|
case StorageFormat::RGBA8888:
|
||||||
set_pixel<StorageFormat::RGBA8888>(x, y, color);
|
set_pixel<StorageFormat::RGBA8888>(x, y, color);
|
||||||
break;
|
return;
|
||||||
case StorageFormat::RGBx8888:
|
case StorageFormat::RGBx8888:
|
||||||
set_pixel<StorageFormat::RGBx8888>(x, y, color);
|
set_pixel<StorageFormat::RGBx8888>(x, y, color);
|
||||||
break;
|
return;
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue