1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Optimize non-shader rotation by clearing non-selected pixels with masking

This commit is contained in:
Emmanouil Papadeas 2024-05-09 01:36:11 +03:00
parent e15b207993
commit 4ec7259c63

View file

@ -77,25 +77,26 @@ func _calculate_pivot() -> void:
_on_Pivot_value_changed(pivot) _on_Pivot_value_changed(pivot)
func commit_action(cel: Image, _project := Global.current_project) -> void: func commit_action(cel: Image, project := Global.current_project) -> void:
var angle := deg_to_rad(animate_panel.get_animated_value(commit_idx, Animate.ANGLE)) var angle := deg_to_rad(animate_panel.get_animated_value(commit_idx, Animate.ANGLE))
var init_angle := deg_to_rad(animate_panel.get_animated_value(commit_idx, Animate.INIT_ANGLE)) var init_angle := deg_to_rad(animate_panel.get_animated_value(commit_idx, Animate.INIT_ANGLE))
var selection_tex: ImageTexture var selection_tex: ImageTexture
var image := Image.new() var image := Image.new()
image.copy_from(cel) image.copy_from(cel)
if _project.has_selection and selection_checkbox.button_pressed: if project.has_selection and selection_checkbox.button_pressed:
var selection := _project.selection_map.return_cropped_copy(_project.size) var selection := project.selection_map.return_cropped_copy(project.size)
selection_tex = ImageTexture.create_from_image(selection) selection_tex = ImageTexture.create_from_image(selection)
if !_type_is_shader(): if !_type_is_shader():
for x in _project.size.x: var blank := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
for y in _project.size.y: cel.blit_rect_mask(
var pos := Vector2i(x, y) blank, selection, Rect2i(Vector2i.ZERO, cel.get_size()), Vector2i.ZERO
if !_project.can_pixel_get_drawn(pos): )
image.set_pixelv(pos, Color(0, 0, 0, 0)) selection.invert()
else: image.blit_rect_mask(
cel.set_pixelv(pos, Color(0, 0, 0, 0)) blank, selection, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO
)
if _type_is_shader(): if _type_is_shader():
var shader := rotxel_shader var shader := rotxel_shader
var params := { var params := {
@ -121,7 +122,7 @@ func commit_action(cel: Image, _project := Global.current_project) -> void:
else: else:
params["preview"] = false params["preview"] = false
var gen := ShaderImageEffect.new() var gen := ShaderImageEffect.new()
gen.generate_image(cel, shader, params, _project.size) gen.generate_image(cel, shader, params, project.size)
else: else:
match type_option_button.get_selected_id(): match type_option_button.get_selected_id():
ROTXEL: ROTXEL:
@ -131,7 +132,7 @@ func commit_action(cel: Image, _project := Global.current_project) -> void:
URD: URD:
DrawingAlgos.fake_rotsprite(image, angle, pivot) DrawingAlgos.fake_rotsprite(image, angle, pivot)
if _project.has_selection and selection_checkbox.button_pressed: if project.has_selection and selection_checkbox.button_pressed:
cel.blend_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO) cel.blend_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO)
else: else:
cel.blit_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO) cel.blit_rect(image, Rect2i(Vector2i.ZERO, image.get_size()), Vector2i.ZERO)