/*
Copyright (C) 2000-2001, 2006-2007 Peter Popovec

This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991.
         
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
                
You should have received a copy of the GNU General Public License
along with this package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
                                
On Debian systems, the complete text of the GNU General
Public License can be found in /usr/share/common-licenses/GPL'.
*/

--------------------------------------------------------------------
                      PXSCANSANE
--------------------------------------------------------------------

pxscansane is a package witch "pxscansane" ("pxscan" from upstream) a user
space program for driving PRIMAX parallel scanners based on the 'E3' ASIC.
At this time 600p and D9600 models are supported. SANE backend in now
included in package.  All tests of this software was made only with primax
colorado 600p.

This pxscansane is derived from original pxscan source downloaded from: 
http://home2.swipnet.se/%7Ew-25069/pxscan.html
sane backend is based on: primaxscan-1.1beta1
http://thor.prohosting.com/~chrordig/Primax/ 
and sane 
ftp://ftp.mostang.com/pub/sane/ sources.
Please check COPYRIGHT inside all sources.
--------------------------------------------------------------------------
INSTALATION:

1. unpack source
2. run "make" 
3. copy binary file "pxscansane" to /usr/bin or /usr/local/bin or whatever else
4. copy pxscansane.1 to /usr/share/man/man1/pxscansane.1
5. copy libsane-pxscan.so.1 /usr/lib/sane/libsane-pxscan.so.1 (or consult
   your sane installation manual) 

Development files (compiler, librarier, binutils etc.) must be installed
before step 2. Special libtiff4-dev, libsane-dev must be installed. 

For enabling autodetect of scanner by sane, insert at enf of file
/etc/sane.d/dll.conf  one line with word "pxscan" or consult sane manual. 


DEBIAN USERS:
please use precompiled package. Or .. compile deb package  by typing
"debian/rules binary" inside source tree. (debian devel packages must be
installed before doing this).

-------------------------------------------------------------------------
USAGE:

Please, for first verify if you have access to /dev/parport0.
(maybe chmod 777 /dev/parport0 may help to get access to scanner, not
recomented for multiusers servers/workstations)

If /dev/parport0 does not exist on your system, consult FAQ below. 

For "pxscansane" use "man pxscansane" to check how to make a scan from
command line.

sane: run "scanimage  -d pxscan"  or "xscanimage pxscan" or "xsane pxscan"
check options for scanimage by "scanimage --help -d pxscan"

If sane autodetect is enabled, xsane and xscanimage detect scanner without
device name. Just type "xsane" or "xscanimage" and select scanner from list.
-----------------------------------------------------------------------------

HISTORY of pxscansane:

2000 Apr. I start witch reverse ingeneering of windows (3.11) driver for
primax colorado 600p. Binary patched driver was created for snooping data
between scanner and computer. This was start of write some experimental
programs to drive scanner. 

2000 May. I found pxscan-0.1 from Gustaf Kroling <g.kroling@swipnet.se>. 
this driver was work with scanner, but only in discrete dpi. 
In my experiments I found registers in scanner for setup all supported
resolution. pxscan-0.2 from Gustaf is based on this resolution setup.

Next I write lot of code for new "0.3" but this code was inconsistent witch
upstream from Gustaf and only available as pxscan-0.3preX on my website.  

2001 I do not hawe scanner for tests ..  

2006 Apr. I found 0.41 version of upstream pxscan from Gustaf. I found my
old scanner. Gustaf code still use direct port access. I write
pxscan-0.41parport version. This is upstream pxscan with modification in
port access. This code uses /dev/parport. Minimum changes was made in
upstream.

2006 Jul. I write sane  backend  based on pxscan-0.41.. still minimum changes
in upstream. 

2006 Sep. It is unable to write sane backend and libieee support witch
minimum changes in upstream. New branch derived from upstream is created
with name "pxscansane".

2006 Dec. debug image of scanarrea, solved bug in B/W scan, minor fix for 
clean compilation with libieee1284-3 0.2.10-4, sane 1.0.18 

Significant part of upstream code was changed:
 
1. More part of original upstream code was moved from pxscan.c to
   libpxscan.c. 

2. New pxscansane.c is only "wrapper" around libpxscan with same
   functionality like old pxscan.c. This enable to create a libsane-pxscan 
   backend for sane with uses libpxscan to access scanner.
   pxscansane.c is now obsollete, but may work like old pxscan.c

3. libpxscan uses libieee1284 to access hardware of scanner

4. more parport and scanners support is included in this version.
   (not fully tested)

5. Autodetection of scanner/port

6. code in libpxscan uses macros and procedures for setup scanner.. Names of
   macros/procedures describes functionality of code, code is more readable.  

7. libpxscan.c is now fully rewrited from scratch. More part is based on
   sequences from WIN driver.

8. debugging support based on settings of envinroment variable PXSCAN_DEBUG

9. 16 bit scanning mode (full 12 bit resolution per color), without gamma
   corrections

10. 8 bit scanning mode  support full gamma corections (by 12 to 8 bit
    conversion tables)

11. B/W scanning with threshold 

12. Manual gamma in advanced settings 

13. new CCD sensors sensitivity compensation in advanced settings 

FAQ:

Q: Why do not use the original "pxscan-XX" source ? 

A: Original source accesses parallel port directly and needs root privileges.
   Direct access to periferals breaks linux security and breaks the parport 
   sharing functionality supported by linux kernel. No sane support. Sane
   bacend enable using scanner in all applications supported by sane and
   using (all ?) features of this scanner.

Q: How does this code accesses scanner ?

A: This driver uses a libieee1284 library.

Q: What need libieee1284 to access hardware of scanner ?

A: if code is run with root privileges (not recomented) only support for
   parport is needed in kernel.

   for user access /dev/parport is used, Kernel must have the support for
   the /dev/parport0. Most distributions of linux (debian, fedora .. ) has
   the support in precompiled kernel for /dev/parport0. For self compiled
   kernels must be CONFIG_PARPORT=m or CONFIG_PARPORT=y and CONFIG_PPDEV=m
   or CONFIG_PPDEV=y included in config file.
   
   For menuconfig please select:
   Device Drivers 
	-> Character devices 
		-> Support for user-space parallel port device drivers 

   if parport and ppdev driver is compiled as a module, please use the 
   command:

   # modprobe ppdev 

   to load module into kernel

   If /dev/parport0 does not exist and kernel support for  CONFIG_PARPORT 
   and CONFIG_PPDEV is enabled, maybe mknod, MAKEDEV od udev can help to 
   create /dev/parport0.


Q: Which kernel version have the support for /dev/parport ? 

A: All kernels 2.4.X and 2.6.X may have support for the /dev/parport

Q: Only root has the  access to /dev/parport. How can I set up privileges 
   for other users ?

A: default privileges on /dev/parport0 allows using parport only for group lp
   Add all users which may have access to scanner to group lp (edit /etc/group) 
   Or, change  owner/group/permisions  on /dev/parport0 ....



DEBUG:

set environment variable PXSCAN_DEBUG to value:
DBG_ALL         255
DBG_PORTIO        1
DBG_ASIC	  2
DBG_CALIBRATION   4
DBG_SCAN          8
DBG_FIFO         16		< lot of debug !!!!!
DBG_HELPERS      32
DBG_SANE        128

by environment variable PXSCAN_DEBUG_IMAGE can be set name of image from
calibration arrea. 

example:
export PXSCAN_DEBUG_IMAGE=/tmp/calibration_arrea.ppm
export PXSCAN_DEBUG=255


for libieee1284 debugging use LIBIEEE1284_DEBUG enviroment variable and read
libieee1284 dev manual. 

hint for port for scanner can be set by enviroment variable
PXSCAN_PORT_HINT (see man pxscansane option -P )

example for find scanner only on port at address 0x278:

export PXSCAN_PORT_HINT=0x278

or only for parport0:
export PXSCAN_PORT_HINT=/dev/parport0


Warning ! 3.Aug.2007

libieee1284 before version 0.2.10 (debian version 0.2.10-6) and kernels
newers that 2.6.21.X is unable to detect parport. This is due change in
kernel proc interface for parport. Wrong is ? kernel ?, number of directory
links for /proc/sys/dev/parport is 0 and libieee1284 check this number for
> 2. This test fail and no parport (scanner) can be detected.  Workaround can
be made by patching and recompilling libieee1284 library.

patch:
--- detect.c.orig       2007-08-03 09:27:29.000000000 +0200
+++ detect.c    2007-08-03 09:27:46.000000000 +0200
@@ -69,8 +69,7 @@
   int which = 0;
   struct stat st;
   if (stat ("/proc/sys/dev/parport", &st) == 0 &&
-      S_ISDIR (st.st_mode) &&
-      st.st_nlink > 2)
+      S_ISDIR (st.st_mode))
     {
       which = PROC_SYS_DEV_PARPORT_CAPABLE;
       debugprintf ("This system has /proc/sys/dev/parport\n");

(patch is already in libieee1284 bugreport system).

Real solution is wanted (by libieee1284 developers or kernel developers).

