From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-media@vger.kernel.org,
Mauro Carvalho Chehab <m.chehab@samsung.com>,
Hans Verkuil <hans.verkuil@cisco.com>,
kernel@pengutronix.de
Subject: Re: [RFC v2] [media] v4l2: add V4L2 pixel format array and helper functions
Date: Tue, 26 Aug 2014 12:01:04 +0200 [thread overview]
Message-ID: <1684313.SfePcxMsjg@avalon> (raw)
In-Reply-To: <1409043654-12252-1-git-send-email-p.zabel@pengutronix.de>
Hi Philipp,
Thank you for the patch.
On Tuesday 26 August 2014 11:00:54 Philipp Zabel wrote:
> This patch adds an array of V4L2 pixel formats and descriptions that can be
> used by drivers so that each driver doesn't have to provide its own slightly
> different format descriptions for VIDIOC_ENUM_FMT.
>
> Each array entry also includes two bits per pixel values (for a single line
> and one for the whole image) that can be used to determine the
> v4l2_pix_format bytesperline and sizeimage values and whether the format is
> planar or compressed.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
> Changes since v1:
> - Added use of DIV_ROUND_UP in v4l2_bytesperline
> - Un-inlined v4l2_sizeimage and made it use v4l2_bytesperline
> for non-planar, non-tiled formats
> - Added .planes property to struct v4l2_pixfmt for
> non-contiguous planar formats
> - Fixed Y41P, YUV410, and YVU420M pixelformat values
> ---
> drivers/media/v4l2-core/v4l2-common.c | 505 +++++++++++++++++++++++++++++++
> include/media/v4l2-common.h | 43 +++
> 2 files changed, 548 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/v4l2-common.c
> b/drivers/media/v4l2-core/v4l2-common.c index ccaa38f..63b91a5 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -533,3 +533,508 @@ void v4l2_get_timestamp(struct timeval *tv)
> tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
> }
> EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
> +
> +static const struct v4l2_pixfmt v4l2_pixfmts[] = {
[snip]
> +};
> +
> +const struct v4l2_pixfmt *v4l2_pixfmt_by_fourcc(u32 fourcc)
> +{
> + int i;
The loop counter is always positive, it can be an unsigned int.
> + for (i = 0; i < ARRAY_SIZE(v4l2_pixfmts); i++) {
> + if (v4l2_pixfmts[i].pixelformat == fourcc)
> + return v4l2_pixfmts + i;
> + }
We currently have 123 pixel formats defined, and that number will keep
increasing. I wonder if something more efficient than an O(n) array lookup
would be worth it.
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_pixfmt_by_fourcc);
> +
> +int v4l2_fill_fmtdesc(struct v4l2_fmtdesc *f, u32 fourcc)
> +{
> + const struct v4l2_pixfmt *fmt;
> +
> + fmt = v4l2_pixfmt_by_fourcc(fourcc);
> + if (!fmt)
> + return -EINVAL;
> +
> + strlcpy((char *)f->description, fmt->name, sizeof(f->description));
> + f->pixelformat = fmt->pixelformat;
> + f->flags = (fmt->bpp_image == 0) ? V4L2_FMT_FLAG_COMPRESSED : 0;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_fill_fmtdesc);
> +
> +unsigned int v4l2_sizeimage(const struct v4l2_pixfmt *fmt, unsigned int
> width,
> + unsigned int height)
> +{
A small comment would be useful here to explain why we don't round up in the
second case.
> + if (fmt->bpp_image == fmt->bpp_line)
> + return height * v4l2_bytesperline(fmt, width);
> + else
> + return height * width * fmt->bpp_image / 8;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_sizeimage);
> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> index 48f9748..dbf7ea4 100644
> --- a/include/media/v4l2-common.h
> +++ b/include/media/v4l2-common.h
> @@ -26,6 +26,7 @@
> #ifndef V4L2_COMMON_H_
> #define V4L2_COMMON_H_
>
> +#include <linux/kernel.h>
> #include <media/v4l2-dev.h>
>
> /* Common printk constucts for v4l-i2c drivers. These macros create a
> unique @@ -204,4 +205,46 @@ const struct v4l2_frmsize_discrete
> *v4l2_find_nearest_format(
>
> void v4l2_get_timestamp(struct timeval *tv);
>
> +/**
> + * struct v4l2_pixfmt - internal V4L2 pixel format description
Maybe struct v4l2_pixfmt_info ?
> + * @name: format description to be returned by enum_fmt
> + * @pixelformat: v4l2 pixel format fourcc
> + * @bpp_line: bits per pixel, averaged over a line (of the first plane
> + * for planar formats), used to calculate bytesperline.
> + * Zero for compressed and macroblock tiled formats.
> + * @bpp_image: bits per pixel, averaged over the whole image. This is used
> to
> + * calculate sizeimage for uncompressed formats.
> + * Zero for compressed formats.
> + * @planes: number of non-contiguous planes for multiplanar formats.
> + * Zero for contiguous formats.
> + */
> +struct v4l2_pixfmt {
> + const char *name;
> + u32 pixelformat;
> + u8 bpp_line;
> + u8 bpp_image;
> + u8 planes;
> +};
> +
> +const struct v4l2_pixfmt *v4l2_pixfmt_by_fourcc(u32 fourcc);
> +int v4l2_fill_fmtdesc(struct v4l2_fmtdesc *f, u32 fourcc);
> +unsigned int v4l2_sizeimage(const struct v4l2_pixfmt *fmt, unsigned int
> width,
> + unsigned int height);
> +
> +static inline unsigned int v4l2_bytesperline(const struct v4l2_pixfmt *fmt,
> + unsigned int width)
> +{
> + return DIV_ROUND_UP(width * fmt->bpp_line, 8);
> +}
> +
> +static inline bool v4l2_pixfmt_is_planar(const struct v4l2_pixfmt *fmt)
> +{
> + return fmt->bpp_line && (fmt->bpp_line != fmt->bpp_image);
> +}
> +
> +static inline bool v4l2_pixfmt_is_compressed(const struct v4l2_pixfmt *fmt)
> +{
> + return fmt->bpp_image == 0;
> +}
> +
> #endif /* V4L2_COMMON_H_ */
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2014-08-26 10:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-26 9:00 [RFC v2] [media] v4l2: add V4L2 pixel format array and helper functions Philipp Zabel
2014-08-26 10:01 ` Laurent Pinchart [this message]
2014-08-27 9:30 ` Philipp Zabel
2014-08-28 12:24 ` Laurent Pinchart
2014-08-28 16:09 ` Philipp Zabel
2014-08-28 16:25 ` Laurent Pinchart
2014-08-28 16:40 ` Hans Verkuil
2014-08-28 17:18 ` Mauro Carvalho Chehab
2014-08-28 17:32 ` Hans Verkuil
2014-08-28 17:41 ` Hans Verkuil
2014-09-02 10:00 ` Philipp Zabel
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=1684313.SfePcxMsjg@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=hans.verkuil@cisco.com \
--cc=kernel@pengutronix.de \
--cc=linux-media@vger.kernel.org \
--cc=m.chehab@samsung.com \
--cc=p.zabel@pengutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).