20 RImage
*img
, *tile
, *icon
, *tmp
;
21 RColor color
, from
, to
;
25 XSetWindowAttributes val
;
29 val
.background_pixel
= ctx
->black
;
30 val
.colormap
= ctx
->cmap
;
31 win
= XCreateWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 128, 256,
32 0, ctx
->depth
, InputOutput
, ctx
->visual
,
33 CWColormap
|CWBackPixel
, &val
);
34 back
= XCreatePixmap(ctx
->dpy
, ctx
->drawable
, 128, 256, ctx
->depth
);
36 /* Dark blue tile gradient */
46 /* Standard gray tile gradient */
56 /* Make the tile, and put it as a sample in the first place */
57 tile
= RRenderGradient(64, 64, &from
, &to
, RGRD_DIAGONAL
);
58 img
= RCloneImage(tile
);
59 RConvertImage(ctx
, img
, &pix
);
60 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 0, 0);
62 /* Read the image, and combine it with the tile. Put it as a sample
63 * in the second slot, and also save a copy for later use. */
64 icon
= RLoadImage(ctx
, "ballot_box.xpm", 0);
66 puts(RMessageForError(RErrorCode
));
69 RCombineArea(img
, icon
, 0, 0, icon
->width
, icon
->height
, 8, 8);
72 RConvertImage(ctx
, img
, &pix
);
73 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 64, 0);
75 img
= RCloneImage(tile
);
77 /* Draw random pixels on image */
78 for (i
=0; i
< 200; i
++) {
79 color
.red
= rand()%256;
80 color
.green
= rand()%256;
81 color
.blue
= rand()%256;
85 RPutPixel(img
, x
, y
, &color
);
88 RConvertImage(ctx
, img
, &pix
);
89 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 0, 64);
92 img
= RCloneImage(tile
);
94 /* Alter random pixels in image with the same amount for r/g/b */
95 for (i
=0; i
< 200; i
++) {
96 cdelta
.red
= cdelta
.green
= cdelta
.blue
= rand()%511 - 255;
100 ROperatePixel(img
, RAddOperation
, x
, y
, &cdelta
);
103 RConvertImage(ctx
, img
, &pix
);
104 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 64, 64);
107 img
= RCloneImage(tile
);
109 /* Draw lines in all directions to test different slopes */
115 segs
[i
].x1
= segs
[i
].y1
= 31;
117 segs
[6].x2
= segs
[7].x2
= segs
[8].x2
= segs
[9].x2
= segs
[10].x2
= 0;
118 segs
[2].y2
= segs
[3].y2
= segs
[4].y2
= segs
[5].y2
= segs
[6].y2
= 0;
119 segs
[5].x2
= segs
[11].x2
= 16;
120 segs
[1].y2
= segs
[7].y2
= 16;
121 segs
[4].x2
= segs
[12].x2
= 31;
122 segs
[0].y2
= segs
[8].y2
= 31;
123 segs
[3].x2
= segs
[13].x2
= 46;
124 segs
[9].y2
= segs
[15].y2
= 46;
125 segs
[0].x2
= segs
[1].x2
= segs
[2].x2
= segs
[14].x2
= segs
[15].x2
= 62;
126 segs
[10].y2
= segs
[11].y2
= segs
[12].y2
= segs
[13].y2
= segs
[14].y2
= 62;
127 RDrawSegments(img
, segs
, 9, &color
);
129 /* Also test how alpha channel behaves when drawing lines */
131 RDrawSegments(img
, &segs
[9], 7, &color
);
133 RConvertImage(ctx
, img
, &pix
);
134 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 0, 128);
137 img
= RCloneImage(tile
);
139 /* Alter lines in all directions (test different slopes) */
140 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
142 ROperateSegments(img
, RAddOperation
, segs
, 16, &cdelta
);
144 RConvertImage(ctx
, img
, &pix
);
145 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 64, 128);
149 /* Create a bevel around the icon, and save it for a later use */
151 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
153 ROperateLine(img
, RAddOperation
, 8, 8, 56, 8, &cdelta
);
154 ROperateLine(img
, RAddOperation
, 8, 9, 8, 56, &cdelta
);
155 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
157 ROperateLine(img
, RSubtractOperation
, 8, 56, 56, 56, &cdelta
);
158 ROperateLine(img
, RSubtractOperation
, 56, 8, 56, 55, &cdelta
);
160 tmp
= RCloneImage(img
);
162 /* Draw some solid lines over the icon */
167 for (i
=16; i
<24; i
++) {
168 RDrawLine(img
, 9, i
, 55, i
, &color
);
171 /* Also try some lines with alpha over the icon */
173 for (i
=40; i
<48; i
++) {
174 RDrawLine(img
, 9, i
, 55, i
, &color
);
177 RConvertImage(ctx
, img
, &pix
);
178 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 0, 192);
182 /* Restore the image with the icon, and alter some lines */
184 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
186 for (i
=16; i
<24; i
++) {
187 ROperateLine(img
, RSubtractOperation
, 9, i
, 55, i
, &cdelta
);
189 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
190 for (i
=40; i
<48; i
++) {
191 ROperateLine(img
, RAddOperation
, 9, i
, 55, i
, &cdelta
);
194 RConvertImage(ctx
, img
, &pix
);
195 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 64, 192);
198 XSetWindowBackgroundPixmap(dpy
, win
, back
);
199 XMapRaised(dpy
, win
);
200 XClearWindow(dpy
, win
);
209 RColor color
, from
, to
;
210 XSetWindowAttributes val
;
214 val
.background_pixel
= ctx
->black
;
215 val
.colormap
= ctx
->cmap
;
216 win
= XCreateWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 140, 140,
217 0, ctx
->depth
, InputOutput
, ctx
->visual
,
218 CWColormap
|CWBackPixel
, &val
);
219 back
= XCreatePixmap(ctx
->dpy
, ctx
->drawable
, 140, 140, ctx
->depth
);
221 /* Standard gray tile gradient */
231 /* Dark blue tile gradient */
241 /* Create Background */
242 img
= RCreateImage(140, 140, True
);
247 RClearImage(img
, &color
);
248 RConvertImage(ctx
, img
, &pix
);
249 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 140, 140, 0, 0);
252 tile
= RRenderGradient(64, 64, &from
, &to
, RGRD_DIAGONAL
);
254 img
= RCloneImage(tile
);
255 RBevelImage(img
, RBEV_SUNKEN
);
256 RConvertImage(ctx
, img
, &pix
);
257 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 3, 3);
260 img
= RCloneImage(tile
);
261 RBevelImage(img
, RBEV_RAISED
);
262 RConvertImage(ctx
, img
, &pix
);
263 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 73, 3);
266 img
= RCloneImage(tile
);
267 RBevelImage(img
, RBEV_RAISED2
);
268 RConvertImage(ctx
, img
, &pix
);
269 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 3, 73);
272 img
= RCloneImage(tile
);
273 RBevelImage(img
, RBEV_RAISED3
);
274 RConvertImage(ctx
, img
, &pix
);
275 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 73, 73);
278 XSetWindowBackgroundPixmap(dpy
, win
, back
);
279 XMapRaised(dpy
, win
);
280 XClearWindow(dpy
, win
);
289 RColor color
, from
, to
, tmp
;
290 RColor cdelta
, cdelta1
;
292 XSetWindowAttributes val
;
296 val
.background_pixel
= ctx
->black
;
297 val
.colormap
= ctx
->cmap
;
298 win
= XCreateWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 64, 64,
299 0, ctx
->depth
, InputOutput
, ctx
->visual
,
300 CWColormap
|CWBackPixel
, &val
);
301 back
= XCreatePixmap(ctx
->dpy
, ctx
->drawable
, 64, 64, ctx
->depth
);
303 /* Standard gray tile gradient */
313 /* Dark blue tile gradient */
323 img
= RRenderGradient(64, 64, &from
, &to
, RGRD_DIAGONAL
);
325 RBevelImage(img
, RBEV_RAISED3
);
328 color
.red
= color
.green
= color
.blue
= 0;
331 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
334 cdelta1
.red
= cdelta1
.green
= cdelta1
.blue
= 40;
336 segs
[0].x1
= segs
[2].y1
= segs
[4].x1
= segs
[4].x2
= 63-21;
337 segs
[0].x2
= segs
[2].y2
= segs
[1].x2
= segs
[3].y2
= 63-2;
338 segs
[0].y1
= segs
[2].x1
= segs
[1].y1
= segs
[3].x1
= 2;
339 segs
[0].y2
= segs
[2].x2
= segs
[6].x1
= segs
[6].x2
= 21;
340 segs
[1].x1
= segs
[3].y1
= segs
[5].x1
= segs
[5].x2
= 63-22;
341 segs
[1].y2
= segs
[3].x2
= segs
[7].x1
= segs
[7].x2
= 22;
343 segs
[4].y1
= segs
[5].y1
= segs
[10].x1
= segs
[11].x1
= 0;
344 segs
[4].y2
= segs
[5].y2
= segs
[10].x2
= segs
[11].x2
= 1;
345 segs
[6].y1
= segs
[7].y1
= segs
[8].x1
= segs
[9].x1
= 63-1;
346 segs
[6].y2
= segs
[7].y2
= segs
[8].x2
= segs
[9].x2
= 63;
347 segs
[8].y1
= segs
[8].y2
= 21;
348 segs
[9].y1
= segs
[9].y2
= 22;
349 segs
[10].y1
= segs
[10].y2
= 63-21;
350 segs
[11].y1
= segs
[11].y2
= 63-22;
352 RDrawSegments(img
, segs
, 12, &color
);
354 segs
[0].x1
= segs
[3].y1
= 63-20;
355 segs
[0].x2
= segs
[1].y2
= segs
[2].x2
= segs
[3].y2
= 63-2;
356 segs
[0].y1
= segs
[1].x1
= segs
[2].y1
= segs
[3].x1
= 2;
357 segs
[1].y1
= segs
[2].x1
= 63-23;
358 segs
[0].y2
= segs
[3].x2
= 20;
359 segs
[1].x2
= segs
[2].y2
= 23;
360 /* Bevels arround black segments */
361 ROperateSegments(img
, RAddOperation
, segs
, 2, &cdelta
);
362 ROperateSegments(img
, RSubtractOperation
, &segs
[2], 2 ,&cdelta1
);
364 RGetPixel(img
, 63-2, 20, &tmp
);
365 /*RPutPixel(img, 63-1, 23, &tmp);*/
366 RDrawLine(img
, 63-1, 23, 63, 23, &tmp
);
367 RGetPixel(img
, 63-23, 2, &tmp
);
368 RDrawLine(img
, 63-23, 0, 63-23, 1, &tmp
);
370 RGetPixel(img
, 23, 63-2, &tmp
);
371 /*RPutPixel(img, 23, 63-1, &tmp);*/
372 RDrawLine(img
, 23, 63-1, 23, 63, &tmp
);
373 RGetPixel(img
, 2, 63-20, &tmp
);
374 RDrawLine(img
, 0, 63-23, 1, 63-23, &tmp
);
377 color
.red
= color
.green
= color
.blue
= 0;
380 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
383 cdelta1
.red
= cdelta1
.green
= cdelta1
.blue
= 40;
385 RDrawLine(img
, 63-21, 2, 63-2, 21, &color
); /* upper 2 black lines */
386 ROperateLine(img
, RAddOperation
, 63-20, 2, 63-2, 20, &cdelta
); /* the bevel arround them */
387 ROperateLine(img
, RSubtractOperation
, 63-22, 2, 63-2, 22, &cdelta1
);
388 RDrawLine(img
, 63-21, 0, 63-21, 1, &color
); /* upper small black lines */
389 RDrawLine(img
, 63-1, 21, 63, 21, &color
);
391 RGetPixel(img
, 63-2, 20, &tmp
);
392 RPutPixel(img
, 63-1, 22, &tmp
);
393 RGetPixel(img
, 2, 63-22, &tmp
);
394 RDrawLine(img
, 63-22, 0, 63-22, 1, &tmp
);
396 RDrawLine(img
, 2, 63-21, 21, 63-2, &color
); /* lower 2 black lines */
397 ROperateLine(img
, RSubtractOperation
, 2, 63-20, 20, 63-2, &cdelta1
); /* the bevel arround them */
398 ROperateLine(img
, RAddOperation
, 2, 63-22, 22, 63-2, &cdelta
);
399 RDrawLine(img
, 21, 63-1, 21, 63, &color
); /* lower small black lines */
400 RDrawLine(img
, 0, 63-21, 1, 63-21, &color
);
401 ROperateLine(img
, RAddOperation
, 22, 63-1, 22, 63, &cdelta
);
402 /*ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta);*/ /* the bevel arround them */
403 ROperateLine(img
, RSubtractOperation
, 0, 63-22, 1, 63-22, &cdelta1
);
406 RConvertImage(ctx
, img
, &pix
);
407 XCopyArea(dpy
, pix
, back
, ctx
->copy_gc
, 0, 0, 64, 64, 0, 0);
410 XSetWindowBackgroundPixmap(dpy
, win
, back
);
411 XMapRaised(dpy
, win
);
412 XClearWindow(dpy
, win
);
424 double t1
, t2
, total
, d1
=0, d2
=0, d3
=0;
425 struct timeval timev
;
428 puts("Starting benchmark");
430 gettimeofday(&timev
, NULL
);
431 t1
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
433 img
= RCreateImage(1024, 768, True
);
435 gettimeofday(&timev
, NULL
);
436 t2
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
438 printf("Image created in %f sec\n", total
);
440 gettimeofday(&timev
, NULL
);
441 t1
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
447 RClearImage(img
, &color
);
453 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
456 gettimeofday(&timev
, NULL
);
457 t2
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
459 printf("Image filled in %f sec\n", total
);
462 printf("Pass %d...\n", j
);
463 gettimeofday(&timev
, NULL
);
464 t1
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
467 for (i
=0; i
< 10000; i
++) {
468 RDrawLine(img
, 0, i
%64, i
%64, 63, &color
);
471 gettimeofday(&timev
, NULL
);
472 t2
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
474 printf("Drawing 10000 lines in %f sec\n", total
);
477 gettimeofday(&timev
, NULL
);
478 t1
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
481 for (i
=0; i
< 10000; i
++) {
482 RDrawLine(img
, 0, i
%64, i
%64, 63, &color
);
485 gettimeofday(&timev
, NULL
);
486 t2
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
488 printf("Drawing 10000 lines with alpha in %f sec\n", total
);
491 gettimeofday(&timev
, NULL
);
492 t1
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
494 for (i
=0; i
< 10000; i
++) {
495 ROperateLine(img
, RAddOperation
, 0, i
%64, i
%64, 63, &cdelta
);
498 gettimeofday(&timev
, NULL
);
499 t2
= (double)timev
.tv_sec
+ (((double)timev
.tv_usec
)/1000000);
501 printf("Altering 10000 lines in %f sec\n", total
);
504 printf("Average: %f, %f, %f\n", d1
/5, d2
/5, d3
/5);
510 int main(int argc
, char **argv
)
512 RContextAttributes attr
;
515 ProgName
= strrchr(argv
[0],'/');
521 dpy
= XOpenDisplay("");
523 puts("cant open display");
527 attr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
529 attr
.render_mode
= RM_DITHER
;
530 attr
.colors_per_channel
= 4;
533 attr
.flags
|= RC_VisualID
;
534 attr
.visualid
= visualID
;
537 ctx
= RCreateContext(dpy
, DefaultScreen(dpy
), &attr
);
540 printf("could not initialize graphics library context: %s\n",
541 RMessageForError(RErrorCode
));
545 /* Here are the things we want to test */