[sane-devel] xscanimage and 16bit - patch

mh crapsite at gmx.net
Thu Oct 11 09:32:31 BST 2001


Hi,
while experimenting with 16bit/channel images, I found the following problem in
xscanimage:
When you scan such an image, xscanimage saves the image in P5/P6 raw PNM
format with the max color component set to 255. I think, this can't be read by
any application.
I'd like to suggest, that we set the max color component to 65535, like it's
done already in scanimage. This format can at least be read by some apps like
Xv. 
Another problem:
When you use xscanimage as a gimp plugin and try to scan a 16bit/channel image,
you get an error message. Nevertheless a new window pops up which displays only
garbage. I think, this could be avoided by checking for a valid bit depth in
scan_start().
Please review the patch for xscanimage.c .

Bye
Michael




-------------- next part --------------
--- xscanimage_orig.c	Thu Oct 11 10:30:46 2001
+++ xscanimage.c	Thu Oct 11 11:34:33 2001
@@ -923,8 +923,9 @@ scan_start (void)
 	    case SANE_FRAME_RED:
 	    case SANE_FRAME_GREEN:
 	    case SANE_FRAME_BLUE:
-	      fprintf (scan_win.out, "P6\n# SANE data follows\n%d %d\n255\n",
-		       scan_win.param.pixels_per_line, scan_win.param.lines);
+	      fprintf (scan_win.out, "P6\n# SANE data follows\n%d %d\n%d\n",
+		       scan_win.param.pixels_per_line, scan_win.param.lines,
+          (scan_win.param.depth <= 8) ? 255 : 65535);
 	      break;
 
 	    case SANE_FRAME_GRAY:
@@ -932,8 +933,9 @@ scan_start (void)
 		fprintf (scan_win.out, "P4\n# SANE data follows\n%d %d\n",
 			 scan_win.param.pixels_per_line, scan_win.param.lines);
 	      else
-		fprintf (scan_win.out, "P5\n# SANE data follows\n%d %d\n255\n",
-			 scan_win.param.pixels_per_line, scan_win.param.lines);
+		fprintf (scan_win.out, "P5\n# SANE data follows\n%d %d\n%d\n",
+			 scan_win.param.pixels_per_line, scan_win.param.lines,
+       (scan_win.param.depth <= 8) ? 255 : 65535);
 	      break;
 	    }
 	  scan_win.header_size = ftell (scan_win.out);
@@ -952,6 +954,15 @@ scan_start (void)
       size_t tile_size;
 
       /* We are running under the GIMP */
+      /*Check whether bit depth is supported by the Gimp*/
+      if (scan_win.param.depth > 8)
+      {
+        gsg_set_sensitivity (dialog, TRUE);
+        snprintf (buf, sizeof (buf), "The Gimp doesn't support images with %d bit/channel.",
+		              scan_win.param.depth);
+        gsg_error (buf);
+        return;
+      }
 
       scan_win.tile_offset = 0;
       tile_size = scan_win.param.pixels_per_line * gimp_tile_height ();


More information about the sane-devel mailing list