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