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