mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Fix palette importing not including all colors if they have more than 64 colors
This commit is contained in:
parent
791e966a71
commit
79b37a95b3
|
@ -445,30 +445,27 @@ func import_gpl(path: String, text: String) -> Palette:
|
|||
var result : Palette = null
|
||||
var lines = text.split('\n')
|
||||
var line_number := 0
|
||||
var palette_name := path.get_basename().get_file()
|
||||
var comments := ""
|
||||
var colors := PoolColorArray()
|
||||
|
||||
for line in lines:
|
||||
# Check if valid Gimp Palette Library file
|
||||
if line_number == 0:
|
||||
if not "GIMP Palette" in line:
|
||||
break
|
||||
else:
|
||||
# Use filename as palette name in case reading old
|
||||
# palette format (must read more to determine)
|
||||
result = Palette.new(path.get_basename().get_file())
|
||||
return result
|
||||
|
||||
# Comments
|
||||
if line.begins_with('#'):
|
||||
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
|
||||
palette_name = line.replace("#Palette Name: ", "")
|
||||
elif line.begins_with("Name: "):
|
||||
result.name = line.replace("Name: ", "")
|
||||
pass
|
||||
palette_name = line.replace("Name: ", "")
|
||||
elif line.begins_with("Columns: "):
|
||||
# Number of colors in this palette. Unecessary and often wrong
|
||||
pass
|
||||
continue
|
||||
elif line_number > 0 && line.length() >= 9:
|
||||
line = line.replace("\t", " ")
|
||||
var color_data : PoolStringArray = line.split(" ", false, 4)
|
||||
|
@ -478,27 +475,28 @@ func import_gpl(path: String, text: String) -> Palette:
|
|||
var color = Color(red, green, blue)
|
||||
if color_data.size() >= 4:
|
||||
# Ignore color name for now - result.add_color(color, color_data[3])
|
||||
result.add_color(color)
|
||||
colors.append(color)
|
||||
#
|
||||
else:
|
||||
result.add_color(color)
|
||||
colors.append(color)
|
||||
line_number += 1
|
||||
|
||||
if result:
|
||||
result.comment = comments
|
||||
if line_number > 0:
|
||||
var height : int = ceil(colors.size() / 8.0)
|
||||
result = Palette.new(palette_name, 8, height, comments)
|
||||
for color in colors:
|
||||
result.add_color(color)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func import_pal_palette(path: String, text: String) -> Palette:
|
||||
var result: Palette = null
|
||||
|
||||
var colors := PoolColorArray()
|
||||
var lines = text.split('\n')
|
||||
|
||||
if not 'JASC-PAL' in lines[0] or not '0100' in lines[1]:
|
||||
return result
|
||||
else:
|
||||
result = Palette.new(path.get_basename().get_file())
|
||||
|
||||
var num_colors = int(lines[2])
|
||||
|
||||
|
@ -509,14 +507,18 @@ func import_pal_palette(path: String, text: String) -> Palette:
|
|||
var blue : float = color_data[2].to_float() / 255.0
|
||||
|
||||
var color = Color(red, green, blue)
|
||||
result.add_color(color)
|
||||
colors.append(color)
|
||||
|
||||
var height : int = ceil(colors.size() / 8.0)
|
||||
result = Palette.new(path.get_basename().get_file(), 8, height)
|
||||
for color in colors:
|
||||
result.add_color(color)
|
||||
return result
|
||||
|
||||
|
||||
func import_image_palette(path: String, image: Image) -> Palette:
|
||||
var result: Palette = Palette.new(path.get_basename().get_file())
|
||||
|
||||
var colors := []
|
||||
var height: int = image.get_height()
|
||||
var width: int = image.get_width()
|
||||
|
||||
|
@ -525,10 +527,15 @@ func import_image_palette(path: String, image: Image) -> Palette:
|
|||
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)
|
||||
if !colors.has(color):
|
||||
colors.append(color)
|
||||
image.unlock()
|
||||
|
||||
var palette_height : int = ceil(colors.size() / 8.0)
|
||||
var result: Palette = Palette.new(path.get_basename().get_file(), 8, palette_height)
|
||||
for color in colors:
|
||||
result.add_color(color)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ margin_right = 324.0
|
|||
margin_bottom = 319.0
|
||||
rect_min_size = Vector2( 300, 0 )
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 8 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
@ -25,7 +24,6 @@ margin_top = 7.0
|
|||
margin_right = 317.0
|
||||
margin_bottom = 312.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="PalettesLabel" type="Label" parent="PaletteVBoxContainer"]
|
||||
margin_right = 310.0
|
||||
|
@ -116,13 +114,12 @@ margin_bottom = 48.0
|
|||
[node name="SwatchesContainer" type="HBoxContainer" parent="PaletteVBoxContainer"]
|
||||
margin_top = 52.0
|
||||
margin_right = 310.0
|
||||
margin_bottom = 305.0
|
||||
margin_bottom = 104.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ColorButtons" type="VBoxContainer" parent="PaletteVBoxContainer/SwatchesContainer"]
|
||||
margin_right = 24.0
|
||||
margin_bottom = 253.0
|
||||
margin_bottom = 52.0
|
||||
|
||||
[node name="AddColor" type="Button" parent="PaletteVBoxContainer/SwatchesContainer/ColorButtons"]
|
||||
margin_right = 24.0
|
||||
|
@ -144,9 +141,8 @@ text = "-"
|
|||
[node name="PaletteScroll" type="VBoxContainer" parent="PaletteVBoxContainer/SwatchesContainer"]
|
||||
margin_left = 28.0
|
||||
margin_right = 310.0
|
||||
margin_bottom = 253.0
|
||||
margin_bottom = 52.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="PaletteVBoxContainer/SwatchesContainer/PaletteScroll"]
|
||||
|
@ -162,7 +158,6 @@ margin_left = 141.0
|
|||
margin_right = 141.0
|
||||
|
||||
[node name="PaletteGrid" type="GridContainer" parent="PaletteVBoxContainer/SwatchesContainer/PaletteScroll/HBoxContainer/CenterContainer/HBoxContainer"]
|
||||
rect_pivot_offset = Vector2( -123.214, 138.568 )
|
||||
columns = 8
|
||||
script = ExtResource( 5 )
|
||||
|
||||
|
|
|
@ -1180,11 +1180,11 @@ size_flags_vertical = 3
|
|||
custom_constants/autohide = 0
|
||||
|
||||
[node name="ColorAndToolOptions" parent="RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit" instance=ExtResource( 17 )]
|
||||
margin_bottom = 248.0
|
||||
margin_bottom = 378.0
|
||||
|
||||
[node name="PalettePanel" parent="RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit" instance=ExtResource( 20 )]
|
||||
margin_left = 15.0
|
||||
margin_top = 260.0
|
||||
margin_top = 390.0
|
||||
margin_right = 315.0
|
||||
margin_bottom = 508.0
|
||||
|
||||
|
|
Loading…
Reference in a new issue