diff options
Diffstat (limited to 'tools/cjxl_bisect_size')
-rwxr-xr-x | tools/cjxl_bisect_size | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/cjxl_bisect_size b/tools/cjxl_bisect_size new file mode 100755 index 0000000..9cd88ea --- /dev/null +++ b/tools/cjxl_bisect_size @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Bisects JPEG XL encoding quality parameter to reach a given +# target byte-size. +# (To be used directly, or as a template for tailored processing.) +# +# Usage: cjxl_bisect_size {input_filename} {output_filename} {target_size} + +# +# We take the `bisector` tool from $PATH, or, if not available, +# try to locate it in the same directory as the current script. +# + +input_filename=$1 +output_filename=$2 +target_size=$3 + +script_dir=$(dirname $(readlink -f $0)) +bisect_tool=$(which bisector) +if [ -z $bisect_tool ] ; then + bisect_tool="${script_dir}/bisector" +fi + +# If $CJXL_BIN is set, we use this instead of looking for `cjxl` on $PATH. + +cjxl_bin=${CJXL_BIN} +if [-z $cjxl_bin ] ; then + cjxl_bin="cjxl" +fi + +# Allow 0.5% tolerance in size (--rtol=0.005). +exec $bisect_tool --var=BISECT --range=0.01,10.0 --target=$target_size \ + --rtol_val=0.005 \ + --cmd="$cjxl_bin --distance=\$BISECT ${input_filename} ${output_filename}_bisect_\$BISECT.jxl && wc -c ${output_filename}_bisect_\$BISECT.jxl" \ + --final="mv ${output_filename}_bisect_\$BISECT.jxl ${output_filename}; rm -f ${output_filename}_bisect_*.jxl" \ + --verbosity=1 |