/*
        hpscanpbm
        User-level SCSI HP Scanjet driver
        Written by David Etherton, etherton@netcom.com
        HPUX Port by John Fehr, fehr@ninja.aes.mb.doe.ca
	Little hacks by Steve Enns  ennss@nhrisv.nhrc.sk.doe.ca
	Copyright 1995, David Etherton
        Released under the terms of the GPL.
        *NO WARRANTY*

        Thanks to Les Johnson (les@ulysses.homer.att.com) for
        suggesting some Linux documentation clarifications.

        THIS IS ALPHA SOFTWARE.  IT WORKS FINE FOR ME.
        IT MIGHT NOT WORK FOR YOU.  You'll need to be
        familiar with rebuilding kernels to take
        advantage of this program (under older versions
	of Linux at least)

	Version 0.3alpha: dpi, save/restore tweaks, documentation
		update for newer linux kernels.

        Version 0.2alpha: HPUX port, better documentation, more
                scanner adjustments.

        Version 0.1alpha: initial release
*/

/*
        Build with cc hpscanpbm.c -o hpscanpbm

        Use "hpscanpbm -help" for instructions.  Creates portable pitmap
        file as output.  Can easily be used in a pipeline or with a
        "real" scanning application.  To use from an application,
        fork, redirect stdout and stderr, then exec this program with the
        -quiet switch.  On termination, if you got anything from
        stderr, issue it as a diagnostic; otherwise, interpret
        stdout as a PBM file.

*** Linux Notes ***

        THIS IS NOT A DEVICE DRIVER.  Your Scanjet must be connected
        to a SCSI adapter that is supported by Linux.  While the chipsets
        used on the boards supplied with the IIc and IIcx (NCR 53C400 and
        53C800) do seem to have some support under Linux, these exact
        board configurations are not supported yet.  I've had good luck
        with a Future Domain TMC-850.  Performance of this 8bit card
        isn't amazing but it definitely works.

        This program uses the generic SCSI interface.  Therefore, you 
        must have generic scsi enabled in your kernel, and you should
        have a series of generic SCSI devices set up:
        
                /dev/sga        major 21, minor 0 (mknod /dev/sga c 21 0)
                /dev/sgb        major 21, minor 1 (mknod /dev/sgb c 21 1)
                :               :

        SCSI generic devices should be character devices, not block
        devices.  Furthermore, even devices that are already assigned
        to other names (like /dev/sda, /dev/sr0) also get a generic
        entry point.  This means that you need at least as many scsi
        generic device entries as you have scsi devices.

       	If you're paranoid, clear all permissions on all generic devices 
       	except the scanner.  Figuring out in advance which generic device 
       	ends up being your scanner can get a little tricky.  If you only
        have one SCSI bus, they're allocated in order of SCSI id.
        In my case, I've got two SCSI controllers, one for my
        internal stuff and one for my scanner; I've got three devices
        on the first bus so my scanner ends up being on /dev/sgd.
        (I've got the wrong kind of cable to hook everything onto
        a single bus).  Unless the program is given the "-quiet" or
        "-dev" options, it will tell you where it found the scanner.
        The scanner's device must have both read and write permission.

        If you're running anthing older than about 1.1.74, you'll probably 
	also need to patch /usr/src/linux/drivers/scsi/scsi.c
        near line 370.  In a switch statement containing the lines:
        (the first line is a bit different as of kernel 1.1.73)

                switch (type = scsi_result[0])
                {
                      case TYPE_TAPE :
                      case TYPE_DISK :
                      case TYPE_MOD :
                        ** add this: **
                      case 3 :
                        SDpnt->writeable = 1;
                        break;

        you'll need to add "case 3:" as indicated above; you'll also need
        to add the HP scanner to the scsi blacklist near the top of
        the file:

        static struct blist blacklist[] =
        {
                :       :         :
                : lots of entries :
                {"HP", "C1750A", "3226"},
                {"HP", "C2500A", "????"},
		{"HP", "C2570A", "3406"},
                {NULL, NULL, NULL}};
        }

        I've tested this under 1.1.49, 1.1.72, 1.1.73, and 1.1.94.
	That shouldn't matter too much, I hope.  

        The program is smart enough to autoprobe for your Scanjet
        and won't try, for example, to read your disk drive.

	Generic SCSI got broken in the late 1.1.70's and didn't
	get fixed again until the late .80's.  All of the patches
	listed above are in the current kernel (1.1.94) *except*
	for the "C2570A" blacklist entry which is for the Scanjet 3p.

*** HPUX Notes ***

        On the 700 series, use the following command:
        mknod /dev/scanner c 105 0x201<N>00 (where N is the scsi #)
        You might also want to do a 'chmod 666 /dev/scanner' to allow 
        everyone to access the scanner.

	Compile:   cc +O3 -Aa -D_HPUX_SOURCE hpscanpbm.c

        (Please direct HPUX questions to John)

*** Steve Enns/Synergrafix Consulting notes ***

	Code changes marked with **ENNS**

	I have added the following options:

	-xres, -yres   to specify the desired width,height of the
		scanned image in pixels.  xdpi,ydpi  will be adjusted
		to get the desired number of pixels for a given scan
		size.
	-s filename, -l filename   to save/load a file containing
		the other optional parameters.  These options are
		sensitive to option order on the command line - 
		i.e. specify -l first if you want to override some 
		settings from the file, and specify -s last if you
		want to save all the options from the current command
		line to the parameter file.  

	e.g.
	
	hpscanpbm -xres 1280 -yres 1280 -cm -width 12 -height 12 -format color -s cdcover.hps > sample.ppm

	will scan an image and save the parameters to  cdcover.hps  which can
	be used later as:

	hpscanpbm -l cdcover.hps > sample2.ppm

	suitable for scanning audio CD covers ;-)

*/


