Skip to content

Commit

Permalink
Implement cleanEdge rotation and scaling (#794)
Browse files Browse the repository at this point in the history
* Implement clear4x rotation

* Don't use pixelated uvs on the final result, only on the preview, and fix pivot positioning

* Update to cleanEdge algorithm

* Add cleanEdge scaling
  • Loading branch information
OverloadedOrama authored Dec 24, 2022
1 parent 4658b1c commit 222e7a1
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/Autoload/DrawingAlgos.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node

enum GradientDirection { TOP, BOTTOM, LEFT, RIGHT }
var clean_edge_shader: Shader = preload("res://src/Shaders/Rotation/cleanEdge.gdshader")


# Algorithm based on http://members.chello.at/easyfilter/bresenham.html
Expand Down Expand Up @@ -427,15 +428,18 @@ func scale_image(width: int, height: int, interpolation: int) -> void:
continue
var sprite := Image.new()
sprite.copy_from(f.cels[i].image)
# Different method for scale_3x
if interpolation == 5:
if interpolation == 5: # scale3x
var times: Vector2 = Vector2(
ceil(width / (3.0 * sprite.get_width())),
ceil(height / (3.0 * sprite.get_height()))
)
for _j in range(max(times.x, times.y)):
sprite.copy_from(scale_3x(sprite))
sprite.resize(width, height, 0)
elif interpolation == 6: # cleanEdge
var params := {"angle": 0, "slope": true, "cleanup": true, "preview": false}
var gen := ShaderImageEffect.new()
gen.generate_image(sprite, clean_edge_shader, params, Vector2(width, height))
else:
sprite.resize(width, height, interpolation)
Global.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
Expand Down
Loading

0 comments on commit 222e7a1

Please sign in to comment.