From patchwork Mon Feb 27 10:23:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 9592911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8B54604AB for ; Mon, 27 Feb 2017 10:25:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E40D728346 for ; Mon, 27 Feb 2017 10:25:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8948283B3; Mon, 27 Feb 2017 10:25:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ED1728346 for ; Mon, 27 Feb 2017 10:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751697AbdB0KZV (ORCPT ); Mon, 27 Feb 2017 05:25:21 -0500 Received: from mout.gmx.net ([212.227.17.20]:57985 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751617AbdB0KZT (ORCPT ); Mon, 27 Feb 2017 05:25:19 -0500 Received: from axis700.grange ([81.173.166.100]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MSY2q-1cs5a243Uq-00RXlV; Mon, 27 Feb 2017 11:23:55 +0100 Received: by axis700.grange (Postfix, from userid 1000) id 541B28B111; Mon, 27 Feb 2017 11:23:35 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 38B5A8B110; Mon, 27 Feb 2017 11:23:35 +0100 (CET) Date: Mon, 27 Feb 2017 11:23:34 +0100 (CET) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List cc: Koji Matsuoka , Yoshihiro Kaneko , Simon Horman , Laurent Pinchart , Hans Verkuil Subject: [PATCH v2] soc-camera: fix rectangle adjustment in cropping Message-ID: MIME-Version: 1.0 X-Provags-ID: V03:K0:w+85vJJUSdRa0qh8uTqTV+B9h07y+YpSvwq5RlHc1xJQwjGouSN XmBkUDJT9rcQ33zLBaCpCA5VAtfijEauwVqJVPXBj+l0sS8vCEB9Mgbu5xxnZ9DYF8JZJxa EIAT6weeTITiJvPpQeTssjPvpWE6oByBzP0/oWzncEADxPGTj0V8p49IgfPQZ/PaB7Qguv8 Qdn0ko7aP+xhBj856hUYg== X-UI-Out-Filterresults: notjunk:1; V01:K0:nWzmHJJs6fg=:2QRRpZhDs8gt5vqsh09jq3 M1+3E5PFXrtZCDt1RM+BAruftEePEvF9ye/Z74aH3GsMRf4j+uHlXpCzzjUL7wj28lH9JaSzK fEQ21rijdefyboOHLeEggOT+GxtFotgwpXluGQeFeMukuFt9C2GOpDxxaaoTJ5N8Rbm2ZB2f5 KCimwnS1E1ikCWcH8+75O4UYN6N7iI2l9TU0nvNGJ5/JfmJ1GFaEpkCaq0o/eA+SzNiRrB/jO CwXRAhITiIEZhT/I+T7z93/WaNlLG6YjXP6NXkL3G39SLUWCNb7vNv37egrutdJeEecJHxTiV 9p+CWvDNSZbmq8bAViNByv/pvK4S8hOy1eAov6DYKbdQShVdlJyEvuTjb9KPJWmSh6OwFSNGh 0zjI1udf6A1YGuwcRBLW45dz5x5AfQW3O4nq4AORzQT7ylYjNr+KHKuYz8QfvRPIssrZEiygf PAyVpss2x939MQAQoXgak0fzUgzDqobbt5KG2sJuFsxqgvkGh9SiHt8ONJkX+lfyG8VzJYMvK MKt1XbQ84dYubhWWsrnDqpG9nF4vkzYDo//k0NnhRjP6W5/e1EYeN8BjBV0SOV1lJkB+MY9Tk bEOByWuwYVr6RatAljQDByTeoRoGQbfPil0iKIhJC5CUWWokwfLxAvILPWzJ+/hccvBRil7TQ h9Rp3HZolPnv/y6CWaiMHv8EnegpZEFk/pHfO06kFK7lrAVLxSahLA0c3SfKSAfVP7axlurey tm+trCPtdydiwGh+rEdMHNc6rq/k/VkWv8Qx3mt96IdDMsl4nSQ9WaQZJ5wE1j9sGwPdLn4zl YmtRWtn Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Koji Matsuoka update_subrect() adjusts the sub-rectangle to be inside a base area. It checks width and height to not exceed those of the area, then it checks the low border (left or top) to lie within the area, then the high border (right or bottom) to lie there too. This latter check has a bug, which is fixed by this patch. Signed-off-by: Koji Matsuoka Signed-off-by: Yoshihiro Kaneko [g.liakhovetski@gmx.de: dropped supposedly wrong hunks] Signed-off-by: Guennadi Liakhovetski --- v2: fix a silly typo, reported by Laurent, thanks! Also renamed the function, according to his suggestion. drivers/media/platform/soc_camera/soc_scale_crop.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.c b/drivers/media/platform/soc_camera/soc_scale_crop.c index f77252d..0116097 100644 --- a/drivers/media/platform/soc_camera/soc_scale_crop.c +++ b/drivers/media/platform/soc_camera/soc_scale_crop.c @@ -62,7 +62,8 @@ int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect) EXPORT_SYMBOL(soc_camera_client_g_rect); /* Client crop has changed, update our sub-rectangle to remain within the area */ -static void update_subrect(struct v4l2_rect *rect, struct v4l2_rect *subrect) +static void move_and_crop_subrect(struct v4l2_rect *rect, + struct v4l2_rect *subrect) { if (rect->width < subrect->width) subrect->width = rect->width; @@ -72,14 +73,14 @@ static void update_subrect(struct v4l2_rect *rect, struct v4l2_rect *subrect) if (rect->left > subrect->left) subrect->left = rect->left; - else if (rect->left + rect->width > + else if (rect->left + rect->width < subrect->left + subrect->width) subrect->left = rect->left + rect->width - subrect->width; if (rect->top > subrect->top) subrect->top = rect->top; - else if (rect->top + rect->height > + else if (rect->top + rect->height < subrect->top + subrect->height) subrect->top = rect->top + rect->height - subrect->height; @@ -216,7 +217,7 @@ int soc_camera_client_s_selection(struct v4l2_subdev *sd, if (!ret) { *target_rect = *cam_rect; - update_subrect(target_rect, subrect); + move_and_crop_subrect(target_rect, subrect); } return ret; @@ -299,7 +300,7 @@ static int client_set_fmt(struct soc_camera_device *icd, if (host_1to1) *subrect = *rect; else - update_subrect(rect, subrect); + move_and_crop_subrect(rect, subrect); return 0; }