
#include <X11/Xlib.h>
#include "../wraster.h"
#include <stdio.h>

Display *dpy;
Window win;
RContext *ctx;
RImage *img, *tile, *new, *mini;
Pixmap pix;

void main()
{
    RContextAttributes attr;

    dpy = XOpenDisplay("");
    if (!dpy) {
	puts("cant open display");
	exit(1);
    }
    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 100, 100,
			      0, 0, 0);
    XMapRaised(dpy, win);
    XFlush(dpy);    
    attr.flags = RC_RenderMode | RC_ColorsPerChannel;

    attr.render_mode = RM_DITHER;
    attr.colors_per_channel = 4;
    ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
#ifdef PNG
    img = RLoadImage(ctx, "test.png", 0);
#else
    img = RLoadImage(ctx, "Clipboard.xpm", 0);
#endif
    if (!img) {
	puts(RErrorString);
	exit(1);
    }
    new = RLoadImage(ctx, "tile.xpm", 0);
    if (!new) {
	puts(RErrorString);
	exit(1);
    }
    RCombineArea(new, img, 0, 0, img->width, img->height, 8, 8);
    RConvertImage(ctx, new, &pix);
    XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, new->width, new->height, 
	      0, 0);

    mini = RScaleImage(new, 16, 16);
    RConvertImage(ctx, mini, &pix);
    XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, 16, 16, 
		new->width, new->height);
    
    XFlush(dpy);
    getchar();  
}
