[Pixman] [PATCH 3/2] test: Use operator_name() and format_name() in composite.c

Søren Sandmann sandmann at cs.au.dk
Sat Jan 19 09:49:21 PST 2013


From: Søren Sandmann Pedersen <ssp at redhat.com>

With the operator_name() and format_name() functions there is no
longer any reason for composite.c to have its own table of format and
operator names.
---

Bonus patch. I didn't notice that these functions could be used in
composite.c as well.

Soren

 test/composite.c |  221 +++++++++++++++++++++++++-----------------------------
 1 files changed, 101 insertions(+), 120 deletions(-)

diff --git a/test/composite.c b/test/composite.c
index 09752c5..b107b11 100644
--- a/test/composite.c
+++ b/test/composite.c
@@ -28,15 +28,7 @@
 #include <time.h>
 #include "utils.h"
 
-typedef struct format_t format_t;
 typedef struct image_t image_t;
-typedef struct operator_t operator_t;
-
-struct format_t
-{
-    pixman_format_code_t format;
-    const char *name;
-};
 
 static const color_t colors[] =
 {
@@ -82,122 +74,111 @@ static const int sizes[] =
     10
 };
 
-static const format_t formats[] =
+static const pixman_format_code_t formats[] =
 {
-#define P(x) { PIXMAN_##x, #x }
-
     /* 32 bpp formats */
-    P(a8r8g8b8),
-    P(x8r8g8b8),
-    P(a8b8g8r8),
-    P(x8b8g8r8),
-    P(b8g8r8a8),
-    P(b8g8r8x8),
-    P(r8g8b8a8),
-    P(r8g8b8x8),
-    P(x2r10g10b10),
-    P(x2b10g10r10),
-    P(a2r10g10b10),
-    P(a2b10g10r10),
+    PIXMAN_a8r8g8b8,
+    PIXMAN_x8r8g8b8,
+    PIXMAN_a8b8g8r8,
+    PIXMAN_x8b8g8r8,
+    PIXMAN_b8g8r8a8,
+    PIXMAN_b8g8r8x8,
+    PIXMAN_r8g8b8a8,
+    PIXMAN_r8g8b8x8,
+    PIXMAN_x2r10g10b10,
+    PIXMAN_x2b10g10r10,
+    PIXMAN_a2r10g10b10,
+    PIXMAN_a2b10g10r10,
     
     /* sRGB formats */
-    P(a8r8g8b8_sRGB),
+    PIXMAN_a8r8g8b8_sRGB,
 
     /* 24 bpp formats */
-    P(r8g8b8),
-    P(b8g8r8),
-    P(r5g6b5),
-    P(b5g6r5),
+    PIXMAN_r8g8b8,
+    PIXMAN_b8g8r8,
+    PIXMAN_r5g6b5,
+    PIXMAN_b5g6r5,
 
     /* 16 bpp formats */
-    P(x1r5g5b5),
-    P(x1b5g5r5),
-    P(a1r5g5b5),
-    P(a1b5g5r5),
-    P(a4b4g4r4),
-    P(x4b4g4r4),
-    P(a4r4g4b4),
-    P(x4r4g4b4),
+    PIXMAN_x1r5g5b5,
+    PIXMAN_x1b5g5r5,
+    PIXMAN_a1r5g5b5,
+    PIXMAN_a1b5g5r5,
+    PIXMAN_a4b4g4r4,
+    PIXMAN_x4b4g4r4,
+    PIXMAN_a4r4g4b4,
+    PIXMAN_x4r4g4b4,
 
     /* 8 bpp formats */
-    P(a8),
-    P(r3g3b2),
-    P(b2g3r3),
-    P(a2r2g2b2),
-    P(a2b2g2r2),
-    P(x4a4),
+    PIXMAN_a8,
+    PIXMAN_r3g3b2,
+    PIXMAN_b2g3r3,
+    PIXMAN_a2r2g2b2,
+    PIXMAN_a2b2g2r2,
+    PIXMAN_x4a4,
 
     /* 4 bpp formats */
-    P(a4),
-    P(r1g2b1),
-    P(b1g2r1),
-    P(a1r1g1b1),
-    P(a1b1g1r1),
+    PIXMAN_a4,
+    PIXMAN_r1g2b1,
+    PIXMAN_b1g2r1,
+    PIXMAN_a1r1g1b1,
+    PIXMAN_a1b1g1r1,
 
     /* 1 bpp formats */
-    P(a1)
-#undef P
+    PIXMAN_a1,
 };
 
 struct image_t
 {
     pixman_image_t *image;
-    const format_t *format;
+    pixman_format_code_t format;
     const color_t *color;
     pixman_repeat_t repeat;
     int size;
 };
 
-struct operator_t
+static const pixman_op_t operators[] =
 {
-    pixman_op_t op;
-    const char *name;
-};
-
-static const operator_t operators[] =
-{
-#define P(x) { PIXMAN_OP_##x, #x }
-    P(CLEAR),
-    P(SRC),
-    P(DST),
-    P(OVER),
-    P(OVER_REVERSE),
-    P(IN),
-    P(IN_REVERSE),
-    P(OUT),
-    P(OUT_REVERSE),
-    P(ATOP),
-    P(ATOP_REVERSE),
-    P(XOR),
-    P(ADD),
-    P(SATURATE),
-
-    P(DISJOINT_CLEAR),
-    P(DISJOINT_SRC),
-    P(DISJOINT_DST),
-    P(DISJOINT_OVER),
-    P(DISJOINT_OVER_REVERSE),
-    P(DISJOINT_IN),
-    P(DISJOINT_IN_REVERSE),
-    P(DISJOINT_OUT),
-    P(DISJOINT_OUT_REVERSE),
-    P(DISJOINT_ATOP),
-    P(DISJOINT_ATOP_REVERSE),
-    P(DISJOINT_XOR),
-
-    P(CONJOINT_CLEAR),
-    P(CONJOINT_SRC),
-    P(CONJOINT_DST),
-    P(CONJOINT_OVER),
-    P(CONJOINT_OVER_REVERSE),
-    P(CONJOINT_IN),
-    P(CONJOINT_IN_REVERSE),
-    P(CONJOINT_OUT),
-    P(CONJOINT_OUT_REVERSE),
-    P(CONJOINT_ATOP),
-    P(CONJOINT_ATOP_REVERSE),
-    P(CONJOINT_XOR),
-#undef P
+    PIXMAN_OP_CLEAR,
+    PIXMAN_OP_SRC,
+    PIXMAN_OP_DST,
+    PIXMAN_OP_OVER,
+    PIXMAN_OP_OVER_REVERSE,
+    PIXMAN_OP_IN,
+    PIXMAN_OP_IN_REVERSE,
+    PIXMAN_OP_OUT,
+    PIXMAN_OP_OUT_REVERSE,
+    PIXMAN_OP_ATOP,
+    PIXMAN_OP_ATOP_REVERSE,
+    PIXMAN_OP_XOR,
+    PIXMAN_OP_ADD,
+    PIXMAN_OP_SATURATE,
+
+    PIXMAN_OP_DISJOINT_CLEAR,
+    PIXMAN_OP_DISJOINT_SRC,
+    PIXMAN_OP_DISJOINT_DST,
+    PIXMAN_OP_DISJOINT_OVER,
+    PIXMAN_OP_DISJOINT_OVER_REVERSE,
+    PIXMAN_OP_DISJOINT_IN,
+    PIXMAN_OP_DISJOINT_IN_REVERSE,
+    PIXMAN_OP_DISJOINT_OUT,
+    PIXMAN_OP_DISJOINT_OUT_REVERSE,
+    PIXMAN_OP_DISJOINT_ATOP,
+    PIXMAN_OP_DISJOINT_ATOP_REVERSE,
+    PIXMAN_OP_DISJOINT_XOR,
+
+    PIXMAN_OP_CONJOINT_CLEAR,
+    PIXMAN_OP_CONJOINT_SRC,
+    PIXMAN_OP_CONJOINT_DST,
+    PIXMAN_OP_CONJOINT_OVER,
+    PIXMAN_OP_CONJOINT_OVER_REVERSE,
+    PIXMAN_OP_CONJOINT_IN,
+    PIXMAN_OP_CONJOINT_IN_REVERSE,
+    PIXMAN_OP_CONJOINT_OUT,
+    PIXMAN_OP_CONJOINT_OUT_REVERSE,
+    PIXMAN_OP_CONJOINT_ATOP,
+    PIXMAN_OP_CONJOINT_ATOP_REVERSE,
+    PIXMAN_OP_CONJOINT_XOR,
 };
 
 static double
@@ -498,7 +479,7 @@ describe_image (image_t *info, char *buf)
     if (info->size)
     {
 	sprintf (buf, "%s, %dx%d%s",
-		 info->format->name,
+		 format_name (info->format),
 		 info->size, info->size,
 		 info->repeat ? " R" :"");
     }
@@ -521,7 +502,7 @@ describe_color (const color_t *color, char *buf)
 
 static pixman_bool_t
 composite_test (image_t *dst,
-		const operator_t *op,
+		pixman_op_t op,
 		image_t *src,
 		image_t *mask,
 		pixman_bool_t component_alpha,
@@ -534,12 +515,12 @@ composite_test (image_t *dst,
     {
 	pixman_image_set_component_alpha (mask->image, component_alpha);
 
-	pixman_image_composite (op->op, src->image, mask->image, dst->image,
+	pixman_image_composite (op, src->image, mask->image, dst->image,
 				0, 0, 0, 0, 0, 0, dst->size, dst->size);
     }
     else
     {
-	pixman_image_composite (op->op, src->image, NULL, dst->image,
+	pixman_image_composite (op, src->image, NULL, dst->image,
 				0, 0,
 				0, 0,
 				0, 0,
@@ -561,43 +542,43 @@ composite_test (image_t *dst,
      */
     if (src->size)
     {
-	if (PIXMAN_FORMAT_TYPE (src->format->format) == PIXMAN_TYPE_ARGB_SRGB)
+	if (PIXMAN_FORMAT_TYPE (src->format) == PIXMAN_TYPE_ARGB_SRGB)
         {
 	    tsrc.r = convert_linear_to_srgb (tsrc.r);
 	    tsrc.g = convert_linear_to_srgb (tsrc.g);
 	    tsrc.b = convert_linear_to_srgb (tsrc.b);
-	    round_color (src->format->format, &tsrc);
+	    round_color (src->format, &tsrc);
 	    tsrc.r = convert_srgb_to_linear (tsrc.r);
 	    tsrc.g = convert_srgb_to_linear (tsrc.g);
 	    tsrc.b = convert_srgb_to_linear (tsrc.b);
 	}
         else
         {
-	    round_color (src->format->format, &tsrc);
+	    round_color (src->format, &tsrc);
 	}
     }
 
     if (mask && mask->size)
     {
-	if (PIXMAN_FORMAT_TYPE (mask->format->format) == PIXMAN_TYPE_ARGB_SRGB)
+	if (PIXMAN_FORMAT_TYPE (mask->format) == PIXMAN_TYPE_ARGB_SRGB)
 	{
 	    tmsk.r = convert_linear_to_srgb (tmsk.r);
 	    tmsk.g = convert_linear_to_srgb (tmsk.g);
 	    tmsk.b = convert_linear_to_srgb (tmsk.b);
-	    round_color (mask->format->format, &tmsk);
+	    round_color (mask->format, &tmsk);
 	    tmsk.r = convert_srgb_to_linear (tmsk.r);
 	    tmsk.g = convert_srgb_to_linear (tmsk.g);
 	    tmsk.b = convert_srgb_to_linear (tmsk.b);
 	}
 	else
 	{
-	    round_color (mask->format->format, &tmsk);
+	    round_color (mask->format, &tmsk);
 	}
     }
 
     if (mask)
     {
-	if (component_alpha && PIXMAN_FORMAT_R (mask->format->format) == 0)
+	if (component_alpha && PIXMAN_FORMAT_R (mask->format) == 0)
 	{
 	    /* Ax component-alpha masks expand alpha into
 	     * all color channels.
@@ -606,29 +587,29 @@ composite_test (image_t *dst,
 	}
     }
 
-    if (PIXMAN_FORMAT_TYPE (dst->format->format) == PIXMAN_TYPE_ARGB_SRGB)
+    if (PIXMAN_FORMAT_TYPE (dst->format) == PIXMAN_TYPE_ARGB_SRGB)
     {
 	tdst.r = convert_linear_to_srgb (tdst.r);
 	tdst.g = convert_linear_to_srgb (tdst.g);
 	tdst.b = convert_linear_to_srgb (tdst.b);
-    	round_color (dst->format->format, &tdst);
+    	round_color (dst->format, &tdst);
 	tdst.r = convert_srgb_to_linear (tdst.r);
 	tdst.g = convert_srgb_to_linear (tdst.g);
 	tdst.b = convert_srgb_to_linear (tdst.b);
     }
     else
     {
-    	round_color (dst->format->format, &tdst);
+    	round_color (dst->format, &tdst);
     }
 
-    do_composite (op->op,
+    do_composite (op,
 		  &tsrc,
 		  mask? &tmsk : NULL,
 		  &tdst,
 		  &expected,
 		  component_alpha);
 
-    pixel_checker_init (&checker, dst->format->format);
+    pixel_checker_init (&checker, dst->format);
 
     if (!pixel_checker_check (&checker, get_value (dst->image), &expected))
     {
@@ -638,7 +619,7 @@ composite_test (image_t *dst,
 
 	printf ("---- Test %d failed ----\n", testno);
 	printf ("Operator:      %s %s\n",
-		 op->name, component_alpha ? "CA" : "");
+                operator_name (op), component_alpha ? "CA" : "");
 
 	printf ("Source:        %s\n", describe_image (src, buf));
 	if (mask != NULL)
@@ -687,7 +668,7 @@ image_init (image_t *info,
     info->color = &colors[color];
     compute_pixman_color (info->color, &fill);
 
-    info->format = &formats[format];
+    info->format = formats[format];
     info->size = sizes[size] & ~FLAGS;
     info->repeat = PIXMAN_REPEAT_NONE;
 
@@ -695,7 +676,7 @@ image_init (image_t *info,
     {
 	pixman_image_t *solid;
 
-	info->image = pixman_image_create_bits (info->format->format,
+	info->image = pixman_image_create_bits (info->format,
 						info->size, info->size,
 						NULL, 0);
 
@@ -744,7 +725,7 @@ static pixman_bool_t
 run_test (uint32_t seed)
 {
     image_t src, mask, dst;
-    const operator_t *op;
+    pixman_op_t op;
     int ca;
     int ok;
 
@@ -754,7 +735,7 @@ run_test (uint32_t seed)
     image_init (&src, random_color(), random_format(), random_size());
     image_init (&mask, random_color(), random_format(), random_size());
 
-    op = &(operators [prng_rand_n (ARRAY_LENGTH (operators))]);
+    op = operators [prng_rand_n (ARRAY_LENGTH (operators))];
 
     ca = prng_rand_n (3);
 
-- 
1.7.4



More information about the Pixman mailing list