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
XSetWindowAttributes val;
293
val.background_pixel = ctx->black;
294
val.colormap = ctx->cmap;
295
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 140, 140,
296
0, ctx->depth, InputOutput, ctx->visual,
297
CWColormap|CWBackPixel, &val);
298
XStoreName(dpy, win, "Scale");
299
pix = XCreatePixmap(ctx->dpy, ctx->drawable, 140, 140, ctx->depth);
301
image = RLoadImage(ctx, "ballot_box.xpm", 0);
303
puts("couldnt load ballot_box.xpm");
307
scaled = RScaleImage(image, 140, 140);
309
RReleaseImage(image);
310
RConvertImage(ctx, scaled, &pix);
311
XSetWindowBackgroundPixmap(dpy, win, pix);
312
XMapRaised(dpy, win);
313
XClearWindow(dpy, win);
323
XSetWindowAttributes val;
327
image = RLoadImage(ctx, "ballot_box.xpm", 0);
329
puts("couldnt load ballot_box.xpm");
333
image = RScaleImage(image, 90, 180);
336
val.background_pixel = ctx->black;
337
val.colormap = ctx->cmap;
338
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, image->height,
340
0, ctx->depth, InputOutput, ctx->visual,
341
CWColormap|CWBackPixel, &val);
342
XStoreName(dpy, win, "Rotate");
343
pix = XCreatePixmap(ctx->dpy, ctx->drawable, image->height, image->width,
346
rotated = RRotateImage(image, 90.0);
348
RReleaseImage(image);
349
RConvertImage(ctx, rotated, &pix);
350
XSetWindowBackgroundPixmap(dpy, win, pix);
351
XMapRaised(dpy, win);
352
XClearWindow(dpy, win);
362
RColor color, from, to, tmp;
363
RColor cdelta, cdelta1;
365
XSetWindowAttributes val;
369
val.background_pixel = ctx->black;
370
val.colormap = ctx->cmap;
371
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 64, 64,
372
0, ctx->depth, InputOutput, ctx->visual,
373
CWColormap|CWBackPixel, &val);
374
back = XCreatePixmap(ctx->dpy, ctx->drawable, 64, 64, ctx->depth);
376
/* Standard gray tile gradient */
386
/* Dark blue tile gradient */
396
img = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);
398
RBevelImage(img, RBEV_RAISED3);
401
color.red = color.green = color.blue = 0;
404
cdelta.red = cdelta.green = cdelta.blue = 80;
407
cdelta1.red = cdelta1.green = cdelta1.blue = 40;
409
segs[0].x1 = segs[2].y1 = segs[4].x1 = segs[4].x2 = 63-21;
410
segs[0].x2 = segs[2].y2 = segs[1].x2 = segs[3].y2 = 63-2;
411
segs[0].y1 = segs[2].x1 = segs[1].y1 = segs[3].x1 = 2;
412
segs[0].y2 = segs[2].x2 = segs[6].x1 = segs[6].x2 = 21;
413
segs[1].x1 = segs[3].y1 = segs[5].x1 = segs[5].x2 = 63-22;
414
segs[1].y2 = segs[3].x2 = segs[7].x1 = segs[7].x2 = 22;
416
segs[4].y1 = segs[5].y1 = segs[10].x1 = segs[11].x1 = 0;
417
segs[4].y2 = segs[5].y2 = segs[10].x2 = segs[11].x2 = 1;
418
segs[6].y1 = segs[7].y1 = segs[8].x1 = segs[9].x1 = 63-1;
419
segs[6].y2 = segs[7].y2 = segs[8].x2 = segs[9].x2 = 63;
420
segs[8].y1 = segs[8].y2 = 21;
421
segs[9].y1 = segs[9].y2 = 22;
422
segs[10].y1 = segs[10].y2 = 63-21;
423
segs[11].y1 = segs[11].y2 = 63-22;
425
RDrawSegments(img, segs, 12, &color);
427
segs[0].x1 = segs[3].y1 = 63-20;
428
segs[0].x2 = segs[1].y2 = segs[2].x2 = segs[3].y2 = 63-2;
429
segs[0].y1 = segs[1].x1 = segs[2].y1 = segs[3].x1 = 2;
430
segs[1].y1 = segs[2].x1 = 63-23;
431
segs[0].y2 = segs[3].x2 = 20;
432
segs[1].x2 = segs[2].y2 = 23;
433
/* Bevels arround black segments */
434
ROperateSegments(img, RAddOperation, segs, 2, &cdelta);
435
ROperateSegments(img, RSubtractOperation, &segs[2], 2 ,&cdelta1);
437
RGetPixel(img, 63-2, 20, &tmp);
438
/*RPutPixel(img, 63-1, 23, &tmp);*/
439
RDrawLine(img, 63-1, 23, 63, 23, &tmp);
440
RGetPixel(img, 63-23, 2, &tmp);
441
RDrawLine(img, 63-23, 0, 63-23, 1, &tmp);
443
RGetPixel(img, 23, 63-2, &tmp);
444
/*RPutPixel(img, 23, 63-1, &tmp);*/
445
RDrawLine(img, 23, 63-1, 23, 63, &tmp);
446
RGetPixel(img, 2, 63-20, &tmp);
447
RDrawLine(img, 0, 63-23, 1, 63-23, &tmp);
450
color.red = color.green = color.blue = 0;
453
cdelta.red = cdelta.green = cdelta.blue = 80;
456
cdelta1.red = cdelta1.green = cdelta1.blue = 40;
458
RDrawLine(img, 63-21, 2, 63-2, 21, &color); /* upper 2 black lines */
459
ROperateLine(img, RAddOperation, 63-20, 2, 63-2, 20, &cdelta); /* the bevel arround them */
460
ROperateLine(img, RSubtractOperation, 63-22, 2, 63-2, 22, &cdelta1);
461
RDrawLine(img, 63-21, 0, 63-21, 1, &color); /* upper small black lines */
462
RDrawLine(img, 63-1, 21, 63, 21, &color);
464
RGetPixel(img, 63-2, 20, &tmp);
465
RPutPixel(img, 63-1, 22, &tmp);
466
RGetPixel(img, 2, 63-22, &tmp);
467
RDrawLine(img, 63-22, 0, 63-22, 1, &tmp);
469
RDrawLine(img, 2, 63-21, 21, 63-2, &color); /* lower 2 black lines */
470
ROperateLine(img, RSubtractOperation, 2, 63-20, 20, 63-2, &cdelta1); /* the bevel arround them */
471
ROperateLine(img, RAddOperation, 2, 63-22, 22, 63-2, &cdelta);
472
RDrawLine(img, 21, 63-1, 21, 63, &color); /* lower small black lines */
473
RDrawLine(img, 0, 63-21, 1, 63-21, &color);
474
ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta);
475
/*ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta);*/ /* the bevel arround them */
476
ROperateLine(img, RSubtractOperation, 0, 63-22, 1, 63-22, &cdelta1);
479
RConvertImage(ctx, img, &pix);
480
XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 0);
483
XSetWindowBackgroundPixmap(dpy, win, back);
484
XMapRaised(dpy, win);
485
XClearWindow(dpy, win);
497
double t1, t2, total, d1=0, d2=0, d3=0;
498
struct timeval timev;
501
puts("Starting benchmark");
503
gettimeofday(&timev, NULL);
504
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
506
img = RCreateImage(1024, 768, True);
508
gettimeofday(&timev, NULL);
509
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
511
printf("Image created in %f sec\n", total);
513
gettimeofday(&timev, NULL);
514
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
520
RClearImage(img, &color);
526
cdelta.red = cdelta.green = cdelta.blue = 80;
529
gettimeofday(&timev, NULL);
530
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
532
printf("Image filled in %f sec\n", total);
535
printf("Pass %d...\n", j);
536
gettimeofday(&timev, NULL);
537
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
540
for (i=0; i< 10000; i++) {
541
RDrawLine(img, 0, i%64, i%64, 63, &color);
544
gettimeofday(&timev, NULL);
545
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
547
printf("Drawing 10000 lines in %f sec\n", total);
550
gettimeofday(&timev, NULL);
551
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
554
for (i=0; i< 10000; i++) {
555
RDrawLine(img, 0, i%64, i%64, 63, &color);
558
gettimeofday(&timev, NULL);
559
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
561
printf("Drawing 10000 lines with alpha in %f sec\n", total);
564
gettimeofday(&timev, NULL);
565
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
567
for (i=0; i< 10000; i++) {
568
ROperateLine(img, RAddOperation, 0, i%64, i%64, 63, &cdelta);
571
gettimeofday(&timev, NULL);
572
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
574
printf("Altering 10000 lines in %f sec\n", total);
577
printf("Average: %f, %f, %f\n", d1/5, d2/5, d3/5);
583
int main(int argc, char **argv)
585
RContextAttributes attr;
588
ProgName = strrchr(argv[0],'/');
594
dpy = XOpenDisplay("");
596
puts("cant open display");
600
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
602
attr.render_mode = RDitheredRendering;
603
attr.colors_per_channel = 4;
606
attr.flags |= RC_VisualID;
607
attr.visualid = visualID;
610
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
613
printf("could not initialize graphics library context: %s\n",
614
RMessageForError(RErrorCode));
618
/* Here are the things we want to test */