mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Add palette import from a PNG file
This commit is contained in:
parent
b3a8eb6d84
commit
3b16b727b9
|
@ -1478,7 +1478,7 @@ visible = false
|
||||||
[node name="NewPaletteDialog" parent="." instance=ExtResource( 52 )]
|
[node name="NewPaletteDialog" parent="." instance=ExtResource( 52 )]
|
||||||
|
|
||||||
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 53 )]
|
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 53 )]
|
||||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" )
|
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics" )
|
||||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||||
|
|
||||||
|
|
|
@ -87,3 +87,33 @@ func import_gpl(path : String) -> Palette:
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
func import_png_palette(path: String) -> Palette:
|
||||||
|
var result: Palette = null
|
||||||
|
|
||||||
|
var image := Image.new()
|
||||||
|
var err := image.load(path)
|
||||||
|
if err != OK: # An error occured
|
||||||
|
return null
|
||||||
|
|
||||||
|
var height: int = image.get_height()
|
||||||
|
var width: int = image.get_width()
|
||||||
|
|
||||||
|
result = Palette.new()
|
||||||
|
|
||||||
|
# Iterate all pixels and store unique colors to palete
|
||||||
|
image.lock()
|
||||||
|
for y in range(0, height):
|
||||||
|
for x in range(0, width):
|
||||||
|
var color: Color = image.get_pixel(x, y)
|
||||||
|
if not result.has_color(color):
|
||||||
|
result.add_color(color, "#" + color.to_html())
|
||||||
|
image.unlock()
|
||||||
|
|
||||||
|
var name_start = path.find_last('/') + 1
|
||||||
|
var name_end = path.find_last('.')
|
||||||
|
if name_end > name_start:
|
||||||
|
result.name = path.substr(name_start, name_end - name_start)
|
||||||
|
|
||||||
|
return result
|
||||||
|
pass
|
||||||
|
|
|
@ -50,6 +50,12 @@ func get_color_data(index : int) -> String:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
func has_color(color: Color) -> bool:
|
||||||
|
for palette_color in colors:
|
||||||
|
if palette_color.color == color:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
func set_color_data(index : int, new_color : String) -> void:
|
func set_color_data(index : int, new_color : String) -> void:
|
||||||
if index < colors.size():
|
if index < colors.size():
|
||||||
colors[index].data = new_color
|
colors[index].data = new_color
|
||||||
|
|
|
@ -43,6 +43,8 @@ func on_palette_import_file_selected(path : String) -> void:
|
||||||
palette = Palette.new().load_from_file(path)
|
palette = Palette.new().load_from_file(path)
|
||||||
elif path.to_lower().ends_with("gpl"):
|
elif path.to_lower().ends_with("gpl"):
|
||||||
palette = Import.import_gpl(path)
|
palette = Import.import_gpl(path)
|
||||||
|
elif path.to_lower().ends_with("png"):
|
||||||
|
palette = Import.import_png_palette(path)
|
||||||
|
|
||||||
if palette:
|
if palette:
|
||||||
if not Global.palettes.has(palette.name):
|
if not Global.palettes.has(palette.name):
|
||||||
|
|
Loading…
Reference in a new issue