[sane-devel] New snapshots available: sane 1.0.10-pre2

Henning Meier-Geinitz henning@meier-geinitz.de
Fri, 24 Jan 2003 16:17:18 +0100


Hi,

On Fri, Jan 24, 2003 at 03:56:18AM +0100, Andrea Suatoni wrote:
> 3) I've tried to fix the xcam code related to the GdkImage data buffer
> filling. I've resorted to the RGB shift values contained in the GdkVisual
> associated to the image.

Good idea.

> It seems to work pretty well now, and should be more
> portable among different platforms and X11 visuals. The code should be tested
> on little endian architectures, and with 15 or 16 bits visuals.

24 bit/ 4 bytes per pixel work (on little endian). I can't test the
other 24/32 bit modes. I've applied this part of the patch.

15/16 bit doesn't work:

>      case 16:								\
> -      rgb = (  (((r) >> 11) << 11)	/* 5 bits of red */		\
> -	     | (((g) >> 10) <<  5)	/* 6 bits of green */		\
> -	     | (((b) >> 11) <<  0));	/* 5 bits of blue */		\
> +      rgb = (  (((r) >> 8) << r_shift)					\
> +	     | (((g) >> 8) << g_shift)					\
> +	     | (((b) >> 8) << b_shift));				\

You can't just >> 8, because only 5/6 bits are significant. So the
shift must be 11/10 as above. The following patch works, however. At
least here on little endian in 15/16 bit modes.

Index: xcam.c
===================================================================
RCS file: /cvsroot/external/sane/sane-frontends/src/xcam.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -u -r1.5 -r1.6
--- xcam.c	24 Jan 2003 14:58:11 -0000	1.5
+++ xcam.c	24 Jan 2003 15:08:26 -0000	1.6
@@ -653,17 +653,17 @@
       break;								\
 									\
     case 15:								\
-      rgb = (  (((r) >> 11) << 10)	/* 5 bits of red */		\
-	     | (((g) >> 11) <<  5)	/* 5 bits of green */		\
-	     | (((b) >> 11) <<  0));	/* 5 bits of blue */		\
+      rgb = (  (((r) >> 11) << r_shift)	/* 5 bits of red */		\
+	     | (((g) >> 11) << g_shift)	/* 5 bits of green */		\
+	     | (((b) >> 11) << b_shift));/* 5 bits of blue */		\
       ((guint16 *)buf)[0] = rgb;					\
       buf += (bpp);							\
       break;								\
 									\
     case 16:								\
-      rgb = (  (((r) >> 11) << 11)	/* 5 bits of red */		\
-	     | (((g) >> 10) <<  5)	/* 6 bits of green */		\
-	     | (((b) >> 11) <<  0));	/* 5 bits of blue */		\
+      rgb = (  (((r) >> 11) << r_shift)	/* 5 bits of red */		\
+	     | (((g) >> 10) << g_shift)/* 6 bits of green */		\
+	     | (((b) >> 11) << b_shift));/* 5 bits of blue */		\
       ((guint16 *)buf)[0] = rgb;					\
       buf += (bpp);							\
       break;								\


I've committed your 24/32 bit patch and this one to CVS. A snapshot is
here:
http://www.meier-geinitz.de/sane/snapshots/sane-frontends-2003-01-24.tar.gz

Thanks for your work.

Bye,
  Henning