#!/bin/sh # pnminterp 1.0.1 (2000-Sep-03-Sun) # Adam M. Costello # pnminterp [ ] # # Scales up an image by an integer factor using linear interpolation. # Note that the depth of the input file affects the round-off error, # so you may wish to deepen the image using pnmdepth before calling # pnminterp. factor=$1 shift fail() { echo "$*" >&2 exit 1 } [ $# -le 1 ] || fail 'at most two arguments are allowed' case "$factor" in *[!0-9]* ) fail 'factor must be an integer' ;; esac [ $factor -gt 0 ] || fail 'factor must be positive' doublefactor=`expr $factor \* 2` filterwidth=`expr $doublefactor - 1` maxval=`expr $filterwidth \* 2` tmpprefix=/tmp/pnminterp$$ xfilter=$tmpprefix-x.pgm yfilter=$tmpprefix-y.pgm { echo P2 echo 1 1 echo $maxval echo $doublefactor } | pnmscale -width $filterwidth -height 1 > $xfilter pnmflip -xy $xfilter > $yfilter pnmscale $doublefactor ${1+"$@"} | pnmconvol $xfilter | pnmconvol $yfilter | pnmscale 0.5 rm -f $xfilter $yfilter