mmx: add x8f8g8b8 fetcher
[profile/ivi/pixman.git] / test / region-test.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "utils.h"
5
6 int
7 main ()
8 {
9     pixman_region32_t r1;
10     pixman_region32_t r2;
11     pixman_region32_t r3;
12     pixman_box32_t boxes[] = {
13         { 10, 10, 20, 20 },
14         { 30, 30, 30, 40 },
15         { 50, 45, 60, 44 },
16     };
17     pixman_box32_t boxes2[] = {
18         { 2, 6, 7, 6 },
19         { 4, 1, 6, 7 },
20     };
21     pixman_box32_t boxes3[] = {
22         { 2, 6, 7, 6 },
23         { 4, 1, 6, 1 },
24     };
25     int i, j;
26     pixman_box32_t *b;
27     pixman_image_t *image, *fill;
28     pixman_color_t white = {
29         0xffff,
30         0xffff,
31         0xffff,
32         0xffff
33     };
34
35     /* This used to go into an infinite loop before pixman-region.c
36      * was fixed to not use explict "short" variables
37      */
38     pixman_region32_init_rect (&r1, 0, 0, 20, 64000);
39     pixman_region32_init_rect (&r2, 0, 0, 20, 64000);
40     pixman_region32_init_rect (&r3, 0, 0, 20, 64000);
41
42     pixman_region32_subtract (&r1, &r2, &r3);
43
44
45     /* This would produce a region containing an empty
46      * rectangle in it. Such regions are considered malformed,
47      * but using an empty rectangle for initialization should
48      * work.
49      */
50     pixman_region32_init_rects (&r1, boxes, 3);
51
52     b = pixman_region32_rectangles (&r1, &i);
53
54     assert (i == 1);
55     
56     while (i--)
57     {
58         assert (b[i].x1 < b[i].x2);
59         assert (b[i].y1 < b[i].y2);
60     }
61
62     /* This would produce a rectangle containing the bounding box
63      * of the two rectangles. The correct result is to eliminate
64      * the broken rectangle.
65      */
66     pixman_region32_init_rects (&r1, boxes2, 2);
67
68     b = pixman_region32_rectangles (&r1, &i);
69
70     assert (i == 1);
71
72     assert (b[0].x1 == 4);
73     assert (b[0].y1 == 1);
74     assert (b[0].x2 == 6);
75     assert (b[0].y2 == 7);
76
77     /* This should produce an empty region */
78     pixman_region32_init_rects (&r1, boxes3, 2);
79
80     b = pixman_region32_rectangles (&r1, &i);
81
82     assert (i == 0);
83
84     fill = pixman_image_create_solid_fill (&white);
85     for (i = 0; i < 100; i++)
86     {
87         int image_size = 128;
88
89         pixman_region32_init (&r1);
90
91         /* Add some random rectangles */
92         for (j = 0; j < 64; j++)
93             pixman_region32_union_rect (&r1, &r1,
94                                         lcg_rand_n (image_size),
95                                         lcg_rand_n (image_size),
96                                         lcg_rand_n (25),
97                                         lcg_rand_n (25));
98
99         /* Clip to image size */
100         pixman_region32_init_rect (&r2, 0, 0, image_size, image_size);
101         pixman_region32_intersect (&r1, &r1, &r2);
102         pixman_region32_fini (&r2);
103
104         /* render region to a1 mask */
105         image = pixman_image_create_bits (PIXMAN_a1, image_size, image_size, NULL, 0);
106         pixman_image_set_clip_region32 (image, &r1);
107         pixman_image_composite32 (PIXMAN_OP_SRC,
108                                   fill, NULL, image,
109                                   0, 0, 0, 0, 0, 0,
110                                   image_size, image_size);
111         pixman_region32_init_from_image (&r2, image);
112
113         pixman_image_unref (image);
114
115         assert (pixman_region32_equal (&r1, &r2));
116         pixman_region32_fini (&r1);
117         pixman_region32_fini (&r2);
118
119     }
120     pixman_image_unref (fill);
121
122     return 0;
123 }