Re: [sane-devel] Converting Raw Image Data to PNG

2020-01-14 Thread Olaf Meeuwissen
Hi Daniel, Andy, list,

Sorry, am a bit pre-occupied and busy with the upcoming 1.0.29 release
:-)

Andy Bennett writes:

> Hi,
>
>> Thank you for your responses. I was able to get something! Almost there.
>>
>> I've attached an image of progress so far. By preapending the
>> "magic pnm code" to the top of the data file I was able to get
>> the raw scan data to display, but not properly. It seems to be
>> separating the images into three sections, seemingly RGB. The
>> sideways slant of the image is also a bit off as I couldn't
>> specify the width with a double.
>
> I think you have the dimensions slightly off, but the width (1296) seems
> correct.
> As you say, the image appears slanted and when I try to convert RGBTest.pnm
> to png I get the following:
>
> -
> $ pnmtopng RGBTest.pnm > RGBTest.png
> pnmtopng: EOF / read error reading a row of pixels
> -
>
> It looks like there's an extra 5 pixels every 15 lines or so, except for
> every 5 set of 15.
>
> 15 lines fit into 20KiB, but 16 do not. I'm not sure if that's relevant at
> all. Perhaps there's some extra framing, checksum or meta data coming in
> from somewhere?

I had a quick look at the image only but it appears to be image in a
format very similar to

  p

where every R, G and B, stands for a single pixel's RGB values.  You'll
have to rearrange those in your backend.  The p stands for padding bytes
and need to be skipped when preparing the image data that your backend
returns.

This kind of image data is(was?) pretty common and you should be able to
find usable code in several of the SANE Backends.  I know that the epson
(and epson2?) backend is able to handle such data.

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



Re: [sane-devel] Converting Raw Image Data to PNG

2020-01-13 Thread Andy Bennett

Hi,

Perhaps just raw raster pixel data? Although the ordering of 
the bytes and channels might take some figuring.


I was able to get 
the raw scan data to display, but not properly. It seems to be 
separating the images into three sections, seemingly RGB.


The format of PNM (with a colour depth of 255) is a byte per pixel per 
colour component in the order red then green then blue.


So I guess you'd have to buffer each channel as it comes in from the 
scanner and then interleave them after each page?


This page shows you some examples http://paulbourke.net/dataformats/ppm/
The examples are in P3 rather than P6 format which just means the pixel 
component data is encoded as ASCII numbers rather than binary bytes.


See "PPM example 4".


The 
sideways slant of the image is also a bit off as I couldn't 
specify the width with a double.


How are you processing the image data? Can you share a code snippet?



Best wishes,
@ndy

--
andy...@ashurst.eu.org
http://www.ashurst.eu.org/
0x7EBA75FF



Re: [sane-devel] Converting Raw Image Data to PNG

2020-01-10 Thread m. allan noah
Please note that the image could be truly raw data from the scanners
read heads, not like the 'raw' files produced by cameras, which
typically contain lots of meta information about the camera and the
image. The data you get could be scrambled, interlaced, interleaved,
inverted and uncorrected, and (unless it is JPEG) will contain no
header at all. Fortunately, you can open such a file with a good text
editor, and add a PNM header, then tweak the header until you start to
see an image form.

The latter part of this presentation I gave a few years ago shows the
process I use: https://www.youtube.com/watch?v=pJ60vVOKVr0

allan

On Fri, Jan 10, 2020 at 11:05 AM Chris Moller  wrote:
>
> ufraw and dcraw will handle that conversion.
>
> On 10/01/2020 00:09, dan...@pixelgrease.co wrote:
>
> 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.
> 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.
>
> THANK YOU!
>
> Daniel
>
>
>


-- 
"well, I stand up next to a mountain- and I chop it down with the edge
of my hand"



Re: [sane-devel] Converting Raw Image Data to PNG

2020-01-10 Thread Olaf Meeuwissen
Hi Daniel,

dan...@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-2FSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Softwarehttps://my.fsf.org/donate
 Join the Free Software Foundation  https://my.fsf.org/join



Re: [sane-devel] Converting Raw Image Data to PNG

2020-01-10 Thread Alexander Pevzner

Hi Daniel,

On 1/10/20 8:09 AM, dan...@pixelgrease.co wrote:
1. What format is that raw data likely to be? I naively expected it to 
be png.
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.


Raw data is likely to be just a matrix (2D array) of pixels. One byte 
per pixel in grayscale mode and 3 bytes per pixel in color mode.


In SANE world, there are drivers, called "backends" and client programs, 
called "frontend".


Backends are dynamically loaded libraries, such as sane-pixma 
(/usr/lib/sane/libsane-pixma.so.1) and so on.


Frontends are programs, line simple-scan, scanimage, xsane or even gimp.

Frontend always returns picture in raw format, even if it comes from 
device in some another format (say, PNG or JPEG). This is a 
responsibility of frontend to convert the image into something useful, 
like JPEG or PDF file.


So if you are about to write sane backend, this is not your 
responsibility to convert the image into PNG, but if image comes from 
device as PNG, this is your responsibility to unpack it.


--

Wishes, Alexander Pevzner (p...@apevzner.com)