diff --git a/cmd/cbconvert-gui/settings.go b/cmd/cbconvert-gui/settings.go index b1e0254..91377c5 100644 --- a/cmd/cbconvert-gui/settings.go +++ b/cmd/cbconvert-gui/settings.go @@ -148,6 +148,8 @@ func settingsApply(group string) { } } + userLossless = iup.GetHandle("Lossless").GetAttribute("VALUE") == "ON" + syncLabels() setActive() previewPost() diff --git a/cmd/cbconvert-gui/state.go b/cmd/cbconvert-gui/state.go index bd26511..392f618 100644 --- a/cmd/cbconvert-gui/state.go +++ b/cmd/cbconvert-gui/state.go @@ -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 { diff --git a/cmd/cbconvert-gui/widgets.go b/cmd/cbconvert-gui/widgets.go index 1ade73b..2714cea 100644 --- a/cmd/cbconvert-gui/widgets.go +++ b/cmd/cbconvert-gui/widgets.go @@ -60,7 +60,7 @@ func list() iup.Ihandle { "TITLE1": i18n.Lng(i18n.ColTitle), "TITLE2": i18n.Lng(i18n.ColType), "TITLE3": i18n.Lng(i18n.ColSize), - "WIDTH1": "300", + "WIDTH1": "250", "WIDTH2": "50", "WIDTH3": "100", "ALIGNMENT2": "ACENTER", @@ -568,6 +568,7 @@ func tabImage() iup.Ihandle { iup.Toggle(i18n.Lng(i18n.TglLossless)).SetHandle("Lossless"). SetAttribute("TIP", i18n.Lng(i18n.TipLossless)). SetCallback("VALUECHANGED_CB", iup.ValueChangedFunc(func(ih iup.Ihandle) int { + userLossless = ih.GetAttribute("VALUE") == "ON" setActive() previewPost()