A simple scheme to produce arbitrary output formats

From: Stefan Illy (stefan.illy@ihm.fzk.de)
Date: Tue Aug 15 2000 - 02:30:11 PDT

  • Next message: Jochen Eisinger: "bug in mustek_pp"

    I'm not very happy with the fact that xscanimage can produce only
    pnm-output.

    By adding a couple of lines to xscanimage.c and providing an additional
    shell script I could get easily around this problem.

    My scheme is quite simple:

    The user specifies the requested output format by the suffix of the
    output file (e.g. `output.eps').

    After the fclose() call in xscanimage.c the program will check for the
    SANE_CONVERT environment variable. If it exists it will call the
    program specified in SANE_CONVERT, in my case a shell script called
    `sane-convert'. This program takes one argument, the name of the
    output file and will convert it to the requested format using
    ImageMagick or the netpbm utilities.

    Here are the changes I had to apply to xscanimage.c
    (line 760+, 7 additinoal lines):
        {
    + char *saneconvert, cmd[2*PATH_MAX];
          fclose (scan_win.out);
          scan_win.out = 0;
    + if ((saneconvert = getenv("SANE_CONVERT")) != NULL)
    + {
    + strcpy(cmd, saneconvert);
    + strcat(cmd, preferences.filename);
    + strcat(cmd, " ");
    + system(cmd);
          }
        }

    And this is the sane-convert shell script:
    -------------snip-------------------------
    #!/bin/sh
    #
    # sane-convert: convert a pnm-file generated by xscanimage to a
    # user-specified format
    # (determined by the filename's suffix).
    #

    SCRIPT=`basename $0`

    #
    # Argument checking.
    #
    if [ $# -ne 1 ]; then
      echo "$SCRIPT: invalid number of arguments." 1>&2
      exit 1
    fi

    if [ ! -r $1 ]; then
      echo "$SCRIPT: input file \`$1' is not readable." 1>&2
      exit 2
    fi

    #
    # Input and output filenames.
    #
    INPUT=$1-$$.pnm
    OUTPUT=$1

    #
    # Specification of the conversion filters (CHANGE TO YOUR NEEDS!).
    #
    case $OUTPUT in
      *.p[bgpn]m) echo "$SCRIPT: pnm format, conversion skipped."
                    exit 0
                    ;;
      *.eps) CONVERT="convert $INPUT eps2:$OUTPUT"
                    ;;
      *.ps) CONVERT="convert -page A4 -border 36x36 -bordercolor white \
                                     -rotate -90\> $INPUT ps2:$OUTPUT"
                    ;;
      *.jpg) CONVERT="cjpeg -quality 75 < $INPUT > $OUTPUT"
                    ;;
      *) CONVERT="convert $INPUT $OUTPUT"
                    ;;
    esac

    echo "$SCRIPT: running \`$CONVERT'..."

    #
    # The converstion step.
    #
    mv $OUTPUT $INPUT && sh -c "$CONVERT"
    if [ $? -eq 0 ]; then
      echo "$SCRIPT: conversion completed successfully."
    else
      echo "$SCRIPT: conversion failed."
    fi

    #
    # Deleting the input file.
    #
    rm $INPUT
    -------------snip-------------------------

    What do you think of this concept?

    Maybe it is a candidate for sane-1.0.4?

    Best regards,

    Stefan

    -- 
    Stefan Illy                     |  Institut fuer Hochleistungsimpuls-
                                    |  und Mikrowellentechnik (IHM)
    e-mail: stefan.illy@ihm.fzk.de  |  Forschungszentrum Karlsruhe GmbH
    phone:  (+49) 07247/82-4165     |  Postfach 3640
    fax:    (+49) 07247/82-4874     |  D-76021 Karlsruhe, Germany
    

    -- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com



    This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 02:28:00 PDT