mesa: added _mesa_pack_ubyte_rgba_rect()
authorBrian Paul <brianp@vmware.com>
Mon, 30 Jan 2012 02:47:37 +0000 (19:47 -0700)
committerBrian Paul <brianp@vmware.com>
Mon, 30 Jan 2012 20:01:08 +0000 (13:01 -0700)
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/main/format_pack.c
src/mesa/main/format_pack.h

index 85b2c691c548424ab28112897727ccbd7abf9a7d..ea1d95ee9e90804191aa5f7243b589f9d7e6c02c 100644 (file)
@@ -2049,6 +2049,48 @@ _mesa_pack_ubyte_rgba_row(gl_format format, GLuint n,
 }
 
 
+/**
+ * Pack a 2D image of ubyte RGBA pixels in the given format.
+ * \param srcRowStride  source image row stride in bytes
+ * \param dstRowStride  destination image row stride in bytes
+ */
+void
+_mesa_pack_ubyte_rgba_rect(gl_format format, GLuint width, GLuint height,
+                           const GLubyte *src, GLint srcRowStride,
+                           void *dst, GLint dstRowStride)
+{
+   pack_ubyte_rgba_row_func packrow = get_pack_ubyte_rgba_row_function(format);
+   GLubyte *dstUB = (GLubyte *) dst;
+   GLuint i;
+
+   if (packrow) {
+      if (srcRowStride == width * 4 * sizeof(GLubyte) &&
+          dstRowStride == _mesa_format_row_stride(format, width)) {
+         /* do whole image at once */
+         packrow(width * height, (const GLubyte (*)[4]) src, dst);
+      }
+      else {
+         /* row by row */
+         for (i = 0; i < height; i++) {
+            packrow(width, (const GLubyte (*)[4]) src, dstUB);
+            src += srcRowStride;
+            dstUB += dstRowStride;
+         }
+      }
+   }
+   else {
+      /* slower fallback */
+      for (i = 0; i < height; i++) {
+         _mesa_pack_ubyte_rgba_row(format, width,
+                                   (const GLubyte (*)[4]) src, dstUB);
+         src += srcRowStride;
+         dstUB += dstRowStride;
+      }
+   }
+}
+
+
+
 /**
  ** Pack float Z pixels
  **/
index f1b4805106525fabe215c5189f8feaaba5851a31..20b2ad8a5ac841123a74e2ce4f9ff6b4e7371c29 100644 (file)
@@ -77,6 +77,10 @@ _mesa_pack_ubyte_rgba_row(gl_format format, GLuint n,
                           const GLubyte src[][4], void *dst);
 
 
+extern void
+_mesa_pack_ubyte_rgba_rect(gl_format format, GLuint width, GLuint height,
+                           const GLubyte *src, GLint srcRowStride,
+                           void *dst, GLint dstRowStride);
 
 extern void
 _mesa_pack_float_z_row(gl_format format, GLuint n,