From efc0c1cc7219113c9b9fa000b76d6ec2f9592d91 Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Sat, 11 Oct 2025 08:07:43 +0200 Subject: [PATCH] Improve handling of supported image formats and file extensions, Update README with more information about supported formats --- README.md | 9 +++++++++ src/Filesystem.gd | 22 ++++++++++++++++------ src/Main.gd | 6 +----- src/MainUI.gd | 7 +++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 56781b6..72516e2 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,15 @@ You can find the latest release ... - [here (remotebranch.eu)](https://remotebranch.eu/ChaoticByte/Pigment/releases/latest) +## Supported Image Formats + +| Format | Import | Export | Notes | +| ------ | :----: | :----: | ----- | +| PNG | ✔ | ✔ | exports to 8-bit RGBA | +| JPEG | ✔ | | | +| WEBP | ✔ | | | + + ## Usage With Pigment, you process images by writing Shader code using Godot's GLSL dialect: GDShader. diff --git a/src/Filesystem.gd b/src/Filesystem.gd index 72aca06..f6f1d9e 100644 --- a/src/Filesystem.gd +++ b/src/Filesystem.gd @@ -1,5 +1,9 @@ extends Node +const SUPPORTED_INPUT_EXT = [ + ".jpeg", ".jpg", ".png", ".webp" +] + var cwd = "." var shader_path = "": @@ -31,16 +35,22 @@ func get_absolute_path(p: String) -> String: return p func load_image() -> String: # returns an error message - print("Load ", input_image_path) + var supported = false + for e in SUPPORTED_INPUT_EXT: + if self.input_image_path.ends_with(e): + supported = true + if not supported: + return "File extension not supported." + print("Load ", self.input_image_path) var img = Image.new() - var err = img.load(input_image_path) + var err = img.load(self.input_image_path) if err == OK: input_image_texture = ImageTexture.create_from_image(img) - if self.last_image_savepath == "" or input_image_path != self.last_input_image_path: - self.last_image_savepath = input_image_path - self.last_input_image_path = input_image_path + if self.last_image_savepath == "" or self.input_image_path != self.last_input_image_path: + self.last_image_savepath = self.input_image_path + self.last_input_image_path = self.input_image_path return "" - return error_string(err) + " " + input_image_path + return error_string(err) + " " + self.input_image_path func save_result(path: String): print("Export ", path) diff --git a/src/Main.gd b/src/Main.gd index 0e2cff0..ef3cbe7 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -1,9 +1,5 @@ extends Node -const BATCH_MODE_SUPPORTED_EXTS = [ - ".bmp", ".dds", ".exr", ".hdr", ".jpeg", ".jpg", ".ktx", ".png", ".svg", ".webp" -] - @onready var app_name = ProjectSettings.get_setting("application/config/name") func show_help(): @@ -75,7 +71,7 @@ func cli(args: PackedStringArray): var out_dir_path: String = kwargs["--output"].rstrip("/") for f in load_image_dir.get_files(): var supported = false - for e in BATCH_MODE_SUPPORTED_EXTS: + for e in Filesystem.SUPPORTED_INPUT_EXT: if f.ends_with(e): supported = true break diff --git a/src/MainUI.gd b/src/MainUI.gd index f2c817c..4de65b1 100644 --- a/src/MainUI.gd +++ b/src/MainUI.gd @@ -26,7 +26,7 @@ enum Status {OKAY, ERROR, UNKNOWN = -1} func _ready() -> void: var exts = [] - for e in main.BATCH_MODE_SUPPORTED_EXTS: + for e in Filesystem.SUPPORTED_INPUT_EXT: exts.append("*" + e) open_image_dialog.add_filter(", ".join(exts), "Image") open_shader_dialog.add_filter("*.gdshader", "Shader") @@ -74,7 +74,10 @@ func _on_apply_shader_button_pressed(): func _on_save_image_button_pressed(): if Filesystem.result != null: set_buttons_disabled(true) - save_image_dialog.current_path = Filesystem.last_image_savepath + var p = Filesystem.last_image_savepath + for ext in Filesystem.SUPPORTED_INPUT_EXT: + p = p.trim_suffix(ext) + save_image_dialog.current_path = p + ".png" save_image_dialog.show() #