mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +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="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_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
|
||||
|
|
|
@ -87,3 +87,33 @@ func import_gpl(path : String) -> Palette:
|
|||
file.close()
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
if index < colors.size():
|
||||
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)
|
||||
elif path.to_lower().ends_with("gpl"):
|
||||
palette = Import.import_gpl(path)
|
||||
elif path.to_lower().ends_with("png"):
|
||||
palette = Import.import_png_palette(path)
|
||||
|
||||
if palette:
|
||||
if not Global.palettes.has(palette.name):
|
||||
|
|
Loading…
Reference in a new issue