Change to the linux kernel coding style
[wmaker-crm.git] / wrlib / tests / testrot.c
1
2 #include <X11/Xlib.h>
3 #include "wraster.h"
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include "tile.xpm"
8 Display *dpy;
9 Window win;
10 RContext *ctx;
11 RImage *img;
12 Pixmap pix;
13
14 #define MAX(a,b) (a)>(b) ? (a) : (b)
15
16 int main(int argc, char **argv)
17 {
18 RContextAttributes attr;
19 float a;
20
21 dpy = XOpenDisplay("");
22 if (!dpy) {
23 puts("cant open display");
24 exit(1);
25 }
26
27 attr.flags = RC_RenderMode | RC_ColorsPerChannel;
28 attr.render_mode = RDitheredRendering;
29 attr.colors_per_channel = 4;
30 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
31
32 if (argc < 2)
33 img = RGetImageFromXPMData(ctx, image_name);
34 else
35 img = RLoadImage(ctx, argv[1], 0);
36
37 if (!img) {
38 puts(RMessageForError(RErrorCode));
39 exit(1);
40 }
41 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
42 MAX(img->width, img->height), MAX(img->height, img->width), 0, 0, 0);
43 XMapRaised(dpy, win);
44 XFlush(dpy);
45
46 a = 0;
47 while (1) {
48 RImage *tmp;
49
50 a = a + 1.0;
51
52 tmp = RRotateImage(img, a);
53 if (!RConvertImage(ctx, tmp, &pix)) {
54 puts(RMessageForError(RErrorCode));
55 exit(1);
56 }
57 RReleaseImage(tmp);
58
59 XSetWindowBackgroundPixmap(dpy, win, pix);
60 XFreePixmap(dpy, pix);
61 XClearWindow(dpy, win);
62 XSync(dpy, 0);
63 usleep(50000);
64 }
65 exit(0);
66 }