void KisStrokeBenchmark::benchmarkRandomLines(QString presetFileName)
{
    KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName);
    bool loadedOk = preset->load();
    if (!loadedOk){
        dbgKrita << "The preset was not loaded correctly. Done.";
        return;
    }else{
        dbgKrita << "preset : " << presetFileName;
    }

    m_painter->setPaintOpPreset(preset, m_layer, m_image);

    QBENCHMARK{
        KisDistanceInformation currentDistance;
        for (int i = 0; i < LINES; i++){
            KisPaintInformation pi1(m_startPoints[i], 0.0);
            KisPaintInformation pi2(m_endPoints[i], 1.0);
            m_painter->paintLine(pi1, pi2, &currentDistance);
        }
    }

#ifdef SAVE_OUTPUT
    m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_randomLines" + OUTPUT_FORMAT);
#endif
}
void KisStrokeBenchmark::benchmarkCircle(QString presetFileName)
{
    dbgKrita << "(circle)preset : " << presetFileName;

    KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName);
    if (!preset->load()){
        dbgKrita << "Preset was not loaded";
        return;
    }

    m_painter->setPaintOpPreset(preset, m_layer, m_image);

QBENCHMARK{

    qreal radius = 300;
    qreal randomOffset = 300 * 0.4;
    int rounds = 20;
    int steps = 20;
    qreal step = 1.0 / steps;

    QPointF center(m_image->width() * 0.5, m_image->height() * 0.5);
    QPointF first(center.x()+radius,center.y());

    srand48(0);
    for (int k = 0; k < rounds; k++){
        KisDistanceInformation currentDistance;
        m_painter->paintLine(center, first, &currentDistance);
        QPointF prev = first;
        for (int i = 1; i < steps; i++) {
            qreal cx = cos(i * step * 2 * M_PI);
            qreal cy = sin(i * step * 2 * M_PI);

            cx *= (radius + drand48() * randomOffset);
            cy *= (radius + drand48() * randomOffset);

            cx += center.x();
            cy += center.y();

            m_painter->paintLine(prev, QPointF(cx,cy), &currentDistance);
            prev = QPointF(cx,cy);
        }
        m_painter->paintLine(prev, first, &currentDistance);
    }
}

#ifdef SAVE_OUTPUT
    m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_circle" + OUTPUT_FORMAT);
#endif

}
Beispiel #3
0
    KisPaintOpPresetSP defaultPreset(const KoID& paintOp)
    {
        QString defaultName = paintOp.id() + ".kpp";
        QString path = KGlobal::mainComponent().dirs()->findResource("kis_defaultpresets", defaultName);

        KisPaintOpPresetSP preset = new KisPaintOpPreset(path);

        if (!preset->load())
            preset = KisPaintOpRegistry::instance()->defaultPreset(paintOp);

        Q_ASSERT(preset);
        Q_ASSERT(preset->valid());

        return preset;
    }
Beispiel #4
0
int main(int argc, char** argv)
{
    KAboutData aboutData("scratchpad",
                         0,
                         ki18n("scratchpad"),
                         "1.0",
                         ki18n("Test application for the single paint device scratchpad canvas"),
                         KAboutData::License_LGPL,
                         ki18n("(c) 2010 Boudewijn Rempt"),
                         KLocalizedString(),
                         "www.krita.org",
                         "*****@*****.**");
    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineOptions options;

    options.add("+preset", ki18n("preset to load"));
    KCmdLineArgs::addCmdLineOptions(options);

    KApplication app;

    KisScratchPad *scratchpad = new KisScratchPad();

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    if (args->count() > 0 ) {
        QString fileName = args->arg(0);
        if (QFile::exists(fileName)) {
            KisPaintOpPresetSP preset = new KisPaintOpPreset(fileName);
            preset->load();
            if (preset->valid()) {
                scratchpad->setPreset(preset);
            }
        }
    }

    const KoColorProfile* profile = KoColorSpaceRegistry::instance()->rgb8()->profile();
    scratchpad->setColorSpace(KoColorSpaceRegistry::instance()->rgb16());
    scratchpad->setDisplayProfile(profile);
    scratchpad->setCanvasColor(Qt::white);
    scratchpad->setPaintColor(Qt::black);
    scratchpad->show();
    return app.exec();
}
inline void KisStrokeBenchmark::benchmarkLine(QString presetFileName)
{
    KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName);
    preset->load();
    m_painter->setPaintOpPreset(preset, m_layer, m_image);

    QPointF startPoint(0.10 * TEST_IMAGE_WIDTH, 0.5 * TEST_IMAGE_HEIGHT);
    QPointF endPoint(0.90 * TEST_IMAGE_WIDTH, 0.5 * TEST_IMAGE_HEIGHT);

    KisDistanceInformation currentDistance;
    KisPaintInformation pi1(startPoint, 0.0);
    KisPaintInformation pi2(endPoint, 1.0);

    QBENCHMARK{
        m_painter->paintLine(pi1, pi2, &currentDistance);
    }

#ifdef SAVE_OUTPUT
    m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_line" + OUTPUT_FORMAT);
#endif

}
void KisStrokeBenchmark::benchmarkStroke(QString presetFileName)
{
    KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName);
    bool loadedOk = preset->load();
    if (!loadedOk){
        dbgKrita << "The preset was not loaded correctly. Done.";
        return;
    } else {
        dbgKrita << "preset : " << presetFileName;
    }

    m_painter->setPaintOpPreset(preset, m_layer, m_image);

    QBENCHMARK{
        KisDistanceInformation currentDistance;
        m_painter->paintBezierCurve(m_pi1, m_c1, m_c1, m_pi2, &currentDistance);
        m_painter->paintBezierCurve(m_pi2, m_c2, m_c2, m_pi3, &currentDistance);
    }

#ifdef SAVE_OUTPUT
    dbgKrita << "Saving output " << m_outputPath + presetFileName + ".png";
    m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + OUTPUT_FORMAT);
#endif
}
KoCanvasResourceManager* utils::createResourceManager(KisImageWSP image,
                                                KisNodeSP node,
                                                const QString &presetFileName)
{
    KoCanvasResourceManager *manager = new KoCanvasResourceManager();

    QVariant i;

    i.setValue(KoColor(Qt::black, image->colorSpace()));
    manager->setResource(KoCanvasResourceManager::ForegroundColor, i);

    i.setValue(KoColor(Qt::white, image->colorSpace()));
    manager->setResource(KoCanvasResourceManager::BackgroundColor, i);

    i.setValue(static_cast<void*>(0));
    manager->setResource(KisCanvasResourceProvider::CurrentPattern, i);
    manager->setResource(KisCanvasResourceProvider::CurrentGradient, i);
    manager->setResource(KisCanvasResourceProvider::CurrentGeneratorConfiguration, i);

    if(!node) {
        node = image->root();

        while(node && !dynamic_cast<KisPaintLayer*>(node.data())) {
            node = node->firstChild();
        }

        Q_ASSERT(node && dynamic_cast<KisPaintLayer*>(node.data()));
    }

    i.setValue(node);
    manager->setResource(KisCanvasResourceProvider::CurrentKritaNode, i);

    KisPaintOpPresetSP preset;

    if (!presetFileName.isEmpty()) {
        QString fullFileName = TestUtil::fetchDataFileLazy(presetFileName);
        preset = new KisPaintOpPreset(fullFileName);
        bool presetValid = preset->load();
        Q_ASSERT(presetValid); Q_UNUSED(presetValid);

        i.setValue(preset);
        manager->setResource(KisCanvasResourceProvider::CurrentPaintOpPreset, i);
    }

    i.setValue(COMPOSITE_OVER);
    manager->setResource(KisCanvasResourceProvider::CurrentCompositeOp, i);

    i.setValue(false);
    manager->setResource(KisCanvasResourceProvider::MirrorHorizontal, i);

    i.setValue(false);
    manager->setResource(KisCanvasResourceProvider::MirrorVertical, i);

    i.setValue(1.0);
    manager->setResource(KisCanvasResourceProvider::Opacity, i);

    i.setValue(1.0);
    manager->setResource(KisCanvasResourceProvider::HdrExposure, i);

    i.setValue(QPoint());
    manager->setResource(KisCanvasResourceProvider::MirrorAxesCenter, i);

    return manager;
}