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

PixelPaint: Correctly apply flip/rotate/crop to layers' alpha mask

-Layer now has methods for flip/rotate/crop, which are responsible
for handling the alpha mask.
-Fixed crash when the display image size is out of sync with
the content image size.
-Changed API for setting content and mask image in Layer. Now, both
must be set at the same time, and it can result in an error if
you provide mismatched dimensions.
This commit is contained in:
Andrew Smith 2022-03-12 12:48:05 -06:00 committed by Andreas Kling
parent 03342876b8
commit 297e095755
3 changed files with 42 additions and 21 deletions

View file

@ -142,16 +142,42 @@ void Layer::erase_selection(Selection const& selection)
did_modify_bitmap(translated_to_layer_space);
}
void Layer::set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap)
ErrorOr<void> Layer::try_set_bitmaps(NonnullRefPtr<Gfx::Bitmap> content, RefPtr<Gfx::Bitmap> mask)
{
m_content_bitmap = move(bitmap);
if (mask && content->size() != mask->size())
return Error::from_string_literal("Layer content and mask must be same size"sv);
m_content_bitmap = move(content);
m_mask_bitmap = move(mask);
update_cached_bitmap();
return {};
}
void Layer::set_mask_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap)
void Layer::flip(Gfx::Orientation orientation)
{
m_mask_bitmap = move(bitmap);
update_cached_bitmap();
m_content_bitmap = *m_content_bitmap->flipped(orientation).release_value_but_fixme_should_propagate_errors();
if (m_mask_bitmap)
m_mask_bitmap = *m_mask_bitmap->flipped(orientation).release_value_but_fixme_should_propagate_errors();
did_modify_bitmap();
}
void Layer::rotate(Gfx::RotationDirection direction)
{
m_content_bitmap = *m_content_bitmap->rotated(direction).release_value_but_fixme_should_propagate_errors();
if (m_mask_bitmap)
m_mask_bitmap = *m_mask_bitmap->rotated(direction).release_value_but_fixme_should_propagate_errors();
did_modify_bitmap();
}
void Layer::crop(Gfx::IntRect const& rect)
{
m_content_bitmap = *m_content_bitmap->cropped(rect).release_value_but_fixme_should_propagate_errors();
if (m_mask_bitmap)
m_mask_bitmap = *m_mask_bitmap->cropped(rect).release_value_but_fixme_should_propagate_errors();
did_modify_bitmap();
}
void Layer::update_cached_bitmap()
@ -163,8 +189,9 @@ void Layer::update_cached_bitmap()
return;
}
if (m_content_bitmap.ptr() == m_cached_display_bitmap.ptr())
if (m_cached_display_bitmap.ptr() == m_content_bitmap.ptr() || m_cached_display_bitmap->size() != size()) {
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);