Signed-off-by: Anuj Phogat <anuj.pho...@gmail.com> --- src/mesa/main/texcompress_etc.c | 95 +++++++++++++++++++++++++++++++++++--- src/mesa/main/texcompress_etc.h | 9 +++- 2 files changed, 95 insertions(+), 9 deletions(-)
diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c index f531416..5b0e576 100644 --- a/src/mesa/main/texcompress_etc.c +++ b/src/mesa/main/texcompress_etc.c @@ -28,6 +28,7 @@ * GL_COMPRESSED_RGB8_ETC2 * GL_COMPRESSED_SRGB8_ETC2 * GL_COMPRESSED_RGBA8_ETC2_EAC + * GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC */ @@ -497,6 +498,14 @@ etc2_alpha8_fetch_texel(const struct etc2_block *block, } static void +etc2_rgba8_fetch_texel(const struct etc2_block *block, + int x, int y, GLubyte *dst) +{ + etc2_rgb8_fetch_texel(block, x, y, dst); + etc2_alpha8_fetch_texel(block, x, y, dst); +} + +static void etc2_alpha8_parse_block(struct etc2_block *block, const GLubyte *src) { block->base_codeword = src[0]; @@ -520,14 +529,6 @@ etc2_rgba8_parse_block(struct etc2_block *block, const GLubyte *src) etc2_alpha8_parse_block(block, src); } -static void -etc2_rgba8_fetch_texel(const struct etc2_block *block, - int x, int y, GLubyte *dst) -{ - etc2_rgb8_fetch_texel(block, x, y, dst); - etc2_alpha8_fetch_texel(block, x, y, dst); -} - /** * Convert from sRGB color space to linear color space, using the * formula from the GL 3.0 spec, section 4.1.8 (sRGB Texture Color @@ -652,6 +653,49 @@ etc2_unpack_rgba8(uint8_t *dst_row, } } +static void +etc2_unpack_srgb8_alpha8(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + /* If internalformat is COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, each 4 ?? 4 block + * of RGBA8888 information is compressed to 128 bits. To decode a block, the + two 64-bit integers int64bitAlpha and int64bitColor are calculated. + */ + const unsigned bw = 4, bh = 4, bs = 16, comps = 4; + struct etc2_block block; + unsigned x, y, i, j; + + for (y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + + for (x = 0; x < width; x+= bw) { + etc2_rgba8_parse_block(&block, src); + + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgba8_fetch_texel(&block, i, j, dst); + + /* sRGB color space to linear color space conversion */ + dst[0] = FLOAT_TO_UBYTE(decode_srgb(UBYTE_TO_FLOAT(dst[0]))); + dst[1] = FLOAT_TO_UBYTE(decode_srgb(UBYTE_TO_FLOAT(dst[1]))); + dst[2] = FLOAT_TO_UBYTE(decode_srgb(UBYTE_TO_FLOAT(dst[2]))); + dst[3] = FLOAT_TO_UBYTE(decode_srgb(UBYTE_TO_FLOAT(dst[3]))); + + dst += comps; + } + } + src += bs; + } + + src_row += src_stride; + } +} + /* ETC2 texture formats are valid in glCompressedTexImage2D and * glCompressedTexSubImage2D functions */ GLboolean @@ -678,6 +722,14 @@ _mesa_texstore_etc2_rgba8_eac(TEXSTORE_PARAMS) return GL_FALSE; } +GLboolean +_mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + void _mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel) @@ -738,11 +790,34 @@ _mesa_fetch_texel_2d_f_etc2_rgba8_eac(const struct swrast_texture_image *texImag texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]); } +void +_mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel) +{ + struct etc2_block block; + GLubyte dst[4]; + const GLubyte *src; + + src = (const GLubyte *) texImage->Map + + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8; + + etc2_rgba8_parse_block(&block, src); + etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst); + + texel[RCOMP] = decode_srgb(UBYTE_TO_FLOAT(dst[0])); + texel[GCOMP] = decode_srgb(UBYTE_TO_FLOAT(dst[1])); + texel[BCOMP] = decode_srgb(UBYTE_TO_FLOAT(dst[2])); + texel[ACOMP] = decode_srgb(UBYTE_TO_FLOAT(dst[3])); +} + /** * Decode texture data in any one of following formats: * `MESA_FORMAT_ETC2_RGB8` * `MESA_FORMAT_ETC2_SRGB8` * `MESA_FORMAT_ETC2_RGBA8_EAC` + * `MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC` * * The size of the source data must be a multiple of the ETC2 block size * even if the texture image's dimensions are not aligned to 4. @@ -773,4 +848,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row, etc2_unpack_rgba8(dst_row, dst_stride, src_row, src_stride, src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC) + etc2_unpack_srgb8_alpha8(dst_row, dst_stride, + src_row, src_stride, + src_width, src_height); } diff --git a/src/mesa/main/texcompress_etc.h b/src/mesa/main/texcompress_etc.h index 2191c97..c10414d 100644 --- a/src/mesa/main/texcompress_etc.h +++ b/src/mesa/main/texcompress_etc.h @@ -43,6 +43,9 @@ _mesa_texstore_etc2_srgb8(TEXSTORE_PARAMS); GLboolean _mesa_texstore_etc2_rgba8_eac(TEXSTORE_PARAMS); +GLboolean +_mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS); + void _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel); @@ -55,7 +58,11 @@ _mesa_fetch_texel_2d_f_etc2_srgb8(const struct swrast_texture_image *texImage, void _mesa_fetch_texel_2d_f_etc2_rgba8_eac(const struct swrast_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel); - +void +_mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct + swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); void _mesa_etc1_unpack_rgba8888(uint8_t *dst_row, unsigned dst_stride, -- 1.7.7.6
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev