[Mesa-dev] [PATCH 1/2] util: add util_format_is_luminance/intensity/rgb(), etc
Brian Paul
brian.e.paul at gmail.com
Wed Sep 14 07:26:46 PDT 2011
From: Brian Paul <brianp at vmware.com>
---
src/gallium/auxiliary/util/u_format.c | 77 +++++++++++++++++++++++++++++++++
src/gallium/auxiliary/util/u_format.h | 16 +++++++
2 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index 34922ab..2bd3737 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -67,6 +67,83 @@ util_format_is_float(enum pipe_format format)
}
+/** Test if the format contains RGB, but not alpha */
+boolean
+util_format_is_rgb(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->nr_channels == 4 &&
+ desc->swizzle[0] <= UTIL_FORMAT_SWIZZLE_W &&
+ desc->swizzle[1] <= UTIL_FORMAT_SWIZZLE_W &&
+ desc->swizzle[2] <= UTIL_FORMAT_SWIZZLE_W &&
+ desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_1) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+boolean
+util_format_is_luminance(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->nr_channels == 1 &&
+ desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_1) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+boolean
+util_format_is_luminance_alpha(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->nr_channels == 2 &&
+ desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_Y) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+boolean
+util_format_is_intensity(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->nr_channels == 1 &&
+ desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_X &&
+ desc->swizzle[3] == UTIL_FORMAT_SWIZZLE_X) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
boolean
util_format_is_supported(enum pipe_format format, unsigned bind)
{
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 3527103..957d1f7 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -477,6 +477,22 @@ boolean
util_format_is_float(enum pipe_format format);
+boolean
+util_format_is_rgb(enum pipe_format format);
+
+
+boolean
+util_format_is_luminance(enum pipe_format format);
+
+
+boolean
+util_format_is_luminance_alpha(enum pipe_format format);
+
+
+boolean
+util_format_is_intensity(enum pipe_format format);
+
+
/**
* Whether the src format can be blitted to destation format with a simple
* memcpy.
--
1.7.3.4
More information about the mesa-dev
mailing list