PixelPaint: Encode layers in PixelPaint project files as PNG

Previously layers weren't compressed at all and the file size could go
up really fast in a project with multiple layers.  By switching to PNG,
the situation is slightly better now.

Interestingly enough, this change won't break compatibility with old
files, as PixelPaint loads layers using ImageDecoder which will try
every codec possible. :^)
This commit is contained in:
Karol Kosek 2022-12-17 16:24:37 +01:00 committed by Andreas Kling
parent 11377bf0f8
commit 5049b103c0
Notes: sideshowbarker 2024-07-17 03:03:48 +09:00

View file

@ -128,7 +128,6 @@ ErrorOr<void> Image::serialize_as_json(JsonObjectSerializer<StringBuilder>& json
{
auto json_layers = TRY(json.add_array("layers"sv));
for (auto const& layer : m_layers) {
Gfx::BMPWriter bmp_writer;
auto json_layer = TRY(json_layers.add_object());
TRY(json_layer.add("width"sv, layer.size().width()));
TRY(json_layer.add("height"sv, layer.size().height()));
@ -138,9 +137,9 @@ ErrorOr<void> Image::serialize_as_json(JsonObjectSerializer<StringBuilder>& json
TRY(json_layer.add("opacity_percent"sv, layer.opacity_percent()));
TRY(json_layer.add("visible"sv, layer.is_visible()));
TRY(json_layer.add("selected"sv, layer.is_selected()));
TRY(json_layer.add("bitmap"sv, encode_base64(bmp_writer.dump(layer.content_bitmap()))));
TRY(json_layer.add("bitmap"sv, encode_base64(TRY(Gfx::PNGWriter::encode(layer.content_bitmap())))));
if (layer.is_masked())
TRY(json_layer.add("mask"sv, encode_base64(bmp_writer.dump(*layer.mask_bitmap()))));
TRY(json_layer.add("mask"sv, encode_base64(TRY(Gfx::PNGWriter::encode(*layer.mask_bitmap())))));
TRY(json_layer.finish());
}