File indexing completed on 2024-11-10 04:00:28

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Thorsten Zachmann <zachmann@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include <simpletest.h>
0008 
0009 #include "kis_level_filter_benchmark.h"
0010 #include "kis_benchmark_values.h"
0011 
0012 #include <KoColorSpace.h>
0013 #include <KoColorSpaceRegistry.h>
0014 #include <KoColor.h>
0015 
0016 #include <kis_image.h>
0017 
0018 #include "filter/kis_filter_registry.h"
0019 #include "filter/kis_filter_configuration.h"
0020 #include "filter/kis_color_transformation_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 "krita_utils.h"
0028 #include <KisGlobalResourcesInterface.h>
0029 
0030 void KisLevelFilterBenchmark::initTestCase()
0031 {
0032     m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0033     m_device = new KisPaintDevice(m_colorSpace);
0034     m_color = KoColor(m_colorSpace);
0035 
0036     QColor qcolor(Qt::red);
0037     srand(31524744);
0038 
0039     int r,g,b;
0040 
0041     KisSequentialIterator it(m_device, QRect(0,0,GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT));
0042     while (it.nextPixel()) {
0043         r = rand() % 255;
0044         g = rand() % 255;
0045         b = rand() % 255;
0046 
0047         m_color.fromQColor(QColor(r,g,b));
0048         memcpy(it.rawData(), m_color.data(), m_colorSpace->pixelSize());
0049     }
0050 }
0051 
0052 void KisLevelFilterBenchmark::cleanupTestCase()
0053 {
0054 }
0055 
0056 void KisLevelFilterBenchmark::benchmarkFilter()
0057 {
0058     KisFilterSP filter = KisFilterRegistry::instance()->value("levels");
0059     //KisFilterConfigurationSP  kfc = filter->defaultConfiguration(m_device);
0060 
0061     KisColorTransformationConfiguration * kfc= new KisColorTransformationConfiguration("levels", 1, KisGlobalResourcesInterface::instance());
0062 
0063     kfc->setProperty("blackvalue", 75);
0064     kfc->setProperty("whitevalue", 231);
0065     kfc->setProperty("gammavalue", 1.0);
0066     kfc->setProperty("outblackvalue", 0);
0067     kfc->setProperty("outwhitevalue", 255);
0068     // Get the predefined configuration from a file
0069     QFile file(QString(FILES_DATA_DIR) + '/' + filter->id() + ".cfg");
0070     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
0071         file.open(QIODevice::WriteOnly | QIODevice::Text);
0072         QTextStream out(&file);
0073         out.setCodec("UTF-8");
0074         out << kfc->toXML();
0075     } else {
0076         QString s;
0077         QTextStream in(&file);
0078         in.setCodec("UTF-8");
0079         s = in.readAll();
0080         kfc->fromXML(s);
0081     }
0082 
0083     QSize size = KritaUtils::optimalPatchSize();
0084     QVector<QRect> rects = KritaUtils::splitRectIntoPatches(QRect(0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT), size);
0085 
0086     QBENCHMARK{
0087         Q_FOREACH (const QRect &rc, rects) {
0088             filter->process(m_device, rc, kfc);
0089         }
0090     }
0091 }
0092 
0093 
0094 
0095 SIMPLE_TEST_MAIN(KisLevelFilterBenchmark)