Mesa (master): mesa: use malloc instead of MAX_WIDTH array in glReadPixels( )

Brian Paul brianp at kemper.freedesktop.org
Thu Dec 8 17:51:45 UTC 2011


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

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Dec  5 20:40:48 2011 -0700

mesa: use malloc instead of MAX_WIDTH array in glReadPixels()

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/mesa/main/readpix.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index a7b7ed7..38b9c64 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -252,10 +252,7 @@ slow_read_rgba_pixels( struct gl_context *ctx,
 {
    struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
    const gl_format rbFormat = _mesa_get_srgb_format_linear(rb->Format);
-   union {
-      float f[MAX_WIDTH][4];
-      unsigned int i[MAX_WIDTH][4];
-   } rgba;
+   void *rgba;
    GLubyte *dst, *map;
    int dstStride, stride, j;
 
@@ -270,19 +267,27 @@ slow_read_rgba_pixels( struct gl_context *ctx,
       return;
    }
 
+   rgba = malloc(width * MAX_PIXEL_BYTES);
+   if (!rgba)
+      goto done;
+
    for (j = 0; j < height; j++) {
       if (_mesa_is_integer_format(format)) {
-	 _mesa_unpack_int_rgba_row(rbFormat, width, map, rgba.i);
-	 _mesa_pack_rgba_span_int(ctx, width, rgba.i, format, type, dst);
+	 _mesa_unpack_int_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba);
+	 _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4]) rgba, format,
+                                  type, dst);
       } else {
-	 _mesa_unpack_rgba_row(rbFormat, width, map, rgba.f);
-	 _mesa_pack_rgba_span_float(ctx, width, rgba.f, format, type, dst,
-				    packing, transferOps);
+	 _mesa_unpack_rgba_row(rbFormat, width, map, (GLfloat (*)[4]) rgba);
+	 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
+                                    type, dst, packing, transferOps);
       }
       dst += dstStride;
       map += stride;
    }
 
+   free(rgba);
+
+done:
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
 }
 




More information about the mesa-commit mailing list