From patchwork Thu Feb 8 09:42:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todor Tomov X-Patchwork-Id: 127277 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1312730ljc; Thu, 8 Feb 2018 01:42:32 -0800 (PST) X-Google-Smtp-Source: AH8x224G6DZvzvvCLFuKeZvhR7lZFIqTJcMSq5RklpJWu6WC0bfgP3fPOkgwI6HV0rjyz6WVcyUk X-Received: by 2002:a17:902:42a5:: with SMTP id h34-v6mr66513pld.265.1518082952588; Thu, 08 Feb 2018 01:42:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518082952; cv=none; d=google.com; s=arc-20160816; b=HjSBaLDn1JbaU7gIxwM24DJSWQ/71FC/KtxqtQ3QMzFd5wNem6C8D5VWPdoyorYhjN cLLpKZXV7pOQjykkkPMWa0FbGnqioOmN8zDell3XWuvoE4JHx+ef8v68Si1MamfujMbV QuKI0zX/JLPruZa3i0yZYiRtFqTf+WJNDZzqGQ13vH/Rc4K/UoA3H8SV0A2MoNzYEO5e Z4RjZ9tGS08fyRoEPdRaQmrdGs8JDJosBT8jLyYTmEiZ3njZGaQKcw4Cb7VVIwk+13Yo ViS/YeWbWRN6tjKb3wd+bW01vs3+ife7wLl62wmUGg9/EpyA9Zck8qIxqkP+6oQeT4dj jxag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=rnpxhDOeTBm/4fot10l/Tjdr0XebKuTAU8cf+/p1SRc=; b=WTrjl6yv8p5qsphRCTrz359AR1x9QSySkvrvBgdp4SLopQrybRi7BqDJCD3/wxmqxA wXv08tFc98ADMsB7W0q3erRagTU1YezLX1yctlDhPyUJEdF/hCNkWl+UK+cAFYIMxtjA MlGc/cmxweAjBw9x0qxsadRtlatjVRmE5e2/JSWGiuE9hGUsLX7PieaGKzTwLHyXNmX7 ZiEahNvdx79xgLB2UcKp4l3FYFhg0ZbEgVXXk4qaZce8EwhK6RNea3qKZd3+WOa5wf1l tmn9cWKvLtEOB2rlFWkQN5u1YzN2ym08woh0LKApy2GFpAK8zlNNyNcTVVXqmG1I+nNo njpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k77si770311pfj.127.2018.02.08.01.42.32; Thu, 08 Feb 2018 01:42:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752178AbeBHJm1 (ORCPT + 11 others); Thu, 8 Feb 2018 04:42:27 -0500 Received: from ns.mm-sol.com ([37.157.136.199]:42526 "EHLO extserv.mm-sol.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750847AbeBHJmX (ORCPT ); Thu, 8 Feb 2018 04:42:23 -0500 Received: from mms-0439.qualcomm.mm-sol.com (unknown [37.157.136.206]) by extserv.mm-sol.com (Postfix) with ESMTPSA id A38D1CCB6; Thu, 8 Feb 2018 11:42:21 +0200 (EET) From: Todor Tomov To: mchehab@kernel.org, sakari.ailus@linux.intel.com, hverkuil@xs4all.nl Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Todor Tomov Subject: [PATCH 2/2] media: ov5645: Improve mode finding function Date: Thu, 8 Feb 2018 11:42:00 +0200 Message-Id: <1518082920-11309-2-git-send-email-todor.tomov@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518082920-11309-1-git-send-email-todor.tomov@linaro.org> References: <1518082920-11309-1-git-send-email-todor.tomov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Find the sensor mode by comparing the size of the requested image size and the sensor mode's image size. The distance between image sizes is the size in pixels of the non-overlapping regions between the requested size and the frame-specified size. This logic is borrowed from et8ek8 sensor driver. Signed-off-by: Todor Tomov --- drivers/media/i2c/ov5645.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index 9755562..6d06c50 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -964,18 +964,24 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct v4l2_subdev_pad_config *cfg, static const struct ov5645_mode_info * ov5645_find_nearest_mode(unsigned int width, unsigned int height) { - int i; + unsigned int max_dist_match = (unsigned int) -1; + int i, n = 0; - for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) { - if (ov5645_mode_info_data[i].width <= width && - ov5645_mode_info_data[i].height <= height) - break; + for (i = 0; i < ARRAY_SIZE(ov5645_mode_info_data); i++) { + unsigned int dist = min(width, ov5645_mode_info_data[i].width) + * min(height, ov5645_mode_info_data[i].height); + + dist = ov5645_mode_info_data[i].width * + ov5645_mode_info_data[i].height + + width * height - 2 * dist; + + if (dist < max_dist_match) { + n = i; + max_dist_match = dist; + } } - if (i < 0) - i = 0; - - return &ov5645_mode_info_data[i]; + return &ov5645_mode_info_data[n]; } static int ov5645_set_format(struct v4l2_subdev *sd,