1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Add a crop_image boolean parameter to Palette.convert_to_image()

Fixes some issues with the Palettize effect where the output would be different if the palette size changed and empty swatches were added, even if the colors themselves stayed the same.
This commit is contained in:
Emmanouil Papadeas 2024-11-22 17:56:39 +02:00
parent 996a234d0d
commit bd7d3b19cc
2 changed files with 6 additions and 4 deletions

View file

@ -84,7 +84,7 @@ func update_palette() -> void:
func convert_indexed_to_rgb() -> void:
if not is_indexed:
return
var palette_image := Palettes.current_palette.convert_to_image()
var palette_image := Palettes.current_palette.convert_to_image(false)
var palette_texture := ImageTexture.create_from_image(palette_image)
var shader_image_effect := ShaderImageEffect.new()
var indices_texture := ImageTexture.create_from_image(indices_image)
@ -98,7 +98,7 @@ func convert_indexed_to_rgb() -> void:
func convert_rgb_to_indexed() -> void:
if not is_indexed:
return
var palette_image := Palettes.current_palette.convert_to_image()
var palette_image := Palettes.current_palette.convert_to_image(false)
var palette_texture := ImageTexture.create_from_image(palette_image)
var params := {
"palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self)

View file

@ -25,7 +25,7 @@ var colors_max := 0
class PaletteColor:
var color := Color.TRANSPARENT
var color := Color(0, 0, 0, 0)
var index := -1
func _init(init_color := Color.BLACK, init_index := -1) -> void:
@ -358,9 +358,11 @@ static func strip_unvalid_characters(string_to_strip: String) -> String:
return regex.sub(string_to_strip, "", true)
func convert_to_image() -> Image:
func convert_to_image(crop_image := true) -> Image:
var image := Image.create(colors_max, 1, false, Image.FORMAT_RGBA8)
for i in colors_max:
if colors.has(i):
image.set_pixel(i, 0, Color(colors[i].color.to_html()))
if crop_image:
image.copy_from(image.get_region(image.get_used_rect()))
return image