From: Matthew Majewski <mattwmajewski@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@xs4all.nl>,
Uwe Kleine-Konig <u.kleine-koenig@baylibre.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Naushir Patuck <naush@raspberrypi.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Matthew Majewski <mattwmajewski@gmail.com>
Subject: [PATCH 2/3] media: vim2m: Simplify try_fmt
Date: Tue, 4 Mar 2025 14:17:00 -0500 [thread overview]
Message-ID: <20250304191701.2957096-3-mattwmajewski@gmail.com> (raw)
In-Reply-To: <20250304191701.2957096-1-mattwmajewski@gmail.com>
Clean up vidioc_try_fmt with the following changes:
1. remove unsused vim2m_fmt parameter
2. use clamp() macro to restrain width/height bounds
3. use ALIGN() macro to align width/height
4. use v4l2_fill_pixfmt to set bytesperline/sizeimage
Signed-off-by: Matthew Majewski <mattwmajewski@gmail.com>
---
drivers/media/test-drivers/vim2m.c | 33 +++++++++++-------------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/drivers/media/test-drivers/vim2m.c b/drivers/media/test-drivers/vim2m.c
index 6c24dcf27eb0..a22b61793a52 100644
--- a/drivers/media/test-drivers/vim2m.c
+++ b/drivers/media/test-drivers/vim2m.c
@@ -26,6 +26,7 @@
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/videobuf2-vmalloc.h>
+#include <media/v4l2-common.h>
MODULE_DESCRIPTION("Virtual device for mem2mem framework testing");
MODULE_AUTHOR("Pawel Osciak, <pawel@osciak.com>");
@@ -755,31 +756,21 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
return vidioc_g_fmt(file2ctx(file), f);
}
-static int vidioc_try_fmt(struct v4l2_format *f, struct vim2m_fmt *fmt)
+static int vidioc_try_fmt(struct v4l2_format *f)
{
- int walign, halign;
- /*
- * V4L2 specification specifies the driver corrects the
- * format struct if any of the dimensions is unsupported
- */
- if (f->fmt.pix.height < MIN_H)
- f->fmt.pix.height = MIN_H;
- else if (f->fmt.pix.height > MAX_H)
- f->fmt.pix.height = MAX_H;
+ int width, height, walign, halign;
- if (f->fmt.pix.width < MIN_W)
- f->fmt.pix.width = MIN_W;
- else if (f->fmt.pix.width > MAX_W)
- f->fmt.pix.width = MAX_W;
+ width = clamp(f->fmt.pix.width, MIN_W, MAX_W);
+ height = clamp(f->fmt.pix.width, MIN_H, MAX_H);
get_alignment(f->fmt.pix.pixelformat, &walign, &halign);
- f->fmt.pix.width &= ~(walign - 1);
- f->fmt.pix.height &= ~(halign - 1);
- f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
- f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+ width = ALIGN(width, walign);
+ height = ALIGN(height, halign);
+
f->fmt.pix.field = V4L2_FIELD_NONE;
- return 0;
+ return v4l2_fill_pixfmt(&f->fmt.pix, f->fmt.pix.pixelformat,
+ width, height);
}
static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
@@ -804,7 +795,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc;
f->fmt.pix.quantization = ctx->quant;
- return vidioc_try_fmt(f, fmt);
+ return vidioc_try_fmt(f);
}
static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
@@ -827,7 +818,7 @@ static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
if (!f->fmt.pix.colorspace)
f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
- return vidioc_try_fmt(f, fmt);
+ return vidioc_try_fmt(f);
}
static int vidioc_s_fmt(struct vim2m_ctx *ctx, struct v4l2_format *f)
--
2.25.1
next prev parent reply other threads:[~2025-03-04 19:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 19:16 [PATCH 0/3] media: vim2m: add multiplanar API support Matthew Majewski
2025-03-04 19:16 ` [PATCH 1/3] media: v4l2-common: Add RGBR format info Matthew Majewski
2025-03-04 19:17 ` Matthew Majewski [this message]
2025-03-04 19:17 ` [PATCH 3/3] media: vim2m: Add parametized support for multiplanar API Matthew Majewski
2025-04-27 9:45 ` [PATCH 0/3] media: vim2m: add multiplanar API support Hans Verkuil
2025-04-28 18:40 ` Matthew Majewski
2025-04-29 6:04 ` Hans Verkuil
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=20250304191701.2957096-3-mattwmajewski@gmail.com \
--to=mattwmajewski@gmail.com \
--cc=hverkuil@xs4all.nl \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=naush@raspberrypi.com \
--cc=sakari.ailus@linux.intel.com \
--cc=skhan@linuxfoundation.org \
--cc=u.kleine-koenig@baylibre.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®