From 10418f2327eb9639fc8efa78a6e7858bdc25f775 Mon Sep 17 00:00:00 2001 From: David Warner Date: Mon, 18 Jan 2021 18:52:26 +1100 Subject: [PATCH 1/2] Expose thread count config as command-line option --- cmd/avif/main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/avif/main.go b/cmd/avif/main.go index a1702b0..842afb7 100644 --- a/cmd/avif/main.go +++ b/cmd/avif/main.go @@ -25,6 +25,7 @@ Options: -o , --output= Destination filename -q , --quality= Compression level (0..63), [default: 25] -s , --speed= Compression speed (0..8), [default: 4] + -t , --threads= Number of threads (1..64, 0 for all available cores), [default: 0] --lossless Lossless compression (alias for -q 0) --best Slowest compression method (alias for -s 0) --fast Fastest compression method (alias for -s 8) @@ -35,6 +36,7 @@ type config struct { Output string Quality int Speed int + Threads int Lossless bool Best bool Fast bool @@ -62,6 +64,7 @@ func main() { checkErr(err) check(conf.Quality >= avif.MinQuality && conf.Quality <= avif.MaxQuality, "bad quality (0..63)") check(conf.Speed >= avif.MinSpeed && conf.Speed <= avif.MaxSpeed, "bad speed (0..8)") + check(conf.Threads == 0 || (conf.Threads >= avif.MinThreads && conf.Threads <= avif.MaxThreads), "bad threads (0..64)") check(!conf.Best || !conf.Fast, "can't use both --best and --fast") if conf.Lossless { conf.Quality = 0 @@ -74,6 +77,7 @@ func main() { avifOpts := avif.Options{ Speed: conf.Speed, Quality: conf.Quality, + Threads: conf.Threads, } var src io.Reader From df3126083e21cda760760cbb0e1371c738ae9f3d Mon Sep 17 00:00:00 2001 From: David Warner Date: Mon, 18 Jan 2021 18:54:02 +1100 Subject: [PATCH 2/2] Tweak usage string --- cmd/avif/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/avif/main.go b/cmd/avif/main.go index 842afb7..e69d6d0 100644 --- a/cmd/avif/main.go +++ b/cmd/avif/main.go @@ -25,7 +25,7 @@ Options: -o , --output= Destination filename -q , --quality= Compression level (0..63), [default: 25] -s , --speed= Compression speed (0..8), [default: 4] - -t , --threads= Number of threads (1..64, 0 for all available cores), [default: 0] + -t , --threads= Number of threads (0..64, 0 for all available cores), [default: 0] --lossless Lossless compression (alias for -q 0) --best Slowest compression method (alias for -s 0) --fast Fastest compression method (alias for -s 8)