mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Todor Tomov <todor.tomov@linaro.org>
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 <todor.tomov@linaro.org>
Subject: [PATCH 2/2] media: ov5645: Improve mode finding function
Date: Thu,  8 Feb 2018 11:42:00 +0200	[thread overview]
Message-ID: <1518082920-11309-2-git-send-email-todor.tomov@linaro.org> (raw)
In-Reply-To: <1518082920-11309-1-git-send-email-todor.tomov@linaro.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 <todor.tomov@linaro.org>
---
 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;
+
+		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,
-- 
2.7.4

  reply	other threads:[~2018-02-08  9:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08  9:41 [PATCH 1/2] media: ov5645: Fix write_reg return code Todor Tomov
2018-02-08  9:42 ` Todor Tomov [this message]
2018-03-06 13:58   ` [PATCH 2/2] media: ov5645: Improve mode finding function Sakari Ailus
2018-03-06 13:40 ` [PATCH 1/2] media: ov5645: Fix write_reg return code Mauro Carvalho Chehab
2018-03-06 13:56   ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1518082920-11309-2-git-send-email-todor.tomov@linaro.org \
    --to=todor.tomov@linaro.org \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®