Code

Use subdirectories with icon sizes.
[inkscape.git] / src / libnr / testnr.cpp
1 #define __TESTNR_C__
3 /*
4  * Pixel buffer rendering library
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * This code is in public domain
10  */
12 #if defined (_WIN32) || defined (__WIN32__)
13 # include <windows.h> 
14 #include <glib.h>
15 #endif
18 #include "nr-blit.h"
20 static double
21 get_time (void)
22 {
23     GTimeVal tv;
24     g_get_current_time (&tv);
25     return tv.tv_sec + 1e-6 * tv.tv_usec;
26 }
28 static unsigned int
29 rand_byte (void)
30 {
31         return (int) (256.0 * rand () / (RAND_MAX + 1.0));
32 }
34 int
35 main (int argc, const char **argv)
36 {
37         double start, end;
38         NRPixBlock d, m[16];
39         int count, i;
41         srand (time (NULL));
43         printf ("Initializing buffers\n");
45         /* Destination */
46         nr_pixblock_setup_fast (&d, NR_PIXBLOCK_MODE_R8G8B8A8P, 0, 0, 64, 64, 1);
47         d.empty = 0;
49         /* Masks */
50         for (i = 0; i < 16; i++) {
51                 int r, b, c;
52                 nr_pixblock_setup_fast (&m[i], NR_PIXBLOCK_MODE_A8, 0, 0, 64, 64, 0);
53                 for (r = 0; r < 64; r++) {
54                         unsigned int q;
55                         unsigned char *p;
56                         p = NR_PIXBLOCK_PX (&m[i]) + r * m[i].rs;
57                         for (b = 0; b < 8; b++) {
58                                 q = rand_byte ();
59                                 if (q < 120) {
60                                         for (c = 0; c < 8; c++) *p++ = 0;
61                                 } else if (q < 240) {
62                                         for (c = 0; c < 8; c++) *p++ = 255;
63                                 } else {
64                                         for (c = 0; c < 8; c++) *p++ = rand_byte ();
65                                 }
66                         }
67                 }
68                 m[i].empty = 0;
69         }
71         printf ("Random transparency\n");
72         count = 0;
73         start = end = get_time ();
74         while ((end - start) < 5.0) {
75                 unsigned char r, g, b, a;
76                 r = rand_byte ();
77                 g = rand_byte ();
78                 b = rand_byte ();
79                 a = rand_byte ();
81                 for (i = 0; i < 16; i++) {
82                         nr_blit_pixblock_mask_rgba32 (&d, &m[i], (a << 24) | (g << 16) | (b << 8) | a);
83                         count += 1;
84                 }
85                 end = get_time ();
86         }
87         printf ("Did %d [64x64] random buffers in %f sec\n", count, end - start); // localizing ok
88         printf ("%f buffers per second\n", count / (end - start)); // localizing ok
89         printf ("%f pixels per second\n", count * (64 * 64) / (end - start)); // localizing ok
91         return 0;
92 }