[sane-devel] Patch to scanimage.c for 16-bit PNM files (was: Epson 2450: scanimage produces invalid PNM files)
Roland Roberts
roland@astrofoto.org
14 Apr 2002 18:40:19 -0400
--=-=-=
>>>>> "Oliver" == Oliver Rauch <oliver.rauch@rauch-domain.de> writes:
Oliver> The pnm format has been extended in april 2000.
Oliver> As far as I can see there are two interesting new things:
Oliver> 1) 16 bit raw data
Oliver> 2) more than one image in a pnm file
Here is a patch against the source in sane-backends 1.07. To be
complete, it requires a patch to configure.in to test for
WORDS_BIGENDIAN since it only byte-flips values in the read buffer if
the native byte-order is little-endian. When writing TIFF files, it
does nothing.
roland
--
PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD RL Enterprises
roland@rlenter.com 76-15 113th Street, Apt 3B
roland@astrofoto.org Forest Hills, NY 11375
--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=scanimage.diff
Content-Description: Write 16-bit/color PNM files MSB first
--- scanimage.c.~1~ Sat Apr 13 12:06:45 2002
+++ scanimage.c Sun Apr 14 18:37:01 2002
@@ -1187,7 +1187,24 @@
}
}
else
+ {
+ if ((output_format == OUTPUT_TIFF) || (image.Bpp == 1))
+ fwrite (buffer, 1, len, stdout);
+ else
+ {
+#if !defined(WORDS_BIGENDIAN)
+ int i;
+ for (i = 0; i < len; i += 2)
+ {
+ unsigned char LSB;
+ LSB = buffer[i];
+ buffer[i] = buffer[i+1];
+ buffer[i+1] = LSB;
+ }
+#endif
fwrite (buffer, 1, len, stdout);
+ }
+ }
if (verbose && parm.depth == 8)
{
@@ -1210,7 +1227,22 @@
parm.lines, parm.depth, resolution_value);
else
write_pnm_header (parm.format, image.width, image.height, parm.depth);
+ if ((output_format == OUTPUT_TIFF) || (image.Bpp == 1))
fwrite (image.data, image.Bpp, image.height * image.width, stdout);
+ else /* image.Bpp == 2 assumed */
+ {
+#if !defined(WORDS_BIGENDIAN)
+ int i;
+ for (i = 0; i < image.Bpp * image.height * image.width; i += 2)
+ {
+ unsigned char LSB;
+ LSB = image.data[i];
+ image.data[i] = image.data[i+1];
+ image.data[i+1] = LSB;
+ }
+#endif
+ fwrite (image.data, image.Bpp, image.height * image.width, stdout);
+ }
}
cleanup:
--=-=-=--