From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com
Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 1/9] video: pixel_format: Add compare helpers
Date: Tue, 17 Jun 2025 16:23:13 +0200 [thread overview]
Message-ID: <20250617143649.143967-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20250617143649.143967-1-tzimmermann@suse.de>
Add helpers that compare two pixel-format descriptions against
each other.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
include/video/pixel_format.h | 58 ++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/include/video/pixel_format.h b/include/video/pixel_format.h
index b5104b2a3a13..c57019cd6ea8 100644
--- a/include/video/pixel_format.h
+++ b/include/video/pixel_format.h
@@ -38,4 +38,62 @@ struct pixel_format {
#define PIXEL_FORMAT_XRGB2101010 \
{ 32, false, { .alpha = {0, 0}, .red = {20, 10}, .green = {10, 10}, .blue = {0, 10} } }
+#define __pixel_format_cmp_field(lhs, rhs, name) \
+ { \
+ int ret = ((lhs)->name) - ((rhs)->name); \
+ if (ret) \
+ return ret; \
+ }
+
+#define __pixel_format_cmp_bitfield(lhs, rhs, name) \
+ { \
+ __pixel_format_cmp_field(lhs, rhs, name.offset); \
+ __pixel_format_cmp_field(lhs, rhs, name.length); \
+ }
+
+/**
+ * pixel_format_cmp - Compares two pixel-format descriptions
+ *
+ * @lhs: a pixel-format description
+ * @rhs: a pixel-format description
+ *
+ * Compares two pixel-format descriptions for their order. The semantics
+ * are equivalent to memcmp().
+ *
+ * Returns:
+ * 0 if both arguments describe the same pixel format, less-than-zero if lhs < rhs,
+ * or greater-than-zero if lhs > rhs.
+ */
+static inline int pixel_format_cmp(const struct pixel_format *lhs, const struct pixel_format *rhs)
+{
+ __pixel_format_cmp_field(lhs, rhs, bits_per_pixel);
+ __pixel_format_cmp_field(lhs, rhs, indexed);
+
+ if (lhs->indexed) {
+ __pixel_format_cmp_bitfield(lhs, rhs, index);
+ } else {
+ __pixel_format_cmp_bitfield(lhs, rhs, alpha);
+ __pixel_format_cmp_bitfield(lhs, rhs, red);
+ __pixel_format_cmp_bitfield(lhs, rhs, green);
+ __pixel_format_cmp_bitfield(lhs, rhs, blue);
+ }
+
+ return 0;
+}
+
+/**
+ * pixel_format_equal - Compares two pixel-format descriptions for equality
+ *
+ * @lhs: a pixel-format description
+ * @rhs: a pixel-format description
+ *
+ * Returns:
+ * True if both arguments describe the same pixel format, or false otherwise.
+ */
+static inline bool pixel_format_equal(const struct pixel_format *lhs,
+ const struct pixel_format *rhs)
+{
+ return !pixel_format_cmp(lhs, rhs);
+}
+
#endif
--
2.49.0
next prev parent reply other threads:[~2025-06-17 14:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 14:23 [PATCH 0/9] drm/vesadrm: Support 8-bit palettes Thomas Zimmermann
2025-06-17 14:23 ` Thomas Zimmermann [this message]
2025-07-11 11:55 ` [PATCH 1/9] video: pixel_format: Add compare helpers Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 2/9] video: screen_info: Add pixel-format helper for linear framebuffers Thomas Zimmermann
2025-07-11 11:58 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 3/9] drm/sysfb: Find screen_info format with helpers Thomas Zimmermann
2025-07-11 12:08 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 4/9] drm/sysfb: Blit to CRTC destination format Thomas Zimmermann
2025-07-11 12:10 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 5/9] drm/color-mgmt: Prepare for RGB332 palettes Thomas Zimmermann
2025-07-11 12:24 ` Javier Martinez Canillas
2025-07-11 12:30 ` Thomas Zimmermann
2025-07-14 7:13 ` Thomas Zimmermann
2025-06-17 14:23 ` [PATCH 6/9] drm/format-helper: Add XRGB8888-to-RGB332 to drm_fb_blit() Thomas Zimmermann
2025-07-11 12:25 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 7/9] drm/vesadrm: Rename vesadrm_set_gamma_lut() to vesadrm_set_color_lut() Thomas Zimmermann
2025-07-11 12:25 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 8/9] drm/vesadrm: Prepare color management for palette-based framebuffers Thomas Zimmermann
2025-07-11 12:26 ` Javier Martinez Canillas
2025-06-17 14:23 ` [PATCH 9/9] drm/vesadrm: Support DRM_FORMAT_C8 Thomas Zimmermann
2025-07-11 12:33 ` Javier Martinez Canillas
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=20250617143649.143967-2-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.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;
as well as URLs for NNTP newsgroup(s).