public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
	Koji Matsuoka <koji.matsuoka.xm@renesas.com>,
	Yoshihiro Kaneko <ykaneko0929@gmail.com>,
	Simon Horman <horms+renesas@verge.net.au>
Subject: Re: [PATCH] soc-camera: fix rectangle adjustment in cropping
Date: Mon, 27 Feb 2017 10:42:31 +0200	[thread overview]
Message-ID: <1908551.GjAGnFoZ8e@avalon> (raw)
In-Reply-To: <Pine.LNX.4.64.1702262150090.17018@axis700.grange>

Hi Guennadi,

Thank you for the patch.

On Sunday 26 Feb 2017 21:58:16 Guennadi Liakhovetski wrote:
> From: Koji Matsuoka <koji.matsuoka.xm@renesas.com>
> 
> 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 <koji.matsuoka.xm@renesas.com>
> Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
> [g.liakhovetski@gmx.de: dropped supposedly wrong hunks]
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> ---
> 
> This is a part of the https://patchwork.linuxtv.org/patch/26441/ submitted
> almost 2.5 years ago. Back then I commented to the patch but never got a
> reply or an update. I preserved original authorship and Sob tags, although
> this version only uses a small portion of the original patch. This version
> is of course completely untested, any testing (at least regression) would
> be highly appreciated! This code is only used by the SH CEU driver and
> only in cropping / zooming scenarios.
> 
>  drivers/media/platform/soc_camera/soc_scale_crop.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 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..4bfc1bf
> 100644
> --- a/drivers/media/platform/soc_camera/soc_scale_crop.c
> +++ b/drivers/media/platform/soc_camera/soc_scale_crop.c
> @@ -70,14 +70,14 @@ static void update_subrect(struct v4l2_rect *rect,
> struct v4l2_rect *subrect) if (rect->height < subrect->height)
>  		subrect->height = rect->height;
> 
> -	if (rect->left > subrect->left)
> +	if (rect->left < subrect->left)

This looks wrong to me. If the purpose of the function is indeed to adjust 
subrect to stay within rect, the condition doesn't need to be changed.

>  		subrect->left = rect->left;
>  	else if (rect->left + rect->width >
>  		 subrect->left + subrect->width)

This condition, however, is wrong.

>  		subrect->left = rect->left + rect->width -
>  			subrect->width;

More than that, adjusting the width first and then the left coordinate can 
result in an incorrect width. It looks to me like you should drop the width 
check at the beginning of this function, and turn the "else if" here into an 
"if" with the right condition. Or, even better in my opinion, use the 
min/max/clamp macros.

Same comments for the vertical checks.

> -	if (rect->top > subrect->top)
> +	if (rect->top < subrect->top)
>  		subrect->top = rect->top;
>  	else if (rect->top + rect->height >
>  		 subrect->top + subrect->height)

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2017-02-27  9:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26 20:58 [PATCH] soc-camera: fix rectangle adjustment in cropping Guennadi Liakhovetski
2017-02-27  8:42 ` Laurent Pinchart [this message]
2017-02-27  8:54   ` Guennadi Liakhovetski
2017-02-27  9:02     ` Laurent Pinchart
2017-02-27  9:13       ` Hans Verkuil
2017-02-27  9:24         ` Guennadi Liakhovetski
2017-02-27  9:13       ` Guennadi Liakhovetski
2017-02-27  9:23         ` Laurent Pinchart

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=1908551.GjAGnFoZ8e@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=horms+renesas@verge.net.au \
    --cc=koji.matsuoka.xm@renesas.com \
    --cc=linux-media@vger.kernel.org \
    --cc=ykaneko0929@gmail.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