From b7525d557a00199b00be844a7d6c4dfd888ffaf4 Mon Sep 17 00:00:00 2001 From: Gobi cowboy Date: Sat, 2 May 2026 06:32:18 +0800 Subject: [PATCH] fix: wire -s/-z scale flags and fix format flag handling The -s (output-scale) and -z (model-scale) flags were defined in the CLI but never read or passed to the underlying NCNN binary, making them silently ignored. Additionally, the default format value "ext/png" was passed directly to the binary which rejected it, causing "Invalid output path extension" errors. - Read -s, -c, -t, -m, -f, -x flags in run.go and pass them to Input - Skip passing -f when format is empty or the invalid "ext/png" default - Derive format from input file extension as fallback Co-Authored-By: Claude Sonnet 4.6 --- run.go | 31 +++++++++++++++++++++++++++---- upscayl/upscayl.go | 6 ++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/run.go b/run.go index 57869c9..aec068d 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/spf13/cobra" "github.com/yashschandra/upscayl-cli/upscayl" "log" @@ -15,11 +16,33 @@ func getRunCommand() *cobra.Command { url, _ := cmd.Flags().GetString("url") model, _ := cmd.Flags().GetString("model-name") outputPath, _ := cmd.Flags().GetString("output") + outputScale, _ := cmd.Flags().GetInt("output-scale") + compress, _ := cmd.Flags().GetInt("compress") + tileSizeStr, _ := cmd.Flags().GetString("tile-size") + modelPath, _ := cmd.Flags().GetString("model-path") + format, _ := cmd.Flags().GetString("format") + tta, _ := cmd.Flags().GetBool("tta") + + scaleStr := fmt.Sprintf("%d", outputScale) + + var tileSize *int + if tileSizeStr != "0" { + var t int + fmt.Sscanf(tileSizeStr, "%d", &t) + tileSize = &t + } + input := upscayl.Input{ - ImagePath: imagePath, - ImageURL: url, - Model: model, - OutputPath: outputPath, + ImagePath: imagePath, + ImageURL: url, + Model: model, + OutputPath: outputPath, + Scale: scaleStr, + Compression: fmt.Sprintf("%d", compress), + TileSize: tileSize, + ModelPath: modelPath, + SaveImageAs: format, + TTAMode: tta, } outputPath, err := upscayl.Upscayl(input) if err != nil { diff --git a/upscayl/upscayl.go b/upscayl/upscayl.go index c1049ae..b90513b 100644 --- a/upscayl/upscayl.go +++ b/upscayl/upscayl.go @@ -226,10 +226,12 @@ func upscaylImage(input Input) (string, error) { return "", errors.New("model does not exist") } args = append(args, fmt.Sprintf("-m %s", input.ModelPath)) - if input.SaveImageAs == "" { + if input.SaveImageAs == "" || input.SaveImageAs == "ext/png" { input.SaveImageAs = filepath.Ext(input.ImagePath)[1:] } - args = append(args, fmt.Sprintf("-f %s", input.SaveImageAs)) + if input.SaveImageAs != "" { + args = append(args, fmt.Sprintf("-f %s", input.SaveImageAs)) + } if input.GPUId != nil { args = append(args, fmt.Sprintf("-g %d", input.GPUId)) }