rem: puts(RErrorString);
add: puts(RMessageForError(RErrorCode));
context: testDraw(){    RImage *img, *tile, *icon, *tmp;    RColor color, from, to;    RColor cdelta;    RSegment segs[20];    int i, x, y;    XSetWindowAttributes val;    Pixmap pix, back;    Window win;    val.background_pixel = ctx->black;    val.colormap = ctx->cmap;    win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 128, 256,                        0, ctx->depth, InputOutput, ctx->visual,                        CWColormap|CWBackPixel, &val);    back = XCreatePixmap(ctx->dpy, ctx->drawable, 128, 256, ctx->depth);    /* Dark blue tile gradient */    from.red = 0x28;    from.green = 0x45;    from.blue = 0x69;    from.alpha = 0xff;    to.red = 0x08;    to.green = 0x24;    to.blue = 0x20;    to.alpha = 0xff;    /* Standard gray tile gradient */    /*from.red = 0xa6;    from.green = 0xa6;    from.blue = 0xb6;    from.alpha = 0xff;    to.red = 0x51;    to.green = 0x55;    to.blue = 0x61;    to.alpha = 0xff;*/    /* Make the tile, and put it as a sample in the first place */    tile = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);    img = RCloneImage(tile);    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 0);    /* Read the image, and combine it with the tile. Put it as a sample     * in the second slot, and also save a copy for later use. */    icon = RLoadImage(ctx, "ballot_box.xpm", 0);    if (!icon) {	puts(RErrorString);	exit(1);    }    RCombineArea(img, icon, 0, 0, icon->width, icon->height, 8, 8);    RDestroyImage(icon);    tmp = img;    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 0);    img = RCloneImage(tile);    /* Draw random pixels on image */    for (i=0; i< 200; i++) {        color.red = rand()%256;        color.green = rand()%256;        color.blue = rand()%256;        color.alpha = 255;        x = rand()%64;        y = rand()%64;        RPutPixel(img, x, y, &color);    }    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 64);    RDestroyImage(img);    img = RCloneImage(tile);    /* Alter random pixels in image with the same amount for r/g/b */    for (i=0; i< 200; i++) {        cdelta.red = cdelta.green = cdelta.blue = rand()%511 - 255;        cdelta.alpha = 0;        x = rand()%64;        y = rand()%64;        ROperatePixel(img, RAddOperation, x, y, &cdelta);    }    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 64);    RDestroyImage(img);    img = RCloneImage(tile);    /* Draw lines in all directions to test different slopes */    color.red = 0xff;    color.green = 0x7d;    color.blue = 0x52;    color.alpha = 0xff;    for (i=0; i<16; i++)        segs[i].x1 = segs[i].y1 = 31;    segs[6].x2 = segs[7].x2 = segs[8].x2 = segs[9].x2 = segs[10].x2 = 0;    segs[2].y2 = segs[3].y2 = segs[4].y2 = segs[5].y2 = segs[6].y2 = 0;    segs[5].x2 = segs[11].x2 = 16;    segs[1].y2 = segs[7].y2 = 16;    segs[4].x2 = segs[12].x2 = 31;    segs[0].y2 = segs[8].y2 = 31;    segs[3].x2 = segs[13].x2 = 46;    segs[9].y2 = segs[15].y2 = 46;    segs[0].x2 = segs[1].x2 = segs[2].x2 = segs[14].x2 = segs[15].x2 = 62;    segs[10].y2 = segs[11].y2 = segs[12].y2 = segs[13].y2 = segs[14].y2 = 62;    RDrawSegments(img, segs, 9, &color);    /* Also test how alpha channel behaves when drawing lines */    color.alpha = 0x80;    RDrawSegments(img, &segs[9], 7, &color);    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 128);    RDestroyImage(img);    img = RCloneImage(tile);    /* Alter lines in all directions (test different slopes) */    cdelta.red = cdelta.green = cdelta.blue = 80;    cdelta.alpha = 0;    ROperateSegments(img, RAddOperation, segs, 16, &cdelta);    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 128);    RDestroyImage(img);    /* Create a bevel around the icon, and save it for a later use */    img = tmp;    cdelta.red = cdelta.green = cdelta.blue = 80;    cdelta.alpha = 0;    ROperateLine(img, RAddOperation, 8, 8, 56, 8, &cdelta);    ROperateLine(img, RAddOperation, 8, 9, 8, 56, &cdelta);    cdelta.red = cdelta.green = cdelta.blue = 40;    cdelta.alpha = 0;    ROperateLine(img, RSubtractOperation, 8, 56, 56, 56, &cdelta);    ROperateLine(img, RSubtractOperation, 56, 8, 56, 55, &cdelta);    RDestroyImage(tile);    tmp = RCloneImage(img);    /* Draw some solid lines over the icon */    color.red = 0xff;    color.green = 0x7d;    color.blue = 0x52;    color.alpha = 0xff;    for (i=16; i<24; i++) {        RDrawLine(img, 9, i, 55, i, &color);    }    /* Also try some lines with alpha over the icon */    color.alpha = 0x80;    for (i=40; i<48; i++) {        RDrawLine(img, 9, i, 55, i, &color);    }    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 192);    RDestroyImage(img);    /* Restore the image with the icon, and alter some lines */    img = tmp;    cdelta.red = cdelta.green = cdelta.blue = 80;    cdelta.alpha = 0;    for (i=16; i<24; i++) {        ROperateLine(img, RSubtractOperation, 9, i, 55, i, &cdelta);    }    cdelta.red = cdelta.green = cdelta.blue = 80;    for (i=40; i<48; i++) {        ROperateLine(img, RAddOperation, 9, i, 55, i, &cdelta);    }    RConvertImage(ctx, img, &pix);    XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 192);    XSetWindowBackgroundPixmap(dpy, win, back);    XMapRaised(dpy, win);    XClearWindow(dpy, win);    XFlush(dpy);}