From b9639ddbcdea2f11c0b15c3a9a8cd99dbe39d181 Mon Sep 17 00:00:00 2001 From: Vinod Govindapillai Date: Tue, 24 Apr 2012 21:48:10 +0300 Subject: [PATCH] OV8830: Change in the nearest resolution index calculation logic 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 Reviewed-on: http://android.intel.com:8080/45962 Reviewed-by: Laakso, Antti Reviewed-by: Toivonen, Tuukka Reviewed-by: Lampila, KalleX Tested-by: Lampila, KalleX Reviewed-by: buildbot Tested-by: buildbot --- drivers/media/video/ov8830.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/media/video/ov8830.c b/drivers/media/video/ov8830.c index 689de29..f764dfa 100644 --- a/drivers/media/video/ov8830.c +++ b/drivers/media/video/ov8830.c @@ -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; } -- 2.7.4