Debian Codegraph @

tools/scripts/cjxl_bisect_size

raw
1 #!/bin/sh
2 #
3 # Copyright (c) the JPEG XL Project Authors. All rights reserved.
4 #
5 # Use of this source code is governed by a BSD-style
6 # license that can be found in the LICENSE file.
7 #
8 # Bisects JPEG XL encoding quality parameter to reach a given
9 # target byte-size.
10 # (To be used directly, or as a template for tailored processing.)
11 #
12 # Usage: cjxl_bisect_size {input_filename} {output_filename} {target_size}
13
14 #
15 # We take the `bisector` tool from $PATH, or, if not available,
16 # try to locate it in the same directory as the current script.
17 #
18
19 self=$(realpath "$0")
20 mydir=$(dirname "${self}")
21
22 input_filename=$1
23 output_filename=$2
24 target_size=$3
25
26 bisect_tool=$(which bisector)
27 if [ -z $bisect_tool ] ; then
28 bisect_tool="${mydir}/bisector"
29 fi
30
31 # If $CJXL_BIN is set, we use this instead of looking for `cjxl` on $PATH.
32
33 cjxl_bin=${CJXL_BIN}
34 if [-z $cjxl_bin ] ; then
35 cjxl_bin="cjxl"
36 fi
37
38 # Allow 0.5% tolerance in size (--rtol=0.005).
39 exec $bisect_tool --var=BISECT --range=0.01,10.0 --target=$target_size \
40 --rtol_val=0.005 \
41 --cmd="$cjxl_bin --distance=\$BISECT ${input_filename} ${output_filename}_bisect_\$BISECT.jxl && wc -c ${output_filename}_bisect_\$BISECT.jxl" \
42 --final="mv ${output_filename}_bisect_\$BISECT.jxl ${output_filename}; rm -f ${output_filename}_bisect_*.jxl" \
43 --verbosity=1