Skip to content

Commit

Permalink
Compress image data that is memorized for undo/redo operations (#890)
Browse files Browse the repository at this point in the history
* Compress image data that is memorized for undo/redo operations

* Fixed formatting issues
  • Loading branch information
MatteoPiovanelli-Laser authored Jul 18, 2023
1 parent e195e32 commit 8fd306b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Tools/Draw.gd
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,31 @@ 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()

_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
Expand Down

0 comments on commit 8fd306b

Please sign in to comment.