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_bcontrast_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 "krita_utils.h"
0028 #include <KisGlobalResourcesInterface.h>
0029 
0030 void KisBContrastBenchmark::initTestCase()
0031 {
0032     m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0033     m_device = new KisPaintDevice(m_colorSpace);
0034     m_color = KoColor(m_colorSpace);
0035 
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 
0052 void KisBContrastBenchmark::cleanupTestCase()
0053 {
0054 }
0055 
0056 
0057 void KisBContrastBenchmark::benchmarkFilter()
0058 {
0059     KisFilterSP filter = KisFilterRegistry::instance()->value("brightnesscontrast");
0060     KisFilterConfigurationSP  kfc = filter->defaultConfiguration(KisGlobalResourcesInterface::instance());
0061 
0062     // Get the predefined configuration from a file
0063     QFile file(QString(FILES_DATA_DIR) + '/' + filter->id() + ".cfg");
0064     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
0065         file.open(QIODevice::WriteOnly | QIODevice::Text);
0066         QTextStream out(&file);
0067         out.setCodec("UTF-8");
0068         out << kfc->toXML();
0069     } else {
0070         QString s;
0071         QTextStream in(&file);
0072         in.setCodec("UTF-8");
0073         s = in.readAll();
0074         kfc->fromXML(s);
0075     }
0076 
0077     QSize size = KritaUtils::optimalPatchSize();
0078     QVector<QRect> rects = KritaUtils::splitRectIntoPatches(QRect(0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT), size);
0079 
0080     QBENCHMARK{
0081         Q_FOREACH (const QRect &rc, rects) {
0082             filter->process(m_device, rc, kfc);
0083         }
0084     }
0085 }
0086 
0087 
0088 
0089 SIMPLE_TEST_MAIN(KisBContrastBenchmark)