To Github!

 updated on Thursday, June 12th, 2014 by Triften

I've commited my current (I think) code to a github repo:


 updated on Saturday, Apr 11th, 2009 by Triften

Latest version: hp4600-scanfullpage11.c Compile with
gcc hp4600-scanfullpage11.c -o hp4600scanfullfile -lusb
You will need libusb and probably libusb-devel installed to compile this. To use, just run
hp4600scanfullfile (output filename)
Image fixer: fixhp4600output02.c Compile with
gcc -o fixhp4600output fixhp4600output.c
./fixhp4600output (input filename) > (output filename)
One step glue script (you must have the other two executables made): hp4600onestep
Just make executable (chmod 770 hp4600onestep), then run
./hp4600onestep (output filename)
It will scan to a temp file, run the fixer, then delete the temp file for you. This is a stopgap until I take the time to incorporate the banding/color correction into the executable.

Fixed color

 posted on Monday, Feb 16th, 2009 by Triften

I went to scan a primarily red document and it came out blue. At first I thought "That is some amazing copy protection!", then I tried another document and the red in that came up blue as well. Turns out that the scanner puts out RGB bytes while the bmp format is BGR. The new fixer, "fixhp4600output02.c", takes care of it. Whee! (Tested and confirmed on a rainbow sock.)

Trimmed some things down

 posted on Monday, Feb 16th, 2009 by Triften

I pulled some commands out into functions and named some routines based on the SQ113 code. The source file is roughly half the size of what it was before and makes some of the functionality a little more apparent. It's still a black magic incantation that results in a completed scan (with a confirmed test from another user!! Yay! Thanks, Stego!) Also, I hardcoded the vendor and device IDs and it now accepts a filename as input so the usage is
hp4600scanfullfile (output filename)
You may or may not need an "sudo" in there.

For instructions on compiling, head farther down the page to here.

I also wrote code to fix the output postscan. It fixes the 4 pixel offset between the bands. I'll eventually incorporate this into the scanning and fix it as it scans. fixhp4600output.c
This uses no libraries or anything so it can compile straight away with
gcc -o fixhp4600output fixhp4600output.c
then to use it run
./fixhp4600output (filename) > (output filename)
Current TODO is:
  • Check for output file already existing
  • Process output during scan to correct goofy offset
  • Do other scan options and figure out how to adjust for B/W and different DPIs
  • Figure out what more of the functions actually do

Detects as SQ113? Mustek_usb2?

 posted on Monday, Dec 8th, 2008 by Triften

The controller chip in the HP Scanjet 4600 detects as an SQ113 according to its page on the SANE website. This is the same chip that the mustek_usb2 backend works on. I don't know how to force sane to use a backend on an unsupported scanner, but I'm just about willing to try it out at least.

I've been looking through the code and comparing it to the log from SniffUSB. A lot of the commands look the same and match up with about when I'd expect the commands to be issued, though I think that HP or SQ expanded a little bit on this one. A register/command labeled GPIO in the mustek_usb2 code gets used by the Windows driver for the HP 4600.

I'm not sure if I should spend time looking at the log to pick it apart, or just get an executable to do a full page scan and consider that good enough. One could always edit it as needed with GIMP.

A basic executable!

 posted on Saturday, Dec 6th, 2008 by Triften

CODE: hp4600-scanfullpage5.c

I used
SniffUSB to capture a log of a full page scan, then ran the log through to get some basic functioning code. I added file output for the image data as well as consolidating the actual scan itself into a nice loop (it was the same 8 commands about 207 times.) Some existing issues are that the image will come in upside-down and it will appear to be cut into 334 pixel wide strips which are offset from their neighbors by about 4 pixels, making horizontal lines jagged.

Also, very light areas (primarily the bed of the scanner) appear to be different shades of white, but this is apparent when scanning under Windows so I'm not sure what is causing that.

Current TODO is:
  • hardcode USB ID sequence?
  • accept filenames
  • Change repeated commands to const unsigned chars
  • Also change really long lines to... well, shorter lines. (Some commands are roughly 4k long and converts them into strings of escaped hexcodes. I think they'd be prettier as arrays.
  • Figure out warm up sequence and change to loop. There are sequence where the driver appears to be reading from various registers by pushing a 4 byte code of "8b xx 8b xx", then reading a single byte. It seems like 8b 03 reads a status byte for warmup or some such. The log I have from a cold start reads 0x51 at the start, polls it a number of times, then before it starts scanning, it reads 0x71. Logging a second scan just after the first showed this value starting at 0x71 and the scanner beginning almost immediately.
  • Remove excess file output. This is just about done. I was printing almost every bulk_read result to the file so there was some garbage in there.
  • Post process output to adjust weird offsets... There's the offset strangeness as well as the bmp being upside down. I'll likely have it write to a temp, then go back and fix the order and offsets.
  • Do other scan options and figure out how to adjust for B/W and different DPIs
  • Check for output file already existing.
To make the executable, download hp4600-scanfullpage5.c, make sure you have libusb installed and run "gcc hp4600-scanfullpage5.c -o hp4600scanfullfile -lusb". To use the command, you'll need to sudo the executable. It will likely gripe about assorted USB things, then return a list of IDs for USB devices on your system. My Scanjet 4600 is 0x03f0 0x3005 (0x03f0 is for HP), yours may be slightly different. Then run "sudo hp4600scanfullfile [USB ID for scanner]" and the scanned image will land in "scanned.bmp". There are no options for scanning at this time, so it will be a full page 24-bit image at 600DPI weighing in at just over 100MB.

Please send any feedback to triften at g mail dot com (no space between g and mail and add the proper symbols, of course.)


[ Index | Webmail ]