Change to the linux kernel coding style
[wmaker-crm.git] / wrlib / tests / view.c
1 #include <X11/Xlib.h>
2 #include "wraster.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include "tile.xpm"
6 Display *dpy;
7 Window win;
8 RContext *ctx;
9 RImage *img;
10 Pixmap pix;
11
12 int main(int argc, char **argv)
13 {
14 RContextAttributes attr;
15
16 dpy = XOpenDisplay("");
17 if (!dpy) {
18 puts("cant open display");
19 exit(1);
20 }
21
22 attr.flags = RC_RenderMode | RC_ColorsPerChannel;
23 attr.render_mode = RDitheredRendering;
24 attr.colors_per_channel = 4;
25 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
26
27 if (argc < 2)
28 img = RGetImageFromXPMData(ctx, image_name);
29 else
30 img = RLoadImage(ctx, argv[1], 0);
31
32 if (!img) {
33 puts(RMessageForError(RErrorCode));
34 exit(1);
35 }
36
37 if (argc > 2) {
38 RImage *tmp = img;
39
40 img = RScaleImage(tmp, tmp->width * atol(argv[2]), tmp->height * atol(argv[2]));
41 /*img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]),
42 tmp->height*atol(argv[2]));
43 */
44
45 RReleaseImage(tmp);
46 }
47 #if 0
48 if (argc > 2) {
49 img = RScaleImage(img, img->width * atof(argv[2]), img->height * atof(argv[2]));
50 }
51
52 {
53 RImage *tmp = RCreateImage(200, 200, True);
54 RColor col = { 0, 0, 255, 255 };
55
56 if (img->format == RRGBAFormat)
57 puts("alpha");
58 else
59 puts("no alpha");
60
61 RClearImage(tmp, &col);
62
63 RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
64 img = tmp;
65 }
66 #endif
67
68 if (!RConvertImage(ctx, img, &pix)) {
69 puts(RMessageForError(RErrorCode));
70 exit(1);
71 }
72
73 printf("%ix%i\n", img->width, img->height);
74
75 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, img->width, img->height, 0, 0, 0);
76 XSetWindowBackgroundPixmap(dpy, win, pix);
77 XClearWindow(dpy, win);
78 XMapRaised(dpy, win);
79 XFlush(dpy);
80 getchar();
81
82 return 0;
83 }