Skip to content

Optimize assets, again#340

Merged
sisby-folk merged 1 commit intosisby-folk:1.20from
lumiscosity:optimize-assets-again
Dec 11, 2025
Merged

Optimize assets, again#340
sisby-folk merged 1 commit intosisby-folk:1.20from
lumiscosity:optimize-assets-again

Conversation

@lumiscosity
Copy link

learned a few new tricks since last time! mostly single-byte improvements but some sprites like the new icon and atlas texture weren't compressed at all yet, plus the book got some bigger wins too.

@sisby-folk
Copy link
Owner

command ran?

@sisby-folk sisby-folk merged commit 17eb534 into sisby-folk:1.20 Dec 11, 2025
1 check passed
@lumiscosity
Copy link
Author

lumiscosity commented Dec 11, 2025

function rcomp() {
    find . -name "*.png" -type f -exec oxipng -o max -a -s {} \;
    find . -name "*.png" -type f -exec pngout {} \;
    find . -name "*.png" -type f -exec oxipng -o max --zopfli -a -s {} \;
    find . -name "*.png" -type f -exec defluff-shim {} \;
    find . -name "*.png" -type f -exec deflopt {} \;
}

where pngout is a wrapper around PNGOUT.EXE:

#!/usr/bin/env bash
# this arcane incantation converts linux paths to windows paths in the first arg
# you'll see it again in a second
set -- $(echo "$1" | sed 's/\//\\/g') "${@:2}"
# you can try different values after b, but i've found 128 to give the best results
wine /usr/bin/pngout.exe "$@" "/b128" "/k1" "/q"

and defluff-shim is a wrapper around defluff:

#!/usr/bin/env bash
if [ $# -eq 1 ]; then
  defluff < "$1" > ~/.cache/defluff-shim-tmp.png
  oldsize=$(wc -c < "$1")
  newsize=$(wc -c < ~/.cache/defluff-shim-tmp.png)
  if [[ newsize -lt oldsize ]]; then
    rm "$1"
    mv ~/.cache/defluff-shim-tmp.png "$1"
  else
    rm ~/.cache/defluff-shim-tmp.png
  fi
else
  echo 'usage: defluff-shim (path)'
fi

and deflopt is a wrapper around deflopt:

#!/usr/bin/env bash
set -- $(echo "$1" | sed 's/\//\\/g') "${@:2}"
wine /usr/bin/DeflOpt.exe "$@"

defluff and deflopt are the final steps that shave off the last tiny bytes by, as far as i understand it, optimizing the headers. pngout is a png compressor with different characteristics than opti/oxipng, it seems to excel at images with large blobs of shared color and small amounts of color from what i can tell. chaining it between the two oxipng calls gave me the best results

i'll probably make a blogpost about this sometime...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants