Files
wmaker/wrlib/tests/view.c
T

86 lines
1.7 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
#include <X11/Xlib.h>
1998-10-21 14:43:47 +00:00
#include "wraster.h"
1998-09-29 22:36:29 +00:00
#include <stdlib.h>
#include <stdio.h>
#include "tile.xpm"
Display *dpy;
Window win;
RContext *ctx;
RImage *img;
Pixmap pix;
2009-08-20 00:59:40 +02:00
int main(int argc, char **argv)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
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);
2014-04-16 22:29:49 +02:00
if (argc < 2) {
printf("using default image as none was provided\n");
2009-08-20 00:59:40 +02:00
img = RGetImageFromXPMData(ctx, image_name);
2014-04-16 22:29:49 +02:00
}
2009-08-20 00:59:40 +02:00
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);
}
2001-02-18 00:41:22 +00:00
#if 0
2009-08-20 00:59:40 +02:00
if (argc > 2) {
img = RScaleImage(img, img->width * atof(argv[2]), img->height * atof(argv[2]));
}
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
{
RImage *tmp = RCreateImage(200, 200, True);
RColor col = { 0, 0, 255, 255 };
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
if (img->format == RRGBAFormat)
puts("alpha");
else
puts("no alpha");
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
RClearImage(tmp, &col);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
img = tmp;
}
2000-05-21 15:33:27 +00:00
#endif
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
if (!RConvertImage(ctx, img, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
2004-10-12 21:28:27 +00:00
2014-04-16 22:29:49 +02:00
printf("size is %ix%i\n", img->width, img->height);
2009-08-20 00:59:40 +02:00
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();
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
return 0;
1998-09-29 22:36:29 +00:00
}