Received: by 10.223.185.116 with SMTP id b49csp3841282wrg; Tue, 6 Mar 2018 06:00:08 -0800 (PST) X-Google-Smtp-Source: AG47ELv5u/lPMpGnEFY286kGsRG35TOg49RibkFfEnIBadVOuB9MAF2Ln2mo8/lPRjw0RjOFCr7L X-Received: by 10.99.157.142 with SMTP id i136mr15550599pgd.14.1520344808501; Tue, 06 Mar 2018 06:00:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520344808; cv=none; d=google.com; s=arc-20160816; b=xty25vUtq6IYZr4tkGg7EfYq88zlGWF10GYZcPquqqUq3s6gV21jM3UdW3SR2qhXQk 5cES52rkRtpRnoIAOHiC5JaNNGRDF4Wg+CxbaGOeDx8wZTQamxGOMA8jyw0DYtVlEPTh WVDxmwfVxkvAy4XxsMxKJ/vdUVj1GikiFxP6YYeqnoCec+LKSkuS8JbtXpCLM6D62qu3 c/Rnd9Tx++ICnPwLEsjbvCL4cluYPbmA5WvT3M1ns9gduoQkcyOO4goj+dQrNZZRQdgQ hBaGWj/vLEDtSTol29Z2exVeIJqkJCSMn21gIwS51BXWaLH2HQn29XebCV3fnAS11blx kIkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=BGv63knU6FsNTm0ACLalOUt4kShcjigiYVaxZVP/z1g=; b=yLViCoa1oQwbOBcbSeeBtkjnwW876ySsnXwTWw7PcoXiwrzGUtAlRnd33NSa65Hkwo u3yHWiBR3gU/ecJWxRyovECUqowO1b7bve1yk2VgAYG0awPM9raeIEDGt0xS9bi0FzLJ TWISOw87wQHuMYkthzp0AYN/MaRUwoAMWK0eezMVja5EIQcZBaL4BIAYDLLi1AezB5Sx RycD3CZzknbo5kWaVTrHNlKyWDjGTdFbcNDiq1OgDWpUSvU9dqJGa8wozHxXff7Wk6Rt D1mHbW8SBKibgK6FOUD5jQwInf/uyfYjoFnPIXi6tsAUdyVkmaIbBnYqCIAgECCTE/16 VncQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c15si11977939pfm.199.2018.03.06.05.59.53; Tue, 06 Mar 2018 06:00:08 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753790AbeCFN63 (ORCPT + 99 others); Tue, 6 Mar 2018 08:58:29 -0500 Received: from mga03.intel.com ([134.134.136.65]:6180 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753768AbeCFN62 (ORCPT ); Tue, 6 Mar 2018 08:58:28 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2018 05:58:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,431,1515484800"; d="scan'208";a="23354834" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga006.jf.intel.com with ESMTP; 06 Mar 2018 05:58:26 -0800 Received: by paasikivi.fi.intel.com (Postfix, from userid 1000) id 4BDC02090E; Tue, 6 Mar 2018 15:58:25 +0200 (EET) Date: Tue, 6 Mar 2018 15:58:25 +0200 From: Sakari Ailus To: Todor Tomov Cc: mchehab@kernel.org, hverkuil@xs4all.nl, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] media: ov5645: Improve mode finding function Message-ID: <20180306135825.6ctnlra3rbz3hub7@paasikivi.fi.intel.com> References: <1518082920-11309-1-git-send-email-todor.tomov@linaro.org> <1518082920-11309-2-git-send-email-todor.tomov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1518082920-11309-2-git-send-email-todor.tomov@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Todor, On Thu, Feb 08, 2018 at 11:42:00AM +0200, Todor Tomov wrote: > 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(-) > > 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; Could you use v4l2_find_nearest_size()? The patch is here: The pull request has been sent on it. -- Sakari Ailus sakari.ailus@linux.intel.com