1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <rfb/PixelFormat.h>
#include <rfb/PixelTransformer.h>
#include "util.h"
static const int tile = 64;
static const int fbsize = 4096;
static rdr::U8 *fb1, *fb2;
static rfb::PixelTransformer *pt = NULL;
typedef void (*testfn) (rfb::PixelFormat&, rfb::PixelFormat&, rdr::U8*, rdr::U8*);
struct TestEntry {
const char *label;
testfn fn;
};
static void testMemcpy(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
rdr::U8 *dst, rdr::U8 *src)
{
int h;
h = tile;
while (h--) {
memcpy(dst, src, tile * dstpf.bpp/8);
dst += fbsize * dstpf.bpp/8;
src += fbsize * dstpf.bpp/8;
}
}
static void testPixelTransformer(rfb::PixelFormat &dstpf,
rfb::PixelFormat &srcpf,
rdr::U8 *dst, rdr::U8 *src)
{
pt->translateRect(src, fbsize, rfb::Rect(0, 0, tile, tile),
dst, fbsize, rfb::Point(0, 0));
}
static void testBuffer(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
rdr::U8 *dst, rdr::U8 *src)
{
dstpf.bufferFromBuffer(dst, srcpf, src, tile, tile, fbsize, fbsize);
}
static void testToRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
rdr::U8 *dst, rdr::U8 *src)
{
srcpf.rgbFromBuffer(dst, src, tile, fbsize, tile);
}
static void testFromRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
rdr::U8 *dst, rdr::U8 *src)
{
dstpf.bufferFromRGB(dst, src, tile, fbsize, tile);
}
static void doTest(testfn fn, rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
{
if (!srcpf.isLittleEndian() && (fn == testPixelTransformer)) {
printf("NaN");
return;
}
startCpuCounter();
for (int i = 0;i < 10000;i++) {
int x, y;
rdr::U8 *dst, *src;
x = rand() % (fbsize - tile);
y = rand() % (fbsize - tile);
dst = fb1 + (x + y * fbsize) * dstpf.bpp/8;
src = fb2 + (x + y * fbsize) * srcpf.bpp/8;
fn(dstpf, srcpf, dst, src);
}
endCpuCounter();
float data, time;
data = (double)tile * tile * 10000;
time = getCpuCounter();
printf("%g", data / (1000.0*1000.0) / time);
}
struct TestEntry tests[] = {
{"memcpy", testMemcpy},
{"PixelTransformer", testPixelTransformer},
{"bufferFromBuffer", testBuffer},
{"rgbFromBuffer", testToRGB},
{"bufferFromRGB", testFromRGB},
};
static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
{
int i;
char dstb[256], srcb[256];
dstpf.print(dstb, sizeof(dstb));
srcpf.print(srcb, sizeof(srcb));
if (srcpf.isLittleEndian()) {
delete pt;
pt = new rfb::PixelTransformer;
pt->init(srcpf, dstpf);
}
printf("%s,%s", srcb, dstb);
for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++) {
printf(",");
doTest(tests[i].fn, dstpf, srcpf);
}
printf("\n");
}
int main(int argc, char **argv)
{
int bufsize;
time_t t;
char datebuffer[256];
int i;
bufsize = fbsize * fbsize * 4;
fb1 = new rdr::U8[bufsize];
fb2 = new rdr::U8[bufsize];
for (int i = 0;i < bufsize;i++) {
fb1[i] = rand();
fb2[i] = rand();
}
time(&t);
strftime(datebuffer, sizeof(datebuffer), "%Y-%m-%d %H:%M UTC", gmtime(&t));
printf("# Pixel Conversion Test %s\n", datebuffer);
printf("#\n");
printf("# Frame buffer: %dx%d pixels\n", fbsize, fbsize);
printf("# Tile size: %dx%d pixels\n", tile, tile);
printf("#\n");
printf("# Note: Results are Mpixels/sec\n");
printf("#\n");
printf("Source format,Destination Format");
for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++)
printf(",%s", tests[i].label);
printf("\n");
rfb::PixelFormat dstpf, srcpf;
/* rgb888 targets */
printf("\n");
dstpf.parse("rgb888");
srcpf.parse("rgb888");
doTests(dstpf, srcpf);
srcpf.parse("bgr888");
doTests(dstpf, srcpf);
srcpf.parse("rgb565");
doTests(dstpf, srcpf);
srcpf.parse("rgb232");
doTests(dstpf, srcpf);
/* rgb565 targets */
printf("\n");
dstpf.parse("rgb565");
srcpf.parse("rgb888");
doTests(dstpf, srcpf);
srcpf.parse("bgr565");
doTests(dstpf, srcpf);
srcpf.parse("rgb232");
doTests(dstpf, srcpf);
/* rgb232 targets */
printf("\n");
dstpf.parse("rgb232");
srcpf.parse("rgb888");
doTests(dstpf, srcpf);
srcpf.parse("rgb565");
doTests(dstpf, srcpf);
srcpf.parse("bgr232");
doTests(dstpf, srcpf);
/* rgb565 with endian conversion (both ways) */
printf("\n");
dstpf = rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 0, 8, 16);
srcpf = rfb::PixelFormat(32, 24, true, true, 255, 255, 255, 0, 8, 16);
doTests(srcpf, dstpf);
doTests(dstpf, srcpf);
dstpf = rfb::PixelFormat(16, 16, false, true, 31, 63, 31, 0, 5, 11);
srcpf = rfb::PixelFormat(16, 16, true, true, 31, 63, 31, 0, 5, 11);
doTests(srcpf, dstpf);
doTests(dstpf, srcpf);
return 0;
}
|