[Mesa-dev] [PATCH 1/3] mesa: Add a new _mesa_format_x_to_a() function.
Kenneth Graunke
kenneth at whitecape.org
Tue Mar 25 18:01:26 PDT 2014
This translates RGBX formats to the equivalent RGBA format.
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/mesa/main/formats.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
src/mesa/main/formats.h | 3 +++
2 files changed, 60 insertions(+)
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 4fb1f11..fa310f0 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -2236,6 +2236,63 @@ _mesa_format_has_color_component(mesa_format format, int component)
/**
+ * Converts RGBX formats to the equivalent RGBA format.
+ *
+ * For non-X formats, returns the original format.
+ */
+mesa_format
+_mesa_format_x_to_a(mesa_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_X8B8G8R8_UNORM:
+ return MESA_FORMAT_A8B8G8R8_UNORM;
+ case MESA_FORMAT_R8G8B8X8_UNORM:
+ return MESA_FORMAT_R8G8B8A8_UNORM;
+ case MESA_FORMAT_B8G8R8X8_UNORM:
+ return MESA_FORMAT_B8G8R8A8_UNORM;
+ case MESA_FORMAT_X8R8G8B8_UNORM:
+ return MESA_FORMAT_A8R8G8B8_UNORM;
+ case MESA_FORMAT_B4G4R4X4_UNORM:
+ return MESA_FORMAT_B4G4R4A4_UNORM;
+ case MESA_FORMAT_B5G5R5X1_UNORM:
+ return MESA_FORMAT_B5G5R5A1_UNORM;
+ case MESA_FORMAT_B10G10R10X2_UNORM:
+ return MESA_FORMAT_B10G10R10A2_UNORM;
+ case MESA_FORMAT_X8B8G8R8_SNORM:
+ return MESA_FORMAT_A8B8G8R8_SNORM;
+ case MESA_FORMAT_R8G8B8X8_SNORM:
+ return MESA_FORMAT_R8G8B8A8_SNORM;
+ case MESA_FORMAT_B8G8R8X8_SRGB:
+ return MESA_FORMAT_B8G8R8A8_SRGB;
+ case MESA_FORMAT_R8G8B8X8_SRGB:
+ return MESA_FORMAT_R8G8B8A8_SRGB;
+ case MESA_FORMAT_RGBX_UNORM16:
+ return MESA_FORMAT_RGBA_UNORM16;
+ case MESA_FORMAT_RGBX_SNORM16:
+ return MESA_FORMAT_RGBA_SNORM16;
+ case MESA_FORMAT_RGBX_FLOAT16:
+ return MESA_FORMAT_RGBA_FLOAT16;
+ case MESA_FORMAT_RGBX_FLOAT32:
+ return MESA_FORMAT_RGBA_FLOAT32;
+ case MESA_FORMAT_RGBX_UINT8:
+ return MESA_FORMAT_RGBA_UINT8;
+ case MESA_FORMAT_RGBX_UINT16:
+ return MESA_FORMAT_RGBA_UINT16;
+ case MESA_FORMAT_RGBX_UINT32:
+ return MESA_FORMAT_RGBA_UINT32;
+ case MESA_FORMAT_RGBX_SINT8:
+ return MESA_FORMAT_RGBA_SINT8;
+ case MESA_FORMAT_RGBX_SINT16:
+ return MESA_FORMAT_RGBA_SINT16;
+ case MESA_FORMAT_RGBX_SINT32:
+ return MESA_FORMAT_RGBA_SINT32;
+ default:
+ return format;
+ }
+}
+
+
+/**
* Return number of bytes needed to store an image of the given size
* in the given format.
*/
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 89bd021..553fe7b 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -478,6 +478,9 @@ _mesa_format_num_components(mesa_format format);
extern bool
_mesa_format_has_color_component(mesa_format format, int component);
+extern mesa_format
+_mesa_format_x_to_a(mesa_format format);
+
GLboolean
_mesa_format_matches_format_and_type(mesa_format mesa_format,
GLenum format, GLenum type,
--
1.9.0
More information about the mesa-dev
mailing list