Handle Lossless

This commit is contained in:
Milan Nikolic
2026-06-27 14:36:25 +02:00
parent 7b71fdae99
commit 629d569667
3 changed files with 48 additions and 2 deletions
+44 -1
View File
@@ -1,10 +1,40 @@
package main
import (
"runtime/debug"
"strings"
"github.com/gen2brain/cbconvert/cmd/cbconvert-gui/i18n"
"github.com/gen2brain/iup-go/iup"
)
// jxlLosslessBuild reports whether wasm2go and nodynamic leave zune-jpegxl (lossless-only) as the only jxl encoder.
var jxlLosslessBuild = func() bool {
info, ok := debug.ReadBuildInfo()
if !ok {
return false
}
var wasm2go, nodynamic bool
for _, kv := range info.Settings {
if kv.Key != "-tags" {
continue
}
for _, t := range strings.Split(kv.Value, ",") {
switch t {
case "wasm2go":
wasm2go = true
case "nodynamic":
nodynamic = true
}
}
}
return wasm2go && nodynamic
}()
// userLossless is the user's Lossless preference, tracked separately because a jxl
// wasm2go build force-sets the widget on.
var userLossless bool
func setActive() {
if busy {
return
@@ -68,7 +98,15 @@ func setActive() {
}
canLossless := opts.Format == "webp" || opts.Format == "avif" || opts.Format == "jxl"
losslessOn := canLossless && opts.Lossless
jxlLossless := jxlLosslessBuild && opts.Format == "jxl"
// jxl wasm2go forces lossless on; otherwise show the user's preference so it doesn't stay stuck on.
losslessVal := "OFF"
if jxlLossless || userLossless {
losslessVal = "ON"
}
iup.GetHandle("Lossless").SetAttribute("VALUE", losslessVal)
losslessOn := jxlLossless || (canLossless && userLossless)
if (opts.Format == "jpeg" || canLossless) && !opts.NoConvert && !losslessOn {
iup.GetHandle("VboxQuality").SetAttribute("ACTIVE", "YES")
@@ -84,6 +122,11 @@ func setActive() {
iup.GetHandle("Lossless").SetAttribute("ACTIVE", "NO")
}
if jxlLossless {
iup.GetHandle("Lossless").SetAttribute("ACTIVE", "NO")
iup.GetHandle("VboxEffort").SetAttribute("ACTIVE", "NO")
}
if opts.Width != 0 && opts.Height != 0 && !opts.NoConvert {
iup.GetHandle("Fit").SetAttribute("ACTIVE", "YES")
} else {