[sane-devel] Using scanimage with measurements in inches

Dave Close dclose@anim.dreamworks.com
Wed, 24 Jul 2002 16:51:36 -0700

For some testing of a new backend, I found it useful to use scanimage.
But the natural units of measure for the scanner for our documents and
the scanner are inches and, unlike the GUI frontends, scanimage doesn't
do any conversion. So I wrote a simple shell script to do it for me. I
called the script "six" for "scanimage extended". It also automatically
saves the received image file and the debug output in separate files,
sends the debug output also to the user, and adds a couple of lines of
comments to the beginning of the debug log file to show the command
used to produce that output. The usage is,

  six --fn name {known scanimage options} -- {other options, if any}

Here's a copy of the script, in case it's of any value to anyone else.
Bear in mind that it is scanner-specific and understands the options of
our scanner. To use it with a different scanner, you will need to change
at least some of the options. You will also probably want to change the
output file pathnames. It has only been tested with bash on Linux.

#! /bin/bash

# Convert units, invoke scanimage, store results
# As written, only useful for Tangent scanner.
# Dave Close, DreamWorks SKG, 2002 July 24

# We accept the following non-scanimage option.
#   --fn word
# word is used to construct the output file names.

# We process these scanimage options.
#   -l 0..609.6mm
#   -t 0..914.4mm
#   -x 0..609.6mm
#   -y 0..914.4mm
#   --mode Color|Gray
#   --graytype ALL|RED|GRN|BLU
#   --byteord RGB|BGR
#   --resolution 250|500dpi
#   --ctrlamps
#   --threshold 0..100
#   --motor 1|2
#   --lamp 0..100
#   --calibrate
#   --calidist 10.16..203.2mm
#   --zerodist 10.16..406.4mm
#   --preview[=(yes|no)]
# If there are others we don't process, you must put "--" before the group.

# set-up
orig="$( basename $0 ) $@"
cmd=" ( ( scanimage -d tangent"
tmp=$( getopt -o l:t:x:y:h -l fn: -l mode: -l graytype: -l byteord: \
       -l preview:: -l calidist: -l zerodist: \
       -l resolution: -l motor: -l threshold: -l lamp: \
       -l calibrate -- "$@" )
eval set -- "$tmp"

# process recognized options
while :; do
  case "$1" in
    # options which should be converted from inches to mm
        newarg=$( echo $2 25.4 \* n | dc )
        cmd="$cmd $1 $newarg"
	shift 2 ;;
    # options with an argument
        cmd="$cmd $1 $2"
	shift 2 ;;
    # options with an optional argument (not optional here)
        cmd="$cmd $1=$2"
	shift 2 ;;
    # options without an argument
        cmd="$cmd $1"
	shift ;;
    # our own private option
	shift 2 ;;
    # delimiter for any unrecognized options
        break ;;
    # anything else
        echo "You must use -- before other scanimage options."
        exit 1 ;;

# validity tests
if [ -z "$pfx" ]; then
  echo "You must provide a -fn name."
  exit 1

# handle any remaining arguments
while :; do
  shift || break
  cmd="$cmd $1"

# compose the actual command
cmd="$cmd >/tmp/tscans/$pfx.data ) 3>&1 1>&2 2>&3 ) | tee -a ~/ttest/$pfx.log"
echo $orig >~/ttest/$pfx.log
echo $cmd >>~/ttest/$pfx.log
echo      >>~/ttest/$pfx.log

# do it
eval $cmd
Dave Close                    DreamWorks SKG, Animation Technology
+1 818 695 6962               Glendale California 91201-3007
dclose@anim.dreamworks.com    http://www.dreamworks.com/