diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-16 19:26:17 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-16 19:26:17 +0100 |
commit | 89c0b158dae1a599a52c104e952f254eefce46cb (patch) | |
tree | f8f47809bce1d5e08fc27717407a3bab40438f33 /Libraries | |
parent | 69dee2076124aeac2bcd3caae78bc08a51d2db35 (diff) | |
download | serenity-89c0b158dae1a599a52c104e952f254eefce46cb.zip |
LibDraw: Add support for colors with alpha in Painter::fill_rect()
This code is naive, but it works and looks okay. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibDraw/Painter.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Libraries/LibDraw/Painter.cpp b/Libraries/LibDraw/Painter.cpp index 2cbf9a2111..8ecb91571a 100644 --- a/Libraries/LibDraw/Painter.cpp +++ b/Libraries/LibDraw/Painter.cpp @@ -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; } } |