16-bit color images with pyinsane
<p>pyinsane's scan sessions return a list of 8-bit PIL images by default. This is true, even when the scan has been done in 16-bit mode (for instance using the transparency unit). Is there any way to get 16-bit images (I suppose PIL does not support that) or the original raw data out of pyinsane?</p>

<p>Here is the sample code I am currently using and getting images with 8 bits colour depth:</p>

<pre><code>import pyinsane.abstract as pyinsane
device = pyinsane.get_devices()[0]

device.options['resolution'].value = 1200
device.options['mode'].value = 'Color'
device.options['source'].value = 'Transparency Unit'

scan_session = device.scan(multiple=False)
try:
    while True:
        scan_session.scan.read()
except EOFError:
    pass
image = scan_session.images[0]
</code></pre>

<p>You're right, this is a limitation from Pillow (PIL). You can actually see the conversion from raw to PIL Image here : <a href="https://github.com/jflesch/pyinsane/blob/stable/src/pyinsane2/sane/abstract.py#L161" rel="nofollow">https://github.com/jflesch/pyinsane/blob/stable/src/pyinsane2/sane/abstract.py#L161</a></p>

<p>If you really need this extra data, I guess the only option is to use the Sane API directly and do your own conversions:</p>

<pre><code>import pyinsane.sane.rawapi

pyinsane.sane.rawapi.sane_init()
(...)
pyinsane.sane.rawapi.sane_exit()
</code></pre>

<p>Unfortunately, doing this will make you loose the Windows portability (WIA support), and this part of Pyinsane is not documented at all. However, pyinsane.sane.rawapi provides the Sane C API with only minor transformations to make it more Pythony-friendly. So I guess you can just refer to the Sane documentation for informations : <a href="http://www.sane-project.org/html/doc009.html" rel="nofollow">http://www.sane-project.org/html/doc009.html</a> .</p>

python pillow scanning pyinsane