summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texgetimage.c
diff options
context:
space:
mode:
authorIago Toral Quiroga <itoral@igalia.com>2015-02-13 12:56:26 +0100
committerIago Toral Quiroga <itoral@igalia.com>2015-02-16 10:51:18 +0100
commitba426522dddf0860f59dedfe9953dbd509160c7d (patch)
tree4c6e294f6d9768f7a9805de192b17eec066c8c53 /src/mesa/main/texgetimage.c
parent4b249d2eed686384d6d7c36f3232360891d5eeda (diff)
downloadexternal_mesa3d-ba426522dddf0860f59dedfe9953dbd509160c7d.zip
external_mesa3d-ba426522dddf0860f59dedfe9953dbd509160c7d.tar.gz
external_mesa3d-ba426522dddf0860f59dedfe9953dbd509160c7d.tar.bz2
mesa: Fix element count for byte-swaps in texstore, readpix and texgetimage
Some old format conversion code in pack.c implemented byte-swapping like this: GLint comps = _mesa_components_in_format(dstFormat); GLint swapSize = _mesa_sizeof_packed_type(dstType); if (swapSize == 2) _mesa_swap2((GLushort *) dstAddr, n * comps); else if (swapSize == 4) _mesa_swap4((GLuint *) dstAddr, n * comps); where n is the pixel count. But this is incorrect for packed formats, where _mesa_sizeof_packed_type is already returning the size of a pixel instead of the size of a single component, so multiplying this by the number of components in the format results in a larger element count for _mesa_swap than we want. Unfortunately, we followed the same implementation for byte-swapping in the rewrite of the format conversion code for texstore, readpixels and texgetimage. This patch computes the correct element counts for _mesa_swap calls by computing the bytes per pixel in the image and dividing that by the swap size to obtain the number of swaps required per pixel. Then multiplies that by the number of pixels in the image to obtain the swap count that we need to use. Also, when handling byte-swapping in texstore_rgba, we were ignoring the image's depth. This patch fixes this too. Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com> Cc: "10.5" <mesa-stable@lists.freedesktop.org>
Diffstat (limited to 'src/mesa/main/texgetimage.c')
-rw-r--r--src/mesa/main/texgetimage.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index ee465e6..405f085 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -511,12 +511,15 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
do_swap:
/* Handle byte swapping if required */
if (ctx->Pack.SwapBytes) {
- int components = _mesa_components_in_format(format);
GLint swapSize = _mesa_sizeof_packed_type(type);
- if (swapSize == 2)
- _mesa_swap2((GLushort *) dest, width * height * components);
- else if (swapSize == 4)
- _mesa_swap4((GLuint *) dest, width * height * components);
+ if (swapSize == 2 || swapSize == 4) {
+ int swapsPerPixel = _mesa_bytes_per_pixel(format, type) / swapSize;
+ assert(_mesa_bytes_per_pixel(format, type) % swapSize == 0);
+ if (swapSize == 2)
+ _mesa_swap2((GLushort *) dest, width * height * swapsPerPixel);
+ else if (swapSize == 4)
+ _mesa_swap4((GLuint *) dest, width * height * swapsPerPixel);
+ }
}
/* Unmap the src texture buffer */