Converting Images to mode8 _scr files
Posted: Sat Dec 25, 2021 5:52 am
So suffering from too much caffeine and because i could not find a simple util to do this I got my bash mojo on.
It will blindly convert any image no matter the size, BUT if you want the aspect ratio to be correct on BBQL then you want to start with an image of 1024x768 or same aspect ratio.
Have a happy christmas!
Code: Select all
#! /bin/bash
INFILE="$1"
OUTFILE="$2"
CONVERTED=`magick "$INFILE" -dither FloydSteinburg -resize 256x256\! -remap ql-palette.png txt:`
if [ -f "$OUTFILE" ]; then
rm "$OUTFILE"
fi
y=-1
s=0
hashstring="#"
IFS=$'\n'
for line in $CONVERTED
do
if [ $y -lt 0 ]; then
y=$[$y+1]
continue
fi
rest=${line#*$hashstring}
position=$(( ${#line} - ${#rest} - ${#searchstring} ))
pixel=${line:$[position]:6}
if [ $s -eq 0 ]; then
byte1=0
byte2=0
fi
if [ $[0x$pixel & 0xFF00] -ne 0 ]; then
byte1=$[($byte1 << 2) | 0x02]
else
byte1=$[$byte1 << 2]
fi
if [ $[0x$pixel & 0xFF0000] -ne 0 ]; then
byte2=$[($byte2 << 1) | 0x01]
else
byte2=$[$byte2 << 1]
fi
if [ $[0x$pixel & 0xFF] -ne 0 ]; then
byte2=$[($byte2 << 1) | 0x01]
else
byte2=$[$byte2 << 1]
fi
s=$[$s+1]
if [ $s -eq 4 ]; then
byte1out=$(printf "%x" $byte1)
byte2out=$(printf "%x" $byte2)
printf "\x$byte1out" >> "$OUTFILE"
printf "\x$byte2out" >> "$OUTFILE"
s=0
fi
done
Have a happy christmas!