From e62548517f4d976bdcf8e6ade3c7fa684ae1d865 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 14 Nov 2023 00:48:02 +0200 Subject: [PATCH] Compress image data saved in undo/redo for image effects, buckets and selection transformations --- src/Autoload/Global.gd | 17 +++++++++++++++++ src/Classes/ImageEffect.gd | 5 +---- src/Tools/Bucket.gd | 5 +---- src/Tools/Draw.gd | 15 +-------------- src/UI/Canvas/Selection.gd | 9 +-------- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 78013eec2c21..52a648ac30ae 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -856,6 +856,23 @@ func path_join_array(basepaths: PackedStringArray, subpath: String) -> PackedStr return res +func undo_redo_compress_images(redo_data: Dictionary, undo_data: Dictionary, project := current_project) -> void: + for image in redo_data: + if not image is Image: + continue + var buffer_size: int = redo_data[image]["data"].size() + var compressed_data: PackedByteArray = redo_data[image]["data"].compress() + project.undo_redo.add_do_method(undo_redo_draw_op.bind(image, compressed_data, buffer_size)) + for image in undo_data: + if not image is Image: + continue + var buffer_size: int = undo_data[image]["data"].size() + var compressed_data: PackedByteArray = undo_data[image]["data"].compress() + project.undo_redo.add_undo_method( + undo_redo_draw_op.bind(image, compressed_data, buffer_size) + ) + + ## Decompresses the [param compressed_image_data] with [params buffer_size] to the [param image] ## This is an opmization method used by [param Draw.gd] while performing undo/redo. func undo_redo_draw_op( diff --git a/src/Classes/ImageEffect.gd b/src/Classes/ImageEffect.gd index 1b4f0656d865..3bc42269b15c 100644 --- a/src/Classes/ImageEffect.gd +++ b/src/Classes/ImageEffect.gd @@ -148,10 +148,7 @@ func _commit_undo(action: String, undo_data: Dictionary, project: Project) -> vo var redo_data := _get_undo_data(project) project.undos += 1 project.undo_redo.create_action(action) - for image in redo_data: - project.undo_redo.add_do_property(image, "data", redo_data[image]) - for image in undo_data: - project.undo_redo.add_undo_property(image, "data", undo_data[image]) + Global.undo_redo_compress_images(redo_data, undo_data, project) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, -1, -1, project)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, -1, -1, project)) project.undo_redo.commit_action() diff --git a/src/Tools/Bucket.gd b/src/Tools/Bucket.gd index 04183e19a300..4e1bc1f626d6 100644 --- a/src/Tools/Bucket.gd +++ b/src/Tools/Bucket.gd @@ -483,10 +483,7 @@ func commit_undo(action: String, undo_data: Dictionary) -> void: project.undos += 1 project.undo_redo.create_action(action) - for image in redo_data: - project.undo_redo.add_do_property(image, "data", redo_data[image]) - for image in undo_data: - project.undo_redo.add_undo_property(image, "data", undo_data[image]) + Global.undo_redo_compress_images(redo_data, undo_data, project) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, frame, layer)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, frame, layer)) project.undo_redo.commit_action() diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index 39a1d75ca6f3..3da3c0fd5c3b 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -213,20 +213,7 @@ func commit_undo() -> void: layer = project.current_layer project.undos += 1 - for image in redo_data: - var compressed_data: Dictionary = redo_data[image] - var buffer_size: int = compressed_data["data"].size() - compressed_data["data"] = compressed_data["data"].compress() - project.undo_redo.add_do_method( - Global.undo_redo_draw_op.bind(image, compressed_data["data"], buffer_size) - ) - for image in _undo_data: - var compressed_data: Dictionary = _undo_data[image] - var buffer_size: int = compressed_data["data"].size() - compressed_data["data"] = compressed_data["data"].compress() - project.undo_redo.add_undo_method( - Global.undo_redo_draw_op.bind(image, compressed_data["data"], buffer_size) - ) + Global.undo_redo_compress_images(redo_data, _undo_data, project) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false, frame, layer)) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true, frame, layer)) project.undo_redo.commit_action() diff --git a/src/UI/Canvas/Selection.gd b/src/UI/Canvas/Selection.gd index d4548e54f4de..6fa288d6d773 100644 --- a/src/UI/Canvas/Selection.gd +++ b/src/UI/Canvas/Selection.gd @@ -610,14 +610,7 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void: ) if undo_data_tmp["undo_image"]: - for image in redo_data: - if not image is Image: - continue - project.undo_redo.add_do_property(image, "data", redo_data[image]) - for image in undo_data_tmp: - if not image is Image: - continue - project.undo_redo.add_undo_property(image, "data", undo_data_tmp[image]) + Global.undo_redo_compress_images(redo_data, undo_data_tmp, project) project.undo_redo.add_do_method(Global.undo_or_redo.bind(false)) project.undo_redo.add_do_method(project.selection_map_changed) project.undo_redo.add_undo_method(Global.undo_or_redo.bind(true))