From ea8baaa1ab92b945d2101445f4d433da8136ab71 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 25 Jan 2021 12:25:56 -0500 Subject: [PATCH] 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. --- Userland/Demos/LibGfxScaleDemo/main.cpp | 9 +++++---- Userland/Libraries/LibGfx/Painter.cpp | 2 +- 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(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity);