summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2021-01-25 12:25:56 -0500
committerAndreas Kling <kling@serenityos.org>2021-01-25 18:39:27 +0100
commitea8baaa1ab92b945d2101445f4d433da8136ab71 (patch)
tree9138fec690682fa5a011dfbebccd47911d28addf /Userland
parentdfb12e2a73872fae62777a85e751ceab5695b9e8 (diff)
downloadserenity-ea8baaa1ab92b945d2101445f4d433da8136ab71.zip
LibGfx: Fix opacity handling in Painter::draw_scaled_bitmap
If the source image had no alpha channel we'd ignore opacity < 1.0 and blit the image as if it was fully opaque. With this fix, adjusting the opacity of windows with mousewheel while holding super works in hidpi mode.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Demos/LibGfxScaleDemo/main.cpp9
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp2
2 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp
index aa4552fc81..a23f061070 100644
--- a/Userland/Demos/LibGfxScaleDemo/main.cpp
+++ b/Userland/Demos/LibGfxScaleDemo/main.cpp
@@ -108,10 +108,11 @@ void Canvas::draw(Gfx::Painter& painter)
painter.blit({ 25, 101 }, *buggie, { 2, 30, 3 * buggie->width(), 20 });
- // banner does not have an alpha channel.
- auto banner = Gfx::Bitmap::load_from_file("/res/graphics/brand-banner.png");
- painter.fill_rect({ 25, 122, 28, 20 }, Color::Green);
- painter.blit({ 25, 122 }, *banner, { 314, 12, 28, 20 }, 0.8);
+ // grid does not have an alpha channel.
+ auto grid = Gfx::Bitmap::load_from_file("/res/wallpapers/grid.png");
+ ASSERT(!grid->has_alpha_channel());
+ painter.fill_rect({ 25, 122, 62, 20 }, Color::Green);
+ painter.blit({ 25, 122 }, *grid, { (grid->width() - 62) / 2, (grid->height() - 20) / 2 + 40, 62, 20 }, 0.9);
}
int main(int argc, char** argv)
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp
index fff871bcd4..baf2a7a7e7 100644
--- a/Userland/Libraries/LibGfx/Painter.cpp
+++ b/Userland/Libraries/LibGfx/Painter.cpp
@@ -848,7 +848,7 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s
if (clipped_rect.is_empty())
return;
- if (source.has_alpha_channel()) {
+ if (source.has_alpha_channel() || opacity != 1.0f) {
switch (source.format()) {
case BitmapFormat::RGB32:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel<BitmapFormat::RGB32>, opacity);