From 212b9dcd383cfa16fa74c300cfe87e816deaea9c Mon Sep 17 00:00:00 2001 From: Mel Henning Date: Tue, 25 Nov 2025 18:00:18 -0500 Subject: [PATCH] util: Add util_format_is_red --- src/util/format/u_format.c | 17 +++++++++++++++++ src/util/format/u_format.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index 8f6defb3291..953e08f16fd 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -302,6 +302,23 @@ util_format_is_luminance_alpha(enum pipe_format format) return false; } +bool +util_format_is_red(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if ((desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB || + desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) && + desc->swizzle[0] == PIPE_SWIZZLE_X && + desc->swizzle[1] == PIPE_SWIZZLE_0 && + desc->swizzle[2] == PIPE_SWIZZLE_0 && + desc->swizzle[3] == PIPE_SWIZZLE_1) { + return true; + } + return false; +} + bool util_format_is_red_alpha(enum pipe_format format) { diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 2614a16150d..74dd51e9951 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -805,6 +805,9 @@ util_format_is_alpha(enum pipe_format format) ATTRIBUTE_CONST; bool util_format_is_luminance_alpha(enum pipe_format format) ATTRIBUTE_CONST; +bool +util_format_is_red(enum pipe_format format) ATTRIBUTE_CONST; + bool util_format_is_red_alpha(enum pipe_format format) ATTRIBUTE_CONST;