8 static const pixman_format_code_t formats[] =
16 static const pixman_format_code_t alpha_formats[] =
24 static const int origins[] =
30 format_name (pixman_format_code_t format)
32 if (format == PIXMAN_a8)
34 else if (format == PIXMAN_a2r10g10b10)
36 else if (format == PIXMAN_a8r8g8b8)
38 else if (format == PIXMAN_a4r4g4b4)
40 else if (format == PIXMAN_null)
45 return "<unknown - bug in alphamap.c>";
49 on_destroy (pixman_image_t *image, void *data)
51 uint32_t *bits = pixman_image_get_data (image);
56 static pixman_image_t *
57 make_image (pixman_format_code_t format)
60 uint8_t bpp = PIXMAN_FORMAT_BPP (format) / 8;
61 pixman_image_t *image;
63 bits = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * bpp);
65 image = pixman_image_create_bits (format, WIDTH, HEIGHT, bits, WIDTH * bpp);
68 pixman_image_set_destroy_function (image, on_destroy, NULL);
74 get_alpha (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
79 if (image->common.alpha_map)
81 if (x - orig_x >= 0 && x - orig_x < WIDTH &&
82 y - orig_y >= 0 && y - orig_y < HEIGHT)
84 image = (pixman_image_t *)image->common.alpha_map;
95 bits = (uint8_t *)image->bits.bits;
97 if (image->bits.format == PIXMAN_a8)
99 r = bits[y * WIDTH + x];
101 else if (image->bits.format == PIXMAN_a2r10g10b10)
103 r = ((uint32_t *)bits)[y * WIDTH + x] >> 30;
107 else if (image->bits.format == PIXMAN_a8r8g8b8)
109 r = ((uint32_t *)bits)[y * WIDTH + x] >> 24;
111 else if (image->bits.format == PIXMAN_a4r4g4b4)
113 r = ((uint16_t *)bits)[y * WIDTH + x] >> 12;
125 get_red (pixman_image_t *image, int x, int y, int orig_x, int orig_y)
130 bits = (uint8_t *)image->bits.bits;
132 if (image->bits.format == PIXMAN_a8)
136 else if (image->bits.format == PIXMAN_a2r10g10b10)
138 r = ((uint32_t *)bits)[y * WIDTH + x] >> 14;
142 else if (image->bits.format == PIXMAN_a8r8g8b8)
144 r = ((uint32_t *)bits)[y * WIDTH + x] >> 16;
148 else if (image->bits.format == PIXMAN_a4r4g4b4)
150 r = ((uint16_t *)bits)[y * WIDTH + x] >> 8;
164 run_test (int s, int d, int sa, int da, int soff, int doff)
166 pixman_format_code_t sf = formats[s];
167 pixman_format_code_t df = formats[d];
168 pixman_format_code_t saf = alpha_formats[sa];
169 pixman_format_code_t daf = alpha_formats[da];
170 pixman_image_t *src, *dst, *orig_dst, *alpha, *orig_alpha;
171 pixman_transform_t t1;
173 int n_alpha_bits, n_red_bits;
175 soff = origins[soff];
176 doff = origins[doff];
178 n_alpha_bits = PIXMAN_FORMAT_A (df);
179 if (daf != PIXMAN_null)
180 n_alpha_bits = PIXMAN_FORMAT_A (daf);
182 n_red_bits = PIXMAN_FORMAT_R (df);
185 src = make_image (sf);
186 if (saf != PIXMAN_null)
188 alpha = make_image (saf);
189 pixman_image_set_alpha_map (src, alpha, soff, soff);
190 pixman_image_unref (alpha);
194 orig_dst = make_image (df);
195 dst = make_image (df);
196 pixman_image_composite (PIXMAN_OP_SRC, orig_dst, NULL, dst,
197 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
199 if (daf != PIXMAN_null)
201 orig_alpha = make_image (daf);
202 alpha = make_image (daf);
204 pixman_image_composite (PIXMAN_OP_SRC, orig_alpha, NULL, alpha,
205 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
207 pixman_image_set_alpha_map (orig_dst, orig_alpha, doff, doff);
208 pixman_image_set_alpha_map (dst, alpha, doff, doff);
210 pixman_image_unref (orig_alpha);
211 pixman_image_unref (alpha);
214 /* Transformations, repeats and filters on destinations should be ignored,
215 * so just set some random ones.
217 pixman_transform_init_identity (&t1);
218 pixman_transform_scale (&t1, NULL, pixman_int_to_fixed (100), pixman_int_to_fixed (11));
219 pixman_transform_rotate (&t1, NULL, pixman_double_to_fixed (0.5), pixman_double_to_fixed (0.11));
220 pixman_transform_translate (&t1, NULL, pixman_int_to_fixed (11), pixman_int_to_fixed (17));
222 pixman_image_set_transform (dst, &t1);
223 pixman_image_set_filter (dst, PIXMAN_FILTER_BILINEAR, NULL, 0);
224 pixman_image_set_repeat (dst, PIXMAN_REPEAT_REFLECT);
226 pixman_image_composite (PIXMAN_OP_ADD, src, NULL, dst,
227 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
229 for (j = MAX (doff, 0); j < MIN (HEIGHT, HEIGHT + doff); ++j)
231 for (k = MAX (doff, 0); k < MIN (WIDTH, WIDTH + doff); ++k)
233 uint8_t sa, da, oda, refa;
234 uint16_t sr, dr, odr, refr;
236 sa = get_alpha (src, k, j, soff, soff);
237 da = get_alpha (dst, k, j, doff, doff);
238 oda = get_alpha (orig_dst, k, j, doff, doff);
245 if (da >> (8 - n_alpha_bits) != refa >> (8 - n_alpha_bits))
247 printf ("\nWrong alpha value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
248 k, j, refa, da, sa, oda);
250 printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
260 /* There are cases where we go through the 8 bit compositing
261 * path even with 10bpc formats. This results in incorrect
262 * results here, so only do the red check for narrow formats
266 sr = get_red (src, k, j, soff, soff);
267 dr = get_red (dst, k, j, doff, doff);
268 odr = get_red (orig_dst, k, j, doff, doff);
270 if (sr + odr > 0xffff)
275 if (abs ((dr >> (16 - n_red_bits)) - (refr >> (16 - n_red_bits))) > 1)
277 printf ("%d red bits\n", n_red_bits);
278 printf ("\nWrong red value at (%d, %d). Should be 0x%x; got 0x%x. Source was 0x%x, original dest was 0x%x\n",
279 k, j, refr, dr, sr, odr);
281 printf ("src: %s, alpha: %s, origin %d %d\ndst: %s, alpha: %s, origin: %d %d\n\n",
294 pixman_image_set_alpha_map (src, NULL, 0, 0);
295 pixman_image_set_alpha_map (dst, NULL, 0, 0);
296 pixman_image_set_alpha_map (orig_dst, NULL, 0, 0);
298 pixman_image_unref (src);
299 pixman_image_unref (dst);
300 pixman_image_unref (orig_dst);
306 main (int argc, char **argv)
308 int i, j, a, b, x, y;
310 for (i = 0; i < ARRAY_LENGTH (formats); ++i)
312 for (j = 0; j < ARRAY_LENGTH (formats); ++j)
314 for (a = 0; a < ARRAY_LENGTH (alpha_formats); ++a)
316 for (b = 0; b < ARRAY_LENGTH (alpha_formats); ++b)
318 for (x = 0; x < ARRAY_LENGTH (origins); ++x)
320 for (y = 0; y < ARRAY_LENGTH (origins); ++y)
322 if (run_test (i, j, a, b, x, y) != 0)