[Mesa-dev] [PATCH 2/6] mesa: fix swapbytes in readpixels paths.

Dave Airlie airlied at gmail.com
Tue Aug 25 18:14:51 PDT 2015


From: Dave Airlie <airlied at redhat.com>

Same as for other paths, need to take into a/c rowlength
vs width differences for 7/RED/UNSIGNED_BYTE cases.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/main/readpix.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 1277944..41b4ab4 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -616,11 +616,19 @@ done_swap:
       GLint swapSize = _mesa_sizeof_packed_type(type);
       if (swapSize == 2 || swapSize == 4) {
          int swapsPerPixel = _mesa_bytes_per_pixel(format, type) / swapSize;
+         int stride = _mesa_image_row_stride(packing, width, format, type);
+         int row;
+         const uint8_t *dstrow;
+
          assert(_mesa_bytes_per_pixel(format, type) % swapSize == 0);
-         if (swapSize == 2)
-            _mesa_swap2((GLushort *) dst, width * height * swapsPerPixel);
-         else if (swapSize == 4)
-            _mesa_swap4((GLuint *) dst, width * height * swapsPerPixel);
+         dstrow = dst;
+         for (row = 0; row < height; row++) {
+            if (swapSize == 2)
+               _mesa_swap2((GLushort *) dstrow, width * swapsPerPixel);
+            else if (swapSize == 4)
+               _mesa_swap4((GLuint *) dstrow, width * swapsPerPixel);
+            dstrow += stride;
+         }
       }
    }
 
-- 
2.4.3



More information about the mesa-dev mailing list