void KisKraLoaderTest::testLoading() { KisDocument *doc = KisPart::instance()->createDocument(); doc->loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra"); KisImageWSP image = doc->image(); image->lock(); QCOMPARE(image->nlayers(), 12); QCOMPARE(doc->documentInfo()->aboutInfo("title"), QString("test image for loading")); QCOMPARE(image->height(), 753); QCOMPARE(image->width(), 1000); QCOMPARE(image->colorSpace()->id(), KoColorSpaceRegistry::instance()->rgb8()->id()); KisNodeSP node = image->root()->firstChild(); QVERIFY(node); QCOMPARE(node->name(), QString("Background")); QVERIFY(node->inherits("KisPaintLayer")); node = node->nextSibling(); QVERIFY(node); QCOMPARE(node->name(), QString("Group 1")); QVERIFY(node->inherits("KisGroupLayer")); QCOMPARE((int) node->childCount(), 2); delete doc; }
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); KisImageWSP 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; }
void KisKraSaveXmlVisitorTest::testCreateDomDocument() { KisDocument* doc = createCompleteDocument(); quint32 count = 0; QDomDocument dom; QDomElement image = dom.createElement("IMAGE"); // Legacy! KisSaveXmlVisitor visitor(dom, image, count, "", true); Q_ASSERT(doc->image()); QStringList list; doc->image()->lock(); KisCountVisitor cv(list, KoProperties()); doc->image()->rootLayer()->accept(cv); doc->image()->rootLayer()->accept(visitor); QCOMPARE((int)visitor.m_count, (int)cv.count()); //delete doc; }
KisImportExportFilter::ConversionStatus KisXCFImport::convert(const QByteArray& from, const QByteArray& to) { Q_UNUSED(from); dbgFile << "Importing using XCFImport!"; if (to != "application/x-krita") return KisImportExportFilter::BadMimeType; KisDocument * doc = outputDocument(); if (!doc) return KisImportExportFilter::NoDocumentCreated; QString filename = inputFile(); if (filename.isEmpty()) { return KisImportExportFilter::FileNotFound; } QFile fp(filename); if (fp.exists()) { doc->prepareForImport(); return loadFromDevice(&fp, doc); } return KisImportExportFilter::CreationError; }
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); }
void KisKraLoaderTest::testLoadAnimated() { KisDocument *doc = KisPart::instance()->createDocument(); doc->loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test_animation.kra"); KisImageSP image = doc->image(); KisNodeSP node1 = image->root()->firstChild(); KisNodeSP node2 = node1->nextSibling(); QVERIFY(node1->inherits("KisPaintLayer")); QVERIFY(node2->inherits("KisPaintLayer")); KisPaintLayerSP layer1 = qobject_cast<KisPaintLayer*>(node1.data()); KisPaintLayerSP layer2 = qobject_cast<KisPaintLayer*>(node2.data()); KisKeyframeChannel *channel1 = layer1->getKeyframeChannel(KisKeyframeChannel::Content.id()); KisKeyframeChannel *channel2 = layer2->getKeyframeChannel(KisKeyframeChannel::Content.id()); QCOMPARE(channel1->keyframeCount(), 3); QCOMPARE(channel2->keyframeCount(), 1); QCOMPARE(image->animationInterface()->framerate(), 17); QCOMPARE(image->animationInterface()->fullClipRange(), KisTimeRange::fromTime(15, 45)); QCOMPARE(image->animationInterface()->currentTime(), 19); KisPaintDeviceSP dev = layer1->paintDevice(); const KoColorSpace *cs = dev->colorSpace(); KoColor transparent(Qt::transparent, cs); KoColor white(Qt::white, cs); KoColor red(Qt::red, cs); image->animationInterface()->switchCurrentTimeAsync(0); image->waitForDone(); QCOMPARE(dev->exactBounds(), QRect(506, 378, 198, 198)); QCOMPARE(dev->x(), -26); QCOMPARE(dev->y(), -128); QCOMPARE(dev->defaultPixel(), transparent); image->animationInterface()->switchCurrentTimeAsync(20); image->waitForDone(); QCOMPARE(dev->nonDefaultPixelArea(), QRect(615, 416, 129, 129)); QCOMPARE(dev->x(), 502); QCOMPARE(dev->y(), 224); QCOMPARE(dev->defaultPixel(), white); image->animationInterface()->switchCurrentTimeAsync(30); image->waitForDone(); QCOMPARE(dev->nonDefaultPixelArea(), QRect(729, 452, 45, 44)); QCOMPARE(dev->x(), 645); QCOMPARE(dev->y(), -10); QCOMPARE(dev->defaultPixel(), red); }
void KisDocumentTest::testOpenImageTwiceInSameDoc() { QString fname2 = QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra"; QString fname = QString(FILES_DATA_DIR) + QDir::separator() + "load_test2.kra"; Q_ASSERT(!fname.isEmpty()); Q_ASSERT(!fname2.isEmpty()); KisDocument *doc = KisPart::instance()->createDocument(); doc->loadNativeFormat(fname); doc->loadNativeFormat(fname2); }
Private(KisDocument *document, int fromTime, int toTime) : document(document), image(document->image()), firstFrame(fromTime), lastFrame(toTime), tmpDoc(KisPart::instance()->createDocument()), exporting(false), batchMode(false) { tmpDoc->setAutoSave(0); tmpImage = new KisImage(tmpDoc->createUndoStore(), image->bounds().width(), image->bounds().height(), image->colorSpace(), QString()); tmpImage->setResolution(image->xRes(), image->yRes()); tmpDoc->setCurrentImage(tmpImage); KisPaintLayer* paintLayer = new KisPaintLayer(tmpImage, "paint device", 255); tmpImage->addNode(paintLayer, tmpImage->rootLayer(), KisLayerSP(0)); tmpDevice = paintLayer->paintDevice(); }
KisImportExportFilter::ConversionStatus KisBMPExport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "BMP export! From:" << from << ", To:" << to << ""; KisDocument *input = m_chain->inputDocument(); QString filename = m_chain->outputFile(); if (!input) return KisImportExportFilter::NoDocumentCreated; if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; if (from != "application/x-krita") return KisImportExportFilter::NotImplemented; QUrl url = QUrl::fromLocalFile(filename); qApp->processEvents(); // For vector layers to be updated input->image()->waitForDone(); QRect rc = input->image()->bounds(); input->image()->refreshGraph(); input->image()->lock(); QImage image = input->image()->projection()->convertToQImage(0, 0, 0, rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); input->image()->unlock(); image.save(url.toLocalFile()); return KisImportExportFilter::OK; }
void TimelineDocker::setCanvas(KoCanvasBase * canvas) { if (canvas && m_d->canvas == canvas) return; if (m_d->model->hasConnectionToCanvas()) { m_d->canvasConnections.clear(); m_d->model->setDummiesFacade(0, 0); m_d->model->setFrameCache(0); m_d->model->setAnimationPlayer(0); m_d->model->setNodeManipulationInterface(0); if (m_d->canvas) { m_d->canvas->disconnectCanvasObserver(this); } } m_d->canvas = dynamic_cast<KisCanvas2*>(canvas); setEnabled(m_d->canvas != 0); if(m_d->canvas) { KisDocument *doc = static_cast<KisDocument*>(m_d->canvas->imageView()->document()); KisShapeController *kritaShapeController = dynamic_cast<KisShapeController*>(doc->shapeController()); m_d->model->setDummiesFacade(kritaShapeController, m_d->canvas->image()); m_d->model->setFrameCache(m_d->canvas->frameCache()); m_d->model->setAnimationPlayer(m_d->canvas->animationPlayer()); m_d->model->setNodeManipulationInterface( new NodeManagerInterface(m_d->canvas->viewManager()->nodeManager())); m_d->canvasConnections.addConnection( m_d->canvas->viewManager()->nodeManager(), SIGNAL(sigNodeActivated(KisNodeSP)), m_d->model, SLOT(slotCurrentNodeChanged(KisNodeSP))); m_d->canvasConnections.addConnection( m_d->model, SIGNAL(requestCurrentNodeChanged(KisNodeSP)), m_d->canvas->viewManager()->nodeManager(), SLOT(slotNonUiActivatedNode(KisNodeSP))); m_d->model->slotCurrentNodeChanged(m_d->canvas->viewManager()->activeNode()); } }
KisImportExportFilter::ConversionStatus KisCSVExport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "CSV export! From:" << from << ", To:" << to << ""; if (from != "application/x-krita") return KisImportExportFilter::NotImplemented; KisDocument* input = inputDocument(); QString filename = outputFile(); if (!input) return KisImportExportFilter::NoDocumentCreated; if (!checkHomogenity(input->image()->rootLayer())) { if (!getBatchMode()) { QMessageBox::critical(0, i18nc("@title:window", "CSV Export Error"), i18n("Unable to save to the CSV format.\n" "The CSV format not supports layer groups or masked layers.")); } return KisImportExportFilter::InvalidFormat; } if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; CSVSaver kpc(input, getBatchMode()); KisImageBuilder_Result res; if ((res = kpc.buildAnimation(filename)) == KisImageBuilder_RESULT_OK) { dbgFile <<"success !"; return KisImportExportFilter::OK; } dbgFile <<" Result =" << res; if (res == KisImageBuilder_RESULT_CANCEL) return KisImportExportFilter::ProgressCancelled; return KisImportExportFilter::InternalError; }
KisImportExportFilter::ConversionStatus KisBMPImport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "BMP import! From:" << from << ", To:" << to << 0; if (to != "application/x-krita") return KisImportExportFilter::BadMimeType; KisDocument * doc = outputDocument(); if (!doc) return KisImportExportFilter::NoDocumentCreated; QString filename = inputFile(); doc->prepareForImport(); if (!filename.isEmpty()) { QFileInfo fi(filename); if (!fi.exists()) { return KisImportExportFilter::FileNotFound; } QImage img(filename); const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8(); KisImageSP image = new KisImage(doc->createUndoStore(), img.width(), img.height(), colorSpace, "imported from bmp"); KisPaintLayerSP layer = new KisPaintLayer(image, image->nextLayerName(), 255); layer->paintDevice()->convertFromQImage(img, 0, 0, 0); image->addNode(layer.data(), image->rootLayer().data()); doc->setCurrentImage(image); return KisImportExportFilter::OK; } return KisImportExportFilter::StorageCreationError; }
void Imagesplit::saveAsImage(const QRect &imgSize, const QString &mimeType, const QString &url) { KisImageWSP image = m_view->image(); KisDocument *document = KisPart::instance()->createDocument(); document->prepareForImport(); KisImageWSP dst = new KisImage(document->createUndoStore(), imgSize.width(), imgSize.height(), image->colorSpace(), image->objectName()); dst->setResolution(image->xRes(), image->yRes()); document->setCurrentImage(dst); KisPaintLayer* paintLayer = new KisPaintLayer(dst, dst->nextLayerName(), 255); KisPainter gc(paintLayer->paintDevice()); gc.bitBlt(QPoint(0, 0), image->projection(), imgSize); dst->addNode(paintLayer, KisNodeSP(0)); dst->refreshGraph(); document->setFileBatchMode(true); document->setOutputMimeType(mimeType.toLatin1()); document->exportDocument(QUrl::fromLocalFile(url)); delete document; }
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "HeightMap export! From:" << from << ", To:" << to; if (from != "application/x-krita") return KisImportExportFilter::NotImplemented; KisDocument *inputDoc = inputDocument(); QString filename = outputFile(); if (!inputDoc) return KisImportExportFilter::NoDocumentCreated; if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; KisImageWSP image = inputDoc->image(); Q_CHECK_PTR(image); if (inputDoc->image()->width() != inputDoc->image()->height()) { inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not square")); return KisImportExportFilter::WrongFormat; } if (inputDoc->image()->colorSpace()->colorModelId() != GrayAColorModelID) { inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not grayscale")); return KisImportExportFilter::WrongFormat; } KoDialog* kdb = new KoDialog(0); kdb->setWindowTitle(i18n("HeightMap Export Options")); kdb->setButtons(KoDialog::Ok | KoDialog::Cancel); Ui::WdgOptionsHeightMap optionsHeightMap; QWidget* wdg = new QWidget(kdb); optionsHeightMap.setupUi(wdg); kdb->setMainWidget(wdg); QApplication::restoreOverrideCursor(); QString filterConfig = KisConfig().exportConfiguration("HeightMap"); KisPropertiesConfiguration cfg; cfg.fromXML(filterConfig); optionsHeightMap.intSize->setValue(image->width()); int endianness = cfg.getInt("endianness", 0); QDataStream::ByteOrder bo = QDataStream::LittleEndian; optionsHeightMap.radioPC->setChecked(true); if (endianness == 0) { bo = QDataStream::BigEndian; optionsHeightMap.radioMac->setChecked(true); } if (!getBatchMode()) { if (kdb->exec() == QDialog::Rejected) { return KisImportExportFilter::UserCancelled; } } if (optionsHeightMap.radioMac->isChecked()) { cfg.setProperty("endianness", 0); bo = QDataStream::BigEndian; } else { cfg.setProperty("endianness", 1); bo = QDataStream::LittleEndian; } KisConfig().setExportConfiguration("HeightMap", cfg); bool downscale = false; if (to == "image/x-r8" && image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) { downscale = (QMessageBox::question(0, i18nc("@title:window", "Downscale Image"), i18n("You specified the .r8 extension for a 16 bit/channel image. Do you want to save as 8 bit? Your image data will not be changed."), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes); } // the image must be locked at the higher levels KIS_SAFE_ASSERT_RECOVER_NOOP(image->locked()); KisPaintDeviceSP pd = new KisPaintDevice(*image->projection()); QFile f(filename); f.open(QIODevice::WriteOnly); QDataStream s(&f); s.setByteOrder(bo); KisRandomConstAccessorSP it = pd->createRandomConstAccessorNG(0, 0); bool r16 = ((image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) && !downscale); for (int i = 0; i < image->height(); ++i) { for (int j = 0; j < image->width(); ++j) { it->moveTo(i, j); if (r16) { s << KoGrayU16Traits::gray(const_cast<quint8*>(it->rawDataConst())); } else { s << KoGrayU8Traits::gray(const_cast<quint8*>(it->rawDataConst())); } } } f.close(); return KisImportExportFilter::OK; }