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 | #ifdef HAVE_CONFIG_H1 |
32 | #include "config.h" |
33 | #endif |
34 | |
35 | #include <stdlib.h> |
36 | #include <stdio.h> |
37 | #include <string.h> |
38 | |
39 | #include <xcb/xcb.h> |
40 | |
41 | #include <xcb/xcb_aux.h> |
42 | #include "xcb_image.h" |
43 | |
44 | #define W_W128 128 |
45 | #define W_H128 128 |
46 | |
47 | static void |
48 | reflect_window (xcb_connection_t *c, |
49 | xcb_drawable_t win, |
50 | xcb_drawable_t new_win, |
51 | xcb_gcontext_t gc, |
52 | uint16_t width, |
53 | uint16_t height) |
54 | { |
55 | xcb_image_t *image; |
56 | uint32_t pixel1; |
57 | uint32_t pixel2; |
58 | int32_t left_x; |
59 | int32_t right_x; |
60 | int32_t y; |
61 | int format; |
62 | |
63 | format = XCB_IMAGE_FORMAT_XY_PIXMAP; |
64 | |
65 | printf ("get_image %d %d\n", width, height); |
66 | image = xcb_image_get (c, win, |
67 | 0, 0, width, height, |
68 | 0xaaaaaaaa, |
69 | format); |
70 | if (!image) { |
71 | printf("xcb_image_get failed: exiting\n"); |
72 | exit(1); |
73 | } |
74 | |
75 | printf ("Create image summary:\n"); |
76 | printf (" * format................: %d\n", image->format); |
77 | printf (" * byte order............: %d\n", image->byte_order); |
78 | printf (" * bitmap order..........: %d\n", image->bit_order); |
79 | printf (" * bitmap pad............: %d\n", image->scanline_pad); |
80 | printf (" * depth.................: %d\n", image->depth); |
81 | printf (" * bytes/line............: %d\n", image->stride); |
82 | printf (" * bits/pixel (or unit)..: %d\n", image->bpp); |
83 | printf (" * plane_mask............: %#x\n", image->plane_mask); |
84 | |
85 | printf ("bpl %d %d\n", image->stride, image->height); |
86 | |
87 | printf("calculating reflection -- this may take awhile...\n"); |
88 | |
89 | for (left_x = 0 ; left_x < width/2 ; left_x++) |
90 | { |
91 | for (y = 0 ; y < height ; y++) |
92 | { |
93 | pixel1 = xcb_image_get_pixel (image, left_x, y); |
94 | right_x = width - left_x-1; |
95 | if (left_x != right_x) |
96 | { |
97 | pixel2 = xcb_image_get_pixel (image, right_x, y); |
98 | xcb_image_put_pixel (image, left_x, y, pixel2); |
99 | } |
100 | xcb_image_put_pixel (image, right_x, y, pixel1); |
101 | } |
102 | } |
103 | |
104 | printf("putting image\n"); |
105 | |
106 | xcb_image_put (c, new_win, gc, image, 0, 0, 0); |
107 | image = xcb_image_get (c, new_win, |
| Value stored to 'image' is never read |
108 | 0, 0, width, height, |
109 | ~0, |
110 | format); |
111 | |
112 | printf ("done\n"); |
113 | } |
114 | |
115 | int |
116 | main (int argc, char *argv[]) |
117 | { |
118 | xcb_connection_t *c; |
119 | xcb_screen_t *screen; |
120 | xcb_drawable_t win; |
121 | xcb_drawable_t new_win; |
122 | xcb_drawable_t rect; |
123 | xcb_rectangle_t rect_coord = { 0, 0, W_W128, W_H128}; |
124 | xcb_gcontext_t bgcolor, fgcolor; |
125 | xcb_point_t points[2]; |
126 | uint32_t mask; |
127 | uint32_t valgc[2]; |
128 | uint32_t valwin[3]; |
129 | int depth; |
130 | int screen_nbr; |
131 | xcb_generic_event_t *e; |
132 | |
133 | |
134 | c = xcb_connect (NULL((void *)0), &screen_nbr); |
135 | screen = xcb_aux_get_screen (c, screen_nbr); |
136 | depth = xcb_aux_get_depth (c, screen); |
137 | |
138 | |
139 | win = screen->root; |
140 | |
141 | fgcolor = xcb_generate_id(c); |
142 | mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; |
143 | valgc[0] = screen->black_pixel; |
144 | valgc[1] = 0; |
145 | xcb_create_gc(c, fgcolor, win, mask, valgc); |
146 | |
147 | bgcolor = xcb_generate_id(c); |
148 | mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; |
149 | valgc[0] = screen->white_pixel; |
150 | valgc[1] = 0; |
151 | xcb_create_gc(c, bgcolor, win, mask, valgc); |
152 | |
153 | |
154 | win = xcb_generate_id(c); |
155 | |
156 | |
157 | mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE; |
158 | valwin[0] = screen->white_pixel; |
159 | valwin[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE; |
160 | valwin[2] = XCB_EVENT_MASK_BUTTON_PRESS; |
161 | xcb_create_window (c, |
162 | 0, |
163 | win, |
164 | screen->root, |
165 | 0, 0, |
166 | W_W128, W_H128, |
167 | 10, |
168 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
169 | screen->root_visual, |
170 | mask, valwin); |
171 | |
172 | |
173 | xcb_change_property (c, XCB_PROP_MODE_REPLACE, win, |
174 | XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, |
175 | strlen ("drew"), "drew"); |
176 | |
177 | |
178 | xcb_map_window (c, win); |
179 | |
180 | |
181 | rect = xcb_generate_id (c); |
182 | xcb_create_pixmap(c, depth, rect, win, W_W128, W_H128); |
183 | xcb_poly_fill_rectangle(c, rect, bgcolor, 1, &rect_coord); |
184 | points[0].x = 0; |
185 | points[0].y = 0; |
186 | points[1].x = W_W128; |
187 | points[1].y = W_H128; |
188 | xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points); |
189 | points[0].x = W_W128 / 4; |
190 | points[0].y = 0; |
191 | points[1].x = W_W128 / 2; |
192 | points[1].y = W_H128 / 2; |
193 | xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points); |
194 | |
195 | |
196 | new_win = xcb_generate_id(c); |
197 | |
198 | |
199 | mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE; |
200 | valwin[0] = screen->white_pixel; |
201 | valwin[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE; |
202 | valwin[2] = XCB_EVENT_MASK_BUTTON_PRESS; |
203 | xcb_create_window (c, |
204 | 0, |
205 | new_win, |
206 | screen->root, |
207 | 0, 0, |
208 | W_W128, W_H128, |
209 | 10, |
210 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
211 | screen->root_visual, |
212 | mask, valwin); |
213 | |
214 | xcb_change_property (c, XCB_PROP_MODE_REPLACE, new_win, |
215 | XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, |
216 | strlen ("got"), "got"); |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | xcb_map_window (c, new_win); |
223 | |
224 | |
225 | xcb_flush (c); |
226 | |
227 | while ((e = xcb_wait_for_event(c))) |
228 | { |
229 | switch (e->response_type) |
230 | { |
231 | case XCB_EXPOSE12: |
232 | { |
233 | xcb_copy_area(c, rect, win, bgcolor, |
234 | 0, 0, 0, 0, W_W128, W_H128); |
235 | reflect_window (c, win, new_win, |
236 | fgcolor, |
237 | W_W128, W_H128); |
238 | xcb_flush (c); |
239 | break; |
240 | } |
241 | } |
242 | free (e); |
243 | } |
244 | |
245 | return 1; |
246 | } |