mesa: Add decoding functions for GL_COMPRESSED_SRGB8_ETC2
authorAnuj Phogat <anuj.phogat@gmail.com>
Fri, 28 Sep 2012 00:05:24 +0000 (17:05 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Sat, 8 Dec 2012 00:29:48 +0000 (16:29 -0800)
Data in GL_COMPRESSED_SRGB8_ETC2 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 3394be9f6adb8f13a4cc4eb7b32d3b6e0789d6ef..3ed0e8593b5c22164c186fe40c8c50c4184bdd80 100644 (file)
@@ -611,7 +611,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
       fetch = _mesa_fetch_texel_2d_f_etc2_rgb8;
       break;
    case MESA_FORMAT_ETC2_SRGB8:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8; -- not implemented yet */
+      fetch = _mesa_fetch_texel_2d_f_etc2_srgb8;
       break;
    case MESA_FORMAT_ETC2_RGBA8_EAC:
       /* fetch = _mesa_fetch_texel_2d_f_etc2_rgba8_eac; -- not implemented yet */
index 42ef74a7d1f05e89fa80c43b0e54d7b24c5669f1..2aa8b6ad7232158d28e21d51f6747e643a1662fb 100644 (file)
@@ -26,6 +26,7 @@
  * GL_OES_compressed_ETC1_RGB8_texture support.
  * Supported ETC2 texture formats are:
  * GL_COMPRESSED_RGB8_ETC2
+ * GL_COMPRESSED_SRGB8_ETC2
  */
 
 #include <stdbool.h>
@@ -35,6 +36,7 @@
 #include "texstore.h"
 #include "macros.h"
 #include "swrast/s_context.h"
+#include "format_unpack.h"
 
 struct etc2_block {
    int distance;
@@ -490,6 +492,45 @@ etc2_unpack_rgb8(uint8_t *dst_row,
    }
 }
 
+static void
+etc2_unpack_srgb8(uint8_t *dst_row,
+                  unsigned dst_stride,
+                  const uint8_t *src_row,
+                  unsigned src_stride,
+                  unsigned width,
+                  unsigned height)
+{
+   const unsigned bw = 4, bh = 4, bs = 8, 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_rgb8_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_rgb8_fetch_texel(&block, i, j, dst);
+               /* Convert to MESA_FORMAT_SARGB8 */
+               tmp = dst[0];
+               dst[0] = dst[2];
+               dst[2] = tmp;
+               dst[3] = 255;
+
+               dst += comps;
+            }
+         }
+         src += bs;
+       }
+
+      src_row += src_stride;
+    }
+}
+
 /* ETC2 texture formats are valid in glCompressedTexImage2D and
  * glCompressedTexSubImage2D functions */
 GLboolean
@@ -500,6 +541,14 @@ _mesa_texstore_etc2_rgb8(TEXSTORE_PARAMS)
    return GL_FALSE;
 }
 
+GLboolean
+_mesa_texstore_etc2_srgb8(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)
@@ -520,9 +569,30 @@ _mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
+void
+_mesa_fetch_texel_2d_f_etc2_srgb8(const struct swrast_texture_image *texImage,
+                                  GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   struct etc2_block block;
+   uint8_t dst[3];
+   const uint8_t *src;
+
+   src = texImage->Map +
+      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
+
+   etc2_rgb8_parse_block(&block, src);
+   etc2_rgb8_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] = 1.0f;
+}
 
 /**
- * Decode texture data in format `MESA_FORMAT_ETC2_RGB8`
+ * Decode texture data in any one of following formats:
+ * `MESA_FORMAT_ETC2_RGB8`
+ * `MESA_FORMAT_ETC2_SRGB8`
  *
  * 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.
@@ -541,7 +611,12 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
                          unsigned src_height,
                          gl_format format)
 {
-   etc2_unpack_rgb8(dst_row, dst_stride,
-                    src_row, src_stride,
-                    src_width, src_height);
+   if (format == MESA_FORMAT_ETC2_RGB8)
+      etc2_unpack_rgb8(dst_row, dst_stride,
+                       src_row, src_stride,
+                       src_width, src_height);
+   else if (format == MESA_FORMAT_ETC2_SRGB8)
+      etc2_unpack_srgb8(dst_row, dst_stride,
+                        src_row, src_stride,
+                        src_width, src_height);
 }
index 2508f5fa3a3df7d0bf422ab139ef157df282e305..1dc1d5a0414736e58914158ce569b948b28a4c20 100644 (file)
@@ -37,6 +37,9 @@ _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS);
 GLboolean
 _mesa_texstore_etc2_rgb8(TEXSTORE_PARAMS);
 
+GLboolean
+_mesa_texstore_etc2_srgb8(TEXSTORE_PARAMS);
+
 void
 _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel);
@@ -44,6 +47,10 @@ void
 _mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel);
 void
+_mesa_fetch_texel_2d_f_etc2_srgb8(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,
index 0908b33e54fbf95a7989bb8949cd2e0e59b9fdd4..3bafd2354712a08c95d5a3ae24efcf0b99fcff5e 100644 (file)
@@ -4125,7 +4125,7 @@ _mesa_get_texstore_func(gl_format format)
       table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2;
       table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8;
       table[MESA_FORMAT_ETC2_RGB8] = _mesa_texstore_etc2_rgb8;
-      /* table[MESA_FORMAT_ETC2_SRGB8] = _mesa_texstore_etc2_srgb8; -- not implemented yet */
+      table[MESA_FORMAT_ETC2_SRGB8] = _mesa_texstore_etc2_srgb8;
       /* table[MESA_FORMAT_ETC2_RGBA8_EAC] = _mesa_texstore_etc2_rgba8_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = _mesa_texstore_etc2_srgb8_alpha8_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac; -- not implemented yet */
index c1e16b4390e39ab58651611dbde87ab8f2d137b6..66f282ce82c28fecfad46cb2e80dac060d33b013 100644 (file)
@@ -1037,7 +1037,7 @@ texfetch_funcs[] =
    {
       MESA_FORMAT_ETC2_SRGB8,
       NULL,
-      NULL /* _mesa_fetch_texel_2d_f_etc2_srgb8 -- not implemented yet */,
+      _mesa_fetch_texel_2d_f_etc2_srgb8,
       NULL
    },
    {