rendered paste bodyvoid main()
{
/* Load the image */
char[] filename = "/home/joe/plasma.png";
ubyte[] data;
Info info = lodepng.png.decode32(data, cast(ubyte[])read(filename));
if (info.error != 0)
throw new Exception("Error loading png " ~ filename ~ ", errorcode: " ~ toString(info.error));
if(data.length % 4 != 0)
throw new Exception("Failcopter");
for(uint i; i<image.length; i+=4){
ubyte temp = data[i+2]
data[i+2] = data[i];
data[i] = temp;
}
/* Display the image to an X window, with XCB */
int screen_num;
xcb_connection_t* conn = xcb_connect(null, &screen_num);
/* Get the preferred screen. */
xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
while(screen_num--)
xcb_screen_next(&screen_iter);
xcb_screen_t* screen = screen_iter.data;
xcb_window_t window = xcb_generate_id(conn);
xcb_create_window(conn, /* connection */
0, /* depth */
window, /* window id */
screen.root, /* parent window */
0, 0, /* x, y */
info.w, info.w, /* width, height */
0, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
screen.root_visual, /* visual */
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, /* masks */
cast(uint*)[screen.black_pixel, XCB_EVENT_MASK_EXPOSURE]);
xcb_map_window(conn, window);
xcb_gcontext_t gc = xcb_generate_id(conn);
xcb_create_gc(conn, gc, window, 0, null);
xcb_flush(conn);
xcb_generic_event_t *event;
while(1) {
event = xcb_wait_for_event(conn);
if(event.response_type == XCB_EXPOSE) {
xcb_put_image(conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
window, gc,
info.w, info.h, /* width, height */
0, 0, /* dst_x, dst_y */
0, 24, /* left_pad, depth */
data.length, data.ptr);
xcb_flush(conn);
}
}
}