rendered paste bodyvoid main()
{
/* Load the image */
char[] filename = "/home/joe/plasma.png";
ubyte[] image;
Info info = lodepng.png.decode32(image, cast(ubyte[])read(filename));
if (info.error != 0)
throw new Exception("Error loading png " ~ filename ~ ", errorcode: " ~ toString(info.error));
if(image.length % 4 != 0)
throw new Exception("Failcopter");
ubyte[] data;
for(uint i; i<image.length; i+=4){
data ~= image[i+2];
data ~= image[i+1];
data ~= image[i];
data ~= image[i+3];
}
image = null;
/* 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(c));
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 */
[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);
/*
Visual* vis = XDefaultVisualOfScreen(screen);
XImage* im = XCreateImage(disp, vis, 24, ZPixmap, 0, data.ptr, info.w, info.h, 8, 0);
data = null;
XPutImage(disp, win, gc, im, 0, 0, 0, 0, info.w, info.h);
*/
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);
}
}
}