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 <jason.ekstrand@intel.com>
This commit is contained in:
Iago Toral Quiroga 2014-11-26 09:39:35 +01:00
parent 3171a09c25
commit b1f0229140
2 changed files with 58 additions and 0 deletions

View File

@ -150,6 +150,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.
*

View File

@ -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,