[cpia] CPiA colour balance problem [patch]

rich@annexia.org rich@annexia.org
Sun, 5 Mar 2000 14:25:44 +0000


--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Dear developers:

I've had a deeper look at the CPiA colour balance / 1.3 firmware
problem, with respect to the developer documentation provided by
Vision. My analysis is that there appear to be two unrelated bugs here.

Firstly, with reference to section 2.4.4 in developer.pdf, it states
that the SetColourBalance command BalanceMode argument has four
possible values:

BalanceMode    Function
-------------------------------------------------------------------
    0          No effect.

    1          Set the red_gain, blue_gain, green_gain parameters.
               According to the documentation, this has *no effect*
	       on whether colour_balance_mode is enabled or disabled.

    2          Enable auto colour_balance_mode algorithm. The
               red_gain, blue_gain and green_gain parameters appear
	       to be *ignored*.

    3          Disable auto colour_balance_mode algorithm. The
               red_gain, blue_gain and green_gain parameters appear
	       to be *ignored*.

Now that's not exactly what the CPiA version 0.7.1 driver was
doing. Attached is a patch which makes the driver do what the
documentation says it should. The patch is against 0.7.1.

Secondly, there must be a bug in the camera firmware (!). The
yellow hue which I found seems to come from the fact that when
you switch the camera into automatic mode, about 90% of the
time, the camera adjusts the blue_gain parameter so it increases
and increases up to 212 (where it stops). However, instead of
giving this a blue hue, it seems to just ignore the blue channel
altogether ... This results in only the red+green channels being
displayed => a yellow picture :-(

What's strange here is obviously the fact that blue_gain goes
AWOL like this. Clearly there's an actual problem with the blue
channel, and the camera itself things that it's getting no signal
from that channel.

Rich.

-- 
rich@annexia.org | Is your school part of http://www.schoolmaster.net ?
BiblioTech Ltd, Unit 2 Piper Centre, 50 Carnwath Road, London, SW6 3EG.
+44 20 7384 6917 | Click here to play XRacer: http://xracer.annexia.org
Copyright © 2000 Richard Jones | GnuPG/PGP key from www.annexia.org

--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="cpia-cb-fix.patch"

diff -ur cpia-0.7.1/module/cpia.c cpia-0.7.1-cb-fix/module/cpia.c
--- cpia-0.7.1/module/cpia.c	Mon Feb  7 08:53:28 2000
+++ cpia-0.7.1-cb-fix/module/cpia.c	Sun Mar  5 14:11:14 2000
@@ -411,17 +411,10 @@
 	               cam->params.ecpTiming ? "slow" : "normal", "slow",
 		       "normal", "normal");
 
-	switch(cam->params.colourBalance.balanceMode) {
-	case 1:
-	// FIXME case 3:
-		sprintf(tmpstr, "manual");
-		break;
-	case 2:
+	if (cam->params.colourBalance.balanceModeIsAuto) {
 		sprintf(tmpstr, "auto");
-		break;
-	default:
-		sprintf(tmpstr, "unknown");
-		break;
+	} else {
+		sprintf(tmpstr, "manual");
 	}
 	out += sprintf(out, "color_balance_mode:     %8s  %8s  %8s"
 		       "  %8s\n",  tmpstr, "manual", "auto", "auto");
@@ -759,11 +752,11 @@
 			if(!retval && MATCH("manual")) {
 				buffer += len;
 				count -= len;
-				new_params.colourBalance.balanceMode=1;
+				new_params.colourBalance.balanceModeIsAuto=0;
 			} else if(!retval && MATCH("auto")) {
 				buffer += len;
 				count -= len;
-				new_params.colourBalance.balanceMode=2;
+				new_params.colourBalance.balanceModeIsAuto=1;
 			} else {
 				retval = -EINVAL;
 			}
@@ -2086,11 +2079,18 @@
 		                    cam->params.exposure.blueComp);
 	}
 	if( cam->cmd_queue & COMMAND_SETCOLOURBALANCE ) {
-		do_command(cam, CPIA_COMMAND_SetColourBalance,
-		           cam->params.colourBalance.balanceMode,
-		           cam->params.colourBalance.redGain,
-		           cam->params.colourBalance.greenGain,
-		           cam->params.colourBalance.blueGain);
+		if (cam->params.colourBalance.balanceModeIsAuto) {
+			do_command(cam, CPIA_COMMAND_SetColourBalance,
+				   2, 0, 0, 0);
+		} else {
+			do_command(cam, CPIA_COMMAND_SetColourBalance,
+				   1,
+				   cam->params.colourBalance.redGain,
+				   cam->params.colourBalance.greenGain,
+				   cam->params.colourBalance.blueGain);
+			do_command(cam, CPIA_COMMAND_SetColourBalance,
+				   3, 0, 0, 0);
+		}
 	}
 	if( cam->cmd_queue & COMMAND_SETSENSORFPS ) {
 		do_command(cam, CPIA_COMMAND_SetSensorFPS,
@@ -2308,15 +2308,18 @@
 
 static void set_camera_state(struct cam_data *cam)
 {
-	if(cam->params.colourBalance.balanceMode != 1) {
+	if(cam->params.colourBalance.balanceModeIsAuto) {
+		do_command(cam, CPIA_COMMAND_SetColourBalance, 
+	        	   2, 0, 0, 0);
+	} else {
 		do_command(cam, CPIA_COMMAND_SetColourBalance, 
 	        	   1,
 	        	   cam->params.colourBalance.redGain,
 	        	   cam->params.colourBalance.greenGain,
 	        	   cam->params.colourBalance.blueGain);
+		do_command(cam, CPIA_COMMAND_SetColourBalance, 
+	        	   3, 0, 0, 0);
 	}
-	if(cam->params.colourBalance.balanceMode == 0)
-		cam->params.colourBalance.balanceMode = 2;
 
 	do_command_extended(cam, CPIA_COMMAND_SetExposure,
 			    cam->params.exposure.gainMode, 1, 1,
@@ -3063,7 +3066,7 @@
 	cam->params.exposure.green1Comp = 214;
 	cam->params.exposure.green2Comp = 214;
 	cam->params.exposure.blueComp = 230;
-	cam->params.colourBalance.balanceMode = 2;	/* auto color balance */
+	cam->params.colourBalance.balanceModeIsAuto = 1;
 	cam->params.colourBalance.redGain = 32;
 	cam->params.colourBalance.greenGain = 6;
 	cam->params.colourBalance.blueGain = 92;
diff -ur cpia-0.7.1/module/cpia.h cpia-0.7.1-cb-fix/module/cpia.h
--- cpia-0.7.1/module/cpia.h	Mon Feb  7 08:53:28 2000
+++ cpia-0.7.1-cb-fix/module/cpia.h	Sun Mar  5 14:01:19 2000
@@ -150,7 +150,7 @@
 		u8 blueComp;
 	} exposure;
 	struct {
-		u8 balanceMode;
+		u8 balanceModeIsAuto;
 		u8 redGain;
 		u8 greenGain;
 		u8 blueGain;

--KsGdsel6WgEHnImy--