File: view.c

package info (click to toggle)
wmaker 0.96.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,416 kB
  • sloc: ansic: 99,483; sh: 7,068; perl: 3,423; makefile: 1,647; lisp: 219; python: 34
file content (85 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <X11/Xlib.h>
#include "wraster.h"
#include <stdlib.h>
#include <stdio.h>
#include "tile.xpm"
Display *dpy;
Window win;
RContext *ctx;
RImage *img;
Pixmap pix;

int main(int argc, char **argv)
{
	RContextAttributes attr;

	dpy = XOpenDisplay("");
	if (!dpy) {
		puts("cant open display");
		exit(1);
	}

	attr.flags = RC_RenderMode | RC_ColorsPerChannel;
	attr.render_mode = RDitheredRendering;
	attr.colors_per_channel = 4;
	ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);

	if (argc < 2) {
		printf("using default image as none was provided\n");
		img = RGetImageFromXPMData(ctx, image_name);
	}
	else
		img = RLoadImage(ctx, argv[1], 0);

	if (!img) {
		puts(RMessageForError(RErrorCode));
		exit(1);
	}

	if (argc > 2) {
		RImage *tmp = img;

		img = RScaleImage(tmp, tmp->width * atol(argv[2]), tmp->height * atol(argv[2]));
		/*img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]),
		   tmp->height*atol(argv[2]));
		 */

		RReleaseImage(tmp);
	}
#if 0
	if (argc > 2) {
		img = RScaleImage(img, img->width * atof(argv[2]), img->height * atof(argv[2]));
	}

	{
		RImage *tmp = RCreateImage(200, 200, True);
		RColor col = { 0, 0, 255, 255 };

		if (img->format == RRGBAFormat)
			puts("alpha");
		else
			puts("no alpha");

		RClearImage(tmp, &col);

		RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
		img = tmp;
	}
#endif

	if (!RConvertImage(ctx, img, &pix)) {
		puts(RMessageForError(RErrorCode));
		exit(1);
	}

	printf("size is %ix%i\n", img->width, img->height);

	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, img->width, img->height, 0, 0, 0);
	XSetWindowBackgroundPixmap(dpy, win, pix);
	XClearWindow(dpy, win);
	XMapRaised(dpy, win);
	XFlush(dpy);
	getchar();

	return 0;
}