8 static const pixman_format_code_t formats[] =
16 static const pixman_format_code_t alpha_formats[] =
24 static const int origins[] =
30 on_destroy (pixman_image_t *image, void *data)
32 uint32_t *bits = pixman_image_get_data (image);
37 static pixman_image_t *
38 make_image (pixman_format_code_t format)
41 uint8_t bpp = PIXMAN_FORMAT_BPP (format) / 8;
42 pixman_image_t *image;
44 bits = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * bpp);
46 image = pixman_image_create_bits (format, WIDTH, HEIGHT, bits, WIDTH * bpp);
49 pixman_image_set_destroy_function (image, on_destroy, NULL);
55 get_alpha (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
60 if (image->common.alpha_map)
62 if (x - orig_x >= 0 && x - orig_x < WIDTH &&
63 y - orig_y >= 0 && y - orig_y < HEIGHT)
65 image = (pixman_image_t *)image->common.alpha_map;
76 bits = (uint8_t *)image->bits.bits;
78 if (image->bits.format == PIXMAN_a8)
80 r = bits[y * WIDTH + x];
82 else if (image->bits.format == PIXMAN_a2r10g10b10)
84 r = ((uint32_t *)bits)[y * WIDTH + x] >> 30;
88 else if (image->bits.format == PIXMAN_a8r8g8b8)
90 r = ((uint32_t *)bits)[y * WIDTH + x] >> 24;
92 else if (image->bits.format == PIXMAN_a4r4g4b4)
94 r = ((uint16_t *)bits)[y * WIDTH + x] >> 12;
106 get_red (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
111 bits = (uint8_t *)image->bits.bits;
113 if (image->bits.format == PIXMAN_a8)
117 else if (image->bits.format == PIXMAN_a2r10g10b10)
119 r = ((uint32_t *)bits)[y * WIDTH + x] >> 14;
123 else if (image->bits.format == PIXMAN_a8r8g8b8)
125 r = ((uint32_t *)bits)[y * WIDTH + x] >> 16;
129 else if (image->bits.format == PIXMAN_a4r4g4b4)
131 r = ((uint16_t *)bits)[y * WIDTH + x] >> 8;
145 run_test (int s, int d, int sa, int da, int soff, int doff)
147 pixman_format_code_t sf = formats[s];
148 pixman_format_code_t df = formats[d];
149 pixman_format_code_t saf = alpha_formats[sa];
150 pixman_format_code_t daf = alpha_formats[da];
151 pixman_image_t *src, *dst, *orig_dst, *alpha, *orig_alpha;
152 pixman_transform_t t1;
154 int n_alpha_bits, n_red_bits;
156 soff = origins[soff];
157 doff = origins[doff];
159 n_alpha_bits = PIXMAN_FORMAT_A (df);
160 if (daf != PIXMAN_null)
161 n_alpha_bits = PIXMAN_FORMAT_A (daf);
163 n_red_bits = PIXMAN_FORMAT_R (df);
166 src = make_image (sf);
167 if (saf != PIXMAN_null)
169 alpha = make_image (saf);
170 pixman_image_set_alpha_map (src, alpha, soff, soff);
171 pixman_image_unref (alpha);
175 orig_dst = make_image (df);
176 dst = make_image (df);
177 pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst,
178 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
180 if (daf != PIXMAN_null)
182 orig_alpha = make_image (daf);
183 alpha = make_image (daf);
185 pixman_image_composite (PIXMAN_OP_SRC, orig_alpha, NULL, alpha,
186 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
188 pixman_image_set_alpha_map (orig_dst, orig_alpha, doff, doff);
189 pixman_image_set_alpha_map (dst, alpha, doff, doff);
191 pixman_image_unref (orig_alpha);
192 pixman_image_unref (alpha);
195 /* Transformations, repeats and filters on destinations should be ignored,
196 * so just set some random ones.
198 pixman_transform_init_identity (&t1);
199 pixman_transform_scale (&t1, NULL, pixman_int_to_fixed (100), pixman_int_to_fixed (11));
200 pixman_transform_rotate (&t1, NULL, pixman_double_to_fixed (0.5), pixman_double_to_fixed (0.11));
201 pixman_transform_translate (&t1, NULL, pixman_int_to_fixed (11), pixman_int_to_fixed (17));
203 pixman_image_set_transform (dst, &t1);
204 pixman_image_set_filter (dst, PIXMAN_FILTER_BILINEAR, NULL, 0);
205 pixman_image_set_repeat (dst, PIXMAN_REPEAT_REFLECT);
207 pixman_image_composite (PIXMAN_OP_ADD, src, NULL, dst,
208 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
210 for (j = MAX (doff, 0); j < MIN (HEIGHT, HEIGHT + doff); ++j)
212 for (k = MAX (doff, 0); k < MIN (WIDTH, WIDTH + doff); ++k)
214 uint8_t sa, da, oda, refa;
215 uint16_t sr, dr, odr, refr;
217 sa = get_alpha (src, k, j, soff, soff);
218 da = get_alpha (dst, k, j, doff, doff);
219 oda = get_alpha (orig_dst, k, j, doff, doff);
226 if (da >> (8 - n_alpha_bits) != refa >> (8 - n_alpha_bits))
228 printf ("\nWrong alpha value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
229 k, j, refa, da, sa, oda);
231 printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
241 /* There are cases where we go through the 8 bit compositing
242 * path even with 10bpc formats. This results in incorrect
243 * results here, so only do the red check for narrow formats
247 sr = get_red (src, k, j, soff, soff);
248 dr = get_red (dst, k, j, doff, doff);
249 odr = get_red (orig_dst, k, j, doff, doff);
251 if (sr + odr > 0xffff)
256 if (abs ((dr >> (16 - n_red_bits)) - (refr >> (16 - n_red_bits))) > 1)
258 printf ("%d red bits\n", n_red_bits);
259 printf ("\nWrong red value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
260 k, j, refr, dr, sr, odr);
262 printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
275 pixman_image_set_alpha_map (src, NULL, 0, 0);
276 pixman_image_set_alpha_map (dst, NULL, 0, 0);
277 pixman_image_set_alpha_map (orig_dst, NULL, 0, 0);
279 pixman_image_unref (src);
280 pixman_image_unref (dst);
281 pixman_image_unref (orig_dst);
287 main (int argc, char **argv)
289 int i, j, a, b, x, y;
293 for (i = 0; i < ARRAY_LENGTH (formats); ++i)
295 for (j = 0; j < ARRAY_LENGTH (formats); ++j)
297 for (a = 0; a < ARRAY_LENGTH (alpha_formats); ++a)
299 for (b = 0; b < ARRAY_LENGTH (alpha_formats); ++b)
301 for (x = 0; x < ARRAY_LENGTH (origins); ++x)
303 for (y = 0; y < ARRAY_LENGTH (origins); ++y)
305 if (run_test (i, j, a, b, x, y) != 0)