From 8fd306b734ae2b08c933e0ad5a5de30c5e2b87c1 Mon Sep 17 00:00:00 2001 From: Matteo Piovanelli Date: Tue, 18 Jul 2023 19:39:36 +0200 Subject: [PATCH] Compress image data that is memorized for undo/redo operations (#890) * Compress image data that is memorized for undo/redo operations * Fixed formatting issues --- src/Tools/Draw.gd | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index 0222842985bb..6a9b0b124344 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -209,10 +209,20 @@ func commit_undo() -> void: project.undos += 1 for image in redo_data: - project.undo_redo.add_do_property(image, "data", redo_data[image]) + var compressed_data = redo_data[image] + var buffer_size = compressed_data["data"].size() + compressed_data["data"] = compressed_data["data"].compress() + project.undo_redo.add_do_method( + self, "undo_redo_draw_op", image, compressed_data, buffer_size + ) image.unlock() for image in _undo_data: - project.undo_redo.add_undo_property(image, "data", _undo_data[image]) + var compressed_data = _undo_data[image] + var buffer_size = compressed_data["data"].size() + compressed_data["data"] = compressed_data["data"].compress() + project.undo_redo.add_undo_method( + self, "undo_redo_draw_op", image, compressed_data, buffer_size + ) project.undo_redo.add_do_method(Global, "undo_or_redo", false, frame, layer) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, frame, layer) project.undo_redo.commit_action() @@ -220,6 +230,10 @@ func commit_undo() -> void: _undo_data.clear() +func undo_redo_draw_op(image: Object, compressed_image_data: Dictionary, buffer_size: int) -> void: + image["data"]["data"] = compressed_image_data["data"].decompress(buffer_size) + + func draw_tool(position: Vector2) -> void: if Global.mirror_view: # Even brushes are not perfectly centred and are offsetted by 1 px so we add it