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.
This commit is contained in:
Nico Weber 2021-01-25 12:25:56 -05:00 committed by Andreas Kling
parent dfb12e2a73
commit ea8baaa1ab
2 changed files with 6 additions and 5 deletions

View file

@ -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)

View file

@ -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);