ftp.nice.ch/pub/next/tools/scanner/scanner.README

This is the README for scanner.0.7.sd.tar.gz [Download] [Browse] [Up]

						SCAN300C		Version 0.7

				Scanning Images with the Epson 300C Scanner


Scan300c provides a line-mode driver for the Epson 300C color scanner.  The program is intended to provide a very simple interface to the scanner.  An obvious extension in the future would be a nice graphical interface.  The program is coded for the Epson 300C specifically.  Unless other scanners use the same protocol (your guess is better than mine), there is little chance this will work with any other device.

While scan300c was developed on my NeXTstation and this early released is geared for the NeXT, I have taken care to make porting this to other platforms as easy as I can anticipate.

This program may be freely redistributable in its original, unmodified form. The author grants you a nonexclusive, royalty-free license to use this software, and modify it as needed provided that this copyright notice remains, and any changes are clearly indicated as such.  No part may be incorporated in products or packages sold for profit without express permission of the copyright holder. The author assumes no responsibility for the consequences of using this program and no warranty of any sort is expressed or implied.

Some parts of this package are re-distributed by the gracious permission of the authors. Please report errors directly to me.

										Terry Gliedt
									<tpg@rchland.vnet.ibm.com>
										October 1992

NeXT Installation

The distribution is done as a compressed tar file, scanner.tar.Z. Extract the files from this with the command "zcat scanner.tar.Z | tar xvf -". This creates several files under the directory scanner.  For the convenience of the NeXT community binary files for scan300c, ppmquant and pnmtotiff are distributed.  You make create a new scan300c file from the sources by simply invoking "make" in the scanner directory.  The command "make install" will install the binaries in /usr/local/bin.  Refer to the Makefile and source files for more details.

Usage

Scan300c recognizes a very large number of options which fall into two groups.  Options specified as lower case letters control general functions of the scanner.  Options specified by upper case letters correspond to specific low-level functions of the scanner.  In general you will only want to deal with the first set.  The second set are really only useful for someone who has an Epson 300C Programmers Guide.  If you enter scan300c with no options the program will generate a short help summary. Note that the options should be specified in the order you wish them performed.

	scan300c  [ options ]

Options:

	-a MO SO ML SL	Set the reading area which will be scanned.  The reading area is
			defined as a rectangle ML by SL pixels at pixel offset MO,SO.
	
	-b N		If the device is a serial line, set the line speed.  N may be 9600 or 19200.
	
	-c		Set the scanner to scan in color (24 bits per pixel).
	
	-d dev	Set the device to open.  The default for this is set in the Makefile.  On the NeXT
			 this is typically /dev/ttya, /dev/ttyb or /dev/sg0.
	
	-f target	Specify a specific NeXT SCSI device address. The default is to search for device.
	
	-g		Set the scanner to scan in gray-scale (8 bits per pixel).

	-g4		Set the scanner to scan in gray-scale (4 bits per pixel).

	-g2		Set the scanner to scan in gray-scale (2 bits per pixel).

	-i		Performa software re-initialize of the scanner. Note this is option is order sensitive.
			The effects of any options specified before -i will be lost. you probably want to
			specify this first.
	
	-m		Set the scanner to scan in monochrome (1 bit per pixel).

	-n name	Set the name of document in the TIFF file.  This is passed as a comment			in PPM files.
	
	-q		Perform a query of the status of device.
	
	-r N		Set the resolution to N dpi. N may vary from 50 to 600 dpi. N will be rounded
			up to the nearest scanning resolution supported by your scanner. Issue
			"scan300c -I" to see what resolutions your scanner is capable of.
	
	-s File	Scan at current settings to File. If this is a non-color scan, File will be a TIFF file.
			Color scans result in a PPM RAWBIT format. Color scans may specify File as
			"-" to generate data to stdout for use in pipes.
	
 	-v		Verbose mode. Specify this to see more detail about what is happening with
			your scanner. Specify this more than once to get more data. Beware, this may
			result in very large amounts of trace information.
	
	-x		Do not generate any confirmation messages about what is happening.
	
	-y serial/scsi/parallel		Force the device access protocol to be serial, scsi or parallel.
			This can be used to force how scan300c will attempt to drive the device. The
			default is to guess based on the device name.
			
 	-z N		Set the zoom level to N where N may vary from 50 to 200%.


Low-level Options:

	-I		Issue the Identify command.
	-F		Issue the Status command.
	-S		Issue the Condition command.
	-G		Start scanning at the current settings.
	-C xx	Set  the color mode to xx  (0, 10, 20, 30, 1, 2).
	-D n		Set the data format  (1-8) .
	-R M,S	Set the main scan resolution to M, Subscan resolution to S.
	-H M,S	Set the main scan zoom to M, Subscan zoom to S (50-200).
	-A MO SO ML SL	Set the reading area.  Offset=MO,SO Scan area=MLxSL.
	-L xx		Set brightness to xx (3, 2, 1, 0, ff, fe, fd).
	-Z xx		Set gamma correction to xx (1, 2, 0, 10, 20).
	-B xx	Set halt tone setting to xx (0, 10, 20, 01).
	-M xx	Set the color correction to xx (0, 20, 40, 80).
	-@		Initialize the scanner.

Examples:

	Reset the scanner and then create a TIFF file from a scan of the entire page.
		scan300c -i -g -s /tmp/gray.tiff

	Scan an area 200 pixels square at an offset of 500,400 in color. A PPM file is created.
		scan300c -a 500 400 200 200 -c -s /tmp/color.ppm

	Scan an area 150 pixels square at an offset of 100,800 in color. A TIFF file is created.
		scan300c -a 100 800 150 150 -c -s - | pnmtotiff > /tmp/color.tiff
	
	
Epson 300C

I make no pretense at being an expert in scanners or imaging technology.  This program was written to take advantage of the only scanner to which I had access.  Scan300c will support both the serial and SCSI interface provided with the Epson scanner. The parallel interface is untested at this time, but I think it should be very trivial to make it work.  My impression is that the Epson scanner is relatively old and slow compared to others on the market these days. I have seen it priced at well under $1000 in the Fall of 1992. I would be interested in extending this code to support other scanners.  Interested parties should contact the author directly.

Motivation

Scan300c was motivated in part because of the remarkably slow and crummy interfaces provided by other tools for the DOS and Windows environments.  The software I was using created huge files. Scans of data was measured  in several minutes on a 386-class machine were common.  The SCSI interface was not supported.  After spending a great deal of time to generate very few images, I decided that trying to use DOS or Windows for anything serious was not worth the effort.  The problem is not what to do with the image once it is generated.  There are many excellent image-products and programs available via FTP.  The problem that scan300c tries to solve is to minimize scan time.

Output Formats

Since the scan time is the big issue, I focused narrowly on the creation of the image.  My intent was to create images quickly and reasonably small.  One issue was what format to create from the resulting image.  Monochrome and gray-scale images (2,4, or 8 bits/pixel) are pretty easy to do.  I have chosen to create TIFF images for these.

Color images with 24 bits/pixel posed a more serious issue.  These files can get quite large (about 3 MB of data for a full page) and the colormaps quickly grow to tens of thousands of entries.  Reducing these colormaps to something smaller means losing information.  Creation of the TIFF images proved a rather large undertaking and the compression of the raw data can require quite a bit of processing.

Since my focus was to scan the images quickly, I chose to leave the color images in the PPM RAWBITS format.  This has the advantage of being widely supported and requires little processing. during the scan. On the negative side, however, the data size for a full page (3 MB) is not as small as it could be.  Compressed 24-bit RGB TIFF files for a page are only 440 KB, but this requires a fair amount of processing to create.

Credits

Writing this program took me into two areas that I had not attempted in the past - programming at the ioctl level and processing image files.  Thanks to NeXT for its /NextDeveloper/Examples/SCSI examples and especially to Sam Leffler for his TIFF libaries and Jef Poskanzer for his PBMplus software. See the file COPYRIGHT.INFO for restrictions placed on this code.

The TIFF libraries are available from ucbvax.berkeley.edu (128.32.133.1) in pub/tiff/v3.0.tar.Z.  The PBMplus package is available from sgi.com  in pub/????.

Line-Mode Interface

Scan300c was not written to be a command an end-user might enter, but rather, from the start the idea is that scan300c would be called by some higher-level and better interface.  As such, scan300c has a rather ugly syntax, supportting dozens of Un*x-style command options. The line mode format does, however, fit nicely in a command of pipes.  For instance to create a 256-color TIFF file, you might enter something like:

	scan300c -c -s - | ppmquant 256 | pnmtotiff > myfile.tiff

Performance

The Epson is capable of  generating a great deal of data.  One would normally want to transfer this data as quickly as possible.  The scanner can generate data by three interfaces, a serial line operating at 9600 or 19200 bps, a parallel interface (unfortunately not available on the NeXTstation), and a SCSI interface.  The SCSI interface is not as fast as I expected. This is apparently due to the relatively slow SCSI bus on the NeXT.  I have yet to compare scan300c on the NeXT with other hardware platforms.

These numbers will give you some idea on the relative speeds you should expect.  I do not believe there is much more that can be done in scan300c to speed these up. The following were used to generate a full page scan (848x1169 pixels at 100% and 100 dpi).

	Data Path			Data	 Type	Time		Data Size
	Serial 19200 bps	monochrome	81 secs	23 KB
	Serial 19200 bps	8-bit gray		554 secs	133 KB
	Serial 19200 bps	24-bit color	1651 secs 2974 KB
	
	Parallel			monochrome	n/a		23 KB
	Parallel			8-bit gray		n/a		133 KB
	Parallel			24-bit gray	n/a		2974 KB
	
	SCSI			monochrome	27 secs	23 KB
	SCSI			8-bit gray		36 secs	133 KB
	SCSI			24-bit gray	120 sec	2974 KB

Data Size

Scanned data from the Epson can quickly become very large. The amount of data depends on several factors:

	Number of bits per pixel (1, 2, 4, 8 or 24)
	Resolution in dots per inch (50 to 600)
	Zoom value (50% to %200)
	
The resolution and zoom values determine the maximum scanning size.  For instance at the lowest resolution and minimum zoom value (50 dpi and 50%) the image is 208 by 292 pixels while at the highest resolution and maximum zoom value (600 dpi and 200%) the image is 10208 by 14032 pixels. The data from the scanner can be calculated by the formula:

	data bytes = ( width pixels X length pixels X bits per pixel ) / 8
	
For example for a scan of the maximum area, the data could for a monochrome scan would range from 7592 bytes to 17,904,831 bytes. The values for a color image would be 24 times larger. 

Bugs

The protocol defined by Epson for the scanner requires synchronous communication (data reception is ackowledged).  If communications are interrupted because of a segment fault in scan300c or because the communication line is interrupted, the scanner will timeout after 30 seconds. This error is shown on the scanner LED with an E-1 code. When this happens the scanner stops listening and cannot be reset by any software. You must manually power the scanner off and then back on.

Despite the best efforts, sometimes the scanner justs gets confused (good technical term, eh?).  Perhaps this was just the scanner I was using.  In any case, if you think the scanner is misbehaving, try powering the scanner off and then on and trying again.  I do not believe this is caused by anything in scan300c, but if you should find otherwise, let me know.

Future Intentions

* Make scan300c useful on non-NeXT platforms.

* Add a NeXTStep interface.

* Extend scan300c to support other scanners like the HP ScanJet.

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.