Debian Codegraph @

tools/scripts/cjxl_bisect_bpp

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 bits-per-pixel value.
10 # (To be used directly, or as a template for tailored processing.)
11 #
12 # Usage: cjxl_bisect_size {input_filename} {output_filename} {target_bpp}
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 # The `get_bpp` helper is taken from the same directory as the current script.
18 #
19
20 self=$(realpath "$0")
21 mydir=$(dirname "${self}")
22
23 input_filename=$1
24 output_filename=$2
25 target_size=$3
26
27 bisect_tool=$(which bisector)
28 if [ -z $bisect_tool ] ; then
29 bisect_tool="${mydir}/bisector"
30 fi
31 jxl_get_bpp_helper="${my}/jxl_get_bpp_helper"
32 # If $CJXL_BIN is set, we use this instead of looking for `cjxl` on $PATH.
33
34 cjxl_bin=${CJXL_BIN}
35 if [ -z $cjxl_bin ] ; then
36 cjxl_bin="cjxl"
37 fi
38
39 # Using `identify` from ImageMagick here.
40 num_pixels=$(identify -format "%w*%h\n" /tmp/baseball.png|bc)
41
42 # Allow 0.5% tolerance in size (--rtol=0.005).
43 exec $bisect_tool --var=BISECT --range=0.01,15.0 --target=$target_size \
44 --rtol_val=0.005 \
45 --cmd="$cjxl_bin --distance=\$BISECT ${input_filename} ${output_filename}_bisect_\$BISECT.jxl ; (find ${output_filename}_bisect_\$BISECT.jxl -printf \"scale=10;%s/$num_pixels\n\" | bc -l)" \
46 --final="mv ${output_filename}_bisect_\$BISECT.jxl ${output_filename}; rm -f ${output_filename}_bisect_*.jxl" \
47 --verbosity=1