mirror of
https://github.com/gen2brain/cbconvert
synced 2026-06-30 09:11:54 +02:00
Add ZipLevel, issue #48
This commit is contained in:
@@ -141,6 +141,7 @@ func options() cbconvert.Options {
|
||||
opts.NoConvert = iup.GetHandle("NoConvert").GetAttribute("VALUE") == "ON"
|
||||
opts.NoNonImage = iup.GetHandle("NoNonImage").GetAttribute("VALUE") == "ON"
|
||||
opts.Archive = strings.ToLower(iup.GetHandle("Archive").GetAttribute("VALUESTRING"))
|
||||
opts.ZipLevel = zipLevel(iup.GetHandle("ZipLevel").GetAttribute("VALUESTRING"))
|
||||
opts.Format = strings.ToLower(iup.GetHandle("Format").GetAttribute("VALUESTRING"))
|
||||
opts.Width = iup.GetHandle("Width").GetInt("VALUE")
|
||||
opts.Height = iup.GetHandle("Height").GetInt("VALUE")
|
||||
@@ -246,6 +247,29 @@ func setActive() {
|
||||
} else {
|
||||
iup.GetHandle("VboxOutFile").SetAttribute("ACTIVE", "NO")
|
||||
}
|
||||
|
||||
if opts.Archive == "zip" {
|
||||
iup.GetHandle("VboxZipLevel").SetAttribute("ACTIVE", "YES")
|
||||
} else {
|
||||
iup.GetHandle("VboxZipLevel").SetAttribute("ACTIVE", "NO")
|
||||
}
|
||||
}
|
||||
|
||||
// zipLevel maps the compression dropdown selection to Options.ZipLevel.
|
||||
func zipLevel(value string) int {
|
||||
switch value {
|
||||
case "Default":
|
||||
return -1
|
||||
case "Store (none)":
|
||||
return 0
|
||||
default:
|
||||
level, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
return level
|
||||
}
|
||||
}
|
||||
|
||||
func setEffort(format string) {
|
||||
@@ -521,8 +545,32 @@ func tabs() iup.Ihandle {
|
||||
"VALUE": "1",
|
||||
"1": "ZIP",
|
||||
"2": "TAR",
|
||||
}).SetHandle("Archive"),
|
||||
}).SetHandle("Archive").
|
||||
SetCallback("VALUECHANGED_CB", iup.ValueChangedFunc(func(ih iup.Ihandle) int {
|
||||
setActive()
|
||||
|
||||
return iup.DEFAULT
|
||||
})),
|
||||
),
|
||||
iup.Vbox(
|
||||
iup.Label("Compression:"),
|
||||
iup.List().SetAttributes(map[string]string{
|
||||
"DROPDOWN": "YES",
|
||||
"VALUE": "1",
|
||||
"1": "Default",
|
||||
"2": "Store (none)",
|
||||
"3": "1",
|
||||
"4": "2",
|
||||
"5": "3",
|
||||
"6": "4",
|
||||
"7": "5",
|
||||
"8": "6",
|
||||
"9": "7",
|
||||
"10": "8",
|
||||
"11": "9",
|
||||
}).SetHandle("ZipLevel").
|
||||
SetAttribute("TIP", "ZIP compression: Store disables it, 1 is fastest, 9 is smallest"),
|
||||
).SetHandle("VboxZipLevel"),
|
||||
).SetAttributes("NGAP=10"),
|
||||
iup.Space().SetAttribute("SIZE", "15"),
|
||||
iup.Vbox(
|
||||
|
||||
@@ -177,6 +177,7 @@ func parseFlags() (cbconvert.Options, []string) {
|
||||
convert.BoolVar(&opts.Fit, "fit", false, "Best fit for required width and height")
|
||||
convert.StringVar(&opts.Format, "format", "jpeg", "Image format, valid values are jpeg, png, tiff, bmp, webp, avif, jxl")
|
||||
convert.StringVar(&opts.Archive, "archive", "zip", "Archive format, valid values are zip, tar")
|
||||
convert.IntVar(&opts.ZipLevel, "zip-level", -1, "ZIP compression level, 0 disables compression, 1-9 sets deflate level (1 fastest, 9 smallest), -1 uses the default")
|
||||
convert.IntVar(&opts.Quality, "quality", 75, "Image quality")
|
||||
convert.IntVar(&opts.Effort, "effort", -1, "Encoder speed/effort, format-specific (webp method 0-6, avif speed 0-10, jxl effort 1-10), -1 uses the format default")
|
||||
convert.BoolVar(&opts.Lossless, "lossless", false, "Lossless compression (webp, avif, jxl), ignores quality")
|
||||
@@ -235,7 +236,7 @@ func parseFlags() (cbconvert.Options, []string) {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s <command> [<flags>] [file1 dir1 ... fileOrDirN]\n\n", filepath.Base(os.Args[0]))
|
||||
fmt.Fprintf(os.Stderr, "\nCommands:\n")
|
||||
fmt.Fprintf(os.Stderr, "\n convert\n \tConvert archive or document\n\n")
|
||||
order := []string{"width", "height", "fit", "format", "archive", "quality", "effort", "lossless", "combine", "outfile", "filter", "no-cover", "no-rgb",
|
||||
order := []string{"width", "height", "fit", "format", "archive", "zip-level", "quality", "effort", "lossless", "combine", "outfile", "filter", "no-cover", "no-rgb",
|
||||
"no-nonimage", "no-convert", "grayscale", "rotate", "brightness", "contrast", "suffix", "outdir", "size", "recursive", "quiet"}
|
||||
for _, name := range order {
|
||||
f := convert.Lookup(name)
|
||||
|
||||
Reference in New Issue
Block a user