From 4312f077365bf9f59423b1694136089c6da6216b Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Thu, 12 Sep 2013 12:52:02 -0400 Subject: [PATCH] test: Share the image printing code 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 | 12 +----------- test/blitters-test.c | 19 +------------------ test/composite-traps-test.c | 12 +----------- test/scaling-test.c | 12 +----------- test/utils.c | 32 ++++++++++++++++++++++++++++++++ test/utils.h | 4 ++++ 6 files changed, 40 insertions(+), 51 deletions(-) diff --git a/test/affine-test.c b/test/affine-test.c index 3a37d7f..03d296f 100644 --- a/test/affine-test.c +++ b/test/affine-test.c @@ -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); diff --git a/test/blitters-test.c b/test/blitters-test.c index a2c6ff4..2120daf 100644 --- a/test/blitters-test.c +++ b/test/blitters-test.c @@ -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); diff --git a/test/composite-traps-test.c b/test/composite-traps-test.c index 34ae340..44d5012 100644 --- a/test/composite-traps-test.c +++ b/test/composite-traps-test.c @@ -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); diff --git a/test/scaling-test.c b/test/scaling-test.c index 04ecb63..0778d2d 100644 --- a/test/scaling-test.c +++ b/test/scaling-test.c @@ -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); diff --git a/test/utils.c b/test/utils.c index 3d1ba22..a693f30 100644 --- a/test/utils.c +++ b/test/utils.c @@ -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 diff --git a/test/utils.h b/test/utils.h index c278151..28b7193 100644 --- a/test/utils.h +++ b/test/utils.h @@ -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 -- 2.7.4