Skip to content

Commit 030b161

Browse files
bparrotmchehab
authored andcommitted
media: use v4l2_rect_enclosed helper
Several drivers implement the same enclosed_rectangle() function to check if a rectangle is enclosed into another. Replace this with the newly added v4l2_rect_enclosed() helper function. Signed-off-by: Benoit Parrot <bparrot@ti.com> Acked-by: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com> Reviewed-by: Lad Prabhakar <prabhakar.csengg@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent d324633 commit 030b161

4 files changed

Lines changed: 11 additions & 60 deletions

File tree

‎drivers/media/platform/am437x/am437x-vpfe.c‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <media/v4l2-ctrls.h>
2727
#include <media/v4l2-event.h>
2828
#include <media/v4l2-fwnode.h>
29+
#include <media/v4l2-rect.h>
2930

3031
#include "am437x-vpfe.h"
3132

@@ -1987,20 +1988,6 @@ vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s)
19871988
return 0;
19881989
}
19891990

1990-
static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
1991-
{
1992-
if (a->left < b->left || a->top < b->top)
1993-
return 0;
1994-
1995-
if (a->left + a->width > b->left + b->width)
1996-
return 0;
1997-
1998-
if (a->top + a->height > b->top + b->height)
1999-
return 0;
2000-
2001-
return 1;
2002-
}
2003-
20041991
static int
20051992
vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
20061993
{
@@ -2025,10 +2012,10 @@ vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
20252012
r.left = clamp_t(unsigned int, r.left, 0, cr.width - r.width);
20262013
r.top = clamp_t(unsigned int, r.top, 0, cr.height - r.height);
20272014

2028-
if (s->flags & V4L2_SEL_FLAG_LE && !enclosed_rectangle(&r, &s->r))
2015+
if (s->flags & V4L2_SEL_FLAG_LE && !v4l2_rect_enclosed(&r, &s->r))
20292016
return -ERANGE;
20302017

2031-
if (s->flags & V4L2_SEL_FLAG_GE && !enclosed_rectangle(&s->r, &r))
2018+
if (s->flags & V4L2_SEL_FLAG_GE && !v4l2_rect_enclosed(&s->r, &r))
20322019
return -ERANGE;
20332020

20342021
s->r = vpfe->crop = r;

‎drivers/media/platform/exynos4-is/fimc-capture.c‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <media/v4l2-device.h>
2222
#include <media/v4l2-ioctl.h>
2323
#include <media/v4l2-mem2mem.h>
24+
#include <media/v4l2-rect.h>
2425
#include <media/videobuf2-v4l2.h>
2526
#include <media/videobuf2-dma-contig.h>
2627

@@ -1301,19 +1302,6 @@ static int fimc_cap_g_selection(struct file *file, void *fh,
13011302
return -EINVAL;
13021303
}
13031304

1304-
/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
1305-
static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
1306-
{
1307-
if (a->left < b->left || a->top < b->top)
1308-
return 0;
1309-
if (a->left + a->width > b->left + b->width)
1310-
return 0;
1311-
if (a->top + a->height > b->top + b->height)
1312-
return 0;
1313-
1314-
return 1;
1315-
}
1316-
13171305
static int fimc_cap_s_selection(struct file *file, void *fh,
13181306
struct v4l2_selection *s)
13191307
{
@@ -1336,11 +1324,11 @@ static int fimc_cap_s_selection(struct file *file, void *fh,
13361324
fimc_capture_try_selection(ctx, &rect, s->target);
13371325

13381326
if (s->flags & V4L2_SEL_FLAG_LE &&
1339-
!enclosed_rectangle(&rect, &s->r))
1327+
!v4l2_rect_enclosed(&rect, &s->r))
13401328
return -ERANGE;
13411329

13421330
if (s->flags & V4L2_SEL_FLAG_GE &&
1343-
!enclosed_rectangle(&s->r, &rect))
1331+
!v4l2_rect_enclosed(&s->r, &rect))
13441332
return -ERANGE;
13451333

13461334
s->r = rect;

‎drivers/media/platform/exynos4-is/fimc-lite.c‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <media/v4l2-device.h>
2626
#include <media/v4l2-ioctl.h>
2727
#include <media/v4l2-mem2mem.h>
28+
#include <media/v4l2-rect.h>
2829
#include <media/videobuf2-v4l2.h>
2930
#include <media/videobuf2-dma-contig.h>
3031
#include <media/drv-intf/exynos-fimc.h>
@@ -868,19 +869,6 @@ static int fimc_lite_reqbufs(struct file *file, void *priv,
868869
return ret;
869870
}
870871

871-
/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
872-
static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
873-
{
874-
if (a->left < b->left || a->top < b->top)
875-
return 0;
876-
if (a->left + a->width > b->left + b->width)
877-
return 0;
878-
if (a->top + a->height > b->top + b->height)
879-
return 0;
880-
881-
return 1;
882-
}
883-
884872
static int fimc_lite_g_selection(struct file *file, void *fh,
885873
struct v4l2_selection *sel)
886874
{
@@ -922,11 +910,11 @@ static int fimc_lite_s_selection(struct file *file, void *fh,
922910
fimc_lite_try_compose(fimc, &rect);
923911

924912
if ((sel->flags & V4L2_SEL_FLAG_LE) &&
925-
!enclosed_rectangle(&rect, &sel->r))
913+
!v4l2_rect_enclosed(&rect, &sel->r))
926914
return -ERANGE;
927915

928916
if ((sel->flags & V4L2_SEL_FLAG_GE) &&
929-
!enclosed_rectangle(&sel->r, &rect))
917+
!v4l2_rect_enclosed(&sel->r, &rect))
930918
return -ERANGE;
931919

932920
sel->r = rect;

‎drivers/media/platform/s5p-jpeg/jpeg-core.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <media/v4l2-event.h>
2525
#include <media/v4l2-mem2mem.h>
2626
#include <media/v4l2-ioctl.h>
27+
#include <media/v4l2-rect.h>
2728
#include <media/videobuf2-v4l2.h>
2829
#include <media/videobuf2-dma-contig.h>
2930

@@ -1735,19 +1736,6 @@ static int exynos3250_jpeg_try_downscale(struct s5p_jpeg_ctx *ctx,
17351736
return 0;
17361737
}
17371738

1738-
/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
1739-
static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
1740-
{
1741-
if (a->left < b->left || a->top < b->top)
1742-
return 0;
1743-
if (a->left + a->width > b->left + b->width)
1744-
return 0;
1745-
if (a->top + a->height > b->top + b->height)
1746-
return 0;
1747-
1748-
return 1;
1749-
}
1750-
17511739
static int exynos3250_jpeg_try_crop(struct s5p_jpeg_ctx *ctx,
17521740
struct v4l2_rect *r)
17531741
{
@@ -1780,7 +1768,7 @@ static int exynos3250_jpeg_try_crop(struct s5p_jpeg_ctx *ctx,
17801768
r->left = round_down(r->left, 2);
17811769
r->top = round_down(r->top, 2);
17821770

1783-
if (!enclosed_rectangle(r, &base_rect))
1771+
if (!v4l2_rect_enclosed(r, &base_rect))
17841772
return -EINVAL;
17851773

17861774
ctx->crop_rect.left = r->left;

0 commit comments

Comments
 (0)