]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Lossless JXL compressor
authorSergey Matveev <stargrave@stargrave.org>
Sun, 26 Mar 2023 14:53:07 +0000 (17:53 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 26 Mar 2023 14:53:07 +0000 (17:53 +0300)
img/bin/my-jxll [new file with mode: 0755]

diff --git a/img/bin/my-jxll b/img/bin/my-jxll
new file mode 100755 (executable)
index 0000000..89f546e
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env zsh
+
+set -e
+tmp=`mktemp`
+trap "rm -f $tmp.pnm $tmp.jxl" HUP PIPE INT QUIT TERM EXIT
+case $1:e in
+pnm) cp $1 $tmp.pnm ;;
+png) pngtopnm < $1 > $tmp.pnm ;;
+webp) dwebp -mt -quiet -o $tmp.pnm $1 ;;
+*)
+    print unknown extension >&2
+    exit 1
+esac
+
+common=(--quiet --distance=0 --effort=9 --brotli_effort=11 --modular_predictor=15)
+prev=$(( 1 << 62 ))
+best=""
+zmodload -F zsh/stat b:zstat
+for g (0 1 2 3) {
+    opts=(--modular_group_size=$g)
+    cjxl $common $opts $tmp.pnm $tmp.jxl
+    zstat -A cur +size $tmp.jxl
+    [[ $cur -gt $prev ]] || {
+        prev=$cur
+        best=($opts)
+    }
+}
+zstat -A cur +size $1
+[[ $cur -lt $prev ]] && {
+    print $1 is smaller : $cur vs $prev
+    exit 2
+}
+cjxl $common $best $tmp.pnm $1:r.jxl