void KisFilterSelectionsBenchmark::initSelection()
{
    m_selection = new KisSelection();
    KisPixelSelectionSP pixelSelection = m_selection->pixelSelection();


//67.2% deselected
    dbgKrita << "Deselected: 67.2%";
    pixelSelection->dataManager()->clear(75, 75, 500, 320, 255);
    pixelSelection->dataManager()->clear(100, 100, 50, 50, quint8(0));
    pixelSelection->dataManager()->clear(150, 150, 50, 50, quint8(0));
    pixelSelection->dataManager()->clear(200, 200, 50, 50, quint8(0));

    pixelSelection->dataManager()->clear(375, 195, 200, 200, quint8(0));
    pixelSelection->dataManager()->clear(75, 195, 200, 200, quint8(0));

    pixelSelection->dataManager()->clear(375, 75, 150, 150, quint8(0));

    pixelSelection->dataManager()->clear(205, 105, 50, 50, quint8(128));

// 94.9% deselected
//    dbgKrita << "Deselected: 94.9%";
//    pixelSelection->dataManager()->clear(75,75,500,320,255);
//    pixelSelection->dataManager()->clear(80,80,490,310,quint8(0));



    pixelSelection->convertToQImage(0).save("TEST_FILTER_SELECTION.png");
}
Example #2
0
void KisFillPainterTest::benchmarkFillingScanlineSelection()
{
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisPaintDeviceSP dev = new KisPaintDevice(cs);

    QImage srcImage(TestUtil::fetchDataFileLazy("heavy_labyrinth.png"));
    QVERIFY(!srcImage.isNull());

    QRect imageRect = srcImage.rect();

    dev->convertFromQImage(srcImage, 0, 0, 0);


    KisPixelSelectionSP pixelSelection = new KisPixelSelection();

    QBENCHMARK_ONCE {
        KisScanlineFill gc(dev, QPoint(), imageRect);
        gc.setThreshold(THRESHOLD);
        gc.fillSelection(pixelSelection);
    }

    QImage resultImage =
        pixelSelection->convertToQImage(0,
                                        imageRect.x(), imageRect.y(),
                                        imageRect.width(), imageRect.height());

    QVERIFY(TestUtil::checkQImage(resultImage,
                                  "fill_painter",
                                  "scanline_",
                                  "heavy_labyrinth_top_left_selection"));
}
void KisSelectionTest::testInvertSelection()
{
    KisSelectionSP selection = new KisSelection();
    KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
    pixelSelection->select(QRect(20, 20, 20, 20));
    QCOMPARE(pixelSelection->selected(30, 30), MAX_SELECTED);
    QCOMPARE(pixelSelection->selected(0, 0), MIN_SELECTED);
    QCOMPARE(pixelSelection->selected(512, 512), MIN_SELECTED);

    pixelSelection->invert();


    QCOMPARE(pixelSelection->selected(100, 100), MAX_SELECTED);
    QCOMPARE(pixelSelection->selected(22, 22), MIN_SELECTED);
    QCOMPARE(pixelSelection->selected(0, 0), MAX_SELECTED);
    QCOMPARE(pixelSelection->selected(512, 512), MAX_SELECTED);
    pixelSelection->convertToQImage(0, 0, 0, 100, 100).save("yyy.png");
    // XXX: This should happen automatically
    selection->updateProjection();
    selection->convertToQImage(0, 0, 0, 100, 100).save("zzz.png");

    QCOMPARE(selection->selectedExactRect(), QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX));
    QCOMPARE(selection->selectedRect(), QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX));

    QCOMPARE(selection->selected(100, 100), MAX_SELECTED);
    QCOMPARE(selection->selected(22, 22), MIN_SELECTED);
    QCOMPARE(selection->selected(10, 10), MAX_SELECTED);
    QCOMPARE(selection->selected(0, 0), MAX_SELECTED);
    QCOMPARE(selection->selected(512, 512), MAX_SELECTED);

}
void testShapedGradientPainterImpl(const QPolygonF &selectionPolygon,
                                   const QString &testName,
                                   const QPolygonF &selectionErasePolygon = QPolygonF())
{
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisPaintDeviceSP dev = new KisPaintDevice(cs);

    QRect imageRect(0,0,300,300);

    KisSelectionSP selection = new KisSelection();
    KisPixelSelectionSP pixelSelection = selection->pixelSelection();

    KisPainter selPainter(pixelSelection);
    selPainter.setFillStyle(KisPainter::FillStyleForegroundColor);
    selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
    selPainter.paintPolygon(selectionPolygon);

    if (!selectionErasePolygon.isEmpty()) {
        selPainter.setCompositeOp(COMPOSITE_ERASE);
        selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
        selPainter.paintPolygon(selectionErasePolygon);
    }

    selPainter.end();

    pixelSelection->invalidateOutlineCache();

    pixelSelection->convertToQImage(0, imageRect).save("sgt_selection.png");

    QLinearGradient testGradient;
    testGradient.setColorAt(0.0, Qt::white);
    testGradient.setColorAt(0.5, Qt::green);
    testGradient.setColorAt(1.0, Qt::black);
    testGradient.setSpread(QGradient::ReflectSpread);
    QScopedPointer<KoStopGradient> gradient(
        KoStopGradient::fromQGradient(&testGradient));

    KisGradientPainter gc(dev, selection);
    gc.setGradient(gradient.data());
    gc.setGradientShape(KisGradientPainter::GradientShapePolygonal);

    gc.paintGradient(selectionPolygon.boundingRect().topLeft(),
                     selectionPolygon.boundingRect().bottomRight(),
                     KisGradientPainter::GradientRepeatNone,
                     0,
                     false,
                     imageRect.x(),
                     imageRect.y(),
                     imageRect.width(),
                     imageRect.height());

    QVERIFY(TestUtil::checkQImageExternal(dev->convertToQImage(0, imageRect),
                                          "shaped_gradient",
                                          "fill",
                                          testName, 1, 1, 0));
}