1 | /* |
2 | * Copyright (c) 2010 Lukáš Tvrdý lukast.dev@gmail.com |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ |
18 | |
19 | #include <qtest_kde.h> |
20 | |
21 | #include "kis_bcontrast_benchmark.h" |
22 | #include "kis_benchmark_values.h" |
23 | |
24 | #include "kis_paint_device.h" |
25 | |
26 | #include <KoColorSpace.h> |
27 | #include <KoColorSpaceRegistry.h> |
28 | #include <KoColor.h> |
29 | |
30 | #include <kis_image.h> |
31 | |
32 | #include "filter/kis_filter_registry.h" |
33 | #include "filter/kis_filter_configuration.h" |
34 | #include "filter/kis_filter.h" |
35 | |
36 | #include "kis_processing_information.h" |
37 | |
38 | #include "kis_selection.h" |
39 | #include <kis_iterator_ng.h> |
40 | |
41 | |
42 | void KisBContrastBenchmark::initTestCase() |
43 | { |
44 | m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); |
45 | m_device = new KisPaintDevice(m_colorSpace); |
46 | m_color = KoColor(m_colorSpace); |
47 | |
48 | srand(31524744); |
49 | |
50 | int r,g,b; |
51 | |
52 | KisSequentialIterator it(m_device, QRect(0, 0, GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT)); |
53 | do { |
54 | r = rand() % 255; |
55 | g = rand() % 255; |
56 | b = rand() % 255; |
57 | |
58 | m_color.fromQColor(QColor(r,g,b)); |
59 | memcpy(it.rawData(), m_color.data(), m_colorSpace->pixelSize()); |
60 | } while (it.nextPixel()); |
61 | |
62 | } |
63 | |
64 | void KisBContrastBenchmark::cleanupTestCase() |
65 | { |
66 | } |
67 | |
68 | |
69 | void KisBContrastBenchmark::benchmarkFilter() |
70 | { |
71 | KisFilterSP filter = KisFilterRegistry::instance()->value("brightnesscontrast" ); |
72 | KisFilterConfiguration * kfc = filter->defaultConfiguration(m_device); |
73 | |
74 | // Get the predefined configuration from a file |
75 | QFile file(QString(FILES_DATA_DIR) + QDir::separator() + filter->id() + ".cfg" ); |
76 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
77 | file.open(QIODevice::WriteOnly | QIODevice::Text); |
78 | QTextStream out(&file); |
79 | out << kfc->toXML(); |
80 | } else { |
81 | QString s; |
82 | QTextStream in(&file); |
83 | s = in.readAll(); |
84 | kfc->fromXML(s); |
85 | } |
86 | |
87 | QBENCHMARK{ |
88 | filter->process(m_device, QRect(0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT), kfc); |
89 | } |
90 | } |
91 | |
92 | |
93 | |
94 | QTEST_KDEMAIN(KisBContrastBenchmark, GUI) |
95 | #include "kis_bcontrast_benchmark.moc" |
96 | |