File indexing completed on 2024-11-10 04:00:27
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý lukast.dev @gmail.com 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <simpletest.h> 0008 0009 #include "kis_blur_benchmark.h" 0010 #include "kis_benchmark_values.h" 0011 0012 0013 #include <KoColorSpace.h> 0014 #include <KoColorSpaceRegistry.h> 0015 #include <KoColor.h> 0016 0017 #include <kis_image.h> 0018 0019 #include "filter/kis_filter_registry.h" 0020 #include "filter/kis_filter_configuration.h" 0021 #include "filter/kis_filter.h" 0022 0023 #include "kis_processing_information.h" 0024 0025 #include "kis_selection.h" 0026 #include <kis_iterator_ng.h> 0027 #include <KisGlobalResourcesInterface.h> 0028 0029 void KisBlurBenchmark::initTestCase() 0030 { 0031 m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); 0032 m_device = new KisPaintDevice(m_colorSpace); 0033 m_color = KoColor(m_colorSpace); 0034 0035 QColor qcolor(Qt::red); 0036 srand(31524744); 0037 0038 int r,g,b; 0039 0040 KisSequentialIterator it(m_device, QRect(0,0,GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT)); 0041 while (it.nextPixel()) { 0042 r = rand() % 255; 0043 g = rand() % 255; 0044 b = rand() % 255; 0045 0046 m_color.fromQColor(QColor(r,g,b)); 0047 memcpy(it.rawData(), m_color.data(), m_colorSpace->pixelSize()); 0048 } 0049 } 0050 0051 void KisBlurBenchmark::cleanupTestCase() 0052 { 0053 } 0054 0055 void KisBlurBenchmark::benchmarkFilter() 0056 { 0057 KisFilterSP filter = KisFilterRegistry::instance()->value("blur"); 0058 KisFilterConfigurationSP kfc = filter->defaultConfiguration(KisGlobalResourcesInterface::instance()); 0059 // Get the predefined configuration from a file 0060 QFile file(QString(FILES_DATA_DIR) + '/' + filter->id() + ".cfg"); 0061 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 0062 file.open(QIODevice::WriteOnly | QIODevice::Text); 0063 QTextStream out(&file); 0064 out.setCodec("UTF-8"); 0065 out << kfc->toXML(); 0066 } else { 0067 QString s; 0068 QTextStream in(&file); 0069 in.setCodec("UTF-8"); 0070 s = in.readAll(); 0071 kfc->fromXML(s); 0072 } 0073 0074 QBENCHMARK{ 0075 filter->process(m_device, QRect(0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT), kfc); 0076 } 0077 } 0078 0079 0080 0081 SIMPLE_TEST_MAIN(KisBlurBenchmark)