1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:37:45 +00:00

PixelPaint: Respect Mask when generating the display bitmap

This commit is contained in:
Tobias Christiansen 2022-03-07 22:19:41 +01:00 committed by Andreas Kling
parent 82bfdec790
commit a180b5f442

View file

@ -156,6 +156,20 @@ void Layer::update_cached_bitmap()
m_cached_display_bitmap = m_content_bitmap;
return;
}
if (m_content_bitmap.ptr() == m_cached_display_bitmap.ptr())
m_cached_display_bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, size()));
// FIXME: This can probably be done nicer
m_cached_display_bitmap->fill(Color::Transparent);
for (int y = 0; y < size().height(); ++y) {
for (int x = 0; x < size().width(); ++x) {
auto opacity_multiplier = (float)m_mask_bitmap->get_pixel(x, y).to_grayscale().red() / 255;
auto content_color = m_content_bitmap->get_pixel(x, y);
content_color.set_alpha(content_color.alpha() * opacity_multiplier);
m_cached_display_bitmap->set_pixel(x, y, content_color);
}
}
}
void Layer::create_mask()