kis_gradient_benchmark.cpp 2.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
 *  Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

20
#include <QTest>
Alexander Potashev's avatar
Alexander Potashev committed
21
#include <kundo2command.h>
22 23 24

#include "kis_benchmark_values.h"

25
#include "kis_random_accessor_ng.h"
26 27 28 29 30 31 32 33 34 35 36 37

#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColor.h>

#include <kis_image.h>

#include "kis_gradient_benchmark.h"

#include <kis_gradient_painter.h>

#include <KoCompositeOps.h>
38
#include <resources/KoStopGradient.h>
39 40 41

void KisGradientBenchmark::initTestCase()
{
42
    m_colorSpace = KoColorSpaceRegistry::instance()->rgb8();    
43 44
    m_device = new KisPaintDevice(m_colorSpace);
    m_color = KoColor(m_colorSpace);
45
    
46 47 48 49 50 51 52 53 54 55
    m_color.fromQColor(QColor(0,0,0,0)); // default pixel
    m_device->fill( 0,0,GMP_IMAGE_WIDTH, GMP_IMAGE_HEIGHT,m_color.data() );
}

void KisGradientBenchmark::benchmarkGradient()
{
    KoColor fg(m_colorSpace);
    KoColor bg(m_colorSpace);
    fg.fromQColor(Qt::blue);
    bg.fromQColor(Qt::black);
56
    
57 58 59 60 61 62 63 64 65 66 67
    QBENCHMARK
    {
        QLinearGradient grad;
        grad.setColorAt(0, Qt::white);
        grad.setColorAt(1.0, Qt::red);
        KoAbstractGradient* kograd = KoStopGradient::fromQGradient(&grad);
        Q_ASSERT(kograd);
        KisGradientPainter fillPainter(m_device);
        //setupPainter(&fillPainter);
        fillPainter.setGradient(kograd);

68
        fillPainter.beginTransaction(kundo2_noi18n("Gradient Fill"));
69 70 71 72 73

        //fillPainter.setProgress(updater->startSubtask());
        fillPainter.setOpacity(OPACITY_OPAQUE_U8);
        // default
        fillPainter.setCompositeOp(COMPOSITE_OVER);
74 75
        fillPainter.setGradientShape(KisGradientPainter::GradientShapeBiLinear);
        fillPainter.paintGradient(QPointF(0,0), QPointF(3000,3000), KisGradientPainter::GradientRepeatNone, true, false, 0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);
76

77
        fillPainter.deleteTransaction();
78
    }
79
    
80 81 82 83 84 85 86 87 88 89 90
    // uncomment this to see the output
    QImage out = m_device->convertToQImage(m_colorSpace->profile(),0,0,GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);
    out.save("fill_output.png");
}


void KisGradientBenchmark::cleanupTestCase()
{

}

91
QTEST_MAIN(KisGradientBenchmark)