Replaced the _min and _max Project variables with Project.selected_pixels

This will allow us to create more selection tools in the future, that aren't necessarily rectangular (See #129) and even enhance the current rectangle selection tool (See #56)

Current issues spotted so far:
Drawing is slower for large images, and bucket filling is also considerably slower even on a 64x64 image. Optimizations are required.
This commit is contained in:
OverloadedOrama 2020-07-20 22:15:34 +03:00
parent 8c965c1858
commit 0f82be765e
10 changed files with 108 additions and 80 deletions

View file

@ -455,51 +455,44 @@ func generate_outline(image : Image, outline_color : Color, thickness : int, dia
func adjust_hsv(img: Image, id : int, delta : float) -> void:
var x_min = Global.current_project.x_min
var x_max = Global.current_project.x_max
var y_min = Global.current_project.y_min
var y_max = Global.current_project.y_max
img.lock()
match id:
0: # Hue
for i in range(x_min, x_max):
for j in range(y_min, y_max):
var c : Color = img.get_pixel(i,j)
var hue = range_lerp(c.h,0,1,-180,180)
hue = hue + delta
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
c.h = range_lerp(hue,-180,180,0,1)
img.set_pixel(i,j,c)
while(hue >= 180):
hue -= 360
while(hue < -180):
hue += 360
c.h = range_lerp(hue,-180,180,0,1)
img.set_pixelv(i,c)
1: # Saturation
for i in range(x_min, x_max):
for j in range(y_min, y_max):
var c : Color = img.get_pixel(i,j)
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_pixel(i,j,c)
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)
2: # Value
for i in range(x_min, x_max):
for j in range(y_min, y_max):
var c : Color = img.get_pixel(i,j)
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)
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_pixel(i,j,c)
c.v = val
img.set_pixelv(i,c)
img.unlock()

View file

@ -322,10 +322,9 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
func open_image_as_new_tab(path : String, image : Image) -> void:
var project = Project.new([], path.get_file())
var project = Project.new([], path.get_file(), image.get_size())
project.layers.append(Layer.new())
Global.projects.append(project)
project.size = image.get_size()
var frame := Frame.new()
image.convert(Image.FORMAT_RGBA8)