• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdlib.h>
2 #include "utils.h"
3 
4 #define WIDTH	32
5 #define HEIGHT	32
6 
7 static const pixman_format_code_t formats[] =
8 {
9     PIXMAN_a8r8g8b8,
10     PIXMAN_a8b8g8r8,
11     PIXMAN_x8r8g8b8,
12     PIXMAN_x8b8g8r8,
13     PIXMAN_r5g6b5,
14     PIXMAN_b5g6r5,
15     PIXMAN_a8,
16     PIXMAN_a1,
17 };
18 
19 static const pixman_op_t ops[] =
20 {
21     PIXMAN_OP_OVER,
22     PIXMAN_OP_SRC,
23     PIXMAN_OP_ADD,
24 };
25 
26 #define TRANSFORM(v00, v01, v10, v11)					\
27     { { { v00, v01, WIDTH * pixman_fixed_1 / 2 },			\
28         { v10, v11, HEIGHT * pixman_fixed_1 / 2 },			\
29 	{ 0, 0, pixman_fixed_1 } } }
30 
31 #define F1 pixman_fixed_1
32 
33 static const pixman_transform_t transforms[] =
34 {
35     TRANSFORM (0, -1, 1, 0),		/* wrong 90 degree rotation */
36     TRANSFORM (0, 1, -1, 0),		/* wrong 270 degree rotation */
37     TRANSFORM (1, 0, 0, 1),		/* wrong identity */
38     TRANSFORM (-1, 0, 0, -1),		/* wrong 180 degree rotation */
39     TRANSFORM (0, -F1, F1, 0),		/* correct 90 degree rotation */
40     TRANSFORM (0, F1, -F1, 0),		/* correct 270 degree rotation */
41     TRANSFORM (F1, 0, 0, F1),		/* correct identity */
42     TRANSFORM (-F1, 0, 0, -F1),		/* correct 180 degree rotation */
43 };
44 
45 #define RANDOM_FORMAT()							\
46     (formats[prng_rand_n (ARRAY_LENGTH (formats))])
47 
48 #define RANDOM_OP()							\
49     (ops[prng_rand_n (ARRAY_LENGTH (ops))])
50 
51 #define RANDOM_TRANSFORM()						\
52     (&(transforms[prng_rand_n (ARRAY_LENGTH (transforms))]))
53 
54 static void
on_destroy(pixman_image_t * image,void * data)55 on_destroy (pixman_image_t *image, void *data)
56 {
57     free (data);
58 }
59 
60 static pixman_image_t *
make_image(void)61 make_image (void)
62 {
63     pixman_format_code_t format = RANDOM_FORMAT();
64     uint32_t *bytes = malloc (WIDTH * HEIGHT * 4);
65     pixman_image_t *image;
66 
67     prng_randmemset (bytes, WIDTH * HEIGHT * 4, 0);
68 
69     image = pixman_image_create_bits (
70 	format, WIDTH, HEIGHT, bytes, WIDTH * 4);
71 
72     pixman_image_set_transform (image, RANDOM_TRANSFORM());
73     pixman_image_set_destroy_function (image, on_destroy, bytes);
74     pixman_image_set_repeat (image, PIXMAN_REPEAT_NORMAL);
75 
76     image_endian_swap (image);
77 
78     return image;
79 }
80 
81 static uint32_t
test_transform(int testnum,int verbose)82 test_transform (int testnum, int verbose)
83 {
84     pixman_image_t *src, *dest;
85     uint32_t crc;
86 
87     prng_srand (testnum);
88 
89     src = make_image ();
90     dest = make_image ();
91 
92     pixman_image_composite (RANDOM_OP(),
93 			    src, NULL, dest,
94 			    0, 0, 0, 0, WIDTH / 2, HEIGHT / 2,
95 			    WIDTH, HEIGHT);
96 
97     crc = compute_crc32_for_image (0, dest);
98 
99     pixman_image_unref (src);
100     pixman_image_unref (dest);
101 
102     return crc;
103 }
104 
105 int
main(int argc,const char * argv[])106 main (int argc, const char *argv[])
107 {
108     return fuzzer_test_main ("rotate", 15000,
109 			     0xECF5E426,
110 			     test_transform, argc, argv);
111 }
112