aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorIago Toral Quiroga <[email protected]>2014-11-26 09:39:35 +0100
committerIago Toral Quiroga <[email protected]>2015-01-12 11:20:28 +0100
commitb1f0229140a66a36de63408b8a3eb45e11e43710 (patch)
treeaee7aa6732d8b8a6763458af7b29de598e24e647 /src/mesa/main
parent3171a09c2539a3d08196d6a4cb91ad6276f9383d (diff)
mesa: Add a helper _mesa_compute_rgba2base2rgba_component_mapping
This will come in handy when callers of _mesa_format_convert need to compute the rebase swizzle parameter to use. Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/format_utils.c55
-rw-r--r--src/mesa/main/format_utils.h3
2 files changed, 58 insertions, 0 deletions
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 2cbe80e77eb..30c7044e2f2 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -151,6 +151,61 @@ compute_src2dst_component_mapping(uint8_t *src2rgba, uint8_t *rgba2dst,
}
/**
+ * This function is used by clients of _mesa_format_convert to obtain
+ * the rebase swizzle to use in a format conversion based on the base
+ * format involved.
+ *
+ * \param baseFormat the base internal format involved in the conversion.
+ * \param map the rebase swizzle to consider
+ *
+ * This function computes 'map' as rgba -> baseformat -> rgba and returns true
+ * if the resulting swizzle transform is not the identity transform (thus, a
+ * rebase is needed). If the function returns false then a rebase swizzle
+ * is not necessary and the value of 'map' is undefined. In this situation
+ * clients of _mesa_format_convert should pass NULL in the 'rebase_swizzle'
+ * parameter.
+ */
+bool
+_mesa_compute_rgba2base2rgba_component_mapping(GLenum baseFormat, uint8_t *map)
+{
+ uint8_t rgba2base[6], base2rgba[6];
+ int i;
+
+ switch (baseFormat) {
+ case GL_ALPHA:
+ case GL_RED:
+ case GL_GREEN:
+ case GL_BLUE:
+ case GL_RG:
+ case GL_RGB:
+ case GL_BGR:
+ case GL_RGBA:
+ case GL_BGRA:
+ case GL_ABGR_EXT:
+ case GL_LUMINANCE:
+ case GL_INTENSITY:
+ case GL_LUMINANCE_ALPHA:
+ {
+ bool needRebase = false;
+ _mesa_compute_component_mapping(GL_RGBA, baseFormat, rgba2base);
+ _mesa_compute_component_mapping(baseFormat, GL_RGBA, base2rgba);
+ for (i = 0; i < 4; i++) {
+ if (base2rgba[i] > MESA_FORMAT_SWIZZLE_W) {
+ map[i] = base2rgba[i];
+ } else {
+ map[i] = rgba2base[base2rgba[i]];
+ }
+ if (map[i] != i)
+ needRebase = true;
+ }
+ return needRebase;
+ }
+ default:
+ assert(!"Unexpected base format");
+ }
+}
+
+/**
* This can be used to convert between most color formats.
*
* Limitations:
diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h
index ae7926e0c75..48e4467f5e9 100644
--- a/src/mesa/main/format_utils.h
+++ b/src/mesa/main/format_utils.h
@@ -212,6 +212,9 @@ _mesa_swizzle_and_convert(void *dst, GLenum dst_type, int num_dst_channels,
const void *src, GLenum src_type, int num_src_channels,
const uint8_t swizzle[4], bool normalized, int count);
+bool
+_mesa_compute_rgba2base2rgba_component_mapping(GLenum baseFormat, uint8_t *map);
+
void
_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
void *void_src, uint32_t src_format, size_t src_stride,