#!/bin/sh

# default is a4 300dpi
W=215mm
H=297mm
R=300
M=Color

while [ $# -gt 0 ] ; do

if [ "$1" = -h -o "$1" = --help ] ; then
    echo "usage: canonLide25 [papersize] [resolution] [colormode]"
    echo "papersize: --letter|-l --legal --juniorlegal --ledger --tabloid"
    echo "           -ansi[a-e] -arch[a-e]"
    echo "           -4a0 -2a0 -a[0..10] -b[0..10] -c[0..10]"
    echo "           --passport"
    echo "resolution: -75 -150 -300 -600 -1200 (dpi)"
    echo "colormode: --color --lineart --gray"
    exit 1
fi

if [ "$1" = -l -o "$1" = --letter ] ; then
    W=216mm
    H=279mm
elif [ "$1" = --legal ] ; then
    W=216mm
    H=356mm
elif [ "$1" = --juniorlegal ] ; then
    W=203mm
    H=127mm
elif [ "$1" = --ledger ] ; then
    W=432mm
    H=279mm
elif [ "$1" = --tabloid ] ; then
    W=279mm
    H=432mm

elif [ "$1" = --passport ] ; then
    W=190mm
    H=135mm

elif [ "$1" = --ansia ] ; then
    W=216mm
    H=279mm
elif [ "$1" = --ansib ] ; then
    W=432mm
    H=279mm
elif [ "$1" = --ansic ] ; then
    W=432mm
    H=559mm
elif [ "$1" = --ansid ] ; then
    W=559mm
    H=864mm
elif [ "$1" = --ansie ] ; then
    W=864mm
    H=1118mm

elif [ "$1" = --archa ] ; then
    W=229mm
    H=305mm
elif [ "$1" = --archb ] ; then
    W=305mm
    H=457mm
elif [ "$1" = --archc ] ; then
    W=457mm
    H=610mm
elif [ "$1" = --archd ] ; then
    W=610mm
    H=914mm
elif [ "$1" = --arche ] ; then
    W=914mm
    H=1219mm
elif [ "$1" = --arche1 ] ; then
    W=762mm
    H=1067mm

elif [ "$1" = -4a0 ] ; then
    W=1682mm
    H=2378mm
elif [ "$1" = -2a0 ] ; then
    W=1189mm
    H=1682mm
elif [ "$1" = -a0 ] ; then
    W=841mm
    H=1189mm
elif [ "$1" = -a1 ] ; then
    W=594mm
    H=841mm
elif [ "$1" = -a2 ] ; then
    W=420mm
    H=594mm
elif [ "$1" = -a3 ] ; then
    W=297mm
    H=420mm
elif [ "$1" = -a4 ] ; then
    W=210mm
    H=297mm
elif [ "$1" = -a5 ] ; then
    W=148mm
    H=210mm
elif [ "$1" = -a6 ] ; then
    W=105mm
    H=148mm
elif [ "$1" = -a7 ] ; then
    W=74mm
    H=105mm
elif [ "$1" = -a8 ] ; then
    W=52mm
    H=74mm
elif [ "$1" = -a9 ] ; then
    W=37mm
    H=52mm
elif [ "$1" = -a10 ] ; then
    W=26mm
    H=37mm

elif [ "$1" = -b0 ] ; then
    W=1000mm
    H=1414mm
elif [ "$1" = -b1 ] ; then
    W=707mm
    H=1000mm
elif [ "$1" = -b2 ] ; then
    W=500mm
    H=707mm
elif [ "$1" = -b3 ] ; then
    W=353mm
    H=500mm
elif [ "$1" = -b4 ] ; then
    W=250mm
    H=353mm
elif [ "$1" = -b5 ] ; then
    W=176mm
    H=250mm
elif [ "$1" = -b6 ] ; then
    W=125mm
    H=176mm
elif [ "$1" = -b7 ] ; then
    W=88mm
    H=125mm
elif [ "$1" = -b8 ] ; then
    W=62mm
    H=88mm
elif [ "$1" = -b9 ] ; then
    W=44mm
    H=62mm
elif [ "$1" = -b10 ] ; then
    W=31mm
    H=44mm

elif [ "$1" = -c0 ] ; then
    W=917mm
    H=1297mm
elif [ "$1" = -c1 ] ; then
    W=648mm
    H=917mm
elif [ "$1" = -c2 ] ; then
    W=458mm
    H=648mm
elif [ "$1" = -c3 ] ; then
    W=324mm
    H=458mm
elif [ "$1" = -c4 ] ; then
    W=229mm
    H=324mm
elif [ "$1" = -c5 ] ; then
    W=162mm
    H=229mm
elif [ "$1" = -c6 ] ; then
    W=114mm
    H=162mm
elif [ "$1" = -c7 ] ; then
    W=81mm
    H=114mm
elif [ "$1" = -c8 ] ; then
    W=57mm
    H=81mm
elif [ "$1" = -c9 ] ; then
    W=40mm
    H=57mm
elif [ "$1" = -c10 ] ; then
    W=28mm
    H=40mm
fi

if [ "$1" = -75 ] ; then
    R=75
elif [ "$1" = -150 ] ; then
    R=150
elif [ "$1" = -300 ] ; then
    R=300
elif [ "$1" = -600 ] ; then
    R=600
elif [ "$1" = -1200 ] ; then
    R=1200
fi

if [ "$1" = --color ] ; then
    M=Color
elif [ "$1" = --lineart ] ; then
    M=Lineart
elif [ "$1" = --gray -o "$1" = --grey ] ; then
    M=Gray
fi

shift
done

scanimage -d `scanimage --help | grep -o "plustek\:.*"` -p -x$W -y$H --depth 8 --mode $M --resolution $R
