[Mesa-dev] [PATCH 23/27] mesa: Add decoding functions for GL_COMPRESSED_SIGNED_R11_EAC
Ian Romanick
idr at freedesktop.org
Tue Nov 6 15:27:45 PST 2012
On 10/19/2012 04:28 PM, Anuj Phogat wrote:
> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
> ---
> src/mesa/main/texcompress_etc.c | 108 +++++++++++++++++++++++++++++++++++++++
> src/mesa/main/texcompress_etc.h | 8 +++
> 2 files changed, 116 insertions(+), 0 deletions(-)
>
> diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
> index 8c6d954..e3e4090 100644
> --- a/src/mesa/main/texcompress_etc.c
> +++ b/src/mesa/main/texcompress_etc.c
> @@ -31,6 +31,7 @@
> * GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
> * GL_COMPRESSED_R11_EAC
> * GL_COMPRESSED_RG11_EAC
> + * GL_COMPRESSED_SIGNED_R11_EAC
> */
>
>
> @@ -330,6 +331,13 @@ etc2_clamp2(int color)
> return (GLushort) ((color < 0) ? 0 : ((color > 2047) ? 2047 : color));
> }
>
> +static GLshort
> +etc2_clamp3(int color)
> +{
> + /* CLAMP(color, -1023, 1023) */
> + return (GLshort) ((color < -1023) ? -1023 : ((color > 1023) ? 1023 : color));
> +}
> +
Just use CLAMP.
> static void
> etc2_rgb8_parse_block(struct etc2_block *block, const GLubyte *src)
> {
> @@ -548,6 +556,40 @@ etc2_r11_fetch_texel(const struct etc2_block *block,
> }
>
> static void
> +etc2_signed_r11_fetch_texel(const struct etc2_block *block,
> + int x, int y, GLbyte *dst)
> +{
> + GLint modifier, idx;
> + GLshort color;
> + GLbyte base_codeword = (GLbyte) block->base_codeword;
> + /* Get pixel index */
> + idx = etc2_get_pixel_index(block, x, y);
> + modifier = etc2_modifier_tables[block->table_index][idx];
> +
> + if (block->multiplier != 0)
> + /* clamp3(base codeword × 8 + modifier × multiplier × 8) */
> + color = etc2_clamp3((base_codeword << 3) +
> + ((modifier * block->multiplier) << 3));
> + else
> + color = etc2_clamp3((base_codeword << 3) + modifier);
> +
> + /* Extend 11 bits color value to 16 bits. OpenGL ES 3.0 specification
> + * allows extending the color value to any number of bits. But, an
> + * implementation is not allowed to truncate the 11-bit value to less than
> + * 11 bits. A negative 11-bit value must first be made positive before bit
> + * replication, and then made negative again
> + */
> + if (color >= 0)
> + color = (color << 5) | (color >> 5);
> + else {
> + color = -color;
> + color = (color << 5) | (color >> 5);
> + color = -color;
> + }
> + ((GLshort *)dst)[0] = color;
> +}
> +
> +static void
> etc2_alpha8_parse_block(struct etc2_block *block, const GLubyte *src)
> {
> block->base_codeword = src[0];
> @@ -828,6 +870,42 @@ etc2_unpack_rg11(uint8_t *dst_row,
> }
> }
>
> +static void
> +etc2_unpack_signed_r11(uint8_t *dst_row,
> + unsigned dst_stride,
> + const uint8_t *src_row,
> + unsigned src_stride,
> + unsigned width,
> + unsigned height)
> +{
> + /* If internalformat is COMPRESSED_SIGNED_R11_EAC, each 4 × 4 block of
> + red color information is compressed to 64 bits.
> + */
> + const unsigned bw = 4, bh = 4, bs = 8, comps = 1, comp_size = 2;
> + 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_r11_parse_block(&block, src);
> +
> + for (j = 0; j < bh; j++) {
> + int8_t *dst = (int8_t *) (dst_row + (y + j) * dst_stride +
> + x * comps * comp_size);
> + for (i = 0; i < bw; i++) {
> + etc2_signed_r11_fetch_texel(&block, i, j, dst);
> + dst += comps * comp_size;
> + }
> + }
> + src += bs;
> + }
> +
> + src_row += src_stride;
> + }
> +}
> +
> /* ETC2 texture formats are valid in glCompressedTexImage2D and
> * glCompressedTexSubImage2D functions */
> GLboolean
> @@ -871,6 +949,14 @@ _mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS)
> }
>
> GLboolean
> +_mesa_texstore_etc2_signed_r11_eac(TEXSTORE_PARAMS)
> +{
> + ASSERT(0);
> +
> + return GL_FALSE;
> +}
> +
> +GLboolean
> _mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS)
> {
> ASSERT(0);
> @@ -1002,6 +1088,23 @@ _mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct
> texel[GCOMP] = USHORT_TO_FLOAT(dst[1]);
> }
>
> +void
> +_mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct swrast_texture_image *texImage,
> + GLint i, GLint j, GLint k, GLfloat *texel)
> +{
> + struct etc2_block block;
> + GLshort dst;
> + const GLubyte *src;
> +
> + src = (const GLubyte *) texImage->Map +
> + (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
> +
> + etc2_r11_parse_block(&block, src);
> + etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (GLbyte *)&dst);
> +
> + texel[RCOMP] = SHORT_TO_FLOAT(dst);
> +}
> +
> /**
> * Decode texture data in any one of following formats:
> * `MESA_FORMAT_ETC2_RGB8`
> @@ -1010,6 +1113,7 @@ _mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct
> * `MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC`
> * `MESA_FORMAT_ETC2_R11_EAC`
> * `MESA_FORMAT_ETC2_RG11_EAC`
> + * `MESA_FORMAT_ETC2_SIGNED_R11_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.
> @@ -1052,4 +1156,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> etc2_unpack_rg11(dst_row, dst_stride,
> src_row, src_stride,
> src_width, src_height);
> + else if (format == MESA_FORMAT_ETC2_SIGNED_R11_EAC)
> + etc2_unpack_signed_r11(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 358163d..362fa78 100644
> --- a/src/mesa/main/texcompress_etc.h
> +++ b/src/mesa/main/texcompress_etc.h
> @@ -52,6 +52,9 @@ _mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS);
> GLboolean
> _mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS);
>
> +GLboolean
> +_mesa_texstore_etc2_signed_r11_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);
> @@ -76,6 +79,11 @@ void
> _mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct swrast_texture_image *texImage,
> GLint i, GLint j, GLint k, GLfloat *texel);
> void
> +_mesa_fetch_texel_2d_f_etc2_signed_r11_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,
> const uint8_t *src_row,
>
>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list