mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +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,45 +454,37 @@ func generate_outline(image : Image, outline_color : Color, thickness : int, dia
|
|||
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()
|
||||
for i in Global.current_project.selected_pixels:
|
||||
var c : Color = img.get_pixelv(i)
|
||||
# Hue
|
||||
var hue = range_lerp(c.h,0,1,-180,180)
|
||||
hue = hue + delta_h
|
||||
|
||||
match id:
|
||||
0: # Hue
|
||||
for i in Global.current_project.selected_pixels:
|
||||
var c : Color = img.get_pixelv(i)
|
||||
var hue = range_lerp(c.h,0,1,-180,180)
|
||||
hue = hue + delta
|
||||
while(hue >= 180):
|
||||
hue -= 360
|
||||
while(hue < -180):
|
||||
hue += 360
|
||||
|
||||
while(hue >= 180):
|
||||
hue -= 360
|
||||
while(hue < -180):
|
||||
hue += 360
|
||||
c.h = range_lerp(hue,-180,180,0,1)
|
||||
img.set_pixelv(i,c)
|
||||
# Saturation
|
||||
var sat = c.s
|
||||
if delta_s > 0:
|
||||
sat = range_lerp(delta_s,0,100,c.s,1)
|
||||
elif delta_s < 0:
|
||||
sat = range_lerp(delta_s,-100,0,0,c.s)
|
||||
|
||||
1: # Saturation
|
||||
for i in Global.current_project.selected_pixels:
|
||||
var c : Color = img.get_pixelv(i)
|
||||
var sat = c.s
|
||||
if delta > 0:
|
||||
sat = range_lerp(delta,0,100,c.s,1)
|
||||
elif delta < 0:
|
||||
sat = range_lerp(delta,-100,0,0,c.s)
|
||||
c.s = sat
|
||||
img.set_pixelv(i,c)
|
||||
# Value
|
||||
var val = c.v
|
||||
if delta_v > 0:
|
||||
val = range_lerp(delta_v,0,100,c.v,1)
|
||||
elif delta_v < 0:
|
||||
val = range_lerp(delta_v,-100,0,0,c.v)
|
||||
|
||||
2: # Value
|
||||
for i in Global.current_project.selected_pixels:
|
||||
var c : Color = img.get_pixelv(i)
|
||||
var val = c.v
|
||||
if delta > 0:
|
||||
val = range_lerp(delta,0,100,c.v,1)
|
||||
elif delta < 0:
|
||||
val = range_lerp(delta,-100,0,0,c.v)
|
||||
|
||||
c.v = val
|
||||
img.set_pixelv(i,c)
|
||||
c.h = range_lerp(hue,-180,180,0,1)
|
||||
c.s = sat
|
||||
c.v = val
|
||||
img.set_pixelv(i,c)
|
||||
|
||||
img.unlock()
|
||||
|
||||
|
|
|
@ -35,9 +35,7 @@ func _on_Cancel_pressed() -> void:
|
|||
|
||||
func _on_Apply_pressed() -> void:
|
||||
Global.canvas.handle_undo("Draw")
|
||||
DrawingAlgos.adjust_hsv(current_cel,0,hue_slider.value)
|
||||
DrawingAlgos.adjust_hsv(current_cel,1,sat_slider.value)
|
||||
DrawingAlgos.adjust_hsv(current_cel,2,val_slider.value)
|
||||
DrawingAlgos.adjust_hsv(current_cel, hue_slider.value, sat_slider.value, val_slider.value)
|
||||
Global.canvas.update_texture(Global.current_project.current_layer)
|
||||
Global.canvas.handle_redo("Draw")
|
||||
reset()
|
||||
|
@ -57,9 +55,7 @@ func reset() -> void:
|
|||
|
||||
func update_preview() -> void:
|
||||
preview_image.copy_from(current_cel)
|
||||
DrawingAlgos.adjust_hsv(preview_image,0,hue_slider.value)
|
||||
DrawingAlgos.adjust_hsv(preview_image,1,sat_slider.value)
|
||||
DrawingAlgos.adjust_hsv(preview_image,2,val_slider.value)
|
||||
DrawingAlgos.adjust_hsv(preview_image, hue_slider.value, sat_slider.value, val_slider.value)
|
||||
preview_texture.create_from_image(preview_image, 0)
|
||||
preview.texture = preview_texture
|
||||
|
||||
|
|
Loading…
Reference in a new issue