[sane-devel] Converting Raw Image Data to PNG

Olaf Meeuwissen paddy-hack at member.fsf.org
Fri Jan 10 11:44:40 GMT 2020

Hi Daniel,

daniel at pixelgrease.co writes:

> Hello,
> I have been trying to get a device running for a few weeks now. After
> failing to build a backend I decided to hack together my own LibUSB
> driver for my unsupported A8 scanner, given my use case is pretty simple
> I went in with a "how hard can it be?" attitude.
> Great success so far. Hasn't been easy but it hasn't been really that
> bad. I have managed to ask my tiny A8 feed scanner to scan a 300dpi
> colour image. I have been able to save the data to a file (about 8mb
> worth) but that's where the fun ends.
> Can't seem to figure out how to get that raw data into a usable format.
> 2 questions:
> 1. What format is that raw data likely to be? I naively expected it to
> be png.

Hmm, more likely to be "raw" data or JPEG.
Save the image data you get to file as is and let the `file` command
take a stab at it.  It should recognize standard image file formats.

If it's raw data, you want to note the image width, height and depth of
your scan and try prepending a PNM header to the data you got.

> 2. Does SANE have some code that handles that sort of conversion I could
> have a look at? Looked around the internet and the SANE docs. Read some
> things about frames, but couldn't find much else.

If it's raw data, you can very likely just pass it to a SANE frontend as
is (assuming 1, 8 or 16 bits per pixel and telling the fronted that).

For JPEG, there are a number of backends that already handle that.  Just
run `git grep -l jpeg -- backend` to find them.  For PNG, you may want
to check the brand new escl backend.

Hope this helps,
Olaf Meeuwissen, LPIC-2            FSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Software                        https://my.fsf.org/donate
 Join the Free Software Foundation              https://my.fsf.org/join

More information about the sane-devel mailing list