This will come in handy when callers of _mesa_format_convert need to compute the rebase swizzle parameter to use.
Reviewed-by: Jason Ekstrand <jason.ekstr...@intel.com> --- src/mesa/main/format_utils.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/format_utils.h | 3 +++ 2 files changed, 58 insertions(+) diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c index 2cbe80e..30c7044 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 ae7926e..48e4467 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, -- 1.9.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev