libjxl

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

demo_vardct_select.sh (2416B)


      1 #!/bin/bash
      2 # Copyright (c) the JPEG XL Project Authors. All rights reserved.
      3 #
      4 # Use of this source code is governed by a BSD-style
      5 # license that can be found in the LICENSE file.
      6 
      7 # Produces a demo video showing VarDCT block type selection
      8 # from very high quality to very low quality.
      9 
     10 # Assumes ImageMagick convert, ffmpeg, bc are available.
     11 
     12 set -eu
     13 
     14 MYDIR=$(dirname $(realpath "$0"))
     15 
     16 CLEANUP_FILES=()
     17 cleanup() {
     18   if [[ ${#CLEANUP_FILES[@]} -ne 0 ]]; then
     19     rm -fr "${CLEANUP_FILES[@]}"
     20   fi
     21 }
     22 trap "{ set +x; } 2>/dev/null; cleanup" INT TERM EXIT
     23 
     24 
     25 
     26 main() {
     27   local infile="${1:-}"
     28   if [[ -z "${infile}" ]]; then
     29     cat >&2 <<EOF
     30 Use: $0 IMAGE [OUT.apng]
     31 
     32 Where IMAGE is an input image and OUT.apng is the output
     33 EOF
     34     exit 1
     35   fi
     36 
     37   shift
     38 
     39   local outfile="$@"
     40   if [[ -z "${outfile}" ]]; then
     41     # default output filename
     42     outfile=vardct-select-demo.apng
     43   fi
     44 
     45   if ! command -v benchmark_xl &>/dev/null 2>&1; then
     46     PATH=$PATH:$MYDIR/../build/tools
     47     if ! command -v benchmark_xl &>/dev/null 2>&1; then
     48       echo "Could not find benchmark_xl, try building first"
     49       exit
     50     fi
     51   fi
     52   local b=benchmark_xl
     53 
     54   if ! command -v ffmpeg &>/dev/null 2>&1; then
     55     echo "Could not find ffmpeg"
     56     exit
     57   fi
     58 
     59   if ! command -v convert &>/dev/null 2>&1; then
     60     echo "Could not find ImageMagick (convert)"
     61     exit
     62   fi
     63 
     64   local tmp=$(mktemp -d --suffix=vardctdemo)
     65   CLEANUP_FILES+=("${tmp}")
     66 
     67   cp $infile $tmp/orig
     68 
     69   local n=0
     70   local pixels="$(identify -format "(%w * %h)" $tmp/orig)"
     71   for i in $(seq 0.2 0.2 2) $(seq 2.5 0.5 5) $(seq 6 1 10) $(seq 12 2 40); do
     72     $b --input=$tmp/orig --codec=jxl:d$i --save_decompressed --save_compressed \
     73       --debug_image_dir=$tmp --output_dir=$tmp
     74     convert $tmp/orig \( $tmp/orig.jxl:d$i.dbg/ac_strategy.png \
     75       -alpha set -channel A -evaluate set 66% \) \
     76       -composite $tmp/t.ppm
     77     bytes=$(stat -c "%s" $tmp/orig.jxl_d$i)
     78     bpp=$( echo "$bytes * 8 / $pixels " | bc -l | cut -b 1-6 )
     79     label="cjxl -d $i  ($((bytes / 1000)) kb, bpp: $bpp)"
     80     convert +append $tmp/t.ppm $tmp/orig.jxl_d$i.png $tmp/t2.ppm
     81     convert $tmp/t2.ppm \
     82           -gravity north \
     83           -pointsize 32 \
     84           -stroke '#000C' -strokewidth 5 -annotate +0+12 "$label" \
     85           -stroke  none   -fill white    -annotate +0+12 "$label" $tmp/frame-$n.png
     86 
     87     n=$((n+1))
     88   done
     89 
     90   ffmpeg -framerate 1 -i $tmp/frame-%d.png $outfile
     91 }
     92 
     93 main "$@"