libv4l: Make new faster autogain slightly slower to avoid overshoot
authorHans de Goede <hdegoede@redhat.com>
Fri, 15 Jan 2010 09:34:06 +0000 (10:34 +0100)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 24 Feb 2010 00:44:40 +0000 (21:44 -0300)
Priority: normal

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
lib/libv4lconvert/cpia1.c
lib/libv4lconvert/processing/autogain.c

index dd6466e..32026f8 100644 (file)
@@ -202,8 +202,9 @@ int v4lconvert_cpia1_to_yuv420(struct v4lconvert_data *data,
     return -1;
   }
 
-  if (src_size != 4 ||
-      src[0] != EOI || src[1] != EOI || src[2] != EOI || src[3] != EOI) {
+  if (src_size < 4 ||
+      src[src_size - 4] != EOI || src[src_size - 3] != EOI ||
+      src[src_size - 2] != EOI || src[src_size - 1] != EOI) {
     fprintf(stderr, "cpia1 decode error: invaled EOI marker\n");
     return -1;
   }
index 8a9bf27..65f3b57 100644 (file)
@@ -45,11 +45,11 @@ static int autogain_adjust(struct v4l2_queryctrl *ctrl, int *value,
 {
   int ctrl_range = (ctrl->maximum - ctrl->minimum) / ctrl->step;
 
-  /* If we are of 2 * deadzone or more, and we have a very fine grained
+  /* If we are of 3 * deadzone or more, and we have a very fine grained
      control, take larger steps, otherwise we take ages to get to the
      right setting point. We use 256 as tripping point for determineing fine
      grained controls here, as avg_lum has a range of 0 - 255. */
-  if (abs(steps) >= 2 && ctrl_range > 256)
+  if (abs(steps) >= 3 && ctrl_range > 256)
     *value += steps * ctrl->step * (ctrl_range / 256);
   else
     *value += steps * ctrl->step;
@@ -178,8 +178,10 @@ static int autogain_calculate_lookup_tables(
   if (steps) {
     data->last_gain_correction = steps;
     /* We are still settling down, force the next update sooner. Note we
-       skip the next frame as that is still captured with the old settings. */
-    data->lookup_table_update_counter = V4L2PROCESSING_UPDATE_RATE - 1;
+       skip the next frame as that is still captured with the old settings,
+       and another one just to be sure (because if we re-adjust based
+       on the old settings we might overshoot). */
+    data->lookup_table_update_counter = V4L2PROCESSING_UPDATE_RATE - 2;
   }
 
   if (gain != orig_gain) {