1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "pixman.h"
GdkPixbuf *
pixbuf_from_argb32 (uint32_t *bits,
int width,
int height,
int stride)
{
GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
8, width, height);
int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
int w, h;
for (h = 0; h < height; ++h)
{
for (w = 0; w < width; ++w)
{
uint32_t argb = bits[h * stride + w];
guint32 abgr;
abgr = (argb & 0xff000000) |
(argb & 0xff) << 16 |
(argb & 0x00ff00) |
(argb & 0xff0000) >> 16;
p_bits[h * (p_stride / 4) + w] = abgr;
}
}
return pixbuf;
}
static gboolean
on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
{
GdkPixbuf *pixbuf = data;
gdk_draw_pixbuf (widget->window, NULL,
pixbuf, 0, 0, 0, 0,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
GDK_RGB_DITHER_NONE,
0, 0);
return TRUE;
}
static void
show_window (pixman_image_t *img, int w, int h, int stride)
{
GdkPixbuf *pixbuf;
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
pixbuf = pixbuf_from_argb32 (pixman_image_get_data (img), w, h, stride);
g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_main ();
}
#define WIDTH 200
#define HEIGHT 200
static pixman_image_t *
create_solid_bits (uint32_t pixel)
{
uint32_t *pixels = malloc (WIDTH * HEIGHT * 4);
int i;
for (i = 0; i < WIDTH * HEIGHT; ++i)
pixels[i] = pixel;
return pixman_image_create_bits (PIXMAN_a8r8g8b8,
WIDTH, HEIGHT,
pixels,
WIDTH * 4);
}
int
main (int argc, char **argv)
{
pixman_image_t *gradient_img;
pixman_image_t *src_img, *dst_img;
pixman_gradient_stop_t stops[2] =
{
{ pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } },
{ pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } }
};
pixman_point_fixed_t p1 = { 0, 0 };
pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH),
pixman_int_to_fixed (HEIGHT) };
pixman_point_fixed_t c_inner;
pixman_point_fixed_t c_outer;
pixman_fixed_t r_inner;
pixman_fixed_t r_outer;
pixman_region32_t clip_region;
pixman_transform_t trans = {
{ { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), },
{ pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), },
{ pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) }
}
};
gtk_init (&argc, &argv);
src_img = create_solid_bits (0xff0000ff);
c_inner.x = pixman_double_to_fixed (100.0);
c_inner.y = pixman_double_to_fixed (100.0);
c_outer.x = pixman_double_to_fixed (100.0);
c_outer.y = pixman_double_to_fixed (100.0);
r_inner = 0;
r_outer = pixman_double_to_fixed (100.0);
gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
r_inner, r_outer,
stops, 2);
#if 0
gradient_img = pixman_image_create_linear_gradient (&p1, &p2,
stops, 2);
#endif
pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img,
0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
pixman_region32_init_rect (&clip_region, 50, 0, 100, 200);
pixman_image_set_clip_region32 (src_img, &clip_region);
pixman_image_set_source_clipping (src_img, TRUE);
pixman_image_set_transform (src_img, &trans);
pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
dst_img = create_solid_bits (0xffff0000);
pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img,
0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
#if 0
printf ("0, 0: %x\n", src[0]);
printf ("10, 10: %x\n", src[10 * 10 + 10]);
printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
#endif
show_window (dst_img, WIDTH, HEIGHT, WIDTH);
pixman_image_unref (gradient_img);
pixman_image_unref (src_img);
return 0;
}
|