[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    Re: Yet another bug. This time filters vs selections
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2009-09-14 10:44:59
Message-ID: ae32c1ef0909140344l6bbe344et71bb7ec8255480f4 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Here is a benchmark that i used for testing. It is done as a separate
unittest.

Really interesting numbers for you are "bitBlt with sel:" and "Selections
inside filter:".

-- 
Dmitry Kazakov

[Attachment #5 (text/html)]

<br>Here is a benchmark that i used for testing. It is done as a separate \
unittest.<br><br>Really interesting numbers for you are &quot;bitBlt with sel:&quot; \
and &quot;Selections inside filter:&quot;.<br clear="all"><br>-- <br> Dmitry \
Kazakov<br>

--0016363b9b8c788d0c0473875b6b--


["00_benchmark_for_filter_selections.diff" (text/x-patch)]

diff --git a/krita/image/tests/CMakeLists.txt b/krita/image/tests/CMakeLists.txt
index 448300e..eaef353 100644
--- a/krita/image/tests/CMakeLists.txt
+++ b/krita/image/tests/CMakeLists.txt
@@ -260,6 +260,12 @@ target_link_libraries(KisFilterTest  ${KDE4_KDEUI_LIBS} \
kritaimage ${QT_QTTEST_L  
 ########### next target ###############
 
+set(kis_filter_selections_benchmark_SRCS kis_filter_selections_benchmark.cpp )
+kde4_add_unit_test(KisFilterSelectionsBenchmark TESTNAME \
krita-image-KisFilterSelectionsBenchmark ${kis_filter_selections_benchmark_SRCS}) \
+target_link_libraries(KisFilterSelectionsBenchmark  ${KDE4_KDEUI_LIBS} kritaimage \
${QT_QTTEST_LIBRARY}) +
+########### next target ###############
+
 set(kis_filter_processing_information_test_SRCS \
kis_filter_processing_information_test.cpp )  \
kde4_add_unit_test(KisFilterProcessingInformationTest TESTNAME \
krita-image-KisFilterProcessingInformationTest \
${kis_filter_processing_information_test_SRCS})  \
target_link_libraries(KisFilterProcessingInformationTest  ${KDE4_KDEUI_LIBS} \
                kritaimage ${QT_QTTEST_LIBRARY})
diff --git a/krita/image/tests/kis_filter_selections_benchmark.cpp \
b/krita/image/tests/kis_filter_selections_benchmark.cpp new file mode 100644
index 0000000..ef17787
--- /dev/null
+++ b/krita/image/tests/kis_filter_selections_benchmark.cpp
@@ -0,0 +1,301 @@
+/*
+ *  Copyright (c) 2009 Dmitry  Kazakov <dimula73@gmail.com>
+ *
+ *  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.
+ */
+
+#include "kis_filter_selections_benchmark.h"
+
+#include "kis_painter.h"
+
+#include <qtest_kde.h>
+#include "testutil.h"
+#include "kis_selection.h"
+#include "kis_transaction.h"
+#include "KoCompositeOp.h"
+#include "kis_datamanager.h"
+
+
+#define NUM_CYCLES 50
+#define WARMUP_CYCLES 2
+#define SHOW_WARMUPS  0
+
+/**
+ * Our filters don't know anything about applyAlphaU8Mask
+ * That's why they treat semy-selected pixels badly
+ *
+ * If you have a hack in KisFilter - processSpecial(..) method
+ * that takes into account this alpha mask then activate
+ * the following define
+ */
+#define USE_GOOD_SELECTIONS 0
+
+#define USE_UTIME 0
+
+
+#if(USE_UTIME==1)
+#include <sys/times.h>
+class KisTimeCounter
+{
+public:
+    KisTimeCounter(){
+        m_factor = double(sysconf(_SC_CLK_TCK))/1000.0;
+        restart();
+    }
+
+    void restart() {
+        times(&m_startTime);
+    }
+
+    double elapsed(){
+        struct tms endTime;
+        times(&endTime);
+        return double(endTime.tms_utime-m_startTime.tms_utime)/m_factor;
+    }
+
+private:
+    struct tms m_startTime;
+    double m_factor;
+};
+#else /* if(USE_UTIME==0) */
+typedef QTime KisTimeCounter;
+#endif
+
+void KisFilterSelectionsBenchmark::initSelection()
+{
+    m_selection = new KisSelection();
+
+//67.2% deselected
+    qDebug() << "Deselected: 67.2%";
+    m_selection->dataManager()->clear(75,75,500,320,255);
+    m_selection->dataManager()->clear(100,100,50,50,quint8(0));
+    m_selection->dataManager()->clear(150,150,50,50,quint8(0));
+    m_selection->dataManager()->clear(200,200,50,50,quint8(0));
+
+    m_selection->dataManager()->clear(375,195,200,200,quint8(0));
+    m_selection->dataManager()->clear(75,195,200,200,quint8(0));
+
+    m_selection->dataManager()->clear(375,75,150,150,quint8(0));
+
+    m_selection->dataManager()->clear(205,105,50,50,quint8(128));
+
+// 94.9% deselected
+//    qDebug() << "Deselected: 94.9%";
+//    m_selection->dataManager()->clear(75,75,500,320,255);
+//    m_selection->dataManager()->clear(80,80,490,310,quint8(0));
+
+
+
+    m_selection->convertToQImage(0).save("TEST_FILTER_SELECTION.png");
+}
+
+void KisFilterSelectionsBenchmark::initFilter(const QString &name)
+{
+    m_filter = KisFilterRegistry::instance()->value(name);
+    Q_ASSERT(m_filter);
+    m_configuration = m_filter->defaultConfiguration(0);
+
+    qDebug() << "Filter initialized:" << name;
+}
+
+void KisFilterSelectionsBenchmark::testFilter(const QString &name)
+{
+    blockSignals(true);
+
+    initFilter(name);
+
+    testUsualSelections(WARMUP_CYCLES);
+    testUsualSelections(NUM_CYCLES);
+
+    testGoodSelections(WARMUP_CYCLES);
+    testGoodSelections(NUM_CYCLES);
+
+    testNoSelections(WARMUP_CYCLES);
+    testNoSelections(NUM_CYCLES);
+
+    testBitBltWOSelections(WARMUP_CYCLES);
+    testBitBltWOSelections(NUM_CYCLES);
+
+    testBitBltSelections(WARMUP_CYCLES);
+    testBitBltSelections(NUM_CYCLES);
+
+    blockSignals(false);
+}
+
+
+void KisFilterSelectionsBenchmark::testAll()
+{
+    initSelection();
+
+    const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8();
+    QImage image(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png");
+    m_device = new KisPaintDevice(cs);
+    m_device->convertFromQImage(image, "", 0, 0);
+
+    testFilter("brightnesscontrast");
+    testFilter("invert");
+//    testFilter("levels");
+
+}
+
+void KisFilterSelectionsBenchmark::testUsualSelections(int num)
+{
+    KisPaintDeviceSP projection =
+        new KisPaintDevice(m_device->colorSpace());
+
+    double avTime;
+    KisTimeCounter timer;
+
+    QRect filterRect = m_selection->selectedExactRect();
+    KisConstProcessingInformation src(m_device,  filterRect.topLeft(), m_selection);
+    KisProcessingInformation dst(projection, filterRect.topLeft(), 0);
+
+    timer.restart();
+    for(int i=0; i<num; i++) {
+        KisTransaction transac("", projection, 0);
+        m_filter->process(src, dst, filterRect.size(), m_configuration, 0);
+    }
+    avTime = double(timer.elapsed())/num;
+
+    projection->convertToQImage(0).save("TFS__USUAL_SELECTIONS.png");
+
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "Selections inside filter:\t\t" << avTime;
+}
+
+void KisFilterSelectionsBenchmark::testNoSelections(int num)
+{
+    KisPaintDeviceSP projection =
+        new KisPaintDevice(m_device->colorSpace());
+
+    double avTime;
+    KisTimeCounter timer;
+
+    QRect filterRect = m_selection->selectedExactRect();
+    KisConstProcessingInformation src(m_device,  filterRect.topLeft(),0);
+    KisProcessingInformation dst(projection, filterRect.topLeft(), 0);
+
+    timer.restart();
+    for(int i=0; i<num; i++) {
+        KisTransaction transac("", projection, 0);
+        m_filter->process(src, dst, filterRect.size(), m_configuration, 0);
+    }
+    avTime = double(timer.elapsed())/num;
+
+    projection->convertToQImage(0).save("TFS__NO_SELECTIONS.png");
+
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "No Selections:\t\t\t\t" << avTime;
+}
+
+void KisFilterSelectionsBenchmark::testGoodSelections(int num)
+{
+#if(USE_GOOD_SELECTIONS==1)
+    KisPaintDeviceSP projection =
+        new KisPaintDevice(m_device->colorSpace());
+
+    double avTime;
+    KisTimeCounter timer;
+
+    QRect filterRect = m_selection->selectedExactRect();
+    KisConstProcessingInformation src(m_device,  filterRect.topLeft(),m_selection);
+    KisProcessingInformation dst(projection, filterRect.topLeft(), 0);
+
+    timer.restart();
+    for(int i=0; i<num; i++) {
+        KisTransaction transac("", projection, 0);
+        m_filter->processSpecial(src, dst, filterRect.size(), m_configuration, 0);
+    }
+    avTime = double(timer.elapsed())/num;
+
+    projection->convertToQImage(0).save("TFS__GOOD_SELECTIONS.png");
+
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "Selections with alpha (filter):\t" << avTime;
+#else /* if (USE_GOOD_SELECTIONS!=1) */
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "Selections with alpha (filter):\t [Disabled]";
+#endif
+}
+
+void KisFilterSelectionsBenchmark::testBitBltWOSelections(int num)
+{
+    KisPaintDeviceSP projection =
+        new KisPaintDevice(m_device->colorSpace());
+
+    double avTime;
+    KisTimeCounter timer;
+
+    QRect filterRect = m_selection->selectedExactRect();
+
+    timer.restart();
+    for(int i=0; i<num; i++) {
+        KisPaintDeviceSP cacheDevice = new KisPaintDevice(projection->colorSpace());
+
+        KisConstProcessingInformation src(m_device,  filterRect.topLeft(),0);
+        KisProcessingInformation dst(cacheDevice, filterRect.topLeft(), 0);
+
+        KisTransaction transac("", cacheDevice, 0);
+        m_filter->process(src, dst, filterRect.size(), m_configuration, 0);
+
+        KisPainter gc(projection);
+        gc.beginTransaction("");
+        gc.setCompositeOp(projection->colorSpace()->compositeOp(COMPOSITE_ALPHA_DARKEN));
 +        gc.bitBlt(filterRect.topLeft(), cacheDevice, filterRect);
+    }
+    avTime = double(timer.elapsed())/num;
+
+    projection->convertToQImage(0).save("TFS__BITBLT_WO_SELECTIONS.png");
+
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "bitBlt w/o sel:\t\t\t" << avTime;
+}
+
+void KisFilterSelectionsBenchmark::testBitBltSelections(int num)
+{
+    KisPaintDeviceSP projection =
+        new KisPaintDevice(m_device->colorSpace());
+
+    double avTime;
+    KisTimeCounter timer;
+
+    QRect filterRect = m_selection->selectedExactRect();
+
+    timer.restart();
+    for(int i=0; i<num; i++) {
+        KisPaintDeviceSP cacheDevice = new KisPaintDevice(projection->colorSpace());
+
+        KisConstProcessingInformation src(m_device,  filterRect.topLeft(),0);
+        KisProcessingInformation dst(cacheDevice, filterRect.topLeft(), 0);
+
+        KisTransaction transac("", cacheDevice, 0);
+        m_filter->process(src, dst, filterRect.size(), m_configuration, 0);
+
+        KisPainter gc(projection);
+        gc.beginTransaction("");
+        gc.setCompositeOp(projection->colorSpace()->compositeOp(COMPOSITE_ALPHA_DARKEN));
 +        gc.setSelection(m_selection);
+        gc.bitBlt(filterRect.topLeft(), cacheDevice, filterRect);
+    }
+    avTime = double(timer.elapsed())/num;
+
+    projection->convertToQImage(0).save("TFS__BITBLT_WITH_SELECTIONS.png");
+
+    if(num > WARMUP_CYCLES || SHOW_WARMUPS)
+        qDebug()<< "bitBlt with sel:\t\t\t" << avTime;
+}
+
+QTEST_KDEMAIN(KisFilterSelectionsBenchmark, GUI)
+#include "kis_filter_selections_benchmark.moc"
diff --git a/krita/image/tests/kis_filter_selections_benchmark.h \
b/krita/image/tests/kis_filter_selections_benchmark.h new file mode 100644
index 0000000..9ff56f8
--- /dev/null
+++ b/krita/image/tests/kis_filter_selections_benchmark.h
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2009 Dmitry  Kazakov <dimula73@gmail.com>
+ *
+ *  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.
+ */
+
+#ifndef KIS_FILTER_SELECTIONS_BENCHMARK_H
+#define KIS_FILTER_SELECTIONS_BENCHMARK_H
+
+#include <QtTest/QtTest>
+#include "kis_selection.h"
+#include "filter/kis_filter.h"
+#include "filter/kis_filter_configuration.h"
+#include "filter/kis_filter_registry.h"
+#include "kis_processing_information.h"
+
+
+class KisFilterSelectionsBenchmark : public QObject
+{
+    Q_OBJECT
+private slots:
+
+    void testAll();
+
+private:
+    void initSelection();
+    void initFilter(const QString &name);
+    void testFilter(const QString &name);
+    void testUsualSelections(int num);
+    void testNoSelections(int num);
+    void testGoodSelections(int num);
+    void testBitBltWOSelections(int num);
+    void testBitBltSelections(int num);
+private:
+    KisSelectionSP m_selection;
+    KisPaintDeviceSP m_device;
+    KisFilterSP m_filter;
+    KisFilterConfiguration *m_configuration;
+};
+
+#endif



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic