Mesa (map-texture-image-v5): mesa: new _mesa_decompress_image() function
Brian Paul
brianp at kemper.freedesktop.org
Thu Sep 1 03:30:57 UTC 2011
Module: Mesa
Branch: map-texture-image-v5
Commit: 0fdeb508eaa7320dd1a367be2a5126c99f0438b2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0fdeb508eaa7320dd1a367be2a5126c99f0438b2
Author: Brian Paul <brianp at vmware.com>
Date: Wed Aug 31 20:04:15 2011 -0600
mesa: new _mesa_decompress_image() function
Use the old texture fetch functions to decompress a whole image.
To be used by glGetTexImage().
---
src/mesa/main/texcompress.c | 86 +++++++++++++++++++++++++++++++++++++++++++
src/mesa/main/texcompress.h | 5 ++
2 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 42bd1ee..28af859 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -37,6 +37,9 @@
#include "mfeatures.h"
#include "mtypes.h"
#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_rgtc.h"
+#include "texcompress_s3tc.h"
/**
@@ -437,3 +440,86 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
return (GLubyte *) image + offset;
}
+
+
+/**
+ * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
+ */
+void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest)
+{
+ void (*fetch)(const struct swrast_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+ struct gl_texture_image texImage; /* dummy teximage */
+ GLuint i, j;
+
+ /* setup dummy texture image info */
+ memset(&texImage, 0, sizeof(texImage));
+ texImage.Data = (void *) src;
+ texImage.RowStride = srcRowStride;
+
+ switch (format) {
+ /* DXT formats */
+ case MESA_FORMAT_RGB_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT3:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt3;
+ break;
+ case MESA_FORMAT_RGBA_DXT5:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt5;
+ break;
+
+ /* FXT1 formats */
+ case MESA_FORMAT_RGB_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_fxt1;
+ break;
+ case MESA_FORMAT_RGBA_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_fxt1;
+ break;
+
+ /* Red/RG formats */
+ case MESA_FORMAT_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_red_rgtc1;
+ break;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_red_rgtc1;
+ break;
+ case MESA_FORMAT_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_rg_rgtc2;
+ break;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_rg_rgtc2;
+ break;
+
+ /* L/LA formats */
+ case MESA_FORMAT_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_l_latc1;
+ break;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_l_latc1;
+ break;
+ case MESA_FORMAT_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_la_latc2;
+ break;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_la_latc2;
+ break;
+
+ default:
+ _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
+ return;
+ }
+
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ fetch((struct swrast_texture_image *) &texImage, i, j, 0, dest);
+ dest += 4;
+ }
+ }
+}
diff --git a/src/mesa/main/texcompress.h b/src/mesa/main/texcompress.h
index 375cf90..2c35706 100644
--- a/src/mesa/main/texcompress.h
+++ b/src/mesa/main/texcompress.h
@@ -50,6 +50,11 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
gl_format mesaFormat,
GLsizei width, const GLubyte *image);
+extern void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest);
+
#else /* _HAVE_FULL_GL */
/* no-op macros */
More information about the mesa-commit
mailing list