#!/bin/sh -x
#
# usage: ./dvi2slides [ XRESxYRES ] file.dvi
#
# XRESxYRES defaults to 640x480
#
# Creates a file XRESxYRES.tmp (huge) and slide files numbered from 100 in
# XRESxYRES.d (GIF). Requires a reasonably recent version of Ghostscript
# with alpha blending support.

RES=${1:-640x480}

if [ ! -z "$2" ]; then
    shift
fi

[ -d $RES.d ] || mkdir $RES.d
X=`echo $RES | sed 's/x.*//'`
Y=`echo $RES | sed 's/.*x//'`
IRES=${Y}x$X
res=`expr 72 \* $X / 800`
n=1
while dvips -t landscape -t a4 -p =$n -l =$n -o tmp.ps "$1"; do
    gs -sDEVICE=ppmraw -sOutputFile=- \
      -g$IRES -r$res \
      -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - <tmp.ps |
      pnmflip -r90 | ppmquant 256 >$RES.d/`expr $n + 99`
  n=`expr $n + 1`
done
rm -f tmp.ps
#      tee $RES.d/$n.ppm |
#      ppmtogif  >$RES.d/`expr $n + 99`
