linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-media@vger.kernel.org
Subject: [PATCH 6/8] v4l2-utils: turn fb_formats to constexpr array
Date: Wed, 21 Apr 2021 00:20:33 -0700	[thread overview]
Message-ID: <20210421072035.4188497-6-rosenp@gmail.com> (raw)
In-Reply-To: <20210421072035.4188497-1-rosenp@gmail.com>

Forces evaluation at compile time and allows usage of a for range loop.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
index 09de70c85..639a41757 100644
--- a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
@@ -1,3 +1,4 @@
+#include <array>
 #include <vector>
 
 #include <linux/fb.h>
@@ -121,16 +122,15 @@ struct bitfield2fmt {
 	__u32 pixfmt;
 };
 
-static const struct bitfield2fmt fb_formats[] = {
-	{ 10, 5,  5, 5,  0, 5, 15, 1, V4L2_PIX_FMT_ARGB555 },
-	{ 11, 5,  5, 6,  0, 5,  0, 0, V4L2_PIX_FMT_RGB565 },
-	{  1, 5,  6, 5, 11, 5,  0, 1, V4L2_PIX_FMT_RGB555X },
-	{  0, 5,  5, 6, 11, 5,  0, 0, V4L2_PIX_FMT_RGB565X },
-	{ 16, 8,  8, 8,  0, 8,  0, 0, V4L2_PIX_FMT_BGR24 },
-	{  0, 8,  8, 8, 16, 8,  0, 0, V4L2_PIX_FMT_RGB24 },
-	{ 16, 8,  8, 8,  0, 8, 24, 8, V4L2_PIX_FMT_ABGR32 },
-	{  8, 8, 16, 8, 24, 8,  0, 8, V4L2_PIX_FMT_ARGB32 },
-	{ }
+static constexpr std::array<bitfield2fmt, 8> fb_formats{
+	bitfield2fmt{ 10, 5, 5, 5, 0, 5, 15, 1, V4L2_PIX_FMT_ARGB555 },
+	bitfield2fmt{ 11, 5, 5, 6, 0, 5, 0, 0, V4L2_PIX_FMT_RGB565 },
+	bitfield2fmt{ 1, 5, 6, 5, 11, 5, 0, 1, V4L2_PIX_FMT_RGB555X },
+	bitfield2fmt{ 0, 5, 5, 6, 11, 5, 0, 0, V4L2_PIX_FMT_RGB565X },
+	bitfield2fmt{ 16, 8, 8, 8, 0, 8, 0, 0, V4L2_PIX_FMT_BGR24 },
+	bitfield2fmt{ 0, 8, 8, 8, 16, 8, 0, 0, V4L2_PIX_FMT_RGB24 },
+	bitfield2fmt{ 16, 8, 8, 8, 0, 8, 24, 8, V4L2_PIX_FMT_ABGR32 },
+	bitfield2fmt{ 8, 8, 16, 8, 24, 8, 0, 8, V4L2_PIX_FMT_ARGB32 },
 };
 
 static bool match_bitfield(const struct fb_bitfield &bf, unsigned off, unsigned len)
@@ -182,9 +182,7 @@ static int fbuf_fill_from_fb(struct v4l2_framebuffer &fb, const char *fb_device)
 			if (vi.bits_per_pixel == 8)
 				fb.fmt.pixelformat = V4L2_PIX_FMT_GREY;
 		} else {
-			for (int i = 0; fb_formats[i].pixfmt; i++) {
-				const struct bitfield2fmt &p = fb_formats[i];
-
+			for (const auto &p : fb_formats) {
 				if (match_bitfield(vi.blue, p.blue_off, p.blue_len) &&
 				    match_bitfield(vi.green, p.green_off, p.green_len) &&
 				    match_bitfield(vi.red, p.red_off, p.red_len) &&
-- 
2.30.2


  parent reply	other threads:[~2021-04-21  7:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21  7:20 [PATCH 1/8] clang-tidy: use auto Rosen Penev
2021-04-21  7:20 ` [PATCH 2/8] clang-tidy: use nullptr Rosen Penev
2021-04-21  7:20 ` [PATCH 3/8] remove unused ARRAY_SIZE Rosen Penev
2021-04-21  7:20 ` [PATCH 4/8] cec-tuner: std::array conversions Rosen Penev
2021-04-21  7:20 ` [PATCH 5/8] v4l2-info: remove a strange sizeof usage Rosen Penev
2021-04-21  8:23   ` Hans Verkuil
2021-04-21  9:19     ` Rosen Penev
2021-04-21  9:33       ` Hans Verkuil
2021-04-21  9:39         ` Rosen Penev
2021-04-21 16:01         ` Nicolas Dufresne
2021-04-21  7:20 ` Rosen Penev [this message]
2021-04-21  7:20 ` [PATCH 7/8] v4l2-utils: turn mbus_names into const vector Rosen Penev
2021-04-21  8:02   ` Hans Verkuil
2021-04-21  9:25     ` Rosen Penev
2021-04-21  7:20 ` [PATCH 8/8] v4l2-utils: turn prefixes to a constexpr array Rosen Penev
2021-04-21  8:06   ` Hans Verkuil
2021-04-21  9:23     ` Rosen Penev

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=20210421072035.4188497-6-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=linux-media@vger.kernel.org \
    /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).