Updating to version 0.20.2
[wmaker-crm.git] / wrlib / test.c
blob66a663e941fdeecf728956ee2dae51fec1b42694
2 #include <X11/Xlib.h>
3 #include "wraster.h"
4 #include <stdio.h>
6 Display *dpy;
7 Window win;
8 RContext *ctx;
9 RImage *img, *tile, *new, *mini, *tiled;
10 Pixmap pix;
12 void main(int argc, char **argv)
14 RContextAttributes attr;
15 int a=0;
17 if (argc<1) {
18 puts("You must supply t,p or x as the file type to load");
19 puts("t is tiff, p is png and x is xpm");
20 exit(0);
23 if (argc>1) {
24 if (argv[1][0]=='t')
25 a=1;
26 else if (argv[1][0]=='p')
27 a=2;
28 else a=0;
31 dpy = XOpenDisplay("");
32 if (!dpy) {
33 puts("cant open display");
34 exit(1);
36 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
37 0, 0, 0);
38 XMapRaised(dpy, win);
39 XFlush(dpy);
40 attr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_DefaultVisual;
42 attr.render_mode = RM_DITHER;
43 attr.colors_per_channel = 4;
44 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
45 #ifdef USE_TIFF
46 if (a==1)
47 img = RLoadImage(ctx, "ballot_box.tiff", 0);
48 #endif
49 #ifdef USE_PNG
50 if (a==2)
51 img = RLoadImage(ctx, "test.png", 0);
52 #endif
53 #ifdef USE_XPM
54 if (a==0)
55 img = RLoadImage(ctx, "ballot_box.xpm", 0);
56 #endif
58 if (!img) {
59 puts(RMessageForError(RErrorCode));
60 exit(1);
62 new = RLoadImage(ctx, "tile.xpm", 0);
63 if (!new) {
64 puts(RMessageForError(RErrorCode));
65 exit(1);
67 RCombineArea(new, img, 0, 0, img->width, img->height, 8, 8);
68 RConvertImage(ctx, new, &pix);
69 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, new->width, new->height,
70 0, 0);
72 mini = RScaleImage(new, 20, 20);
73 RConvertImage(ctx, mini, &pix);
74 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, 20, 20,
75 new->width, new->height);
77 tiled = RMakeTiledImage(img, 160, 160);
78 RConvertImage(ctx, tiled, &pix);
79 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, 160, 160,
80 new->width+mini->width, new->height+mini->height);
82 XFlush(dpy);
83 getchar();