Mesa (master): mesa: Add support for unpacking 32-bit integer formats to int spans.

Eric Anholt anholt at kemper.freedesktop.org
Thu Nov 10 00:11:58 UTC 2011


Module: Mesa
Branch: master
Commit: e34c9edcda9167c634fe8381bd039f1a65925d0a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e34c9edcda9167c634fe8381bd039f1a65925d0a

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Nov  3 17:08:16 2011 -0700

mesa: Add support for unpacking 32-bit integer formats to int spans.

This is the inverse operation to _mesa_pack_rgba_span_int.  The 16-bit
code isn't done because of lack of testing and not being sure how sign
extension/clamping should be handled between, say, 16-bit int and
32-bit int or uint.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/main/format_unpack.c |  120 +++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/format_unpack.h |    8 +++
 2 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index eaa33df..525bbcb 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -1258,7 +1258,127 @@ _mesa_unpack_rgba_row(gl_format format, GLuint n,
    }
 }
 
+static void
+unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   memcpy(dst, src, n * 4 * sizeof(GLuint));
+}
+
+static void
+unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 3 + 0];
+      dst[i][1] = src[i * 3 + 1];
+      dst[i][2] = src[i * 3 + 2];
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 2 + 0];
+      dst[i][1] = src[i * 2 + 1];
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i];
+      dst[i][1] = 0;
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
+      dst[i][3] = 1;
+   }
+}
 
+static void
+unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
+      dst[i][3] = src[i * 2 + 1];
+   }
+}
+
+static void
+unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
+   }
+}
+
+void
+_mesa_unpack_int_rgba_row(gl_format format, GLuint n,
+			  const void *src, GLuint dst[][4])
+{
+   switch (format) {
+      /* Since there won't be any sign extension happening, there's no need to
+       * make separate paths for 32-bit-to-32-bit integer unpack.
+       */
+   case MESA_FORMAT_RGBA_UINT32:
+   case MESA_FORMAT_RGBA_INT32:
+      unpack_int_rgba_RGBA_UINT32(src, dst, n);
+      break;
+   case MESA_FORMAT_RGB_UINT32:
+   case MESA_FORMAT_RGB_INT32:
+      unpack_int_rgba_RGB_UINT32(src, dst, n);
+      break;
+   case MESA_FORMAT_RG_UINT32:
+   case MESA_FORMAT_RG_INT32:
+      unpack_int_rgba_RG_UINT32(src, dst, n);
+      break;
+   case MESA_FORMAT_R_UINT32:
+   case MESA_FORMAT_R_INT32:
+      unpack_int_rgba_R_UINT32(src, dst, n);
+      break;
+
+   case MESA_FORMAT_LUMINANCE_UINT32:
+   case MESA_FORMAT_LUMINANCE_INT32:
+      unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
+      break;
+   case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
+   case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
+      unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
+      break;
+   case MESA_FORMAT_INTENSITY_UINT32:
+   case MESA_FORMAT_INTENSITY_INT32:
+      unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
+      break;
+
+   default:
+      _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
+                    _mesa_get_format_name(format));
+      return;
+   }
+}
 
 /**
  * Unpack a 2D rect of pixels returning float RGBA colors.
diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h
index a8a829c..0d13a2d 100644
--- a/src/mesa/main/format_unpack.h
+++ b/src/mesa/main/format_unpack.h
@@ -29,12 +29,20 @@ _mesa_unpack_rgba_row(gl_format format, GLuint n,
                       const void *src, GLfloat dst[][4]);
 
 
+void
+_mesa_unpack_int_rgba_row(gl_format format, GLuint n,
+			  const void *src, GLuint dst[][4]);
+
 extern void
 _mesa_unpack_rgba_block(gl_format format,
                         const void *src, GLint srcRowStride,
                         GLfloat dst[][4], GLint dstRowStride,
                         GLuint x, GLuint y, GLuint width, GLuint height);
 
+extern void
+_mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
+			   const void *src, GLuint dst[][4]);
+
 
 extern void
 _mesa_unpack_float_z_row(gl_format format, GLuint n,




More information about the mesa-commit mailing list