From 5049b103c06865ab0de6a20c25acaa4704a04e66 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sat, 17 Dec 2022 16:24:37 +0100 Subject: [PATCH] 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. :^) --- Userland/Applications/PixelPaint/Image.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 86c691035df..e26cf8cdabd 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -128,7 +128,6 @@ ErrorOr Image::serialize_as_json(JsonObjectSerializer& 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 Image::serialize_as_json(JsonObjectSerializer& 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()); }