1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "pixman.h"
4 #include "gtk-utils.h"
5 
6 int
main(int argc,char ** argv)7 main (int argc, char **argv)
8 {
9 #define WIDTH 400
10 #define HEIGHT 200
11 
12     uint32_t *alpha = malloc (WIDTH * HEIGHT * 4);
13     uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
14     uint32_t *src = malloc (WIDTH * HEIGHT * 4);
15     pixman_image_t *grad_img;
16     pixman_image_t *alpha_img;
17     pixman_image_t *dest_img;
18     pixman_image_t *src_img;
19     int i;
20     pixman_gradient_stop_t stops[2] =
21 	{
22 	    { pixman_int_to_fixed (0), { 0x0000, 0x0000, 0x0000, 0x0000 } },
23 	    { pixman_int_to_fixed (1), { 0xffff, 0x0000, 0x1111, 0xffff } }
24 	};
25     pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 };
26     pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH),
27 				pixman_int_to_fixed (0) };
28 #if 0
29     pixman_transform_t trans = {
30 	{ { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), },
31 	  { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), },
32 	  { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) }
33 	}
34     };
35 #else
36     pixman_transform_t trans = {
37 	{ { pixman_fixed_1, 0, 0 },
38 	  { 0, pixman_fixed_1, 0 },
39 	  { 0, 0, pixman_fixed_1 } }
40     };
41 #endif
42 
43 #if 0
44     pixman_point_fixed_t c_inner;
45     pixman_point_fixed_t c_outer;
46     pixman_fixed_t r_inner;
47     pixman_fixed_t r_outer;
48 #endif
49 
50     for (i = 0; i < WIDTH * HEIGHT; ++i)
51 	alpha[i] = 0x4f00004f; /* pale blue */
52 
53     alpha_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
54 					 WIDTH, HEIGHT,
55 					  alpha,
56 					 WIDTH * 4);
57 
58     for (i = 0; i < WIDTH * HEIGHT; ++i)
59 	dest[i] = 0xffffff00;		/* yellow */
60 
61     dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
62 					 WIDTH, HEIGHT,
63 					 dest,
64 					 WIDTH * 4);
65 
66     for (i = 0; i < WIDTH * HEIGHT; ++i)
67 	src[i] = 0xffff0000;
68 
69     src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
70 					WIDTH, HEIGHT,
71 					src,
72 					WIDTH * 4);
73 
74 #if 0
75     c_inner.x = pixman_double_to_fixed (50.0);
76     c_inner.y = pixman_double_to_fixed (50.0);
77     c_outer.x = pixman_double_to_fixed (50.0);
78     c_outer.y = pixman_double_to_fixed (50.0);
79     r_inner = 0;
80     r_outer = pixman_double_to_fixed (50.0);
81 
82     grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
83 						    stops, 2);
84 #endif
85 #if 0
86     grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
87 						    stops, 2);
88     grad_img = pixman_image_create_linear_gradient (&c_inner, &c_outer,
89 						   r_inner, r_outer,
90 						   stops, 2);
91 #endif
92 
93     grad_img = pixman_image_create_linear_gradient  (&p1, &p2,
94 						    stops, 2);
95 
96     pixman_image_set_transform (grad_img, &trans);
97     pixman_image_set_repeat (grad_img, PIXMAN_REPEAT_PAD);
98 
99     pixman_image_composite (PIXMAN_OP_OVER, grad_img, NULL, alpha_img,
100 			    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
101 
102     pixman_image_set_alpha_map (src_img, alpha_img, 10, 10);
103 
104     pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
105 			    0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
106 
107     printf ("0, 0: %x\n", dest[0]);
108     printf ("10, 10: %x\n", dest[10 * 10 + 10]);
109     printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
110 
111     show_image (dest_img);
112 
113     pixman_image_unref (src_img);
114     pixman_image_unref (grad_img);
115     pixman_image_unref (alpha_img);
116     free (dest);
117 
118     return 0;
119 }
120