mesa: Add function for decoding ETC1 textures
authorChad Versace <chad.versace@linux.intel.com>
Tue, 10 Jul 2012 23:34:27 +0000 (16:34 -0700)
committerChad Versace <chad.versace@linux.intel.com>
Mon, 16 Jul 2012 21:07:57 +0000 (14:07 -0700)
Add function _mesa_etc1_unpack_rgba8888. It is intended to be used by
glCompressedTexSubImage2D to decode ETC1 textures into RGBA.

CC: Chia-I <olv@lunarg.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
src/mesa/main/texcompress_etc.c
src/mesa/main/texcompress_etc.h

index 5b331a92a1443c8b97b64b51ba81191d667ca90c..c645f52b9e1ddf1acd7d351ca64a595666de0719 100644 (file)
@@ -69,3 +69,35 @@ _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
    texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]);
    texel[ACOMP] = 1.0f;
 }
+
+/**
+ * Decode texture data in format `MESA_FORMAT_ETC1_RGB8` to
+ * `MESA_FORMAT_ABGR8888`.
+ *
+ * The size of the source data must be a multiple of the ETC1 block size,
+ * which is 8, even if the texture image's dimensions are not aligned to 4.
+ * From the GL_OES_compressed_ETC1_RGB8_texture spec:
+ *   The texture is described as a number of 4x4 pixel blocks. If the
+ *   texture (or a particular mip-level) is smaller than 4 pixels in
+ *   any dimension (such as a 2x2 or a 8x1 texture), the texture is
+ *   found in the upper left part of the block(s), and the rest of the
+ *   pixels are not used. For instance, a texture of size 4x2 will be
+ *   placed in the upper half of a 4x4 block, and the lower half of the
+ *   pixels in the block will not be accessed.
+ *
+ * \param src_width in pixels
+ * \param src_height in pixels
+ * \param dst_stride in bytes
+ */
+void
+_mesa_etc1_unpack_rgba8888(uint8_t *dst_row,
+                           unsigned dst_stride,
+                           const uint8_t *src_row,
+                           unsigned src_stride,
+                           unsigned src_width,
+                           unsigned src_height)
+{
+   etc1_unpack_rgba8888(dst_row, dst_stride,
+                        src_row, src_stride,
+                        src_width, src_height);
+}
index 8e8427f8fd4259db9e6ab912f1189b88374f289b..bfba4ff85e99cf632f2700bbd84320d40cdffc48 100644 (file)
@@ -37,4 +37,12 @@ void
 _mesa_fetch_texel_2d_f_etc1_rgb8(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,
+                           unsigned src_stride,
+                           unsigned src_width,
+                           unsigned src_height);
+
 #endif