Re: [Announce] WinSANE 0.1.0.0 Release

Ewald R. de Wit (ewald@pobox.com)
Wed, 12 May 1999 11:47:28 +0200

Matthias Fleischer (FLEISCHER@ito311.ito.uni-stuttgart.de) wrote:

> >
> > ----------
> > Valid bit depths are 1, 8, or 16 bits per sample. If a device's
> > natural bit depth is something else, it is up to the driver to scale
> > the sample values appropriately (e.g., a 4 bit sample could be scaled
> > by a factor of four to represent a sample value of depth 8).
> > ----------
> >
> Maybe I'm just nitpicking or simply don't get it -
> but shouldn't this actually read:
>
> ...a 4 bit sample could be scaled by a factor of _seventeen_...
>
> or maybe
>
> e.g., a 4 bit sample could be shifted left by 4 bit to represent a
> sample value of depth 8 or even better multiplied by a factor of
> 0x11 (17) so that white pixels still map to white pixels (15*17=255)

Yes, that is correct. Going from 8 < n < 16 bits to 16 bits is a bit
trickier; you then use

scaled = unscaled << (newlen - oldlen) +
unscaled >> (oldlen - (newlen - oldlen))

with newlen=16 and oldlen the original bit depth.
Andreas Beck was so friendly to explain this in more detail in a
message to this listed dated 6 Apr 1999.

I implemented it like this in the HP backend (although it uses
little CPU I'm open to suggestions on optimizing):

static void
hp_scale_to_16bit(int count, register unsigned char *data, int depth)
{
register uint tmp;
int shift1 = 16 - depth;
int shift2 = 2*depth - 16;
if (count <= 0) return;

while (count--) {
tmp = 256*data[0] + data[1];
tmp = (tmp << shift1) + (tmp >> shift2);
data[0] = (tmp >> 8) & 255U;
data[1] = tmp & 255U;
data += 2;
}
}

-- 
  --  Ewald

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com