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
+2
View File
@@ -148,6 +148,8 @@ func settingsApply(group string) {
}
}
userLossless = iup.GetHandle("Lossless").GetAttribute("VALUE") == "ON"
syncLabels()
setActive()
previewPost()
+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 {
+2 -1
View File
@@ -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()