[sane-devel] HP5470c scanner nearly working!

Bertrik Sikken bertrik@zonnet.nl
Thu, 20 Feb 2003 21:19:26 +0100


Martijn van Oosterhout wrote:

>[Please CC any replies so I can more easily find them through the rest of my
>mail. Thanks.]
>
>I finally got totally sick of waiting for someone to make my scanner work,
>so I did it myself. The results are on my webpage:
>http://svana.org/kleptog/hp5470/. I'm doing it over USB.
>
>Situation is:
>1. It finds the scanner and warms up the lamp
>2. It performs two calibrations scans like in windows
>3. Performs the preview scan and dumps it to disk
>
Cool!

>
>This is only a test program, not a backend. Things still to do:
>1. Actually use results of calibration scans. Anyone who has an idea how
>scanners are calibrated, point me at some info, please.
>
With my hp3300 I do this by scanning an area on the inside of the scanner,
which is mostly white but with a small square black area.
I then determine the color of the darkest pixel and call this the black
level. From the white area, several lines are averaged into a single
white line, which gives a white level for each CCD pixel.
Then a table is calculated which contains a gain and offset value for
each color component (R,G,B) of each CCD pixel. The gain is
proportional to as (white(x) - 'black') and I use simply a value
proportional to 'black' for the offset.

In the hp3300, the calibration table uses a 16-bit word for each
calibration value, lower 6 bits are offset and upper 10 bits gain.

>
>2. Do gamma correction. Right now the gamma correction is linear. Again,
>someone who knows the theory would be helpful here.
>
I my case, I have 4096 entries of 8-bit each and I use
  for (i = 0; i < 4096; i++) {
    iData = floor(256.0 * pow(((double)i / 4096.0), 1.0 / Gamma));
    pabTable[i] = iData;
  }

For your 16-bit to 16-bit table you could use something like
  for (i = 0; i < 65536; i++) {
    buffer[i] = floor(65536.0 * pow(((double)i / 65536.0), 1.0 / Gamma));
  }

The table can be used not only for gamma correction, but also for
brightness and contrast compensation. Infact, if a backend presents
this table to xsane, then xsane will use it automatically for
gamma, brightness and contrast and the backend does not even
need to know how to calculate gamma.

>
>3. Decipher data format. Looks pretty straight forward. R, G, B seperate.
>4. Work out the parameters for the different scan types (B&W, 24-bit, etc).
>5. Turn it into a SANE backend. Hopefully this will not be hard.
>
I won't mind helping you with this.
What I did with the hp3300 was to put the core functionality in one
source file. Then on top of this, I could put either a sane interface
(which is quite simple) or a frontend for a console testtool.

>
>6. Make negative/slide addon work.
>
>Hopefully not far to go now. If anyone can test my code it would be much
>appreciated. Note this version produces a *lot* of debug info. Please send
>it all for bug reports. Thanks.
>
>I'd like to thank Bertrik Sikken for doing some of the ground work.
>
>Have a nice day,
>
Kind regards,
Bertrik