All pastes #450994 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-21 05:43 UTC
rendered paste body
void 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_pixmap_t pixmap;
        /* Fill in the pixmap */

        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_PIXMAP | XCB_CW_EVENT_MASK, /* masks */
                          cast(uint*)[pixmap, XCB_EVENT_MASK_EXPOSURE]);

        xcb_map_window(conn, window);

        xcb_flush(conn);
        while(1);
}