mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
PixelPaint: Support saving/loading masks to project file
This commit is contained in:
parent
0dd5f5672c
commit
51be2283f5
3 changed files with 17 additions and 2 deletions
|
@ -92,6 +92,13 @@ ErrorOr<NonnullRefPtr<Image>> Image::try_create_from_pixel_paint_json(JsonObject
|
||||||
auto bitmap = TRY(try_decode_bitmap(bitmap_data));
|
auto bitmap = TRY(try_decode_bitmap(bitmap_data));
|
||||||
auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name));
|
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 width = layer_object.get("width").to_i32();
|
||||||
auto height = layer_object.get("height").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("opacity_percent", layer.opacity_percent()));
|
||||||
MUST(json_layer.add("visible", layer.is_visible()));
|
MUST(json_layer.add("visible", layer.is_visible()));
|
||||||
MUST(json_layer.add("selected", layer.is_selected()));
|
MUST(json_layer.add("selected", layer.is_selected()));
|
||||||
// FIXME: Respect mask
|
|
||||||
MUST(json_layer.add("bitmap", encode_base64(bmp_writer.dump(layer.content_bitmap()))));
|
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());
|
MUST(json_layer.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,12 @@ void Layer::set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap)
|
||||||
update_cached_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()
|
void Layer::update_cached_bitmap()
|
||||||
{
|
{
|
||||||
if (!is_masked()) {
|
if (!is_masked()) {
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
void set_name(String);
|
void set_name(String);
|
||||||
|
|
||||||
void set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap);
|
void set_content_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap);
|
||||||
|
void set_mask_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap);
|
||||||
|
|
||||||
void did_modify_bitmap(Gfx::IntRect const& = {});
|
void did_modify_bitmap(Gfx::IntRect const& = {});
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public:
|
||||||
|
|
||||||
void erase_selection(Selection const&);
|
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 {
|
enum class EditMode {
|
||||||
Content,
|
Content,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue