From 47a91bbb9a5b9a461bb2124a5c6d0ca3c07e69b8 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:43:05 +0200 Subject: [PATCH] Allow the image to be expanded in `DrawingAlgos.transform` --- src/Autoload/DrawingAlgos.gd | 20 ++++++++++++++------ src/UI/Dialogs/ImageEffects/RotateImage.gd | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 565ee775d..4b274604f 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -274,12 +274,21 @@ func scale_3x(sprite: Image, tol := 0.196078) -> Image: func transform( - image: Image, - params: Dictionary, - algorithm: RotationAlgorithm, - project := Global.current_project + image: Image, params: Dictionary, algorithm: RotationAlgorithm, expand := false ) -> void: + var transformation_matrix: Transform2D = params.get("transformation_matrix", Transform2D()) var pivot: Vector2 = params.get("pivot", image.get_size() / 2) + if expand: + var image_rect := Rect2(Vector2.ZERO, image.get_size()) + var new_image_rect := image_rect * transformation_matrix as Rect2i + var new_image_size := new_image_rect.size + if image.get_size() != new_image_size: + pivot = new_image_size / 2 - (Vector2i(pivot) - image.get_size() / 2) + var tmp_image := Image.create_empty( + new_image_size.x, new_image_size.y, image.has_mipmaps(), image.get_format() + ) + tmp_image.blit_rect(image, image_rect, (new_image_size - image.get_size()) / 2) + image.copy_from(tmp_image) if type_is_shader(algorithm): params["pivot"] = pivot / Vector2(image.get_size()) var shader := rotxel_shader @@ -291,9 +300,8 @@ func transform( RotationAlgorithm.NNS: shader = nn_shader var gen := ShaderImageEffect.new() - gen.generate_image(image, shader, params, project.size) + gen.generate_image(image, shader, params, image.get_size()) else: - var transformation_matrix: Transform2D = params.get("transformation_matrix", Transform2D()) var angle := transformation_matrix.get_rotation() match algorithm: RotationAlgorithm.ROTXEL: diff --git a/src/UI/Dialogs/ImageEffects/RotateImage.gd b/src/UI/Dialogs/ImageEffects/RotateImage.gd index 31612ec49..d39001871 100644 --- a/src/UI/Dialogs/ImageEffects/RotateImage.gd +++ b/src/UI/Dialogs/ImageEffects/RotateImage.gd @@ -114,9 +114,9 @@ func commit_action(cel: Image, project := Global.current_project) -> void: preview.material.set_shader_parameter(param, params[param]) else: params["preview"] = false - DrawingAlgos.transform(cel, params, rotation_algorithm, project) + DrawingAlgos.transform(cel, params, rotation_algorithm) else: - DrawingAlgos.transform(image, params, rotation_algorithm, project) + DrawingAlgos.transform(image, params, rotation_algorithm) if project.has_selection and selection_checkbox.button_pressed: cel.blend_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO) else: