mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Refactored adjust_hsv to be 3 times faster
adjust_hsv() now gets executed once instead of thrice. The results should be the same.
This commit is contained in:
parent
46717692ef
commit
af915caf7a
|
@ -454,43 +454,35 @@ func generate_outline(image : Image, outline_color : Color, thickness : int, dia
|
||||||
Global.canvas.handle_redo("Draw")
|
Global.canvas.handle_redo("Draw")
|
||||||
|
|
||||||
|
|
||||||
func adjust_hsv(img: Image, id : int, delta : float) -> void:
|
func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float) -> void:
|
||||||
img.lock()
|
img.lock()
|
||||||
|
|
||||||
match id:
|
|
||||||
0: # Hue
|
|
||||||
for i in Global.current_project.selected_pixels:
|
for i in Global.current_project.selected_pixels:
|
||||||
var c : Color = img.get_pixelv(i)
|
var c : Color = img.get_pixelv(i)
|
||||||
|
# Hue
|
||||||
var hue = range_lerp(c.h,0,1,-180,180)
|
var hue = range_lerp(c.h,0,1,-180,180)
|
||||||
hue = hue + delta
|
hue = hue + delta_h
|
||||||
|
|
||||||
while(hue >= 180):
|
while(hue >= 180):
|
||||||
hue -= 360
|
hue -= 360
|
||||||
while(hue < -180):
|
while(hue < -180):
|
||||||
hue += 360
|
hue += 360
|
||||||
c.h = range_lerp(hue,-180,180,0,1)
|
|
||||||
img.set_pixelv(i,c)
|
|
||||||
|
|
||||||
1: # Saturation
|
# Saturation
|
||||||
for i in Global.current_project.selected_pixels:
|
|
||||||
var c : Color = img.get_pixelv(i)
|
|
||||||
var sat = c.s
|
var sat = c.s
|
||||||
if delta > 0:
|
if delta_s > 0:
|
||||||
sat = range_lerp(delta,0,100,c.s,1)
|
sat = range_lerp(delta_s,0,100,c.s,1)
|
||||||
elif delta < 0:
|
elif delta_s < 0:
|
||||||
sat = range_lerp(delta,-100,0,0,c.s)
|
sat = range_lerp(delta_s,-100,0,0,c.s)
|
||||||
c.s = sat
|
|
||||||
img.set_pixelv(i,c)
|
|
||||||
|
|
||||||
2: # Value
|
# Value
|
||||||
for i in Global.current_project.selected_pixels:
|
|
||||||
var c : Color = img.get_pixelv(i)
|
|
||||||
var val = c.v
|
var val = c.v
|
||||||
if delta > 0:
|
if delta_v > 0:
|
||||||
val = range_lerp(delta,0,100,c.v,1)
|
val = range_lerp(delta_v,0,100,c.v,1)
|
||||||
elif delta < 0:
|
elif delta_v < 0:
|
||||||
val = range_lerp(delta,-100,0,0,c.v)
|
val = range_lerp(delta_v,-100,0,0,c.v)
|
||||||
|
|
||||||
|
c.h = range_lerp(hue,-180,180,0,1)
|
||||||
|
c.s = sat
|
||||||
c.v = val
|
c.v = val
|
||||||
img.set_pixelv(i,c)
|
img.set_pixelv(i,c)
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,7 @@ func _on_Cancel_pressed() -> void:
|
||||||
|
|
||||||
func _on_Apply_pressed() -> void:
|
func _on_Apply_pressed() -> void:
|
||||||
Global.canvas.handle_undo("Draw")
|
Global.canvas.handle_undo("Draw")
|
||||||
DrawingAlgos.adjust_hsv(current_cel,0,hue_slider.value)
|
DrawingAlgos.adjust_hsv(current_cel, hue_slider.value, sat_slider.value, val_slider.value)
|
||||||
DrawingAlgos.adjust_hsv(current_cel,1,sat_slider.value)
|
|
||||||
DrawingAlgos.adjust_hsv(current_cel,2,val_slider.value)
|
|
||||||
Global.canvas.update_texture(Global.current_project.current_layer)
|
Global.canvas.update_texture(Global.current_project.current_layer)
|
||||||
Global.canvas.handle_redo("Draw")
|
Global.canvas.handle_redo("Draw")
|
||||||
reset()
|
reset()
|
||||||
|
@ -57,9 +55,7 @@ func reset() -> void:
|
||||||
|
|
||||||
func update_preview() -> void:
|
func update_preview() -> void:
|
||||||
preview_image.copy_from(current_cel)
|
preview_image.copy_from(current_cel)
|
||||||
DrawingAlgos.adjust_hsv(preview_image,0,hue_slider.value)
|
DrawingAlgos.adjust_hsv(preview_image, hue_slider.value, sat_slider.value, val_slider.value)
|
||||||
DrawingAlgos.adjust_hsv(preview_image,1,sat_slider.value)
|
|
||||||
DrawingAlgos.adjust_hsv(preview_image,2,val_slider.value)
|
|
||||||
preview_texture.create_from_image(preview_image, 0)
|
preview_texture.create_from_image(preview_image, 0)
|
||||||
preview.texture = preview_texture
|
preview.texture = preview_texture
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue