#! /bin/bash
# Last edited on 2019-05-22 15:48:09 by stolfilocal

usage="$0 [ PPMFILE ] > EPSFILE.eps"

# Converts a PPM image to B/W eps file, with Floyd-Steinberg dithering
# (Does not use the printer screen). For good results, the EPS file
# should be printed unscaled on a 300 dpi printer, and will show 150
# original pixels per inch. For a 600 dpi printer, the EPS file should
# be scaled by 0.5.

if [[ $# -gt 1 ]]; then
  echo "usage: ${usage}" 1>&2; exit 1
fi

cat $* \
  | ppmtopgm \
  | pnmscale 2 \
  | pgmnorm -bpercent 1 -wpercent 1 \
  | pgmtopbm -floyd \
  | pnmtopsx -scale 0.5 -noturn
