sane-project-website/old-archive/2000-08/0132.html

253 wiersze
7.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>sane-devel: A simple scheme to produce arbitrary output formats</TITLE>
<META NAME="Author" CONTENT="Stefan Illy (stefan.illy@ihm.fzk.de)">
<META NAME="Subject" CONTENT="A simple scheme to produce arbitrary output formats">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>A simple scheme to produce arbitrary output formats</H1>
<!-- received="Tue Aug 15 02:26:00 2000" -->
<!-- isoreceived="20000815092600" -->
<!-- sent="Tue, 15 Aug 2000 11:30:11 +0200 (CEST)" -->
<!-- isosent="20000815093011" -->
<!-- name="Stefan Illy" -->
<!-- email="stefan.illy@ihm.fzk.de" -->
<!-- subject="A simple scheme to produce arbitrary output formats" -->
<!-- id="14745.3491.849563.564819@ihmgyro5.fzk.de" -->
<STRONG>From:</STRONG> Stefan Illy (<A HREF="mailto:stefan.illy@ihm.fzk.de?Subject=Re:%20A%20simple%20scheme%20to%20produce%20arbitrary%20output%20formats&In-Reply-To=&lt;14745.3491.849563.564819@ihmgyro5.fzk.de&gt;"><EM>stefan.illy@ihm.fzk.de</EM></A>)<BR>
<STRONG>Date:</STRONG> Tue Aug 15 2000 - 02:30:11 PDT
<P>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0133.html">Jochen Eisinger: "bug in mustek_pp"</A>
<UL>
<LI><STRONG>Previous message:</STRONG> <A HREF="0131.html">Chris Pinkham: "Re: sane-1.0.3 released"</A>
<!-- nextthread="start" -->
<LI><STRONG>Next in thread:</STRONG> <A HREF="0160.html">Henning Meier-Geinitz: "Re: A simple scheme to produce arbitrary output formats"</A>
<LI><STRONG>Reply:</STRONG> <A HREF="0160.html">Henning Meier-Geinitz: "Re: A simple scheme to produce arbitrary output formats"</A>
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#132">[ date ]</A>
<A HREF="index.html#132">[ thread ]</A>
<A HREF="subject.html#132">[ subject ]</A>
<A HREF="author.html#132">[ author ]</A>
</UL>
<HR NOSHADE><P>
<!-- body="start" -->
<P>
I'm not very happy with the fact that xscanimage can produce only
<BR>
pnm-output.
<BR>
<P>By adding a couple of lines to xscanimage.c and providing an additional
<BR>
shell script I could get easily around this problem.
<BR>
<P>My scheme is quite simple:
<BR>
<P>The user specifies the requested output format by the suffix of the
<BR>
output file (e.g. `output.eps').
<BR>
<P>After the fclose() call in xscanimage.c the program will check for the
<BR>
SANE_CONVERT environment variable. If it exists it will call the
<BR>
program specified in SANE_CONVERT, in my case a shell script called
<BR>
`sane-convert'. This program takes one argument, the name of the
<BR>
output file and will convert it to the requested format using
<BR>
ImageMagick or the netpbm utilities.
<BR>
<P>Here are the changes I had to apply to xscanimage.c
<BR>
(line 760+, 7 additinoal lines):
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;{
<BR>
+ char *saneconvert, cmd[2*PATH_MAX];
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose (scan_win.out);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scan_win.out = 0;
<BR>
+ if ((saneconvert = getenv(&quot;SANE_CONVERT&quot;)) != NULL)
<BR>
+ {
<BR>
+ strcpy(cmd, saneconvert);
<BR>
+ strcat(cmd, preferences.filename);
<BR>
+ strcat(cmd, &quot; &quot;);
<BR>
+ system(cmd);
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}
<BR>
<P><P>And this is the sane-convert shell script:
<BR>
-------------snip-------------------------
<BR>
#!/bin/sh
<BR>
#
<BR>
# sane-convert: convert a pnm-file generated by xscanimage to a
<BR>
# user-specified format
<BR>
# (determined by the filename's suffix).
<BR>
#
<BR>
<P>SCRIPT=`basename $0`
<BR>
<P>#
<BR>
# Argument checking.
<BR>
#
<BR>
if [ $# -ne 1 ]; then
<BR>
&nbsp;&nbsp;echo &quot;$SCRIPT: invalid number of arguments.&quot; 1&gt;&amp;2
<BR>
&nbsp;&nbsp;exit 1
<BR>
fi
<BR>
<P>if [ ! -r $1 ]; then
<BR>
&nbsp;&nbsp;echo &quot;$SCRIPT: input file \`$1' is not readable.&quot; 1&gt;&amp;2
<BR>
&nbsp;&nbsp;exit 2
<BR>
fi
<BR>
<P>#
<BR>
# Input and output filenames.
<BR>
#
<BR>
INPUT=$1-$$.pnm
<BR>
OUTPUT=$1
<BR>
<P>#
<BR>
# Specification of the conversion filters (CHANGE TO YOUR NEEDS!).
<BR>
#
<BR>
case $OUTPUT in
<BR>
&nbsp;&nbsp;*.p[bgpn]m) echo &quot;$SCRIPT: pnm format, conversion skipped.&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit 0
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
<BR>
&nbsp;&nbsp;*.eps) CONVERT=&quot;convert $INPUT eps2:$OUTPUT&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
<BR>
&nbsp;&nbsp;*.ps) CONVERT=&quot;convert -page A4 -border 36x36 -bordercolor white \
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-rotate -90\&gt; $INPUT ps2:$OUTPUT&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
<BR>
&nbsp;&nbsp;*.jpg) CONVERT=&quot;cjpeg -quality 75 &lt; $INPUT &gt; $OUTPUT&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
<BR>
&nbsp;&nbsp;*) CONVERT=&quot;convert $INPUT $OUTPUT&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
<BR>
esac
<BR>
<P>echo &quot;$SCRIPT: running \`$CONVERT'...&quot;
<BR>
<P>#
<BR>
# The converstion step.
<BR>
#
<BR>
mv $OUTPUT $INPUT &amp;&amp; sh -c &quot;$CONVERT&quot;
<BR>
if [ $? -eq 0 ]; then
<BR>
&nbsp;&nbsp;echo &quot;$SCRIPT: conversion completed successfully.&quot;
<BR>
else
<BR>
&nbsp;&nbsp;echo &quot;$SCRIPT: conversion failed.&quot;
<BR>
fi
<BR>
<P>#
<BR>
# Deleting the input file.
<BR>
#
<BR>
rm $INPUT
<BR>
-------------snip-------------------------
<BR>
<P>What do you think of this concept?
<BR>
<P>Maybe it is a candidate for sane-1.0.4?
<BR>
<P><P>Best regards,
<BR>
<P>Stefan
<BR>
<P><P><PRE>
--
Stefan Illy | Institut fuer Hochleistungsimpuls-
| und Mikrowellentechnik (IHM)
e-mail: <A HREF="mailto:stefan.illy@ihm.fzk.de?Subject=Re:%20A%20simple%20scheme%20to%20produce%20arbitrary%20output%20formats&In-Reply-To=&lt;14745.3491.849563.564819@ihmgyro5.fzk.de&gt;">stefan.illy@ihm.fzk.de</A> | Forschungszentrum Karlsruhe GmbH
phone: (+49) 07247/82-4165 | Postfach 3640
fax: (+49) 07247/82-4874 | D-76021 Karlsruhe, Germany
<P><P>--
Source code, list archive, and docs: <A HREF="http://www.mostang.com/sane/">http://www.mostang.com/sane/</A>
To unsubscribe: echo unsubscribe sane-devel | mail <A HREF="mailto:majordomo@mostang.com?Subject=Re:%20A%20simple%20scheme%20to%20produce%20arbitrary%20output%20formats&In-Reply-To=&lt;14745.3491.849563.564819@ihmgyro5.fzk.de&gt;">majordomo@mostang.com</A>
</PRE>
<P><!-- body="end" -->
<HR NOSHADE>
<UL>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0133.html">Jochen Eisinger: "bug in mustek_pp"</A>
<LI><STRONG>Previous message:</STRONG> <A HREF="0131.html">Chris Pinkham: "Re: sane-1.0.3 released"</A>
<!-- nextthread="start" -->
<LI><STRONG>Next in thread:</STRONG> <A HREF="0160.html">Henning Meier-Geinitz: "Re: A simple scheme to produce arbitrary output formats"</A>
<LI><STRONG>Reply:</STRONG> <A HREF="0160.html">Henning Meier-Geinitz: "Re: A simple scheme to produce arbitrary output formats"</A>
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#132">[ date ]</A>
<A HREF="index.html#132">[ thread ]</A>
<A HREF="subject.html#132">[ subject ]</A>
<A HREF="author.html#132">[ author ]</A>
</UL>
<!-- trailer="footer" -->
<HR NOSHADE>
<P>
<SMALL>
<EM>
This archive was generated by <A HREF="http://www.hypermail.org/">hypermail 2b29</A>
: <EM>Tue Aug 15 2000 - 02:28:00 PDT</EM>
</EM>
</SMALL>
</BODY>
</HTML>