[Mesa-dev] [PATCH 06/13] mesa pack: handle uint and int clamping properly

Jordan Justen jordan.l.justen at intel.com
Mon Jun 25 17:34:37 PDT 2012


Rename _mesa_pack_rgba_span_int to _mesa_pack_rgba_span_from_uints.
Add _mesa_pack_rgba_span_from_ints.

These separate routines allow the integer clamping to be handled
properly for signed versus unsigned integers.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/mesa/main/pack.c        |  107 +++++++++++++++++++++++++++++++++++++++++--
 src/mesa/main/pack.h        |   12 +++--
 src/mesa/main/readpix.c     |    4 +-
 src/mesa/main/texgetimage.c |    4 +-
 4 files changed, 115 insertions(+), 12 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index a0c4fb3..9fb8771 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -461,6 +461,14 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef SRC_CONVERT
 #undef FN_NAME
 
+#define DST_TYPE GLint
+#define SRC_CONVERT(x) MIN2(x, 0x7fffffff)
+#define FN_NAME pack_int_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
 #define DST_TYPE GLushort
 #define SRC_CONVERT(x) MIN2(x, 0xffff)
 #define FN_NAME pack_ushort_from_uint_rgba
@@ -493,18 +501,21 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef SRC_CONVERT
 #undef FN_NAME
 
+#undef SRC_TYPE
+
 void
-_mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
-                         GLenum dstFormat, GLenum dstType,
-                         GLvoid *dstAddr)
+_mesa_pack_rgba_span_from_uints(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
+                                GLenum dstFormat, GLenum dstType,
+                                GLvoid *dstAddr)
 {
+   GLuint i; /* Used in pack_int_cases_tmp.h */
+
    switch(dstType) {
    case GL_UNSIGNED_INT:
       pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
       break;
    case GL_INT:
-      /* No conversion necessary. */
-      pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
       break;
    case GL_UNSIGNED_SHORT:
       pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
@@ -518,6 +529,92 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
    case GL_BYTE:
       pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
       break;
+
+   default:
+      _mesa_problem(ctx,
+         "Unsupported type (%s) for format (%s)",
+         _mesa_lookup_enum_by_nr(dstType),
+         _mesa_lookup_enum_by_nr(dstFormat));
+      return;
+   }
+}
+
+
+/* Customization of integer packing.  We always treat src as int, and can pack dst
+ * as any integer type/format combo.
+ */
+#define SRC_TYPE GLint
+
+#define DST_TYPE GLuint
+#define SRC_CONVERT(x) MAX2(x, 0)
+#define FN_NAME pack_uint_from_int_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLushort
+#define SRC_CONVERT(x) MAX2(x, 0)
+#define FN_NAME pack_ushort_from_int_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLshort
+#define SRC_CONVERT(x) CLAMP(x, -0x8000, 0x7fff)
+#define FN_NAME pack_short_from_int_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLubyte
+#define SRC_CONVERT(x) MAX2(x, 0)
+#define FN_NAME pack_ubyte_from_int_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLbyte
+#define SRC_CONVERT(x) CLAMP(x, -0x80, 0x7f)
+#define FN_NAME pack_byte_from_int_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#undef SRC_TYPE
+
+void
+_mesa_pack_rgba_span_from_ints(struct gl_context *ctx, GLuint n, GLint rgba[][4],
+                               GLenum dstFormat, GLenum dstType,
+                               GLvoid *dstAddr)
+{
+   GLuint i; /* Used in pack_int_cases_tmp.h */
+
+   switch(dstType) {
+   case GL_UNSIGNED_INT:
+      pack_uint_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_INT:
+      /* No conversion necessary. */
+      pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_UNSIGNED_SHORT:
+      pack_ushort_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_SHORT:
+      pack_short_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_UNSIGNED_BYTE:
+      pack_ubyte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_BYTE:
+      pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+      break;
+
    default:
       _mesa_problem(ctx,
          "Unsupported type (%s) for format (%s)",
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index cd49c74..2fbdf91 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -145,9 +145,15 @@ _mesa_unpack_image(GLuint dimensions,
 
 
 void
-_mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
-                         GLenum dstFormat, GLenum dstType,
-                         GLvoid *dstAddr);
+_mesa_pack_rgba_span_from_uints(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
+                                GLenum dstFormat, GLenum dstType,
+                                GLvoid *dstAddr);
+
+
+void
+_mesa_pack_rgba_span_from_ints(struct gl_context *ctx, GLuint n, GLint rgba[][4],
+                               GLenum dstFormat, GLenum dstType,
+                               GLvoid *dstAddr);
 
 
 extern void
diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index e3c4611..145cb6c 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -341,8 +341,8 @@ slow_read_rgba_pixels( struct gl_context *ctx,
 	 _mesa_unpack_uint_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba);
          _mesa_rebase_rgba_uint(width, (GLuint (*)[4]) rgba,
                                 rb->_BaseFormat);
-	 _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4]) rgba, format,
-                                  type, dst);
+         _mesa_pack_rgba_span_from_uints(ctx, width, (GLuint (*)[4]) rgba, format,
+                                         type, dst);
       } else {
 	 _mesa_unpack_rgba_row(rbFormat, width, map, (GLfloat (*)[4]) rgba);
          _mesa_rebase_rgba_float(width, (GLfloat (*)[4]) rgba,
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 05b052a..5d2f4da 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -361,8 +361,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
 	       _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
                if (rebaseFormat)
                   _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
-	       _mesa_pack_rgba_span_int(ctx, width, rgba_uint,
-					format, type, dest);
+               _mesa_pack_rgba_span_from_uints(ctx, width, rgba_uint,
+                                        format, type, dest);
 	    } else {
 	       _mesa_unpack_rgba_row(texFormat, width, src, rgba);
                if (rebaseFormat)
-- 
1.7.9.5



More information about the mesa-dev mailing list