1 #include <ctype.h>
2 #include "utils.h"
3
4 static int
check_op(pixman_op_t op,pixman_format_code_t src_format,pixman_format_code_t dest_format)5 check_op (pixman_op_t op,
6 pixman_format_code_t src_format,
7 pixman_format_code_t dest_format)
8 {
9 uint32_t src_alpha_mask, src_green_mask;
10 uint32_t dest_alpha_mask, dest_green_mask;
11 pixel_checker_t src_checker, dest_checker;
12 pixman_image_t *si, *di;
13 uint32_t sa, sg, da, dg;
14 uint32_t s, d;
15 int retval = 0;
16
17 pixel_checker_init (&src_checker, src_format);
18 pixel_checker_init (&dest_checker, dest_format);
19
20 pixel_checker_get_masks (
21 &src_checker, &src_alpha_mask, NULL, &src_green_mask, NULL);
22 pixel_checker_get_masks (
23 &dest_checker, &dest_alpha_mask, NULL, &dest_green_mask, NULL);
24
25 /* printf ("masks: %x %x %x %x\n", */
26 /* src_alpha_mask, src_green_mask, */
27 /* dest_alpha_mask, dest_green_mask); */
28
29 si = pixman_image_create_bits (src_format, 1, 1, &s, 4);
30 di = pixman_image_create_bits (dest_format, 1, 1, &d, 4);
31
32 sa = 0;
33 do
34 {
35 sg = 0;
36 do
37 {
38 da = 0;
39 do
40 {
41 dg = 0;
42 do
43 {
44 color_t src_color, dest_color, result_color;
45 uint32_t orig_d;
46
47 s = sa | sg;
48 d = da | dg;
49
50 orig_d = d;
51
52 pixel_checker_convert_pixel_to_color (&src_checker, s, &src_color);
53 pixel_checker_convert_pixel_to_color (&dest_checker, d, &dest_color);
54
55 do_composite (op, &src_color, NULL, &dest_color, &result_color, FALSE);
56
57
58 if (!is_little_endian())
59 {
60 s <<= 32 - PIXMAN_FORMAT_BPP (src_format);
61 d <<= 32 - PIXMAN_FORMAT_BPP (dest_format);
62 }
63
64 pixman_image_composite32 (op, si, NULL, di,
65 0, 0, 0, 0, 0, 0, 1, 1);
66
67 if (!is_little_endian())
68 d >>= (32 - PIXMAN_FORMAT_BPP (dest_format));
69
70 if (!pixel_checker_check (&dest_checker, d, &result_color))
71 {
72 printf ("---- test failed ----\n");
73 printf ("operator: %-32s\n", operator_name (op));
74 printf ("source: %-12s pixel: %08x\n", format_name (src_format), s);
75 printf ("dest: %-12s pixel: %08x\n", format_name (dest_format), orig_d);
76 printf ("got: %-12s pixel: %08x\n", format_name (dest_format), d);
77
78 retval = 1;
79 }
80
81 dg -= dest_green_mask;
82 dg &= dest_green_mask;
83 }
84 while (dg != 0);
85
86 da -= dest_alpha_mask;
87 da &= dest_alpha_mask;
88 }
89 while (da != 0);
90
91 sg -= src_green_mask;
92 sg &= src_green_mask;
93 }
94 while (sg != 0);
95
96 sa -= src_alpha_mask;
97 sa &= src_alpha_mask;
98 }
99 while (sa != 0);
100
101 pixman_image_unref (si);
102 pixman_image_unref (di);
103
104 return retval;
105 }
106
107 int
main(int argc,char ** argv)108 main (int argc, char **argv)
109 {
110 enum { OPTION_OP, OPTION_SRC, OPTION_DEST, LAST_OPTION } option;
111 pixman_format_code_t src_fmt, dest_fmt;
112 pixman_op_t op;
113
114 op = PIXMAN_OP_NONE;
115 src_fmt = PIXMAN_null;
116 dest_fmt = PIXMAN_null;
117
118 argc--;
119 argv++;
120
121 for (option = OPTION_OP; option < LAST_OPTION; ++option)
122 {
123 char *arg = NULL;
124
125 if (argc)
126 {
127 argc--;
128 arg = *argv++;
129 }
130
131 switch (option)
132 {
133 case OPTION_OP:
134 if (!arg)
135 printf (" - missing operator\n");
136 else if ((op = operator_from_string (arg)) == PIXMAN_OP_NONE)
137 printf (" - unknown operator %s\n", arg);
138 break;
139
140 case OPTION_SRC:
141 if (!arg)
142 printf (" - missing source format\n");
143 else if ((src_fmt = format_from_string (arg)) == PIXMAN_null)
144 printf (" - unknown source format %s\n", arg);
145 break;
146
147 case OPTION_DEST:
148 if (!arg)
149 printf (" - missing destination format\n");
150 else if ((dest_fmt = format_from_string (arg)) == PIXMAN_null)
151 printf (" - unknown destination format %s\n", arg);
152 break;
153
154 default:
155 assert (0);
156 break;
157 }
158 }
159
160 while (argc--)
161 {
162 op = PIXMAN_OP_NONE;
163 printf (" - unexpected argument: %s\n", *argv++);
164 }
165
166 if (op == PIXMAN_OP_NONE || src_fmt == PIXMAN_null || dest_fmt == PIXMAN_null)
167 {
168 printf ("\nUsage:\n check-formats <operator> <src-format> <dest-format>\n\n");
169 list_operators();
170 list_formats();
171
172 return -1;
173 }
174
175 return check_op (op, src_fmt, dest_fmt);
176 }
177