Beispiel #1
0
void testObligeSingleChildImpl(bool transpDefaultPixel)
{

    QString id = !transpDefaultPixel ?
        "single_layer_no_channel_flags_nontransp_def_pixel.kra" :
        "single_layer_no_channel_flags_transp_def_pixel.kra";

    QString fileName = TestUtil::fetchDataFileLazy(id);

    KisDocument *doc = KisPart::instance()->createDocument();
    doc->loadNativeFormat(fileName);
    KisImageSP image = doc->image();

    QVERIFY(image);
    QCOMPARE(image->nlayers(), 2);

    KisNodeSP root = image->root();
    KisNodeSP child = root->firstChild();

    QVERIFY(child);

    QCOMPARE(root->original(), root->projection());

    if (transpDefaultPixel) {
        QCOMPARE(root->original(), child->projection());
    } else {
        QVERIFY(root->original() != child->projection());
    }

    delete doc;
}
Beispiel #2
0
void KritaShape::tryLoadFromImageData(KoImageData *data)
{

    if (data == 0)
        return;

    // TODO maybe we want to use the image rawData for that
    QImage image = data->image();

    if (image.isNull())
        return;

    delete m_d->doc;

    m_d->doc = new KisDoc2(0, 0, false);
    connect(m_d->doc, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));

    // Create an empty image
    KisImageSP img = m_d->doc->newImage(i18n("Converted from KoImageData"), image.width(), image.height(), 0);

    // Convert the QImage to a paint device
    KisPaintLayer * layer = dynamic_cast<KisPaintLayer*>(img->root()->firstChild().data());
    if (layer)
        layer->paintDevice()->convertFromQImage(image, "", 0, 0);

    // emits sigLoadingFinished
    m_d->doc->setCurrentImage(img);
}
void KisPrescaledProjectionTest::testScalingUndeferredSmoothing()
{
    // Set up a nice image
    QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "lena.png");

    // Undo adapter not necessary
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, qimage.width(), qimage.height(), cs, "projection test");

    // 300 dpi recalculated to pixels per point (of which there are 72
    // to the inch)
    image->setResolution(100, 100);

    KisPaintLayerSP layer = new KisPaintLayer(image, "test", OPACITY_OPAQUE_U8, cs);
    image->addNode(layer.data(), image->rootLayer(), 0);
    layer->paintDevice()->convertFromQImage(qimage, 0);

    KisPrescaledProjection projection;
    KisCoordinatesConverter converter;
    
    converter.setImage(image);
    projection.setCoordinatesConverter(&converter);
    projection.setMonitorProfile(0,
                                 KoColorConversionTransformation::internalRenderingIntent(),
                                 KoColorConversionTransformation::internalConversionFlags());
    projection.setImage(image);

    testProjectionScenario(projection, &converter, "120dpi");

}
void KisImageViewConverterTest::testViewToDocument()
{
    const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, 512, 512, colorSpace, "test");
    KisImageViewConverter viewConverter(image);

    image->setResolution(1.38888888, 1.38888888);

    QVERIFY(viewConverter.viewToDocument(QPointF(0.0, 0.0))
            == QPointF(0.0, 0.0));

    QPointF f = viewConverter.viewToDocument(QPointF(5, 5));
    QVERIFY(f.x() < 3.7 && f.x() > 3.5 && f.y() < 3.7 && f.y() > 3.5);

    QRectF r = viewConverter.viewToDocument(QRectF(0.0, 0.0, 5, 5));
    QVERIFY(r.width() < 3.7 && r.width() > 3.5
            && r.height() < 3.7 && r.height() > 3.5);

    QSizeF s = viewConverter.viewToDocument(QSizeF(1.0, 1.0));
    QVERIFY(s.width() < 0.721 && s.width() > 0.719
            && s.height() < 0.721 && s.height() > 0.719);

    double x = viewConverter.viewToDocumentX(1.0);
    QVERIFY(x < 0.721 && x > 0.719);

    double y = viewConverter.viewToDocumentY(1.0);
    QVERIFY(y < 0.721 && y > 0.719);

}
void KisSimpleUpdateQueueTest::testMixingTypes()
{
    QRect imageRect(0,0,1024,1024);

    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, imageRect.width(), imageRect.height(), cs, "merge test");

    KisPaintLayerSP paintLayer = new KisPaintLayer(image, "test", OPACITY_OPAQUE_U8);

    image->lock();
    image->addNode(paintLayer);
    image->unlock();

    QRect dirtyRect1(0,0,200,200);
    QRect dirtyRect2(0,0,200,200);
    QRect dirtyRect3(20,20,200,200);

    KisTestableSimpleUpdateQueue queue;
    KisWalkersList& walkersList = queue.getWalkersList();

    queue.addUpdateJob(paintLayer, dirtyRect1, imageRect, 0);
    queue.addFullRefreshJob(paintLayer, dirtyRect2, imageRect, 0);
    queue.addFullRefreshJob(paintLayer, dirtyRect3, imageRect, 0);
    queue.addUpdateNoFilthyJob(paintLayer, dirtyRect1, imageRect, 0);

    QCOMPARE(walkersList.size(), 3);

    QVERIFY(checkWalker(walkersList[0], QRect(0,0,200,200)));
    QVERIFY(checkWalker(walkersList[1], QRect(0,0,220,220)));
    QVERIFY(checkWalker(walkersList[2], QRect(0,0,200,200)));

    QCOMPARE(walkersList[0]->type(), KisBaseRectsWalker::UPDATE);
    QCOMPARE(walkersList[1]->type(), KisBaseRectsWalker::FULL_REFRESH);
    QCOMPARE(walkersList[2]->type(), KisBaseRectsWalker::UPDATE_NO_FILTHY);
}
void KisPasteNewActionFactory::run(KisView2 *view)
{
    Q_UNUSED(view);

    KisPaintDeviceSP clip = KisClipboard::instance()->clip(QRect(), true);
    if (!clip) return;

    QRect rect = clip->exactBounds();
    if (rect.isEmpty()) return;

    KisDoc2 *doc = new KisDoc2();
    if (!doc) return;

    KisImageSP image = new KisImage(doc->createUndoStore(),
                                    rect.width(),
                                    rect.height(),
                                    clip->colorSpace(),
                                    i18n("Pasted"));
    KisPaintLayerSP layer =
        new KisPaintLayer(image.data(), clip->objectName(),
                          OPACITY_OPAQUE_U8, clip->colorSpace());

    KisPainter p(layer->paintDevice());
    p.setCompositeOp(COMPOSITE_COPY);
    p.bitBlt(0, 0, clip, rect.x(), rect.y(), rect.width(), rect.height());
    p.end();

    image->addNode(layer.data(), image->rootLayer());
    doc->setCurrentImage(image);

    KoMainWindow *win = doc->documentPart()->createMainWindow();
    win->show();
    win->setRootDocument(doc);
}
void KisPasteNewActionFactory::run(KisViewManager *viewManager)
{
    Q_UNUSED(viewManager);

    KisPaintDeviceSP clip = KisClipboard::instance()->clip(QRect(), true);
    if (!clip) return;

    QRect rect = clip->exactBounds();
    if (rect.isEmpty()) return;

    KisDocument *doc = KisPart::instance()->createDocument();

    KisImageSP image = new KisImage(doc->createUndoStore(),
                                    rect.width(),
                                    rect.height(),
                                    clip->colorSpace(),
                                    i18n("Pasted"));
    KisPaintLayerSP layer =
        new KisPaintLayer(image.data(), clip->objectName(),
                          OPACITY_OPAQUE_U8, clip->colorSpace());

    KisPainter::copyAreaOptimized(QPoint(), clip, layer->paintDevice(), rect);

    image->addNode(layer.data(), image->rootLayer());
    doc->setCurrentImage(image);
    KisPart::instance()->addDocument(doc);

    KisMainWindow *win = viewManager->mainWindow();
    win->addViewAndNotifyLoadingCompleted(doc);
}
Beispiel #8
0
KoFilter::ConversionStatus MagickExport::convert(const QCString& from, const QCString& to)
{
    kdDebug(41008) << "magick export! From: " << from << ", To: " << to << "\n";
    
    if (from != "application/x-krita")
        return KoFilter::NotImplemented;

    // XXX: Add dialog about flattening layers here

    KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
    QString filename = m_chain->outputFile();
    
    if (!output)
        return KoFilter::CreationError;
    
    if (filename.isEmpty()) return KoFilter::FileNotFound;

    KURL url;
    url.setPath(filename);

    KisImageSP img = output->currentImage();

    KisImageMagickConverter ib(output, output->undoAdapter());

    KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
    KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
    
    vKisAnnotationSP_it beginIt = img->beginAnnotations();
    vKisAnnotationSP_it endIt = img->endAnnotations();
    if (ib.buildFile(url, l, beginIt, endIt) == KisImageBuilder_RESULT_OK) {
        return KoFilter::OK;
    }
    return KoFilter::InternalError;
}
void KisImageViewConverterTest::testDocumentToView()
{
    const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, 512, 512, colorSpace, "test");
    KisImageViewConverter viewConverter(image);

    image->setResolution(1.38888888, 1.38888888);

    QVERIFY(viewConverter.documentToView(QPointF(0.0, 0.0))
            == QPointF(0.0, 0.0));

    QPointF f = viewConverter.documentToView(QPointF(3.2, 5.2));
    QVERIFY(f.x() < 4.44445 && f.x() > 4.44443 && f.y() < 7.22223 && f.y() > 7.22221);

    QRectF r = viewConverter.documentToView(QRectF(0.0, 0.0, 10.0, 10.0));
    QVERIFY(r.width() < 13.889 && r.width() > 13.8888
            && r.height() < 13.889 && r.height() > 13.8888);

    QSizeF s = viewConverter.documentToView(QSizeF(1.0, 1.0));
    QVERIFY(s.width() < 1.3888889 && s.width() > 1.388887
            && s.height() < 1.3888889 && s.height() > 1.388887);

    double x = viewConverter.documentToViewX(1.0);
    QVERIFY(x < 1.3888889 && x > 1.388887);

    double y = viewConverter.documentToViewY(1.0);
    QVERIFY(y < 1.3888889 && y > 1.388887);

}
void KisProcessingApplicatorTest::testNoUIUpdates()
{
    KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
    KisPaintLayerSP paintLayer1;
    KisPaintLayerSP paintLayer2;
    KisImageSP image = createImage(undoStore, paintLayer1, paintLayer2);
    QSignalSpy uiSignalsCounter(image.data(), SIGNAL(sigImageUpdated(const QRect&)));

    QRect cropRect1(40,40,86,86);

    {
        KisProcessingApplicator applicator(image, image->rootLayer(),
                                           KisProcessingApplicator::RECURSIVE |
                                           KisProcessingApplicator::NO_UI_UPDATES);

        KisProcessingVisitorSP visitor =
            new KisCropProcessingVisitor(cropRect1, true, true);
        applicator.applyVisitor(visitor);
        applicator.end();
        image->waitForDone();
    }

    QCOMPARE(uiSignalsCounter.size(), 0);

    uiSignalsCounter.clear();

    undoStore->undo();
    image->waitForDone();

    QCOMPARE(uiSignalsCounter.size(), 0);
}
void KisProcessingApplicatorTest::testRecursiveProcessing()
{
    KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
    KisPaintLayerSP paintLayer1;
    KisPaintLayerSP paintLayer2;
    KisImageSP image = createImage(undoStore, paintLayer1, paintLayer2);

    QRect cropRect1(40,40,86,86);

    QVERIFY(checkLayers(image, "recursive_initial"));

    {
        KisProcessingApplicator applicator(image, image->rootLayer(),
                                           KisProcessingApplicator::RECURSIVE);

        KisProcessingVisitorSP visitor =
            new KisCropProcessingVisitor(cropRect1, true, true);
        applicator.applyVisitor(visitor);
        applicator.end();
        image->waitForDone();
    }

    QVERIFY(checkLayers(image, "recursive_crop"));

    undoStore->undo();
    image->waitForDone();
    QVERIFY(checkLayers(image, "recursive_initial"));
}
void KisImageTest::testLayerComposition()
{
    KisImageSP image = new KisImage(0, IMAGE_WIDTH, IMAGE_WIDTH, 0, "layer tests");
    QVERIFY(image->rootLayer() != 0);
    QVERIFY(image->rootLayer()->firstChild() == 0);

    KisLayerSP layer = new KisPaintLayer(image, "layer 1", OPACITY_OPAQUE_U8);
    image->addNode(layer);
    KisLayerSP layer2 = new KisPaintLayer(image, "layer 2", OPACITY_OPAQUE_U8);
    image->addNode(layer2);

    QVERIFY(layer->visible());
    QVERIFY(layer2->visible());

    KisLayerComposition comp(image, "comp 1");
    comp.store();

    layer2->setVisible(false);

    QVERIFY(layer->visible());
    QVERIFY(!layer2->visible());

    KisLayerComposition comp2(image, "comp 2");
    comp2.store();

    comp.apply();

    QVERIFY(layer->visible());
    QVERIFY(layer2->visible());

    comp2.apply();

    QVERIFY(layer->visible());
    QVERIFY(!layer2->visible());
}
Beispiel #13
0
void KisMaskTest::testDeferredOffsetInitialization()
{
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, 100, 100, cs, "stest");

    KisMaskSP mask = new TestMask;

    QCOMPARE(mask->x(), 0);
    QCOMPARE(mask->y(), 0);

    mask->setX(10);
    QCOMPARE(mask->x(), 10);
    QCOMPARE(mask->y(), 0);

    mask->setY(11);
    QCOMPARE(mask->x(), 10);
    QCOMPARE(mask->y(), 11);

    mask->initSelection(image->rootLayer());

    // IMPORTANT: a bit weird behavior, but it is needed for
    // KisKraLoadVisitor to work properly
    QCOMPARE(mask->x(), 10);
    QCOMPARE(mask->y(), 11);

    // Now there is no deferred initialization, so the offest
    // should simply be reset
    mask->initSelection(image->rootLayer());
    QCOMPARE(mask->x(), 0);
    QCOMPARE(mask->y(), 0);

    KisSelectionSP selection = mask->selection();
    QCOMPARE(selection->parentNode(), KisNodeSP(mask));
}
Beispiel #14
0
bool KisOpenGLImageTextures::imageCanUseHDRExposureProgram(KisImageSP image)
{
#ifdef HAVE_GLEW
    if (!image->colorSpace()->hasHighDynamicRange()) {
        return false;
    }

    KisConfig cfg;

    if (!cfg.useOpenGLShaders()) {
        return false;
    }
    if (HDRExposureProgram == 0) {
        return false;
    }
    if (!HDRExposureProgram->isValid()) {
        return false;
    }
    if (!haveHDRTextureFormat(image->colorSpace())) {
        return false;
    }
    return true;
#else
    Q_UNUSED(image);
    return false;
#endif
}
void KisCutCopyActionFactory::run(bool willCut, KisView2 *view)
{
    KisImageSP image = view->image();
    bool haveShapesSelected = view->selectionManager()->haveShapesSelected();

    if (haveShapesSelected) {
#ifdef __GNUC__
#warning "Add saving of XML data for Cut/Copy of shapes"
#endif

        image->barrierLock();
        if (willCut) {
            view->canvasBase()->toolProxy()->cut();
        } else {
            view->canvasBase()->toolProxy()->copy();
        }
        image->unlock();
    } else {
        KisNodeSP node = view->activeNode();
        if (!node) return;

        image->barrierLock();
        ActionHelper::copyFromDevice(view, node->paintDevice());
        image->unlock();

        KUndo2Command *command = 0;

        if (willCut && node->isEditable()) {
            struct ClearSelection : public KisTransactionBasedCommand {
                ClearSelection(KisNodeSP node, KisSelectionSP sel)
                    : m_node(node), m_sel(sel) {}
                KisNodeSP m_node;
                KisSelectionSP m_sel;

                KUndo2Command* paint() {
                    KisTransaction transaction("", m_node->paintDevice());
                    m_node->paintDevice()->clearSelection(m_sel);
                    m_node->setDirty(m_sel->selectedRect());
                    return transaction.endAndTake();
                }
            };

            command = new ClearSelection(node, view->selection());
        }

        QString actionName = willCut ? i18n("Cut") : i18n("Copy");
        KisProcessingApplicator *ap = beginAction(view, actionName);

        if (command) {
            ap->applyCommand(command,
                             KisStrokeJobData::SEQUENTIAL,
                             KisStrokeJobData::NORMAL);
        }

        KisOperationConfiguration config(id());
        config.setProperty("will-cut", willCut);
        endAction(ap, config.toXML());
    }
}
Beispiel #16
0
QImage KritaShape::convertToQImage()
{
    if (m_d->doc && m_d->doc->image()) {
        KisImageSP img = m_d->doc->image();
        return img->convertToQImage(0, 0, img->width(), img->height(), m_d->displayProfile);
    }
    return QImage();
}
Beispiel #17
0
void KisImageResizeCommand::redo()
{
    KisImageSP image = m_image.toStrongRef();
    if (!image) {
        return;
    }
    image->setSize(m_sizeAfter);
}
Beispiel #18
0
void KisImageLockCommand::undo()
{
    KisImageSP image = m_image.toStrongRef();
    if (!image) {
        return;
    }
    image->refreshGraph();
}
Beispiel #19
0
void KisImageResizeCommand::undo()
{
    KisImageSP image = m_image.toStrongRef();
    if (!image) {
        return;
    }
    image->setSize(m_sizeBefore);
}
void KisSimpleUpdateQueueTest::testJobProcessing()
{
    KisTestableUpdaterContext context(2);

    QRect imageRect(0,0,200,200);

    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisImageSP image = new KisImage(0, imageRect.width(), imageRect.height(), cs, "merge test");

    KisPaintLayerSP paintLayer = new KisPaintLayer(image, "test", OPACITY_OPAQUE_U8);

    image->lock();
    image->addNode(paintLayer);
    image->unlock();

    QRect dirtyRect1(0,0,50,100);
    QRect dirtyRect2(0,0,100,100);
    QRect dirtyRect3(50,0,50,100);
    QRect dirtyRect4(150,150,50,50);
    QRect dirtyRect5(dirtyRect4); // theoretically, should be merged with 4

    QVector<KisUpdateJobItem*> jobs;
    KisWalkersList walkersList;

    /**
     * Process the queue and look what has been added into
     * the updater context
     */

    KisTestableSimpleUpdateQueue queue;

    queue.addUpdateJob(paintLayer, dirtyRect1, imageRect, 0);
    queue.addUpdateJob(paintLayer, dirtyRect2, imageRect, 0);
    queue.addUpdateJob(paintLayer, dirtyRect3, imageRect, 0);
    queue.addUpdateJob(paintLayer, dirtyRect4, imageRect, 0);

    {
        TestUtil::LodOverride l(1, image);
        queue.addUpdateJob(paintLayer, dirtyRect5, imageRect, 1);
    }

    queue.processQueue(context);

    jobs = context.getJobs();

    QVERIFY(checkWalker(jobs[0]->walker(), dirtyRect2));
    QVERIFY(checkWalker(jobs[1]->walker(), dirtyRect4));
    QCOMPARE(jobs.size(), 2);

    QCOMPARE(context.currentLevelOfDetail(), 0);


    walkersList = queue.getWalkersList();

    QCOMPARE(walkersList.size(), 1);
    QVERIFY(checkWalker(walkersList[0], dirtyRect5, 1));
}
QImage utils::StrokeTester::doStroke(bool cancelled,
                                     bool indirectPainting,
                                     bool externalLayer,
                                     bool testUpdates,
                                     bool needQImage)
{
    KisImageSP image = utils::createImage(0, m_imageSize);
    KoCanvasResourceManager *manager = utils::createResourceManager(image, 0, m_presetFilename);
    KisNodeSP currentNode;

    for (int i = 0; i < m_numIterations; i++) {
        modifyResourceManager(manager, image, i);

        KisPainter *painter = new KisPainter();
        KisResourcesSnapshotSP resources =
            new KisResourcesSnapshot(image,
                                     image->rootLayer()->firstChild(),
                                     image->postExecutionUndoAdapter(),
                                     manager);

        if(externalLayer) {
            KisNodeSP externalNode = new KisPaintLayer(0, "extlyr", OPACITY_OPAQUE_U8, image->colorSpace());
            resources->setCurrentNode(externalNode);
            Q_ASSERT(resources->currentNode() == externalNode);
        }

        initImage(image, resources->currentNode(), i);

        KisStrokeStrategy *stroke = createStroke(indirectPainting, resources, painter, image);
        m_strokeId = image->startStroke(stroke);
        addPaintingJobs(image, resources, painter, i);

        if(!cancelled) {
            image->endStroke(m_strokeId);
        }
        else {
            image->cancelStroke(m_strokeId);
        }

        image->waitForDone();
        currentNode = resources->currentNode();
    }

    QImage resultImage;
    if(needQImage) {
        KisPaintDeviceSP device = testUpdates ?
            image->projection() :
            currentNode->paintDevice();

        resultImage = device->convertToQImage(0, 0, 0, image->width(), image->height());
    }

    image = 0;
    delete manager;
    return resultImage;
}
Beispiel #22
0
void KisLayerTest::testMoveLayer()
{
    const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
    KisImageSP image = new KisImage(0, 512, 512, colorSpace, "layer test");

    KisLayerSP node1 = new TestLayer(image, "layer1", OPACITY_OPAQUE);
    KisLayerSP node2 = new TestLayer(image, "layer2", OPACITY_OPAQUE);
    KisLayerSP node3 = new TestLayer(image, "layer3", OPACITY_OPAQUE);
    node1->setName("node1");
    node2->setName("node2");
    node3->setName("node3");

    QVERIFY(image->addNode(node1));
    QVERIFY(image->addNode(node2));
    QVERIFY(image->addNode(node3));

    QVERIFY(image->root()->at(0) == node1.data());
    QVERIFY(image->root()->at(1) == node2.data());
    QVERIFY(image->root()->at(2) == node3.data());

    QVERIFY(image->moveNode(node3, image->rootLayer(), node1));

    QVERIFY(image->root()->at(0) == node1.data());
    QVERIFY(image->root()->at(1) == node3.data());
    QVERIFY(image->root()->at(2) == node2.data());

}
void KisImageTest::layerTests()
{
    KisImageSP image = new KisImage(0, IMAGE_WIDTH, IMAGE_WIDTH, 0, "layer tests");
    QVERIFY(image->rootLayer() != 0);
    QVERIFY(image->rootLayer()->firstChild() == 0);

    KisLayerSP layer = new KisPaintLayer(image, "layer 1", OPACITY_OPAQUE_U8);
    image->addNode(layer);

    QVERIFY(image->rootLayer()->firstChild()->objectName() == layer->objectName());
}
Beispiel #24
0
QRectF KisDuplicateOpSettings::duplicateOutlineRect(const QPointF& pos, KisImageSP image) const
{
    // Compute the rectangle for the offset
    QRectF rect2 = QRectF( -5, -5, 10, 10);
    if(m_isOffsetNotUptodate)
    {
        rect2.translate(m_position);
    } else {
        rect2.translate(- m_offset + image->documentToPixel( pos) );
    }
    return image->pixelToDocument(rect2);
}
void KisTransparencyMaskTest::testMoveMaskItself()
{
    KisImageSP image;
    KisPaintLayerSP layer;
    KisPaintDeviceSP dev;
    KisTransparencyMaskSP mask;

    initImage(image, layer, dev, mask);
    mask->initSelection(layer);
    mask->selection()->pixelSelection()->invert();
    mask->select(QRect(50, 50, 100, 100));

    KisFullRefreshWalker walker(image->bounds());
    KisAsyncMerger merger;

    walker.collectRects(layer, image->bounds());
    merger.startMerge(walker);

    // image->projection()->convertToQImage(0, 0,0,300,300).save("proj_before.png");

    QRect initialRect(0,0,200,100);
    QCOMPARE(layer->exactBounds(), initialRect);
    QCOMPARE(image->projection()->exactBounds(), QRect(50,50,100,50));


    //layer->setX(100);
    //layer->setY(100);

    dbgKrita << "Sel. rect before:" << mask->selection()->selectedExactRect();

    mask->setX(50);
    mask->setY(25);

    dbgKrita << "Sel. rect after:" << mask->selection()->selectedExactRect();


    QCOMPARE(mask->selection()->selectedExactRect(), QRect(100, 75, 100, 100));
    QCOMPARE(layer->paintDevice()->exactBounds(), initialRect);
    QCOMPARE(layer->projection()->exactBounds(), QRect(50, 50, 100, 50));

    dbgKrita << "";

    QRect updateRect(0,0,300,300);

    walker.collectRects(mask, updateRect);
    merger.startMerge(walker);

    // image->projection()->convertToQImage(0, 0,0,300,300).save("proj_after.png");

    QCOMPARE(layer->paintDevice()->exactBounds(), initialRect);
    QCOMPARE(layer->projection()->exactBounds(), QRect(100, 75, 100, 25));
}
Beispiel #26
0
KisDocument *createDocument(QList<KisNodeSP> nodes)
{
    KisDocument *doc = KisPart::instance()->createDocument();
    QRect rc;
    Q_FOREACH (KisNodeSP node, nodes) {
        rc |= node->exactBounds();
    }

    KisImageSP image = new KisImage(0, rc.width(), rc.height(), nodes.first()->colorSpace(), nodes.first()->name());

    Q_FOREACH (KisNodeSP node, nodes) {
        image->addNode(node->clone());
    }
Beispiel #27
0
void addLayers(const QVector<Layer> &layers, KisImageSP image, int depth)
{
    for(int i = 0; i < layers.size(); i++) {
        const Layer &layer = layers[i];
        if (layer.depth == depth) {
            KisGroupLayerSP group = (depth == 0 ? image->rootLayer() : findGroup(layers, layer, i));
            image->addNode(layer.layer, group);
            if (layer.mask) {
                image->addNode(layer.mask, layer.layer);
            }
        }
    }
}
Beispiel #28
0
KisImageResizeCommand::KisImageResizeCommand(KisImageWSP image,
                                             const QSize& newSize)
    : KUndo2Command(kundo2_i18n("Resize Image")),
      m_image(image)
{
    // do we really need a translatable name for the command?
    KisImageSP imageSP = m_image.toStrongRef();
    if (!imageSP) {
        return;
    }
    m_sizeBefore = imageSP->size();
    m_sizeAfter = newSize;
}
Beispiel #29
0
KisDoc2 *createDocument(QList<KisNodeSP> nodes)
{
    KisDoc2 *doc = new KisDoc2();
    QRect rc;
    foreach(KisNodeSP node, nodes) {
        rc |= node->exactBounds();
    }

    KisImageSP image = new KisImage(0, rc.width(), rc.height(), nodes.first()->colorSpace(), nodes.first()->name(), false);

    foreach(KisNodeSP node, nodes) {
        image->addNode(node->clone());
    }
Beispiel #30
0
    bool pickWrapped(KisPaintDeviceSP dev, QPoint pos, KoColor *color, KisImageSP image)
    {
        if (!image->tryBarrierLock()) return false;

        if (image->wrapAroundModePermitted()) {
            pos = KisWrappedRect::ptToWrappedPt(pos, image->bounds());
        }

        bool result = pick(dev, pos, color);

        image->unlock();
        return result;
    }