libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

cjxl_bisect_size (1303B)


      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 input_filename=$1
     20 output_filename=$2
     21 target_size=$3
     22 
     23 script_dir=$(dirname $(readlink -f $0))
     24 bisect_tool=$(which bisector)
     25 if [ -z $bisect_tool ] ; then
     26   bisect_tool="${script_dir}/bisector"
     27 fi
     28 
     29 # If $CJXL_BIN is set, we use this instead of looking for `cjxl` on $PATH.
     30 
     31 cjxl_bin=${CJXL_BIN}
     32 if [-z $cjxl_bin ] ; then
     33   cjxl_bin="cjxl"
     34 fi
     35 
     36 # Allow 0.5% tolerance in size (--rtol=0.005).
     37 exec $bisect_tool --var=BISECT --range=0.01,10.0 --target=$target_size \
     38   --rtol_val=0.005 \
     39   --cmd="$cjxl_bin --distance=\$BISECT ${input_filename} ${output_filename}_bisect_\$BISECT.jxl && wc -c ${output_filename}_bisect_\$BISECT.jxl" \
     40   --final="mv ${output_filename}_bisect_\$BISECT.jxl ${output_filename}; rm -f ${output_filename}_bisect_*.jxl" \
     41   --verbosity=1