mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibDraw: Add support for colors with alpha in Painter::fill_rect()
This code is naive, but it works and looks okay. :^)
This commit is contained in:
parent
69dee20761
commit
89c0b158da
Notes:
sideshowbarker
2024-07-19 11:11:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/89c0b158dae
1 changed files with 13 additions and 1 deletions
|
@ -56,6 +56,9 @@ void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
|
|||
|
||||
void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||
{
|
||||
if (color.alpha() == 0)
|
||||
return;
|
||||
|
||||
if (draw_op() != DrawOp::Copy) {
|
||||
fill_rect_with_draw_op(a_rect, color);
|
||||
return;
|
||||
|
@ -70,8 +73,17 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
|||
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
||||
|
||||
if (color.alpha() == 0xff) {
|
||||
for (int i = rect.height() - 1; i >= 0; --i) {
|
||||
fast_u32_fill(dst, color.value(), rect.width());
|
||||
dst += dst_skip;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = rect.height() - 1; i >= 0; --i) {
|
||||
fast_u32_fill(dst, color.value(), rect.width());
|
||||
for (int j = 0; j < rect.width(); ++j)
|
||||
dst[j] = Color::from_rgba(dst[j]).blend(color).value();
|
||||
dst += dst_skip;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue