All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: v4l: vsp1: fix and generalize offset calculation for plane cropping
@ 2021-11-23 14:59 Michael Rodin
  0 siblings, 0 replies; only message in thread
From: Michael Rodin @ 2021-11-23 14:59 UTC (permalink / raw)
  To: Laurent Pinchart, Kieran Bingham, Mauro Carvalho Chehab,
	linux-media, linux-renesas-soc, linux-kernel
  Cc: Michael Rodin, michael, efriedrich, erosca

The vertical subsampling factor is currently not considered in the offset
calculation for plane cropping done in rpf_configure_partition. This causes
a distortion (shift of the color plane) when formats with the vsub factor
larger than 1 are used (e.g. NV12, see vsp1_video_formats in vsp1_pipe.c).
This commit considers vsub factor for all planes except plane 0
(luminance). Also this commit generalizes calculation of the offset, so
the formula is same for all of the planes.

Fixes: e5ad37b64de9 ("[media] v4l: vsp1: Add cropping support")
Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
---
 drivers/media/platform/vsp1/vsp1_rpf.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 85587c1..ea5503d 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -249,6 +249,7 @@ static void rpf_configure_partition(struct vsp1_entity *entity,
 	const struct vsp1_format_info *fmtinfo = rpf->fmtinfo;
 	const struct v4l2_pix_format_mplane *format = &rpf->format;
 	struct v4l2_rect crop;
+	unsigned int i;
 
 	/*
 	 * Source size and crop offsets.
@@ -287,17 +288,13 @@ static void rpf_configure_partition(struct vsp1_entity *entity,
 		       (crop.width << VI6_RPF_SRC_ESIZE_EHSIZE_SHIFT) |
 		       (crop.height << VI6_RPF_SRC_ESIZE_EVSIZE_SHIFT));
 
-	mem.addr[0] += crop.top * format->plane_fmt[0].bytesperline
-		     + crop.left * fmtinfo->bpp[0] / 8;
-
-	if (format->num_planes > 1) {
+	for (i = 0; i < format->num_planes; ++i) {
 		unsigned int offset;
 
-		offset = crop.top * format->plane_fmt[1].bytesperline
-		       + crop.left / fmtinfo->hsub
-		       * fmtinfo->bpp[1] / 8;
-		mem.addr[1] += offset;
-		mem.addr[2] += offset;
+		offset = crop.top * format->plane_fmt[i].bytesperline / (i ? fmtinfo->vsub : 1)
+		       + crop.left / (i ? fmtinfo->hsub : 1)
+		       * fmtinfo->bpp[i] / 8;
+		mem.addr[i] += offset;
 	}
 
 	/*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-23 15:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 14:59 [PATCH] media: v4l: vsp1: fix and generalize offset calculation for plane cropping Michael Rodin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.