mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +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
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)
|
void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
{
|
{
|
||||||
|
if (color.alpha() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (draw_op() != DrawOp::Copy) {
|
if (draw_op() != DrawOp::Copy) {
|
||||||
fill_rect_with_draw_op(a_rect, color);
|
fill_rect_with_draw_op(a_rect, color);
|
||||||
return;
|
return;
|
||||||
|
@ -70,8 +73,17 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
||||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
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) {
|
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;
|
dst += dst_skip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue