libjxl

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

compute_octave_metric.sh (1126B)


      1 #!/usr/bin/env 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 # Usage: ./compute-octave-metric.sh <original> <decoded> <output> <intensity_target> [octave args...]
      8 # Where octave args do not need to contain -qf or the path to the original and decoded images.
      9 
     10 set -euo pipefail
     11 
     12 original="$1"
     13 decoded="$2"
     14 output="$3"
     15 intensity_target="$4"
     16 shift 4
     17 
     18 tmpdir="$(mktemp --directory)"
     19 
     20 linearized_original="$(mktemp --tmpdir="$tmpdir" --suffix='.pfm')"
     21 linearized_decoded="$(mktemp --tmpdir="$tmpdir" --suffix='.pfm')"
     22 
     23 cleanup() {
     24   rm -- "$linearized_original" "$linearized_decoded"
     25   rmdir --ignore-fail-on-non-empty -- "$tmpdir"
     26 }
     27 trap cleanup EXIT
     28 
     29 linearize() {
     30   local input="$1"
     31   local output="$2"
     32   convert "$input" -set colorspace sRGB -colorspace RGB -evaluate multiply "$intensity_target" "$output"
     33 }
     34 
     35 linearize "$original" "$linearized_original"
     36 linearize "$decoded" "$linearized_decoded"
     37 
     38 octave -qf "$@" \
     39   "$linearized_original" "$linearized_decoded" \
     40   2> /dev/null \
     41   > "$output"