Delete FbIntMult and FbIntDiv macros, and move FbIntAdd to pixman-combine.h
[profile/ivi/pixman.git] / test / clip-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "pixman.h"
4 #include "utils.h"
5
6 #define WIDTH 200
7 #define HEIGHT 200
8     
9 static pixman_image_t *
10 create_solid_bits (uint32_t pixel)
11 {
12     uint32_t *pixels = malloc (WIDTH * HEIGHT * 4);
13     int i;
14     
15     for (i = 0; i < WIDTH * HEIGHT; ++i)
16         pixels[i] = pixel;
17
18     return pixman_image_create_bits (PIXMAN_a8r8g8b8,
19                                      WIDTH, HEIGHT, 
20                                      pixels,
21                                      WIDTH * 4);
22 }
23
24 int
25 main (int argc, char **argv)
26 {
27     pixman_image_t *gradient_img;
28     pixman_image_t *src_img, *dst_img;
29     pixman_gradient_stop_t stops[2] =
30         {
31             { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } },
32             { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } }
33         };
34     pixman_point_fixed_t p1 = { 0, 0 };
35     pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH),
36                                 pixman_int_to_fixed (HEIGHT) };
37     pixman_point_fixed_t c_inner;
38     pixman_point_fixed_t c_outer;
39     pixman_fixed_t r_inner;
40     pixman_fixed_t r_outer;
41     pixman_region32_t clip_region;
42     pixman_transform_t trans = {
43         { { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), },
44           { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), },
45           { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) } 
46         }
47     };
48     
49     src_img = create_solid_bits (0xff0000ff);
50     
51     c_inner.x = pixman_double_to_fixed (100.0);
52     c_inner.y = pixman_double_to_fixed (100.0);
53     c_outer.x = pixman_double_to_fixed (100.0);
54     c_outer.y = pixman_double_to_fixed (100.0);
55     r_inner = 0;
56     r_outer = pixman_double_to_fixed (100.0);
57     
58     gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
59                                                         r_inner, r_outer,
60                                                         stops, 2);
61
62 #if 0
63     gradient_img = pixman_image_create_linear_gradient  (&p1, &p2,
64                                                          stops, 2);
65     
66 #endif
67
68     pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img,
69                             0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
70     
71     pixman_region32_init_rect (&clip_region, 50, 0, 100, 200);
72     pixman_image_set_clip_region32 (src_img, &clip_region);
73     pixman_image_set_source_clipping (src_img, TRUE);
74     pixman_image_set_has_client_clip (src_img, TRUE);
75     pixman_image_set_transform (src_img, &trans);
76     pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
77     
78     dst_img = create_solid_bits (0xffff0000);
79     pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img,
80                             0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
81     
82
83 #if 0
84     printf ("0, 0: %x\n", src[0]);
85     printf ("10, 10: %x\n", src[10 * 10 + 10]);
86     printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
87 #endif
88     
89     show_image (dst_img);
90     
91     pixman_image_unref (gradient_img);
92     pixman_image_unref (src_img);
93     
94     return 0;
95 }