-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfile.cpp
More file actions
executable file
·138 lines (104 loc) · 4.69 KB
/
Profile.cpp
File metadata and controls
executable file
·138 lines (104 loc) · 4.69 KB
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
// Profile conversion routines
// Copyright © 2004-2007 Glenn Fiedler
// Part of the PixelToaster Framebuffer Library - http://www.pixeltoaster.com
#include "PixelToaster.h"
#include <stdio.h>
#include <stdlib.h>
using namespace PixelToaster;
const char * getFormatString( Format format )
{
switch ( format )
{
case Format::XRGB8888: return "truecolor";
case Format::XBGR8888: return "xbgr8888";
case Format::RGB888: return "rgb888";
case Format::BGR888: return "bgr888";
case Format::RGB565: return "rgb565";
case Format::BGR565: return "bgr565";
case Format::XRGB1555: return "xrgb1555";
case Format::XBGR1555: return "xbgr1555";
case Format::XBGRFFFF: return "floating point";
default: return "???";
}
}
const float duration = 1.0f;
Timer timer;
void profilePixelConverter( Format format, const Pixel * source, void * destination, int count )
{
printf( " floating point -> %s", getFormatString(format) );
Converter * converter = requestConverter( Format::XBGRFFFF, format );
if ( !converter )
{
printf( "\n failed: null converter\n" );
exit(1);
}
double startTime = timer.time();
double time = 0.0;
int iterations = 0;
while ( time < duration )
{
converter->convert( source, destination, count );
time = timer.time() - startTime;
iterations ++;
}
printf( " = %f ms\n", (double) time / iterations * 1000 );
}
void profileIntegerConverter( Format format, const integer32 *source, void *destination, int count )
{
printf( " truecolor -> %s", getFormatString(format) );
Converter * converter = requestConverter( Format::XRGB8888, format );
if ( !converter )
{
printf( "\n failed: null converter\n" );
exit(1);
}
double startTime = timer.time();
double time = 0.0;
int iterations = 0;
while ( time < duration )
{
converter->convert( source, destination, count );
time = timer.time() - startTime;
iterations ++;
}
printf( " = %f ms\n", (double) time / iterations * 1000 );
}
int main()
{
const int width = 256;
const int height = 256;
vector<Pixel> pixelSource( width * height );
for ( unsigned int i = 0; i < pixelSource.size(); ++i )
{
pixelSource[i].r = 1.5;
pixelSource[i].g = 0.5;
pixelSource[i].b = 0.25;
pixelSource[i].a = 0;
}
vector<integer32> integerSource( width * height );
for ( unsigned int i = 0; i < integerSource.size(); ++i )
integerSource[i] = 0x00FF6677;
integer8 * destination = new integer8[width*height*16];
printf( "\n[ PixelToaster Profiling Suite ]\n\n" );
printf( "floating point color conversion routines:\n\n" );
profilePixelConverter( Format::XBGRFFFF, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::XRGB8888, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::XBGR8888, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::RGB888, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::BGR888, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::RGB565, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::BGR565, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::XRGB1555, &pixelSource[0], destination, (int) pixelSource.size() );
profilePixelConverter( Format::XBGR1555, &pixelSource[0], destination, (int) pixelSource.size() );
printf( "\ntruecolor conversion routines:\n\n" );
profileIntegerConverter( Format::XBGRFFFF, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::XRGB8888, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::XBGR8888, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::RGB888, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::BGR888, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::RGB565, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::BGR565, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::XRGB1555, &integerSource[0], destination, (int) integerSource.size() );
profileIntegerConverter( Format::XBGR1555, &integerSource[0], destination, (int) integerSource.size() );
printf( "\n" );
}