Don't use __thread on MinGW.
[profile/ivi/pixman.git] / test / alpha-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "pixman.h"
4 #include "gtk-utils.h"
5
6 int
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     pixman_point_fixed_t c_inner;
44     pixman_point_fixed_t c_outer;
45     pixman_fixed_t r_inner;
46     pixman_fixed_t r_outer;
47     
48     for (i = 0; i < WIDTH * HEIGHT; ++i)
49         alpha[i] = 0x4f00004f; /* pale blue */
50     
51     alpha_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
52                                          WIDTH, HEIGHT, 
53                                           alpha,
54                                          WIDTH * 4);
55
56     for (i = 0; i < WIDTH * HEIGHT; ++i)
57         dest[i] = 0xffffff00;           /* yellow */
58     
59     dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
60                                          WIDTH, HEIGHT, 
61                                          dest,
62                                          WIDTH * 4);
63
64     for (i = 0; i < WIDTH * HEIGHT; ++i)
65         src[i] = 0xffff0000;
66
67     src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
68                                         WIDTH, HEIGHT,
69                                         src,
70                                         WIDTH * 4);
71     
72     c_inner.x = pixman_double_to_fixed (50.0);
73     c_inner.y = pixman_double_to_fixed (50.0);
74     c_outer.x = pixman_double_to_fixed (50.0);
75     c_outer.y = pixman_double_to_fixed (50.0);
76     r_inner = 0;
77     r_outer = pixman_double_to_fixed (50.0);
78     
79 #if 0
80     grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
81                                                     stops, 2);
82 #endif
83 #if 0
84     grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
85                                                     stops, 2);
86     grad_img = pixman_image_create_linear_gradient (&c_inner, &c_outer,
87                                                    r_inner, r_outer,
88                                                    stops, 2);
89 #endif
90     
91     grad_img = pixman_image_create_linear_gradient  (&p1, &p2,
92                                                     stops, 2);
93
94     pixman_image_set_transform (grad_img, &trans);
95     pixman_image_set_repeat (grad_img, PIXMAN_REPEAT_PAD);
96     
97     pixman_image_composite (PIXMAN_OP_OVER, grad_img, NULL, alpha_img,
98                             0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
99
100     pixman_image_set_alpha_map (src_img, alpha_img, 10, 10);
101     
102     pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
103                             0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
104     
105     printf ("0, 0: %x\n", dest[0]);
106     printf ("10, 10: %x\n", dest[10 * 10 + 10]);
107     printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
108     
109     show_image (dest_img);
110
111     pixman_image_unref (src_img);
112     pixman_image_unref (grad_img);
113     pixman_image_unref (alpha_img);
114     free (dest);
115     
116     return 0;
117 }