Skip to content

Commit

Permalink
Compress image data saved in undo/redo for image effects, buckets and…
Browse files Browse the repository at this point in the history
… selection transformations
  • Loading branch information
OverloadedOrama committed Nov 13, 2023
1 parent 1a1d82a commit e625485
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
17 changes: 17 additions & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions src/Classes/ImageEffect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions src/Tools/Bucket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 1 addition & 14 deletions src/Tools/Draw.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 1 addition & 8 deletions src/UI/Canvas/Selection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e625485

Please sign in to comment.