1
0
Fork 0
Projet_Barbapapa_Firmware/Utils/convertAnimGif.sh
Teo-CD 8935a6ee6d Utils: Update conversion command
For some gifs, my original convert command mangled the deltas and produced
completly wrong frames.
This is due to a couple of mistakes in the order of operations
1. The -coalesce option to flatten all layers up to the current frame
   needs to be before the output, not the input
2. Resizing was done *before* the coalesce option, leading to invalid
   delta frames and image corruption
3. This was emphasized by the thresholding, making it look mangled.

Update the command in the script and the example in the README.
2024-03-18 13:15:41 +00:00

52 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
if [[ $# -eq 0 ]]; then
echo "This script expects the name of the files to convert as arguments"
exit 1
fi
if [[ ! $(command -v convert) ]]; then
echo "Could not find 'convert' utility, cannot proceed."
exit 1
fi
# Get the absolute path to the source of the script
scriptSrcDir="$(dirname -- "$0")"
pushd "$scriptSrcDir"
scriptSrcDir="$(pwd)"
popd
if [[ $(command -v bitmap_helper) ]]; then
bmp_help="$(command -v bitmap_helper)"
elif [[ $(command -v "$scriptSrcDir"/bitmap_helper/target/debug/bitmap_helper) ]]; then
bmp_help="$scriptSrcDir"/bitmap_helper/target/debug/bitmap_helper
elif [[ $(command -v "$scriptSrcDir"/bitmap_helper) ]]; then
bmp_help="$scriptSrcDir"/bitmap_helper
else
echo "Could not find 'bitmap_helper'."
echo "Have you compiled it or placed it in the same directory as the script ?"
exit 1
fi
for gifToConvert in "$@"; do
if [[ -z "$(echo "$gifToConvert" | grep -e 'gif')" ]]; then
echo "Cannot convert $gifToConvert : not a gif."
continue
fi
animDir=ANIM_"${gifToConvert//.gif//}"
mkdir "$animDir"
pushd "$animDir"
convert ../"$gifToConvert" -coalesce -resize 84x48 -threshold 50% %02d.mono
"$bmp_help" ./*.mono
# Clean up and remove the extension
rm -f ./*.mono
for f in ./*.bin; do
mv "$f" "${f//.bin/}"
done
popd
done