1 #include <math.h>
2 #include "pixman.h"
3 #include "gtk-utils.h"
4
5 #define F(x) \
6 pixman_double_to_fixed (x)
7
8 #define WIDTH 600
9 #define HEIGHT 300
10
11 static uint16_t
convert_to_srgb(uint16_t in)12 convert_to_srgb (uint16_t in)
13 {
14 double d = in * (1/65535.0);
15 double a = 0.055;
16
17 if (d < 0.0031308)
18 d = 12.92 * d;
19 else
20 d = (1 + a) * pow (d, 1 / 2.4) - a;
21
22 return (d * 65535.0) + 0.5;
23 }
24
25 static void
convert_color(pixman_color_t * dest_srgb,pixman_color_t * linear)26 convert_color (pixman_color_t *dest_srgb, pixman_color_t *linear)
27 {
28 dest_srgb->alpha = convert_to_srgb (linear->alpha);
29 dest_srgb->red = convert_to_srgb (linear->red);
30 dest_srgb->green = convert_to_srgb (linear->green);
31 dest_srgb->blue = convert_to_srgb (linear->blue);
32 }
33
34 int
main(int argc,char ** argv)35 main (int argc, char **argv)
36 {
37 static const pixman_trapezoid_t traps[] =
38 {
39 { F(10.10), F(280.0),
40 { { F(20.0), F(10.10) },
41 { F(5.3), F(280.0) } },
42 { { F(20.3), F(10.10) },
43 { F(5.6), F(280.0) } }
44 },
45 { F(10.10), F(280.0),
46 { { F(40.0), F(10.10) },
47 { F(15.3), F(280.0) } },
48 { { F(41.0), F(10.10) },
49 { F(16.3), F(280.0) } }
50 },
51 { F(10.10), F(280.0),
52 { { F(120.0), F(10.10) },
53 { F(5.3), F(280.0) } },
54 { { F(128.3), F(10.10) },
55 { F(6.6), F(280.0) } }
56 },
57 { F(10.10), F(280.0),
58 { { F(60.0), F(10.10) },
59 { F(25.3), F(280.0) } },
60 { { F(61.0), F(10.10) },
61 { F(26.3), F(280.0) } }
62 },
63 { F(10.10), F(280.0),
64 { { F(90.0), F(10.10) },
65 { F(55.3), F(280.0) } },
66 { { F(93.0), F(10.10) },
67 { F(58.3), F(280.0) } }
68 },
69 { F(130.10), F(150.0),
70 { { F(100.0), F(130.10) },
71 { F(250.3), F(150.0) } },
72 { { F(110.0), F(130.10) },
73 { F(260.3), F(150.0) } }
74 },
75 { F(170.10), F(240.0),
76 { { F(100.0), F(170.10) },
77 { F(120.3), F(240.0) } },
78 { { F(250.0), F(170.10) },
79 { F(250.3), F(240.0) } }
80 },
81 };
82
83 pixman_image_t *src, *dest_srgb, *dest_linear;
84 pixman_color_t bg = { 0x0000, 0x0000, 0x0000, 0xffff };
85 pixman_color_t fg = { 0xffff, 0xffff, 0xffff, 0xffff };
86 pixman_color_t fg_srgb;
87 uint32_t *d;
88
89 d = malloc (WIDTH * HEIGHT * 4);
90
91 dest_srgb = pixman_image_create_bits (
92 PIXMAN_a8r8g8b8_sRGB, WIDTH, HEIGHT, d, WIDTH * 4);
93 dest_linear = pixman_image_create_bits (
94 PIXMAN_a8r8g8b8, WIDTH, HEIGHT, d, WIDTH * 4);
95
96 src = pixman_image_create_solid_fill (&bg);
97 pixman_image_composite32 (PIXMAN_OP_SRC,
98 src, NULL, dest_srgb,
99 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
100
101 src = pixman_image_create_solid_fill (&fg);
102
103 pixman_composite_trapezoids (PIXMAN_OP_OVER,
104 src, dest_srgb, PIXMAN_a8,
105 0, 0, 10, 10, G_N_ELEMENTS (traps), traps);
106
107 convert_color (&fg_srgb, &fg);
108 src = pixman_image_create_solid_fill (&fg_srgb);
109
110 pixman_composite_trapezoids (PIXMAN_OP_OVER,
111 src, dest_linear, PIXMAN_a8,
112 0, 0, 310, 10, G_N_ELEMENTS (traps), traps);
113
114 show_image (dest_linear);
115 pixman_image_unref(dest_linear);
116 free(d);
117
118 return 0;
119 }
120