utils.c: Make image_endian_swap() deal with negative strides
authorSøren Sandmann Pedersen <ssp@redhat.com>
Thu, 26 Sep 2013 22:56:07 +0000 (18:56 -0400)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Fri, 27 Sep 2013 21:11:08 +0000 (17:11 -0400)
Use a temporary variable s containing the absolute value of the stride
as the upper bound in the inner loops.

V2: Do this for the bpp == 16 case as well

test/utils.c

index a83fc06e64e8c7dbecfcda7f66dde633a73f234b..0cd982e737edc31212afc96c02cbffe70be92107 100644 (file)
@@ -297,11 +297,12 @@ image_endian_swap (pixman_image_t *img)
     for (i = 0; i < height; i++)
     {
        uint8_t *line_data = (uint8_t *)data + stride * i;
-       
+       int s = (stride >= 0)? stride : - stride;
+       
        switch (bpp)
        {
        case 1:
-           for (j = 0; j < stride; j++)
+           for (j = 0; j < s; j++)
            {
                line_data[j] =
                    ((line_data[j] & 0x80) >> 7) |
@@ -315,13 +316,13 @@ image_endian_swap (pixman_image_t *img)
            }
            break;
        case 4:
-           for (j = 0; j < stride; j++)
+           for (j = 0; j < s; j++)
            {
                line_data[j] = (line_data[j] >> 4) | (line_data[j] << 4);
            }
            break;
        case 16:
-           for (j = 0; j + 2 <= stride; j += 2)
+           for (j = 0; j + 2 <= s; j += 2)
            {
                char t1 = line_data[j + 0];
                char t2 = line_data[j + 1];
@@ -331,7 +332,7 @@ image_endian_swap (pixman_image_t *img)
            }
            break;
        case 24:
-           for (j = 0; j + 3 <= stride; j += 3)
+           for (j = 0; j + 3 <= s; j += 3)
            {
                char t1 = line_data[j + 0];
                char t2 = line_data[j + 1];
@@ -343,7 +344,7 @@ image_endian_swap (pixman_image_t *img)
            }
            break;
        case 32:
-           for (j = 0; j + 4 <= stride; j += 4)
+           for (j = 0; j + 4 <= s; j += 4)
            {
                char t1 = line_data[j + 0];
                char t2 = line_data[j + 1];