mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Add PAL palette format import (#315)
* Add PAL palette format import * Move .pal selection into Dialog; Attempt HTML implementation * Fix issue with HTML5 pal palette import.
This commit is contained in:
parent
f121c39ddc
commit
348d758ef4
|
@ -47,7 +47,7 @@ func _define_js() -> void:
|
|||
canceled = true;
|
||||
var input = document.createElement('INPUT');
|
||||
input.setAttribute("type", "file");
|
||||
input.setAttribute("accept", "application/json, .gpl, image/png, image/jpeg, image/webp");
|
||||
input.setAttribute("accept", "application/json, .gpl, .pal, image/png, image/jpeg, image/webp");
|
||||
input.click();
|
||||
input.addEventListener('change', event => {
|
||||
if (event.target.files.length > 0){
|
||||
|
@ -173,6 +173,10 @@ func load_palette() -> void:
|
|||
var palette := Palette.new()
|
||||
palette = Import.import_gpl(file_name, palette_data)
|
||||
Global.palette_container.attempt_to_import_palette(palette)
|
||||
elif file_name.ends_with(".pal"):
|
||||
var palette := Palette.new()
|
||||
palette = Import.import_pal_palette(file_name, palette_data)
|
||||
Global.palette_container.attempt_to_import_palette(palette)
|
||||
else:
|
||||
match file_type:
|
||||
"image/png":
|
||||
|
|
|
@ -294,3 +294,28 @@ func import_png_palette(path: String, image : Image) -> Palette:
|
|||
result.name = path.get_basename().get_file()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func import_pal_palette(path : String, text : String) -> Palette:
|
||||
var result: Palette = null
|
||||
|
||||
var lines = text.split('\n')
|
||||
|
||||
if not 'JASC-PAL' in lines[0] or not '0100' in lines[1]:
|
||||
return result
|
||||
else:
|
||||
result = Palette.new()
|
||||
result.name = path.get_basename().get_file()
|
||||
|
||||
var num_colors = int(lines[2])
|
||||
|
||||
for i in range(3, num_colors + 3):
|
||||
var color_data = lines[i].split(' ')
|
||||
var red : float = color_data[0].to_float() / 255.0
|
||||
var green : float = color_data[1].to_float() / 255.0
|
||||
var blue : float = color_data[2].to_float() / 255.0
|
||||
|
||||
var color = Color(red, green, blue)
|
||||
result.add_color(color)
|
||||
|
||||
return result
|
||||
|
|
|
@ -58,6 +58,13 @@ func on_palette_import_file_selected(path : String) -> void:
|
|||
var text = file.get_as_text()
|
||||
file.close()
|
||||
palette = Import.import_gpl(path, text)
|
||||
elif path.to_lower().ends_with("pal"):
|
||||
var file = File.new()
|
||||
if file.file_exists(path):
|
||||
file.open(path, File.READ)
|
||||
var text = file.get_as_text()
|
||||
file.close()
|
||||
palette = Import.import_pal_palette(path, text)
|
||||
elif path.to_lower().ends_with("png") or path.to_lower().ends_with("bmp") or path.to_lower().ends_with("hdr") or path.to_lower().ends_with("jpg") or path.to_lower().ends_with("svg") or path.to_lower().ends_with("tga") or path.to_lower().ends_with("webp"):
|
||||
var image := Image.new()
|
||||
var err := image.load(path)
|
||||
|
|
|
@ -10,6 +10,6 @@ window_title = "Open a File"
|
|||
resizable = true
|
||||
mode = 0
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics" )
|
||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics", "*.pal; JASC Palette" )
|
||||
current_dir = "/Users"
|
||||
current_path = "/Users/"
|
||||
|
|
Loading…
Reference in a new issue