shithub: sce

ref: d0e226919d3d681e36cdd2476324dc0c973774f6
dir: /utils/scespr/

View raw version
#!/bin/rc -e
if(! ~ $#* 4){
	echo usage: $0 fi fo Δx Δy
	exit usage
}
tmp=/tmp/scespr.$pid
fi=$1
fo=$2
Δx=$3
Δy=$4
dim=`{read -c 60 $fi | awk '{print $4-$2, $5-$3, 8*($5-$3)}'}
dx=$dim(1)
dh=$dim(2)
dy=$dim(3)

cat <<EOF | pico
!r $fi s
m = z == 3 ? Z : s[x,y,0] == Z && s[x,y,1] == 0 && s[x,y,2] == Z || s[x,y,0] == 222 && s[x,y,1] == 0 && s[x,y,2] == 222 || s[x,y,0] == 189 && s[x,y,1] == 0 && s[x,y,2] == 189 || s[x,y,0] == 156 && s[x,y,1] == 0 && s[x,y,2] == 156 || s[x,y,0] == 124 && s[x,y,1] == 0 && s[x,y,2] == 124 || s[x,y,0] == 91 && s[x,y,1] == 0 && s[x,y,2] == 91 || s[x,y,0] == 58 && s[x,y,1] == 0 && s[x,y,2] == 58 || s[x,y,0] == 25 && s[x,y,1] == 0 && s[x,y,2] == 25 ? s[x,y,0] : 0
white = m > 0 ? m : s
red = m > 0 ? z == 0 ? s[x,y,0] : z == 1 ? s[x,y,1] : z == 2 ? s[x,y,1] : Z : s
blue = m > 0 ? z == 0 ? s[x,y,1] : z == 1 ? s[x,y,1] : z == 2 ? m : Z : s
teal = m > 0 ? z == 0 ? s[x,y,1] : z == 1 ? s[x,y,0] : z == 2 ? s[x,y,0] : Z : s
yellow = m > 0 ? z == 0 ? s[x,y,0] : z == 1 ? s[x,y,0] : z == 2 ? s[x,y,1] : Z : s
purple = m > 0 ? z == 0 ? s[x,y,0]/2 : z == 1 ? s[x,y,1] : z == 2 ? s[x,y,0] : Z : s
brown = m > 0 ? z == 0 ? s[x,y,0]/2 : z == 1 ? s[x,y,0]/2 : z == 2 ? s[x,y,1] : Z : s
orange = m > 0 ? z == 0 ? s[x,y,0] : z == 1 ? s[x,y,0]/2 : z == 2 ? s[x,y,1] : Z : s
!s $dx $dy
r = red
r = y >= 1*$dh && y < 2*$dh ? blue[x,y-1*$dh] : r
r = y >= 2*$dh && y < 3*$dh ? teal[x,y-2*$dh] : r
r = y >= 3*$dh && y < 4*$dh ? purple[x,y-3*$dh] : r
r = y >= 4*$dh && y < 5*$dh ? orange[x,y-4*$dh] : r
r = y >= 5*$dh && y < 6*$dh ? brown[x,y-5*$dh] : r
r = y >= 6*$dh && y < 7*$dh ? white[x,y-6*$dh] : r
r = y >= 7*$dh && y < 8*$dh ? yellow[x,y-7*$dh] : r
!w r $tmp
EOF

iconv -c r8g8b8 $tmp |\
	crop -t $Δx $Δy >$fo
rm $tmp