17 RImage *img, *tile, *icon, *tmp;
18 RColor color, from, to;
22 XSetWindowAttributes val;
26 val.background_pixel = ctx->black;
27 val.colormap = ctx->cmap;
28 win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 128, 256,
29 0, ctx->depth, InputOutput, ctx->visual, CWColormap | CWBackPixel, &val);
30 back = XCreatePixmap(ctx->dpy, ctx->drawable, 128, 256, ctx->depth);
32 /* Dark blue tile gradient */
42 /* Standard gray tile gradient */
52 /* Make the tile, and put it as a sample in the first place */
53 tile = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);
54 img = RCloneImage(tile);
55 RConvertImage(ctx, img, &pix);
56 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 0);
58 /* Read the image, and combine it with the tile. Put it as a sample
59 * in the second slot, and also save a copy for later use. */
60 icon = RLoadImage(ctx, "ballot_box.xpm", 0);
62 puts(RMessageForError(RErrorCode));
65 RCombineArea(img, icon, 0, 0, icon->width, icon->height, 8, 8);
68 RConvertImage(ctx, img, &pix);
69 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 0);
71 img = RCloneImage(tile);
73 /* Draw random pixels on image */
74 for (i = 0; i < 200; i++) {
75 color.red = rand() % 256;
76 color.green = rand() % 256;
77 color.blue = rand() % 256;
81 RPutPixel(img, x, y, &color);
84 RConvertImage(ctx, img, &pix);
85 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 64);
88 img = RCloneImage(tile);
90 /* Alter random pixels in image with the same amount for r/g/b */
91 for (i = 0; i < 200; i++) {
92 cdelta.red = cdelta.green = cdelta.blue = rand() % 511 - 255;
96 ROperatePixel(img, RAddOperation, x, y, &cdelta);
99 RConvertImage(ctx, img, &pix);
100 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 64);
103 img = RCloneImage(tile);
105 /* Draw lines in all directions to test different slopes */
110 for (i = 0; i < 16; i++)
111 segs[i].x1 = segs[i].y1 = 31;
113 segs[6].x2 = segs[7].x2 = segs[8].x2 = segs[9].x2 = segs[10].x2 = 0;
114 segs[2].y2 = segs[3].y2 = segs[4].y2 = segs[5].y2 = segs[6].y2 = 0;
115 segs[5].x2 = segs[11].x2 = 16;
116 segs[1].y2 = segs[7].y2 = 16;
117 segs[4].x2 = segs[12].x2 = 31;
118 segs[0].y2 = segs[8].y2 = 31;
119 segs[3].x2 = segs[13].x2 = 46;
120 segs[9].y2 = segs[15].y2 = 46;
121 segs[0].x2 = segs[1].x2 = segs[2].x2 = segs[14].x2 = segs[15].x2 = 62;
122 segs[10].y2 = segs[11].y2 = segs[12].y2 = segs[13].y2 = segs[14].y2 = 62;
123 RDrawSegments(img, segs, 9, &color);
125 /* Also test how alpha channel behaves when drawing lines */
127 RDrawSegments(img, &segs[9], 7, &color);
129 RConvertImage(ctx, img, &pix);
130 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 128);
133 img = RCloneImage(tile);
135 /* Alter lines in all directions (test different slopes) */
136 cdelta.red = cdelta.green = cdelta.blue = 80;
138 ROperateSegments(img, RAddOperation, segs, 16, &cdelta);
140 RConvertImage(ctx, img, &pix);
141 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 128);
145 /* Create a bevel around the icon, and save it for a later use */
147 cdelta.red = cdelta.green = cdelta.blue = 80;
149 ROperateLine(img, RAddOperation, 8, 8, 56, 8, &cdelta);
150 ROperateLine(img, RAddOperation, 8, 9, 8, 56, &cdelta);
151 cdelta.red = cdelta.green = cdelta.blue = 40;
153 ROperateLine(img, RSubtractOperation, 8, 56, 56, 56, &cdelta);
154 ROperateLine(img, RSubtractOperation, 56, 8, 56, 55, &cdelta);
156 tmp = RCloneImage(img);
158 /* Draw some solid lines over the icon */
163 for (i = 16; i < 24; i++) {
164 RDrawLine(img, 9, i, 55, i, &color);
167 /* Also try some lines with alpha over the icon */
169 for (i = 40; i < 48; i++) {
170 RDrawLine(img, 9, i, 55, i, &color);
173 RConvertImage(ctx, img, &pix);
174 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 192);
178 /* Restore the image with the icon, and alter some lines */
180 cdelta.red = cdelta.green = cdelta.blue = 80;
182 for (i = 16; i < 24; i++) {
183 ROperateLine(img, RSubtractOperation, 9, i, 55, i, &cdelta);
185 cdelta.red = cdelta.green = cdelta.blue = 80;
186 for (i = 40; i < 48; i++) {
187 ROperateLine(img, RAddOperation, 9, i, 55, i, &cdelta);
190 RConvertImage(ctx, img, &pix);
191 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 64, 192);
193 XSetWindowBackgroundPixmap(dpy, win, back);
194 XMapRaised(dpy, win);
195 XClearWindow(dpy, win);
202 RColor color, from, to;
203 XSetWindowAttributes val;
207 val.background_pixel = ctx->black;
208 val.colormap = ctx->cmap;
209 win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 140, 140,
210 0, ctx->depth, InputOutput, ctx->visual, CWColormap | CWBackPixel, &val);
211 back = XCreatePixmap(ctx->dpy, ctx->drawable, 140, 140, ctx->depth);
213 /* Standard gray tile gradient */
223 /* Dark blue tile gradient */
233 /* Create Background */
234 img = RCreateImage(140, 140, True);
239 RClearImage(img, &color);
240 RConvertImage(ctx, img, &pix);
241 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 140, 140, 0, 0);
244 tile = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);
246 img = RCloneImage(tile);
247 RBevelImage(img, RBEV_SUNKEN);
248 RConvertImage(ctx, img, &pix);
249 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 3, 3);
252 img = RCloneImage(tile);
253 RBevelImage(img, RBEV_RAISED);
254 RConvertImage(ctx, img, &pix);
255 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 73, 3);
258 img = RCloneImage(tile);
259 RBevelImage(img, RBEV_RAISED2);
260 RConvertImage(ctx, img, &pix);
261 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 3, 73);
264 img = RCloneImage(tile);
265 RBevelImage(img, RBEV_RAISED3);
266 RConvertImage(ctx, img, &pix);
267 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 73, 73);
270 XSetWindowBackgroundPixmap(dpy, win, back);
271 XMapRaised(dpy, win);
272 XClearWindow(dpy, win);
280 XSetWindowAttributes val;
284 val.background_pixel = ctx->black;
285 val.colormap = ctx->cmap;
286 win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 140, 140,
287 0, ctx->depth, InputOutput, ctx->visual, CWColormap | CWBackPixel, &val);
288 XStoreName(dpy, win, "Scale");
289 pix = XCreatePixmap(ctx->dpy, ctx->drawable, 140, 140, ctx->depth);
291 image = RLoadImage(ctx, "ballot_box.xpm", 0);
293 puts("couldnt load ballot_box.xpm");
297 scaled = RScaleImage(image, 140, 140);
299 RReleaseImage(image);
300 RConvertImage(ctx, scaled, &pix);
301 XSetWindowBackgroundPixmap(dpy, win, pix);
302 XMapRaised(dpy, win);
303 XClearWindow(dpy, win);
312 XSetWindowAttributes val;
316 image = RLoadImage(ctx, "ballot_box.xpm", 0);
318 puts("couldnt load ballot_box.xpm");
322 image = RScaleImage(image, 90, 180);
324 val.background_pixel = ctx->black;
325 val.colormap = ctx->cmap;
326 win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, image->height,
327 image->width, 0, ctx->depth, InputOutput, ctx->visual, CWColormap | CWBackPixel, &val);
328 XStoreName(dpy, win, "Rotate");
329 pix = XCreatePixmap(ctx->dpy, ctx->drawable, image->height, image->width, ctx->depth);
331 rotated = RRotateImage(image, 90.0);
333 RReleaseImage(image);
334 RConvertImage(ctx, rotated, &pix);
335 XSetWindowBackgroundPixmap(dpy, win, pix);
336 XMapRaised(dpy, win);
337 XClearWindow(dpy, win);
344 RColor color, from, to, tmp;
345 RColor cdelta, cdelta1;
347 XSetWindowAttributes val;
351 val.background_pixel = ctx->black;
352 val.colormap = ctx->cmap;
353 win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 64, 64,
354 0, ctx->depth, InputOutput, ctx->visual, CWColormap | CWBackPixel, &val);
355 back = XCreatePixmap(ctx->dpy, ctx->drawable, 64, 64, ctx->depth);
357 /* Standard gray tile gradient */
367 /* Dark blue tile gradient */
377 img = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);
379 RBevelImage(img, RBEV_RAISED3);
382 color.red = color.green = color.blue = 0;
385 cdelta.red = cdelta.green = cdelta.blue = 80;
388 cdelta1.red = cdelta1.green = cdelta1.blue = 40;
390 segs[0].x1 = segs[2].y1 = segs[4].x1 = segs[4].x2 = 63 - 21;
391 segs[0].x2 = segs[2].y2 = segs[1].x2 = segs[3].y2 = 63 - 2;
392 segs[0].y1 = segs[2].x1 = segs[1].y1 = segs[3].x1 = 2;
393 segs[0].y2 = segs[2].x2 = segs[6].x1 = segs[6].x2 = 21;
394 segs[1].x1 = segs[3].y1 = segs[5].x1 = segs[5].x2 = 63 - 22;
395 segs[1].y2 = segs[3].x2 = segs[7].x1 = segs[7].x2 = 22;
397 segs[4].y1 = segs[5].y1 = segs[10].x1 = segs[11].x1 = 0;
398 segs[4].y2 = segs[5].y2 = segs[10].x2 = segs[11].x2 = 1;
399 segs[6].y1 = segs[7].y1 = segs[8].x1 = segs[9].x1 = 63 - 1;
400 segs[6].y2 = segs[7].y2 = segs[8].x2 = segs[9].x2 = 63;
401 segs[8].y1 = segs[8].y2 = 21;
402 segs[9].y1 = segs[9].y2 = 22;
403 segs[10].y1 = segs[10].y2 = 63 - 21;
404 segs[11].y1 = segs[11].y2 = 63 - 22;
406 RDrawSegments(img, segs, 12, &color);
408 segs[0].x1 = segs[3].y1 = 63 - 20;
409 segs[0].x2 = segs[1].y2 = segs[2].x2 = segs[3].y2 = 63 - 2;
410 segs[0].y1 = segs[1].x1 = segs[2].y1 = segs[3].x1 = 2;
411 segs[1].y1 = segs[2].x1 = 63 - 23;
412 segs[0].y2 = segs[3].x2 = 20;
413 segs[1].x2 = segs[2].y2 = 23;
414 /* Bevels arround black segments */
415 ROperateSegments(img, RAddOperation, segs, 2, &cdelta);
416 ROperateSegments(img, RSubtractOperation, &segs[2], 2, &cdelta1);
418 RGetPixel(img, 63 - 2, 20, &tmp);
419 /*RPutPixel(img, 63-1, 23, &tmp); */
420 RDrawLine(img, 63 - 1, 23, 63, 23, &tmp);
421 RGetPixel(img, 63 - 23, 2, &tmp);
422 RDrawLine(img, 63 - 23, 0, 63 - 23, 1, &tmp);
424 RGetPixel(img, 23, 63 - 2, &tmp);
425 /*RPutPixel(img, 23, 63-1, &tmp); */
426 RDrawLine(img, 23, 63 - 1, 23, 63, &tmp);
427 RGetPixel(img, 2, 63 - 20, &tmp);
428 RDrawLine(img, 0, 63 - 23, 1, 63 - 23, &tmp);
431 color.red = color.green = color.blue = 0;
434 cdelta.red = cdelta.green = cdelta.blue = 80;
437 cdelta1.red = cdelta1.green = cdelta1.blue = 40;
439 RDrawLine(img, 63 - 21, 2, 63 - 2, 21, &color); /* upper 2 black lines */
440 ROperateLine(img, RAddOperation, 63 - 20, 2, 63 - 2, 20, &cdelta); /* the bevel arround them */
441 ROperateLine(img, RSubtractOperation, 63 - 22, 2, 63 - 2, 22, &cdelta1);
442 RDrawLine(img, 63 - 21, 0, 63 - 21, 1, &color); /* upper small black lines */
443 RDrawLine(img, 63 - 1, 21, 63, 21, &color);
445 RGetPixel(img, 63 - 2, 20, &tmp);
446 RPutPixel(img, 63 - 1, 22, &tmp);
447 RGetPixel(img, 2, 63 - 22, &tmp);
448 RDrawLine(img, 63 - 22, 0, 63 - 22, 1, &tmp);
450 RDrawLine(img, 2, 63 - 21, 21, 63 - 2, &color); /* lower 2 black lines */
451 ROperateLine(img, RSubtractOperation, 2, 63 - 20, 20, 63 - 2, &cdelta1); /* the bevel arround them */
452 ROperateLine(img, RAddOperation, 2, 63 - 22, 22, 63 - 2, &cdelta);
453 RDrawLine(img, 21, 63 - 1, 21, 63, &color); /* lower small black lines */
454 RDrawLine(img, 0, 63 - 21, 1, 63 - 21, &color);
455 ROperateLine(img, RAddOperation, 22, 63 - 1, 22, 63, &cdelta);
456 /*ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta); *//* the bevel arround them */
457 ROperateLine(img, RSubtractOperation, 0, 63 - 22, 1, 63 - 22, &cdelta1);
460 RConvertImage(ctx, img, &pix);
461 XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 0);
464 XSetWindowBackgroundPixmap(dpy, win, back);
465 XMapRaised(dpy, win);
466 XClearWindow(dpy, win);
475 double t1, t2, total, d1 = 0, d2 = 0, d3 = 0;
476 struct timeval timev;
479 puts("Starting benchmark");
481 gettimeofday(&timev, NULL);
482 t1 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
484 img = RCreateImage(1024, 768, True);
486 gettimeofday(&timev, NULL);
487 t2 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
489 printf("Image created in %f sec\n", total);
491 gettimeofday(&timev, NULL);
492 t1 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
498 RClearImage(img, &color);
504 cdelta.red = cdelta.green = cdelta.blue = 80;
507 gettimeofday(&timev, NULL);
508 t2 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
510 printf("Image filled in %f sec\n", total);
512 for (j = 1; j < 6; j++) {
513 printf("Pass %d...\n", j);
514 gettimeofday(&timev, NULL);
515 t1 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
518 for (i = 0; i < 10000; i++) {
519 RDrawLine(img, 0, i % 64, i % 64, 63, &color);
522 gettimeofday(&timev, NULL);
523 t2 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
525 printf("Drawing 10000 lines in %f sec\n", total);
528 gettimeofday(&timev, NULL);
529 t1 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
532 for (i = 0; i < 10000; i++) {
533 RDrawLine(img, 0, i % 64, i % 64, 63, &color);
536 gettimeofday(&timev, NULL);
537 t2 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
539 printf("Drawing 10000 lines with alpha in %f sec\n", total);
542 gettimeofday(&timev, NULL);
543 t1 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
545 for (i = 0; i < 10000; i++) {
546 ROperateLine(img, RAddOperation, 0, i % 64, i % 64, 63, &cdelta);
549 gettimeofday(&timev, NULL);
550 t2 = (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
552 printf("Altering 10000 lines in %f sec\n", total);
555 printf("Average: %f, %f, %f\n", d1 / 5, d2 / 5, d3 / 5);
560 int main(int argc, char **argv)
562 RContextAttributes attr;
565 ProgName = strrchr(argv[0], '/');
571 dpy = XOpenDisplay("");
573 puts("cant open display");
577 attr.flags = RC_RenderMode | RC_ColorsPerChannel;
579 attr.render_mode = RDitheredRendering;
580 attr.colors_per_channel = 4;
583 attr.flags |= RC_VisualID;
584 attr.visualid = visualID;
587 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
590 printf("could not initialize graphics library context: %s\n", RMessageForError(RErrorCode));
594 /* Here are the things we want to test */