2 * Test program, which can detect some problems with nearest neighbour
3 * and bilinear scaling in pixman. Testing is done by running lots
4 * of random SRC and OVER compositing operations a8r8g8b8, x8a8r8g8b8
5 * and r5g6b5 color formats.
7 * Script 'fuzzer-find-diff.pl' can be used to narrow down the problem in
8 * the case of test failure.
14 #define MAX_SRC_WIDTH 48
15 #define MAX_SRC_HEIGHT 8
16 #define MAX_DST_WIDTH 48
17 #define MAX_DST_HEIGHT 8
21 * Composite operation with pseudorandom images
24 static pixman_format_code_t
29 switch (prng_rand_n (4))
33 return PIXMAN_a8r8g8b8;
35 return PIXMAN_x8r8g8b8;
37 return PIXMAN_a8b8g8r8;
39 return PIXMAN_x8b8g8r8;
49 test_composite (int testnum,
53 pixman_image_t * src_img;
54 pixman_image_t * mask_img;
55 pixman_image_t * dst_img;
56 pixman_transform_t transform;
57 pixman_region16_t clip;
58 int src_width, src_height;
59 int mask_width, mask_height;
60 int dst_width, dst_height;
61 int src_stride, mask_stride, dst_stride;
69 pixman_fixed_t scale_x = 65536, scale_y = 65536;
70 pixman_fixed_t translate_x = 0, translate_y = 0;
71 pixman_fixed_t mask_scale_x = 65536, mask_scale_y = 65536;
72 pixman_fixed_t mask_translate_x = 0, mask_translate_y = 0;
74 pixman_repeat_t repeat = PIXMAN_REPEAT_NONE;
75 pixman_repeat_t mask_repeat = PIXMAN_REPEAT_NONE;
76 pixman_format_code_t src_fmt, dst_fmt;
81 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
85 src_bpp = (prng_rand_n (2) == 0) ? 2 : 4;
86 dst_bpp = (prng_rand_n (2) == 0) ? 2 : 4;
87 switch (prng_rand_n (3))
100 src_width = prng_rand_n (MAX_SRC_WIDTH) + 1;
101 src_height = prng_rand_n (MAX_SRC_HEIGHT) + 1;
105 mask_width = prng_rand_n (MAX_SRC_WIDTH) + 1;
106 mask_height = prng_rand_n (MAX_SRC_HEIGHT) + 1;
110 mask_width = mask_height = 1;
113 dst_width = prng_rand_n (MAX_DST_WIDTH) + 1;
114 dst_height = prng_rand_n (MAX_DST_HEIGHT) + 1;
115 src_stride = src_width * src_bpp + prng_rand_n (MAX_STRIDE) * src_bpp;
116 mask_stride = mask_width * mask_bpp + prng_rand_n (MAX_STRIDE) * mask_bpp;
117 dst_stride = dst_width * dst_bpp + prng_rand_n (MAX_STRIDE) * dst_bpp;
130 src_x = -(src_width / 4) + prng_rand_n (src_width * 3 / 2);
131 src_y = -(src_height / 4) + prng_rand_n (src_height * 3 / 2);
132 mask_x = -(mask_width / 4) + prng_rand_n (mask_width * 3 / 2);
133 mask_y = -(mask_height / 4) + prng_rand_n (mask_height * 3 / 2);
134 dst_x = -(dst_width / 4) + prng_rand_n (dst_width * 3 / 2);
135 dst_y = -(dst_height / 4) + prng_rand_n (dst_height * 3 / 2);
136 w = prng_rand_n (dst_width * 3 / 2 - dst_x);
137 h = prng_rand_n (dst_height * 3 / 2 - dst_y);
139 srcbuf = (uint32_t *)malloc (src_stride * src_height);
140 maskbuf = (uint32_t *)malloc (mask_stride * mask_height);
141 dstbuf = (uint32_t *)malloc (dst_stride * dst_height);
143 prng_randmemset (srcbuf, src_stride * src_height, 0);
144 prng_randmemset (maskbuf, mask_stride * mask_height, 0);
145 prng_randmemset (dstbuf, dst_stride * dst_height, 0);
147 src_fmt = get_format (src_bpp);
148 dst_fmt = get_format (dst_bpp);
152 srcbuf += (src_stride / 4) * (src_height - 1);
153 src_stride = - src_stride;
158 maskbuf += (mask_stride / 4) * (mask_height - 1);
159 mask_stride = - mask_stride;
164 dstbuf += (dst_stride / 4) * (dst_height - 1);
165 dst_stride = - dst_stride;
168 src_img = pixman_image_create_bits (
169 src_fmt, src_width, src_height, srcbuf, src_stride);
171 mask_img = pixman_image_create_bits (
172 PIXMAN_a8, mask_width, mask_height, maskbuf, mask_stride);
174 dst_img = pixman_image_create_bits (
175 dst_fmt, dst_width, dst_height, dstbuf, dst_stride);
177 image_endian_swap (src_img);
178 image_endian_swap (dst_img);
180 if (prng_rand_n (4) > 0)
182 scale_x = -32768 * 3 + prng_rand_n (65536 * 5);
183 scale_y = -32768 * 3 + prng_rand_n (65536 * 5);
184 translate_x = prng_rand_n (65536);
185 translate_y = prng_rand_n (65536);
186 pixman_transform_init_scale (&transform, scale_x, scale_y);
187 pixman_transform_translate (&transform, NULL, translate_x, translate_y);
188 pixman_image_set_transform (src_img, &transform);
191 if (prng_rand_n (2) > 0)
193 mask_scale_x = -32768 * 3 + prng_rand_n (65536 * 5);
194 mask_scale_y = -32768 * 3 + prng_rand_n (65536 * 5);
195 mask_translate_x = prng_rand_n (65536);
196 mask_translate_y = prng_rand_n (65536);
197 pixman_transform_init_scale (&transform, mask_scale_x, mask_scale_y);
198 pixman_transform_translate (&transform, NULL, mask_translate_x, mask_translate_y);
199 pixman_image_set_transform (mask_img, &transform);
202 switch (prng_rand_n (4))
205 mask_repeat = PIXMAN_REPEAT_NONE;
209 mask_repeat = PIXMAN_REPEAT_NORMAL;
213 mask_repeat = PIXMAN_REPEAT_PAD;
217 mask_repeat = PIXMAN_REPEAT_REFLECT;
223 pixman_image_set_repeat (mask_img, mask_repeat);
225 switch (prng_rand_n (4))
228 repeat = PIXMAN_REPEAT_NONE;
232 repeat = PIXMAN_REPEAT_NORMAL;
236 repeat = PIXMAN_REPEAT_PAD;
240 repeat = PIXMAN_REPEAT_REFLECT;
246 pixman_image_set_repeat (src_img, repeat);
249 pixman_image_set_filter (src_img, PIXMAN_FILTER_NEAREST, NULL, 0);
251 pixman_image_set_filter (src_img, PIXMAN_FILTER_BILINEAR, NULL, 0);
254 pixman_image_set_filter (mask_img, PIXMAN_FILTER_NEAREST, NULL, 0);
256 pixman_image_set_filter (mask_img, PIXMAN_FILTER_BILINEAR, NULL, 0);
260 printf ("src_fmt=%s, dst_fmt=%s\n",
261 format_name (src_fmt), format_name (dst_fmt));
262 printf ("op=%s, scale_x=%d, scale_y=%d, repeat=%d\n",
263 operator_name (op), scale_x, scale_y, repeat);
264 printf ("translate_x=%d, translate_y=%d\n",
265 translate_x, translate_y);
266 printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
267 src_width, src_height, dst_width, dst_height);
268 printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
269 src_x, src_y, dst_x, dst_y);
270 printf ("w=%d, h=%d\n", w, h);
273 if (prng_rand_n (8) == 0)
275 pixman_box16_t clip_boxes[2];
276 int n = prng_rand_n (2) + 1;
278 for (i = 0; i < n; i++)
280 clip_boxes[i].x1 = prng_rand_n (src_width);
281 clip_boxes[i].y1 = prng_rand_n (src_height);
283 clip_boxes[i].x1 + prng_rand_n (src_width - clip_boxes[i].x1);
285 clip_boxes[i].y1 + prng_rand_n (src_height - clip_boxes[i].y1);
289 printf ("source clip box: [%d,%d-%d,%d]\n",
290 clip_boxes[i].x1, clip_boxes[i].y1,
291 clip_boxes[i].x2, clip_boxes[i].y2);
295 pixman_region_init_rects (&clip, clip_boxes, n);
296 pixman_image_set_clip_region (src_img, &clip);
297 pixman_image_set_source_clipping (src_img, 1);
298 pixman_region_fini (&clip);
301 if (prng_rand_n (8) == 0)
303 pixman_box16_t clip_boxes[2];
304 int n = prng_rand_n (2) + 1;
306 for (i = 0; i < n; i++)
308 clip_boxes[i].x1 = prng_rand_n (mask_width);
309 clip_boxes[i].y1 = prng_rand_n (mask_height);
311 clip_boxes[i].x1 + prng_rand_n (mask_width - clip_boxes[i].x1);
313 clip_boxes[i].y1 + prng_rand_n (mask_height - clip_boxes[i].y1);
317 printf ("mask clip box: [%d,%d-%d,%d]\n",
318 clip_boxes[i].x1, clip_boxes[i].y1,
319 clip_boxes[i].x2, clip_boxes[i].y2);
323 pixman_region_init_rects (&clip, clip_boxes, n);
324 pixman_image_set_clip_region (mask_img, &clip);
325 pixman_image_set_source_clipping (mask_img, 1);
326 pixman_region_fini (&clip);
329 if (prng_rand_n (8) == 0)
331 pixman_box16_t clip_boxes[2];
332 int n = prng_rand_n (2) + 1;
333 for (i = 0; i < n; i++)
335 clip_boxes[i].x1 = prng_rand_n (dst_width);
336 clip_boxes[i].y1 = prng_rand_n (dst_height);
338 clip_boxes[i].x1 + prng_rand_n (dst_width - clip_boxes[i].x1);
340 clip_boxes[i].y1 + prng_rand_n (dst_height - clip_boxes[i].y1);
344 printf ("destination clip box: [%d,%d-%d,%d]\n",
345 clip_boxes[i].x1, clip_boxes[i].y1,
346 clip_boxes[i].x2, clip_boxes[i].y2);
349 pixman_region_init_rects (&clip, clip_boxes, n);
350 pixman_image_set_clip_region (dst_img, &clip);
351 pixman_region_fini (&clip);
354 if (prng_rand_n (2) == 0)
355 pixman_image_composite (op, src_img, NULL, dst_img,
356 src_x, src_y, 0, 0, dst_x, dst_y, w, h);
358 pixman_image_composite (op, src_img, mask_img, dst_img,
359 src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
361 crc32 = compute_crc32_for_image (0, dst_img);
364 print_image (dst_img);
366 pixman_image_unref (src_img);
367 pixman_image_unref (mask_img);
368 pixman_image_unref (dst_img);
371 srcbuf += (src_stride / 4) * (src_height - 1);
374 maskbuf += (mask_stride / 4) * (mask_height - 1);
377 dstbuf += (dst_stride / 4) * (dst_height - 1);
383 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
387 #if BILINEAR_INTERPOLATION_BITS == 7
388 #define CHECKSUM 0x92E0F068
389 #elif BILINEAR_INTERPOLATION_BITS == 4
390 #define CHECKSUM 0x8EFFA1E5
392 #define CHECKSUM 0x00000000
396 main (int argc, const char *argv[])
398 pixman_disable_out_of_bounds_workaround ();
400 return fuzzer_test_main("scaling", 8000000, CHECKSUM,
401 test_composite, argc, argv);