diff options
author | Iago Toral Quiroga <[email protected]> | 2014-11-07 08:32:14 +0100 |
---|---|---|
committer | Iago Toral Quiroga <[email protected]> | 2015-01-12 11:20:29 +0100 |
commit | 2ec8718dae126e6699640de37cbd950878635cbd (patch) | |
tree | 434e7c76fc136dfecc8a01a6949b885798cc0369 /src/mesa/main/pack.c | |
parent | d71a1adff253aa75a3474723209c35831bb3f048 (diff) |
mesa: Add helpers to extract GL_COLOR_INDEX to RGBA float/ubyte
We only use _mesa_make_temp_ubyte_image in texstore.c to convert
GL_COLOR_INDEX to RGBA, but this helper does more stuff than this.
All uses of this helper can be replaced with calls to
_mesa_format_convert except for this GL_COLOR_INDEX conversion.
This patch extracts the GL_COLOR_INDEX to RGBA logic to a separate
helper so we can use that instead from texstore.c.
In future patches we will replace all remaining calls to
_mesa_make_temp_ubyte_image in the repository (related to compressed
formats) with calls to _mesa_format_convert so we can remove
_mesa_make_temp_ubyte_image and related functions.
v2:
- Remove ‘for’ loop initial declaration. They are only allowed in C99 or C11
mode.
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/mesa/main/pack.c')
-rw-r--r-- | src/mesa/main/pack.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c index 140ba29e4fa..a64535210b2 100644 --- a/src/mesa/main/pack.c +++ b/src/mesa/main/pack.c @@ -4549,3 +4549,88 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n, } } +GLfloat * +_mesa_unpack_color_index_to_rgba_float(struct gl_context *ctx, GLuint dims, + const void *src, GLenum srcFormat, GLenum srcType, + int srcWidth, int srcHeight, int srcDepth, + const struct gl_pixelstore_attrib *srcPacking, + GLbitfield transferOps) +{ + int count, img; + GLuint *indexes; + GLfloat *rgba, *dstPtr; + + count = srcWidth * srcHeight; + indexes = malloc(count * sizeof(GLuint)); + if (!indexes) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking"); + return NULL; + } + + rgba = malloc(4 * count * srcDepth * sizeof(GLfloat)); + if (!rgba) { + free(indexes); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking"); + return NULL; + } + + /* Convert indexes to RGBA float */ + dstPtr = rgba; + for (img = 0; img < srcDepth; img++) { + const GLubyte *srcPtr = + (const GLubyte *) _mesa_image_address(dims, srcPacking, src, + srcWidth, srcHeight, + srcFormat, srcType, + img, 0, 0); + + extract_uint_indexes(count, indexes, srcFormat, srcType, srcPtr, srcPacking); + + if (transferOps & IMAGE_SHIFT_OFFSET_BIT) + _mesa_shift_and_offset_ci(ctx, count, indexes); + + _mesa_map_ci_to_rgba(ctx, count, indexes, (float (*)[4])dstPtr); + + /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting + * with color indexes. + */ + transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT); + _mesa_apply_rgba_transfer_ops(ctx, transferOps, count, (float (*)[4])dstPtr); + + dstPtr += srcHeight * srcWidth * 4; + } + + free(indexes); + + return rgba; +} + +GLubyte * +_mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims, + const void *src, GLenum srcFormat, GLenum srcType, + int srcWidth, int srcHeight, int srcDepth, + const struct gl_pixelstore_attrib *srcPacking, + GLbitfield transferOps) +{ + GLfloat *rgba; + GLubyte *dst; + int count, i; + + transferOps |= IMAGE_CLAMP_BIT; + rgba = _mesa_unpack_color_index_to_rgba_float(ctx, dims, + src, srcFormat, srcType, + srcWidth, srcHeight, srcDepth, + srcPacking, transferOps); + + count = srcWidth * srcHeight * srcDepth; + dst = malloc(count * 4 * sizeof(GLubyte)); + for (i = 0; i < count; i++) { + CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 0], rgba[i * 4 + 0]); + CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 1], rgba[i * 4 + 1]); + CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 2], rgba[i * 4 + 2]); + CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 3], rgba[i * 4 + 3]); + } + + free(rgba); + + return dst; +} |