1#include <stdio.h>
2#include <stdlib.h>
3#include "utils.h"
4
5int
6main (int argc, char **argv)
7{
8#define WIDTH 400
9#define HEIGHT 200
10
11    uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
12    pixman_image_t *src_img;
13    pixman_image_t *dest_img;
14    int i, j, k, p;
15
16    typedef struct
17    {
18	pixman_point_fixed_t p0;
19	pixman_point_fixed_t p1;
20    } point_pair_t;
21
22    pixman_gradient_stop_t onestop[1] =
23	{
24	    { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
25	};
26
27    pixman_gradient_stop_t subsetstops[2] =
28	{
29	    { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
30	    { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
31	};
32
33    pixman_gradient_stop_t stops01[2] =
34	{
35	    { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
36	    { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } }
37	};
38
39    point_pair_t point_pairs [] =
40	{ { { pixman_double_to_fixed (0), 0 },
41	    { pixman_double_to_fixed (WIDTH / 8.), pixman_int_to_fixed (0) } },
42	  { { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) },
43	    { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) } }
44	};
45
46    pixman_transform_t transformations[] = {
47	{
48	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), },
49	      { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), },
50	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) }
51	    }
52	},
53	{
54	    { { pixman_double_to_fixed (1), pixman_double_to_fixed (0), pixman_double_to_fixed (0), },
55	      { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
56	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) }
57	    }
58	},
59	{
60	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
61	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
62	      { pixman_double_to_fixed (2), pixman_double_to_fixed (1.000), pixman_double_to_fixed (1.0) }
63	    }
64	},
65	{
66	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
67	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
68	      { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (0) }
69	    }
70	},
71	{
72	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
73	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
74	      { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) }
75	    }
76	},
77	{
78	    { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (3), },
79	      { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), },
80	      { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) }
81	    }
82	},
83    };
84
85    pixman_fixed_t r_inner;
86    pixman_fixed_t r_outer;
87
88    enable_divbyzero_exceptions();
89
90    for (i = 0; i < WIDTH * HEIGHT; ++i)
91	dest[i] = 0x4f00004f; /* pale blue */
92
93    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
94					 WIDTH, HEIGHT,
95					 dest,
96					 WIDTH * 4);
97
98    r_inner = 0;
99    r_outer = pixman_double_to_fixed (50.0);
100
101    for (i = 0; i < 3; ++i)
102    {
103	pixman_gradient_stop_t *stops;
104        int num_stops;
105
106	if (i == 0)
107	{
108	    stops = onestop;
109	    num_stops = ARRAY_LENGTH (onestop);
110	}
111	else if (i == 1)
112	{
113	    stops = subsetstops;
114	    num_stops = ARRAY_LENGTH (subsetstops);
115	}
116	else
117	{
118	    stops = stops01;
119	    num_stops = ARRAY_LENGTH (stops01);
120	}
121
122	for (j = 0; j < 3; ++j)
123	{
124	    for (p = 0; p < ARRAY_LENGTH (point_pairs); ++p)
125	    {
126		point_pair_t *pair = &(point_pairs[p]);
127
128		if (j == 0)
129		    src_img = pixman_image_create_conical_gradient (&(pair->p0), r_inner,
130								    stops, num_stops);
131		else if (j == 1)
132		    src_img = pixman_image_create_radial_gradient  (&(pair->p0), &(pair->p1),
133								    r_inner, r_outer,
134								    stops, num_stops);
135		else
136		    src_img = pixman_image_create_linear_gradient  (&(pair->p0), &(pair->p1),
137								    stops, num_stops);
138
139		for (k = 0; k < ARRAY_LENGTH (transformations); ++k)
140		{
141		    pixman_image_set_transform (src_img, &transformations[k]);
142
143		    pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE);
144		    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
145					    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
146		}
147
148		pixman_image_unref (src_img);
149	    }
150
151	}
152    }
153
154    pixman_image_unref (dest_img);
155    free (dest);
156
157    return 0;
158}
159