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

PixelPaint: Introduce new mask features

This patch adds a new Editing-Mask type to layers. This kind of mask
is used to restrict changes on the content bitmap only to areas where
the mask is drawn. The intensity of a pixel change is controlled by the
alpha-value of the mask.

Furthermore a function to invert and clear masks has been introduced.
When a new mask is created for a layer the edit mode of the layer is
also changed to Mask so that the user can immediately start to draw the
mask.
This commit is contained in:
Torstennator 2023-05-12 16:07:51 +02:00 committed by Jelle Raaijmakers
parent 7e5f1fa895
commit e3509efc1b
6 changed files with 147 additions and 7 deletions

View file

@ -45,9 +45,17 @@ public:
Gfx::Bitmap const* mask_bitmap() const { return m_mask_bitmap; }
Gfx::Bitmap* mask_bitmap() { return m_mask_bitmap; }
ErrorOr<void> create_mask();
enum class MaskType {
None,
BasicMask,
EditingMask,
};
ErrorOr<void> create_mask(MaskType);
void delete_mask();
void apply_mask();
void invert_mask();
void clear_mask();
Gfx::Bitmap& get_scratch_edited_bitmap();
@ -91,6 +99,7 @@ public:
void erase_selection(Selection const&);
bool is_masked() const { return !m_mask_bitmap.is_null(); }
MaskType mask_type();
enum class EditMode {
Content,
@ -104,6 +113,19 @@ public:
ErrorOr<NonnullRefPtr<Layer>> duplicate(DeprecatedString name);
ALWAYS_INLINE Color modify_pixel_with_editing_mask(int x, int y, Color const& target_color, Color const& current_color)
{
if (mask_type() != MaskType::EditingMask)
return target_color;
auto mask = mask_bitmap()->get_pixel(x, y).alpha();
if (!mask)
return current_color;
float mask_intensity = mask / 255.0f;
return current_color.mixed_with(target_color, mask_intensity);
}
private:
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, DeprecatedString name);
@ -122,6 +144,7 @@ private:
int m_opacity_percent { 100 };
EditMode m_edit_mode { EditMode::Content };
MaskType m_mask_type { MaskType::None };
void update_cached_bitmap();
};