test: Share the image printing code
authorSøren Sandmann Pedersen <ssp@redhat.com>
Thu, 12 Sep 2013 16:52:02 +0000 (12:52 -0400)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Fri, 20 Sep 2013 01:37:56 +0000 (21:37 -0400)
The affine-test, blitters-test, and scaling-test all have the ability
to print out the bytes of the destination image. Share this code by
moving it to utils.c.

At the same time make the code work correctly with negative strides.

test/affine-test.c
test/blitters-test.c
test/composite-traps-test.c
test/scaling-test.c
test/utils.c
test/utils.h

index 3a37d7fa4d365aa6e67e5a3343ed5fbb15b71b63..03d296fb5dc3d0d39e2c633fa3f291363e794483 100644 (file)
@@ -276,17 +276,7 @@ test_composite (int      testnum,
     crc32 = compute_crc32_for_image (0, dst_img);
     
     if (verbose)
-    {
-       int j;
-
-       for (i = 0; i < dst_height; i++)
-       {
-           for (j = 0; j < dst_stride; j++)
-               printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
-
-           printf ("\n");
-       }
-    }
+       print_image (dst_img);
 
     pixman_image_unref (src_img);
     pixman_image_unref (dst_img);
index a2c6ff4d891ba28d4613a75e800918f4357c0196..2120daf0db87a93dc4ef83dcf32e32ff85ac17d2 100644 (file)
@@ -222,7 +222,6 @@ static pixman_format_code_t mask_fmt_list[] = {
 uint32_t
 test_composite (int testnum, int verbose)
 {
-    int i;
     pixman_image_t *src_img = NULL;
     pixman_image_t *dst_img = NULL;
     pixman_image_t *mask_img = NULL;
@@ -355,23 +354,7 @@ test_composite (int testnum, int verbose)
                            src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
 
     if (verbose)
-    {
-       int j;
-
-       printf ("---\n");
-       for (i = 0; i < dst_height; i++)
-       {
-           for (j = 0; j < dst_stride; j++)
-           {
-               if (j == (dst_width * PIXMAN_FORMAT_BPP (dst_fmt) + 7) / 8)
-                   printf ("| ");
-
-               printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
-           }
-           printf ("\n");
-       }
-       printf ("---\n");
-    }
+       print_image (dst_img);
 
     free_random_image (0, src_img, PIXMAN_null);
     crc32 = free_random_image (0, dst_img, dst_fmt);
index 34ae3407e5f20ce74a6f5c8c19da6ce43a1bfbe8..44d5012782b5ae0006aee4ab1d25545eb50fcde5 100644 (file)
@@ -217,17 +217,7 @@ test_composite (int      testnum,
     crc32 = compute_crc32_for_image (0, dst_img);
 
     if (verbose)
-    {
-       int j;
-       
-       for (i = 0; i < dst_height; i++)
-       {
-           for (j = 0; j < dst_stride; j++)
-               printf ("%02X ", *((uint8_t *)dst_bits + i * dst_stride + j));
-
-           printf ("\n");
-       }
-    }
+       print_image (dst_img);
 
     fence_free (dst_bits);
     
index 04ecb633137ce1b21d633c4225a93cc04cde769a..0778d2d6673e14000011e2654a108f993380d1c7 100644 (file)
@@ -343,17 +343,7 @@ test_composite (int      testnum,
     crc32 = compute_crc32_for_image (0, dst_img);
     
     if (verbose)
-    {
-       int j;
-       
-       for (i = 0; i < dst_height; i++)
-       {
-           for (j = 0; j < dst_stride; j++)
-               printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
-
-           printf ("\n");
-       }
-    }
+       print_image (dst_img);
 
     pixman_image_unref (src_img);
     pixman_image_unref (mask_img);
index 3d1ba22aeab7905e150c05276b5550b51c9a6641..a693f30f135a7c162ece34577e2505843d70971e 100644 (file)
@@ -238,6 +238,38 @@ compute_crc32_for_image (uint32_t        crc32,
     return crc32;
 }
 
+void
+print_image (pixman_image_t *image)
+{
+    int i, j;
+    int width, height, stride;
+    pixman_format_code_t format;
+    uint8_t *buffer;
+
+    width = pixman_image_get_width (image);
+    height = pixman_image_get_height (image);
+    stride = pixman_image_get_stride (image);
+    format = pixman_image_get_format (image);
+    buffer = (uint8_t *)pixman_image_get_data (image);
+
+    if (stride < 0)
+       stride = - stride;
+    
+    printf ("---\n");
+    for (i = 0; i < height; i++)
+    {
+       for (j = 0; j < stride; j++)
+       {
+           if (j == (width * PIXMAN_FORMAT_BPP (format) + 7) / 8)
+               printf ("| ");
+
+           printf ("%02X ", *((uint8_t *)buffer + i * stride + j));
+       }
+       printf ("\n");
+    }
+    printf ("---\n");
+}
+
 /* perform endian conversion of pixel data
  */
 void
index c2781516fbe21b8d8d9b673c7389545777121d8c..28b7193edfe5313a31512954747815ecab3516b4 100644 (file)
@@ -63,6 +63,10 @@ uint32_t
 compute_crc32_for_image (uint32_t        in_crc32,
                         pixman_image_t *image);
 
+/* Print the image in hexadecimal */
+void
+print_image (pixman_image_t *image);
+
 /* Returns TRUE if running on a little endian system
  */
 static force_inline pixman_bool_t