#!/bin/sh

tifftopnm ballots/00010_00000_000853.tif >ballot.pgm
<ballot.pgm pamthreshold -simple -threshold .5 >ballot.pbm

./mkbit ballot.pbm

<ballot.pbm pamtopng >ballot.png
mar=20; export mar

convert \
ballot.png \
-crop 800x400+40+550 \
+repage \
-trim \
+repage \
-bordercolor 'black' \
-border 2 \
-bordercolor 'white' \
-border ${mar} \
+repage \
getbitcrop.png
cp getbitcrop.png ..
####-scale 800% \
####+repage \

w=$( convert getbitcrop.png -format "%w" info: ); export w
h=$( convert getbitcrop.png -format "%h" info: ); export h

./mkbit getbitcrop.png

{
echo "convert \\"
echo "getbitcrop.png \\"
echo "-fill black \\"
./mkdraw
echo "getbitrule.png"
} >getbit.cmd
. ./getbit.cmd

cp getbitrule.png ..
