OV8830: Change in the nearest resolution index calculation logic
authorVinod Govindapillai <vinod.govindapillai@intel.com>
Tue, 24 Apr 2012 18:48:10 +0000 (21:48 +0300)
committerbuildbot <buildbot@intel.com>
Thu, 3 May 2012 20:12:10 +0000 (13:12 -0700)
BZ: 30047

16:9 resolutions are failing to get a correct matching resolution
index from the OV8830 preview resolution table. The threshold to
the minimum allowed ratio mismatch is changed to accommodate some
slight deviations from the standard aspect ratio so that the
function returns most appropriate index.

Change-Id: I7922b366cd5773f15d2d384d736fb14ca3a6b8ae
Signed-off-by: Vinod Govindapillai <vinod.govindapillai@intel.com>
Reviewed-on: http://android.intel.com:8080/45962
Reviewed-by: Laakso, Antti <antti.laakso@intel.com>
Reviewed-by: Toivonen, Tuukka <tuukka.toivonen@intel.com>
Reviewed-by: Lampila, KalleX <kallex.lampila@intel.com>
Tested-by: Lampila, KalleX <kallex.lampila@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
drivers/media/video/ov8830.c

index 689de29..f764dfa 100644 (file)
@@ -2340,20 +2340,32 @@ static int ov8830_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
  * res->width/height smaller than w/h wouldn't be considered.
  * Returns the value of gap or -1 if fail.
  */
-#define LARGEST_ALLOWED_RATIO_MISMATCH 140   /* tune this value so that the DVS resolutions get selected properly, but make sure 16:9 do not match 4:3*/
-static int distance(struct ov8830_resolution *res, u32 w, u32 h)
+/* tune this value so that the DVS resolutions get selected properly,
+ * but make sure 16:9 does not match 4:3.
+ */
+#define LARGEST_ALLOWED_RATIO_MISMATCH 600
+static int distance(struct ov8830_resolution const *res, const u32 w,
+                               const u32 h)
 {
        unsigned int w_ratio = ((res->width<<13)/w);
        unsigned int h_ratio = ((res->height<<13)/h);
        int match   = abs(((w_ratio<<13)/h_ratio) - ((int)8192));
 
-       if ((w_ratio < (int)8192) || (h_ratio < (int)8192)  || (match > LARGEST_ALLOWED_RATIO_MISMATCH))
+       if ((w_ratio < (int)8192) || (h_ratio < (int)8192)
+               || (match > LARGEST_ALLOWED_RATIO_MISMATCH))
                return -1;
 
        return w_ratio + h_ratio;
 }
 
-/* Return the nearest higher resolution index */
+/*
+ * Returns the nearest higher resolution index.
+ * @w: width
+ * @h: height
+ * matching is done based on enveloping resolution and
+ * aspect ratio. If the aspect ratio cannot be matched
+ * to any index, -1 is returned.
+ */
 static int nearest_resolution_index(int w, int h)
 {
        int i;
@@ -2372,10 +2384,6 @@ static int nearest_resolution_index(int w, int h)
                        idx = i;
                }
        }
-
-       if (idx == -1)
-               return -1;
-
        return idx;
 }