diff options
author | Tobias Christiansen <tobyase@serenityos.org> | 2022-03-08 23:23:20 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-09 17:15:17 +0100 |
commit | 51be2283f515c128eb6643a4f92170d1e68a85df (patch) | |
tree | aeffdf10c0ff1c4f6aa68680b7007b79f91bb063 /Userland/Applications/PixelPaint | |
parent | 0dd5f5672c7d6e6c58bd8c782a0fd0e63634b98b (diff) | |
download | serenity-51be2283f515c128eb6643a4f92170d1e68a85df.zip |
PixelPaint: Support saving/loading masks to project file
Diffstat (limited to 'Userland/Applications/PixelPaint')
-rw-r--r-- | Userland/Applications/PixelPaint/Image.cpp | 10 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Layer.cpp | 6 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Layer.h | 3 |
3 files changed, 17 insertions, 2 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 82a67b6ca6..7ce629a54a 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -92,6 +92,13 @@ ErrorOr<NonnullRefPtr<Image>> Image::try_create_from_pixel_paint_json(JsonObject auto bitmap = TRY(try_decode_bitmap(bitmap_data)); auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name)); + if (auto mask_object = layer_object.get("mask"); !mask_object.is_null()) { + auto mask_base64_encoded = mask_object.as_string(); + auto mask_data = TRY(decode_base64(mask_base64_encoded)); + auto mask = TRY(try_decode_bitmap(mask_data)); + layer->set_mask_bitmap(move(mask)); + } + auto width = layer_object.get("width").to_i32(); auto height = layer_object.get("height").to_i32(); @@ -126,8 +133,9 @@ void Image::serialize_as_json(JsonObjectSerializer<StringBuilder>& json) const MUST(json_layer.add("opacity_percent", layer.opacity_percent())); MUST(json_layer.add("visible", layer.is_visible())); MUST(json_layer.add("selected", layer.is_selected())); - // FIXME: Respect mask MUST(json_layer.add("bitmap", encode_base64(bmp_writer.dump(layer.content_bitmap())))); + if (layer.is_masked()) + MUST(json_layer.add("mask", encode_base64(bmp_writer.dump(*layer.mask_bitmap())))); MUST(json_layer.finish()); } diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index bf90f60b3b..f3f5dc5e73 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -148,6 +148,12 @@ void Layer::set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap) update_cached_bitmap(); } +void Layer::set_mask_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap) +{ + m_mask_bitmap = move(bitmap); + update_cached_bitmap(); +} + void Layer::update_cached_bitmap() { if (!is_masked()) { diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h index 74c1cdc65a..b9197872c9 100644 --- a/Userland/Applications/PixelPaint/Layer.h +++ b/Userland/Applications/PixelPaint/Layer.h @@ -54,6 +54,7 @@ public: void set_name(String); void set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap); + void set_mask_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap); void did_modify_bitmap(Gfx::IntRect const& = {}); @@ -72,7 +73,7 @@ public: void erase_selection(Selection const&); - bool is_masked() { return !m_mask_bitmap.is_null(); } + bool is_masked() const { return !m_mask_bitmap.is_null(); } enum class EditMode { Content, |