File indexing completed on 2025-02-09 05:01:42
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com> 0003 * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include <simpletest.h> 0009 #include <kundo2command.h> 0010 0011 #include "kis_benchmark_values.h" 0012 0013 #include "kis_random_accessor_ng.h" 0014 0015 #include <KoColorSpace.h> 0016 #include <KoColorSpaceRegistry.h> 0017 #include <KoColor.h> 0018 #include <KoCompositeOpRegistry.h> 0019 0020 #include <kis_image.h> 0021 0022 #include "kis_gradient_benchmark.h" 0023 0024 #include <kis_gradient_painter.h> 0025 0026 #include <resources/KoStopGradient.h> 0027 0028 void KisGradientBenchmark::initTestCase() 0029 { 0030 m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); 0031 m_device = new KisPaintDevice(m_colorSpace); 0032 m_color = KoColor(m_colorSpace); 0033 0034 m_color.fromQColor(QColor(0,0,0,0)); // default pixel 0035 m_device->fill( 0,0,GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT,m_color.data() ); 0036 } 0037 0038 void KisGradientBenchmark::benchmarkGradient() 0039 { 0040 KoColor fg(m_colorSpace); 0041 KoColor bg(m_colorSpace); 0042 fg.fromQColor(Qt::blue); 0043 bg.fromQColor(Qt::black); 0044 0045 QBENCHMARK 0046 { 0047 QLinearGradient grad; 0048 grad.setColorAt(0, Qt::white); 0049 grad.setColorAt(1.0, Qt::red); 0050 KoAbstractGradientSP kograd(KoStopGradient::fromQGradient(&grad)); 0051 Q_ASSERT(kograd); 0052 KisGradientPainter fillPainter(m_device); 0053 //setupPainter(&fillPainter); 0054 fillPainter.setGradient(kograd); 0055 0056 fillPainter.beginTransaction(kundo2_noi18n("Gradient Fill")); 0057 0058 //fillPainter.setProgress(updater->startSubtask()); 0059 fillPainter.setOpacity(OPACITY_OPAQUE_U8); 0060 // default 0061 fillPainter.setCompositeOpId(COMPOSITE_OVER); 0062 fillPainter.setGradientShape(KisGradientPainter::GradientShapeBiLinear); 0063 fillPainter.paintGradient(QPointF(0,0), QPointF(3000,3000), KisGradientPainter::GradientRepeatNone, 1.0, false, 0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT); 0064 0065 fillPainter.deleteTransaction(); 0066 } 0067 0068 // uncomment this to see the output 0069 QImage out = m_device->convertToQImage(m_colorSpace->profile(),0,0,GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT); 0070 out.save("fill_output.png"); 0071 } 0072 0073 0074 void KisGradientBenchmark::cleanupTestCase() 0075 { 0076 0077 } 0078 0079 SIMPLE_TEST_MAIN(KisGradientBenchmark)