summaryrefslogtreecommitdiff
path: root/src/graphics/benchmarkgraphics.cpp
blob: 85200334eacaf648e1247930cfb4d54b79afafe0 (plain)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//
//  libavg - Media Playback Engine. 
//  Copyright (C) 2003-2014 Ulrich von Zadow
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//


#include "Bitmap.h"
#include "BitmapLoader.h"
#include "Pixel32.h"
#include "Pixel24.h"
#include "Pixel16.h"
#include "Filtergrayscale.h"
#include "Filterfill.h"
#include "Filterflip.h"
#include "Filterfliprgb.h"
#include "Filterflipuv.h"
#include "Filter3x3.h"
#include "FilterConvol.h"
#include "HistoryPreProcessor.h"
#include "FilterHighpass.h"
#include "FilterGauss.h"
#include "FilterBlur.h"
#include "FilterBandpass.h"

#include "../base/TimeSource.h"

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace avg;
using namespace std;

template<class TEST>
void runPerformanceTest(int numRuns=500)
{
    TEST PerfTest;
    long long StartTime = TimeSource::get()->getCurrentMicrosecs();
    for (int i = 0; i < numRuns; ++i) {
        PerfTest.run();
    }
    float ActiveTime = (TimeSource::get()->getCurrentMicrosecs()-StartTime)/1000.; 
    cerr << PerfTest.getName() << ": " << ActiveTime/numRuns << " ms" << endl;
    
}

class PerfTestBase {
public:
    PerfTestBase(string sName) 
        : m_sName(sName)
    {
    }

    std::string getName()
    {
        return m_sName;
    }

private:
    std::string m_sName;
};

class LoadPNGPerfTest: public PerfTestBase {
public:
    LoadPNGPerfTest()
        : PerfTestBase("LoadPNGPerfTest")
    {
    }

    void run()
    {
        BitmapPtr pBmp = loadBitmap("../test/media/rgb24alpha-64x64.png");
    }
};

class FillI8PerfTest: public PerfTestBase {
public:
    FillI8PerfTest() 
        : PerfTestBase("FillI8PerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), I8));
    }

    void run()
    {
        FilterFill<Pixel8> Filter = FilterFill<Pixel8>(Pixel8(0));
        Filter.applyInPlace(m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class FillRGBPerfTest: public PerfTestBase {
public:
    FillRGBPerfTest() 
        : PerfTestBase("FillRGBPerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), R8G8B8));
    }

    void run()
    {
        FilterFill<Pixel24> Filter = FilterFill<Pixel24>(Pixel24(0,0,0));
        Filter.applyInPlace(m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class FillRGBAPerfTest: public PerfTestBase {
public:
    FillRGBAPerfTest() 
        : PerfTestBase("FillRGBAPerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), R8G8B8A8));
    }

    void run()
    {
        FilterFill<Pixel32> Filter = FilterFill<Pixel32>(Pixel32(0,0,0,0));
        Filter.applyInPlace(m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class EqualityI8PerfTest: public PerfTestBase {
public:
    EqualityI8PerfTest() 
        : PerfTestBase("EqualityI8PerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), I8));
    }

    void run() 
    {
        Bitmap CopyBmp = *m_pBmp;
    }

private:
    BitmapPtr m_pBmp;
};

class CopyI8PerfTest: public PerfTestBase {
public:
    CopyI8PerfTest() 
        : PerfTestBase("CopyI8PerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), I8));
    }

    void run()
    {
        Bitmap CopyBmp(*m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class CopyRGBPerfTest: public PerfTestBase {
public:
    CopyRGBPerfTest() 
        : PerfTestBase("CopyRGBPerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), R8G8B8));
    }

    void run()
    {
        Bitmap CopyBmp(*m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class CopyRGBAPerfTest: public PerfTestBase {
public:
    CopyRGBAPerfTest() 
        : PerfTestBase("CopyRGBAPerfTest")
    {
        m_pBmp = BitmapPtr(new Bitmap(IntPoint(1024,1024), R8G8B8A8));
    }

    void run()
    {
        Bitmap CopyBmp(*m_pBmp);
    }

private:
    BitmapPtr m_pBmp;
};

class YUV2RGBPerfTest: public PerfTestBase {
public:
    YUV2RGBPerfTest() 
        : PerfTestBase("YUV2RGBPerfTest")
    {
        m_pYBmp = BitmapPtr(new Bitmap(IntPoint(1024, 1024), I8));
        m_pUBmp = BitmapPtr(new Bitmap(IntPoint(512, 512), I8));
        m_pVBmp = BitmapPtr(new Bitmap(IntPoint(512, 512), I8));
    }

    void run()
    {
        Bitmap RGBBmp(IntPoint(1024, 1024), B8G8R8X8);
        RGBBmp.copyYUVPixels(*m_pYBmp, *m_pUBmp, *m_pVBmp, false);
    }

private:
    BitmapPtr m_pYBmp;
    BitmapPtr m_pUBmp;
    BitmapPtr m_pVBmp;
        
};

void runPerformanceTests()
{
    runPerformanceTest<LoadPNGPerfTest>();
    runPerformanceTest<FillI8PerfTest>();
    runPerformanceTest<FillRGBPerfTest>();
    runPerformanceTest<FillRGBAPerfTest>();
    runPerformanceTest<EqualityI8PerfTest>();
    runPerformanceTest<CopyI8PerfTest>();
    runPerformanceTest<CopyRGBPerfTest>();
    runPerformanceTest<CopyRGBAPerfTest>();
    runPerformanceTest<YUV2RGBPerfTest>(200);
}

int main(int nargs, char** args)
{
    BitmapLoader::init(true);
    runPerformanceTests();
}