[Mesa-dev] [PATCH 1/6] mesa: fix SwapBytes handling in texstore.

Brian Paul brianp at vmware.com
Thu Aug 27 16:16:42 PDT 2015


Some of the commit messages, like this one, seem to line-wrapped shorter 
than necessary.

For patches 1-4, the changes look OK, AFAICT.  Though, it seems there's 
some very similar byte-swap code duplicated in several places.  Would it 
be possible to write a function which does byte swapping for whole 2D 
images?

For 1-4, Reviewed-by: Brian Paul <brianp at vmware.com>


On 08/25/2015 07:14 PM, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> This code doesn't handle the the user setting
> GL_UNPACK_ALIGNMENT at all well since we have
> the cases where 7 byte wide (GL_RED/GL_UNSIGNED_BYTE)
> still has it's rows aligned to 8, and the old
> code failed in that case.
>
> Just iterate the swaps over rows and images
> to handle this instead.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>   src/mesa/main/texstore.c | 34 ++++++++++++++++++++++++++--------
>   1 file changed, 26 insertions(+), 8 deletions(-)
>
> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
> index fc83310..d07acca 100644
> --- a/src/mesa/main/texstore.c
> +++ b/src/mesa/main/texstore.c
> @@ -729,17 +729,35 @@ texstore_rgba(TEXSTORE_PARAMS)
>         if (swapSize == 2 || swapSize == 4) {
>            int bytesPerPixel = _mesa_bytes_per_pixel(srcFormat, srcType);
>            int swapsPerPixel = bytesPerPixel / swapSize;
> -         int elementCount = srcWidth * srcHeight * srcDepth;
> +         int srcStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
> +         int imageStride = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat, srcType);
> +         int bufferSize = imageStride * srcDepth;
> +         int row, layer;
> +         const uint8_t *src, *srcrow;
> +         uint8_t *dst, *dstrow;
> +
>            assert(bytesPerPixel % swapSize == 0);
> -         tempImage = malloc(elementCount * bytesPerPixel);
> +         tempImage = malloc(bufferSize);
>            if (!tempImage)
>               return GL_FALSE;
> -         if (swapSize == 2)
> -            _mesa_swap2_copy(tempImage, (GLushort *) srcAddr,
> -                             elementCount * swapsPerPixel);
> -         else
> -            _mesa_swap4_copy(tempImage, (GLuint *) srcAddr,
> -                             elementCount * swapsPerPixel);
> +         src = srcAddr;
> +         dst = tempImage;
> +         for (layer = 0; layer < srcDepth; layer++) {
> +            srcrow = src;
> +            dstrow = dst;
> +            for (row = 0; row < srcHeight; row++) {
> +               if (swapSize == 2)
> +                  _mesa_swap2_copy((GLushort *)dstrow, (GLushort *)srcrow,
> +                                   srcWidth * swapsPerPixel);
> +               else
> +                  _mesa_swap4_copy((GLuint *)dstrow, (GLuint *)srcrow,
> +                                   srcWidth * swapsPerPixel);
> +               srcrow += srcStride;
> +               dstrow += srcStride;
> +            }
> +            src += imageStride;
> +            dst += imageStride;
> +         }
>            srcAddr = tempImage;
>         }
>      }
>



More information about the mesa-dev mailing list