114b11b2bSmrg#include "utils.h"
2f4f78bb6Smrg#include "gtk-utils.h"
3f4f78bb6Smrg
4f4f78bb6Smrg#define SIZE 128
5f4f78bb6Smrg#define GRADIENTS_PER_ROW 7
6f4f78bb6Smrg#define NUM_ROWS ((NUM_GRADIENTS + GRADIENTS_PER_ROW - 1) / GRADIENTS_PER_ROW)
7f4f78bb6Smrg#define WIDTH (SIZE * GRADIENTS_PER_ROW)
8f4f78bb6Smrg#define HEIGHT (SIZE * NUM_ROWS)
9f4f78bb6Smrg#define NUM_GRADIENTS 35
10f4f78bb6Smrg
11f4f78bb6Smrg#define double_to_color(x)					\
12f4f78bb6Smrg    (((uint32_t) ((x)*65536)) - (((uint32_t) ((x)*65536)) >> 16))
13f4f78bb6Smrg
14f4f78bb6Smrg#define PIXMAN_STOP(offset,r,g,b,a)		\
15f4f78bb6Smrg    { pixman_double_to_fixed (offset),		\
16f4f78bb6Smrg	{					\
17f4f78bb6Smrg	    double_to_color (r),		\
18f4f78bb6Smrg		double_to_color (g),		\
19f4f78bb6Smrg		double_to_color (b),		\
20f4f78bb6Smrg		double_to_color (a)		\
21f4f78bb6Smrg	}					\
22f4f78bb6Smrg    }
23f4f78bb6Smrg
24f4f78bb6Smrg
25f4f78bb6Smrgstatic const pixman_gradient_stop_t stops[] = {
26f4f78bb6Smrg    PIXMAN_STOP (0.25,       1, 0, 0, 0.7),
27f4f78bb6Smrg    PIXMAN_STOP (0.5,        1, 1, 0, 0.7),
28f4f78bb6Smrg    PIXMAN_STOP (0.75,       0, 1, 0, 0.7),
29f4f78bb6Smrg    PIXMAN_STOP (1.0,        0, 0, 1, 0.7)
30f4f78bb6Smrg};
31f4f78bb6Smrg
32f4f78bb6Smrg#define NUM_STOPS (sizeof (stops) / sizeof (stops[0]))
33f4f78bb6Smrg
34f4f78bb6Smrgstatic pixman_image_t *
35f4f78bb6Smrgcreate_conical (int index)
36f4f78bb6Smrg{
37f4f78bb6Smrg    pixman_point_fixed_t c;
38f4f78bb6Smrg    double angle;
39f4f78bb6Smrg
40f4f78bb6Smrg    c.x = pixman_double_to_fixed (0);
41f4f78bb6Smrg    c.y = pixman_double_to_fixed (0);
42f4f78bb6Smrg
43f4f78bb6Smrg    angle = (0.5 / NUM_GRADIENTS + index / (double)NUM_GRADIENTS) * 720 - 180;
44f4f78bb6Smrg
45f4f78bb6Smrg    return pixman_image_create_conical_gradient (
46f4f78bb6Smrg	&c, pixman_double_to_fixed (angle), stops, NUM_STOPS);
47f4f78bb6Smrg}
48f4f78bb6Smrg
49f4f78bb6Smrgint
50f4f78bb6Smrgmain (int argc, char **argv)
51f4f78bb6Smrg{
52f4f78bb6Smrg    pixman_transform_t transform;
53f4f78bb6Smrg    pixman_image_t *src_img, *dest_img;
54f4f78bb6Smrg    int i;
55f4f78bb6Smrg
56f4f78bb6Smrg    enable_divbyzero_exceptions ();
57f4f78bb6Smrg
58f4f78bb6Smrg    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
59f4f78bb6Smrg					 WIDTH, HEIGHT,
60f4f78bb6Smrg					 NULL, 0);
61f4f78bb6Smrg
62f4f78bb6Smrg    draw_checkerboard (dest_img, 25, 0xffaaaaaa, 0xff888888);
63f4f78bb6Smrg
64f4f78bb6Smrg    pixman_transform_init_identity (&transform);
65f4f78bb6Smrg
66f4f78bb6Smrg    pixman_transform_translate (NULL, &transform,
67f4f78bb6Smrg				pixman_double_to_fixed (0.5),
68f4f78bb6Smrg				pixman_double_to_fixed (0.5));
69f4f78bb6Smrg
70f4f78bb6Smrg    pixman_transform_scale (NULL, &transform,
71f4f78bb6Smrg			    pixman_double_to_fixed (SIZE),
72f4f78bb6Smrg			    pixman_double_to_fixed (SIZE));
73f4f78bb6Smrg    pixman_transform_translate (NULL, &transform,
74f4f78bb6Smrg				pixman_double_to_fixed (0.5),
75f4f78bb6Smrg				pixman_double_to_fixed (0.5));
76f4f78bb6Smrg
77f4f78bb6Smrg    for (i = 0; i < NUM_GRADIENTS; i++)
78f4f78bb6Smrg    {
79f4f78bb6Smrg	int column = i % GRADIENTS_PER_ROW;
80f4f78bb6Smrg	int row = i / GRADIENTS_PER_ROW;
81f4f78bb6Smrg
82f4f78bb6Smrg	src_img = create_conical (i);
83f4f78bb6Smrg	pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
84f4f78bb6Smrg
85f4f78bb6Smrg	pixman_image_set_transform (src_img, &transform);
86f4f78bb6Smrg
87f4f78bb6Smrg	pixman_image_composite32 (
88f4f78bb6Smrg	    PIXMAN_OP_OVER, src_img, NULL,dest_img,
89f4f78bb6Smrg	    0, 0, 0, 0, column * SIZE, row * SIZE,
90f4f78bb6Smrg	    SIZE, SIZE);
91f4f78bb6Smrg
92f4f78bb6Smrg	pixman_image_unref (src_img);
93f4f78bb6Smrg    }
94f4f78bb6Smrg
95f4f78bb6Smrg    show_image (dest_img);
96f4f78bb6Smrg
97f4f78bb6Smrg    pixman_image_unref (dest_img);
98f4f78bb6Smrg
99f4f78bb6Smrg    return 0;
100f4f78bb6Smrg}
101