mesa: Add decoding functions for GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
authorAnuj Phogat <anuj.phogat@gmail.com>
Tue, 13 Nov 2012 00:13:25 +0000 (16:13 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Sat, 8 Dec 2012 00:29:48 +0000 (16:29 -0800)
Data in GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC format is decoded and stored
in MESA_FORMAT_SARGB8.

Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/main/texcompress.c
src/mesa/main/texcompress_etc.c
src/mesa/main/texcompress_etc.h
src/mesa/main/texstore.c
src/mesa/swrast/s_texfetch.c

index 7dc337c429175ddd4215a9876a82cebd55c0a749..2d4c6df85a8a7d871cdec6401df694097ade3f3c 100644 (file)
@@ -617,7 +617,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
       fetch = _mesa_fetch_texel_2d_f_etc2_rgba8_eac;
       break;
    case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac; -- not implemented yet */
+      fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac;
       break;
    case MESA_FORMAT_ETC2_R11_EAC:
       /* fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac; -- not implemented yet */
index 26375d8e9ff0b4b465010030024306df8b60ae95..d704388d6306ea7a6a4b54e4efc11a72f1e1ba0e 100644 (file)
@@ -28,6 +28,7 @@
  * GL_COMPRESSED_RGB8_ETC2
  * GL_COMPRESSED_SRGB8_ETC2
  * GL_COMPRESSED_RGBA8_ETC2_EAC
+ * GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
  */
 
 #include <stdbool.h>
@@ -635,6 +636,50 @@ 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;
+   uint8_t tmp;
+
+   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);
+
+               /* Convert to MESA_FORMAT_SARGB8 */
+               tmp = dst[0];
+               dst[0] = dst[2];
+               dst[2] = tmp;
+               dst[3] = dst[3];
+
+               dst += comps;
+            }
+         }
+         src += bs;
+       }
+
+      src_row += src_stride;
+    }
+}
+
 /* ETC2 texture formats are valid in glCompressedTexImage2D and
  * glCompressedTexSubImage2D functions */
 GLboolean
@@ -661,6 +706,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)
@@ -721,11 +774,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;
+   uint8_t dst[4];
+   const uint8_t *src;
+
+   src = texImage->Map +
+      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16;
+
+   etc2_rgba8_parse_block(&block, src);
+   etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst);
+
+   texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
+   texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
+   texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
+   texel[ACOMP] = 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.
@@ -756,4 +832,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);
 }
index fd9d2d7224bd23084414a73acb00f3aa6fbda6fe..cfe8da3dabc1f9232a9a615b4bd5a15b09d84a42 100644 (file)
@@ -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);
@@ -56,6 +59,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,
index b5ef595cb586ad77d3f49ff57b4980b4d9604d69..6007775169b660054cf14d870e33eb2dba0ac728 100644 (file)
@@ -4127,7 +4127,7 @@ _mesa_get_texstore_func(gl_format format)
       table[MESA_FORMAT_ETC2_RGB8] = _mesa_texstore_etc2_rgb8;
       table[MESA_FORMAT_ETC2_SRGB8] = _mesa_texstore_etc2_srgb8;
       table[MESA_FORMAT_ETC2_RGBA8_EAC] = _mesa_texstore_etc2_rgba8_eac;
-      /* table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = _mesa_texstore_etc2_srgb8_alpha8_eac; -- not implemented yet */
+      table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = _mesa_texstore_etc2_srgb8_alpha8_eac;
       /* table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = _mesa_texstore_etc2_signed_r11_eac; -- not implemented yet */
index 504d39400e580908b794eb1583914bb1e99b3551..b5989e4ae568f1531a9dad4538fc43721aca9d8c 100644 (file)
@@ -1049,7 +1049,7 @@ texfetch_funcs[] =
    {
       MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC,
       NULL,
-      NULL /* _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac -- not implemented yet */,
+      _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac,
       NULL
    },
    {