mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Gimp palette import fixes. Support for newer format, and support for unnamed colours (#250)
This commit is contained in:
parent
9a1f5bf5b8
commit
145e3de7c4
|
@ -265,6 +265,7 @@ func import_patterns(priority_ordered_search_path: Array) -> void:
|
||||||
|
|
||||||
|
|
||||||
func import_gpl(path : String) -> Palette:
|
func import_gpl(path : String) -> Palette:
|
||||||
|
# Refer to app/core/gimppalette-load.c of the GIMP for the "living spec"
|
||||||
var result : Palette = null
|
var result : Palette = null
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
if file.file_exists(path):
|
if file.file_exists(path):
|
||||||
|
@ -280,6 +281,8 @@ func import_gpl(path : String) -> Palette:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
result = Palette.new()
|
result = Palette.new()
|
||||||
|
# Use filename as palette name in case reading old
|
||||||
|
# palette format (must read more to determine)
|
||||||
var name_start = path.find_last('/') + 1
|
var name_start = path.find_last('/') + 1
|
||||||
var name_end = path.find_last('.')
|
var name_end = path.find_last('.')
|
||||||
if name_end > name_start:
|
if name_end > name_start:
|
||||||
|
@ -288,15 +291,27 @@ func import_gpl(path : String) -> Palette:
|
||||||
# Comments
|
# Comments
|
||||||
if line.begins_with('#'):
|
if line.begins_with('#'):
|
||||||
comments += line.trim_prefix('#') + '\n'
|
comments += line.trim_prefix('#') + '\n'
|
||||||
|
# Some programs output palette name in a comment for old format
|
||||||
|
if line.begins_with("#Palette Name: "):
|
||||||
|
result.name = line.replace("#Palette Name: ", "")
|
||||||
pass
|
pass
|
||||||
elif line_number > 0 && line.length() >= 12:
|
elif line.begins_with("Name: "):
|
||||||
|
result.name = line.replace("Name: ", "")
|
||||||
|
pass
|
||||||
|
elif line.begins_with("Columns: "):
|
||||||
|
# Number of colors in this palette. Unecessary and often wrong
|
||||||
|
pass
|
||||||
|
elif line_number > 0 && line.length() >= 9:
|
||||||
line = line.replace("\t", " ")
|
line = line.replace("\t", " ")
|
||||||
var color_data : PoolStringArray = line.split(" ", false, 4)
|
var color_data : PoolStringArray = line.split(" ", false, 4)
|
||||||
var red : float = color_data[0].to_float() / 255.0
|
var red : float = color_data[0].to_float() / 255.0
|
||||||
var green : float = color_data[1].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 blue : float = color_data[2].to_float() / 255.0
|
||||||
var color = Color(red, green, blue)
|
var color = Color(red, green, blue)
|
||||||
|
if color_data.size() >= 4:
|
||||||
result.add_color(color, color_data[3])
|
result.add_color(color, color_data[3])
|
||||||
|
else:
|
||||||
|
result.add_color(color)
|
||||||
line_number += 1
|
line_number += 1
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
|
|
Loading…
Reference in a new issue