void ImageWindow::slotChanged() { QString mpixels; QSize dims(m_canvas->imageWidth(), m_canvas->imageHeight()); mpixels.setNum(dims.width()*dims.height()/1000000.0, 'f', 2); QString str = (!dims.isValid()) ? i18n("Unknown") : i18n("%1x%2 (%3Mpx)", dims.width(), dims.height(), mpixels); m_resLabel->setText(str); if (!d->currentIsValid()) return; DImg* img = m_canvas->interface()->getImg(); DImageHistory history = m_canvas->interface()->getImageHistory(); DImageHistory redoHistory = m_canvas->interface()->getImageHistoryOfFullRedo(); d->rightSideBar->itemChanged(d->currentImageInfo, m_canvas->getSelectedArea(), img, redoHistory); // Filters for redo will be greyed out d->rightSideBar->getFiltersHistoryTab()->setEnabledHistorySteps(history.actionCount()); /*if (!d->currentImageInfo.isNull()) { } else { d->rightSideBar->itemChanged(d->currentUrl(), m_canvas->getSelectedArea(), img); } }*/ }
void DImageFilterActionTest::testActions() { QStringList files = QDir(imagePath()).entryList(QDir::Files); files.removeOne(originalImage()); DImg original(imagePath() + originalImage()); QVERIFY(!original.isNull()); foreach (const QString& fileName, files) { DImg ref(imagePath() + fileName); QVERIFY(!ref.isNull()); DImageHistory history = ref.getImageHistory(); FilterActionFilter filter; filter.setFilterActions(history.allActions()); QVERIFY(filter.isReproducible() || filter.isComplexAction()); filter.setupFilter(original.copy()); filter.startFilterDirectly(); qDebug() << filter.filterActions().size(); DImg img = filter.getTargetImage(); QVERIFY(ref.size() == img.size()); bool isEqual = true; DImg diff(ref.width(), ref.height(), ref.sixteenBit()); diff.fill(DColor(Qt::black)); for (uint x=0; x<ref.width(); x++) { for (uint y=0; y<ref.height(); y++) { DColor cref = ref.getPixelColor(x,y); DColor cres = img.getPixelColor(x,y); if (cref.red() != cres.red() || cref.green() != cres.green() || cref.blue() != cres.blue()) { //qDebug() << x << y; diff.setPixelColor(x,y, DColor(Qt::white)); isEqual = false; } } } if (!isEqual) { showDiff(original, ref, img, diff); } QVERIFY(isEqual); }
void DImageHistoryTest::testXml() { DImageHistory history = history1(); QString xml = history.toXml(); DImageHistory history2 = DImageHistory::fromXml(xml); QString xml2 = history2.toXml(); QCOMPARE(xml, xml2); // Does not need to work: Some fields in the ids like originalUUID are filled out even if not in XML //QCOMPARE(history2, historyWithoutCurrent); }
bool ImageScanner::resolveImageHistory(qlonglong imageId, const QString& historyXml, QList<qlonglong>* needTaggingIds) { /** Stage 2 of history scanning */ if (historyXml.isNull()) { return true; // "true" means nothing is left to resolve } DImageHistory history = DImageHistory::fromXml(historyXml); if (history.isNull()) { return true; } ImageHistoryGraph graph; graph.addScannedHistory(history, imageId); if (!graph.hasEdges()) { return true; } QPair<QList<qlonglong>, QList<qlonglong> > cloud = graph.relationCloudParallel(); DatabaseAccess().db()->addImageRelations(cloud.first, cloud.second, DatabaseRelation::DerivedFrom); int needResolvingTag = TagsCache::instance()->getOrCreateInternalTag(InternalTagName::needResolvingHistory()); int needTaggingTag = TagsCache::instance()->getOrCreateInternalTag(InternalTagName::needTaggingHistoryGraph()); // remove the needResolvingHistory tag from all images in graph DatabaseAccess().db()->removeTagsFromItems(graph.allImageIds(), QList<int>() << needResolvingTag); // mark a single image from the graph (sufficient for find the full relation cloud) QList<ImageInfo> roots = graph.rootImages(); if (!roots.isEmpty()) { DatabaseAccess().db()->addItemTag(roots.first().id(), needTaggingTag); if (needTaggingIds) { *needTaggingIds << roots.first().id(); } } return !graph.hasUnresolvedEntries(); }
void DImageHistoryTest::slotImageSaved(const QString& fileName, bool success) { QVERIFY(success); m_im->setLastSaved(fileName); DImg img(fileName); DImageHistory history = img.getImageHistory(); qDebug() << history.toXml(); QCOMPARE(history.size(), 3); QCOMPARE(history.entries().first().referredImages.size(), 1); QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Original); QCOMPARE(history.action(1).category(), FilterAction::ReproducibleFilter); QCOMPARE(history.action(2).category(), FilterAction::ReproducibleFilter); DImageHistory history2 = DImageHistory::fromXml(history.toXml()); QCOMPARE(history2.size(), 3); QCOMPARE(history2.entries().first().referredImages.size(), 1); QCOMPARE(history2.entries().first().referredImages.first().m_type, HistoryImageId::Original); QCOMPARE(history2.action(1).category(), FilterAction::ReproducibleFilter); QCOMPARE(history2.action(2).category(), FilterAction::ReproducibleFilter); m_loop.quit(); }
DImageHistory ImageScanner::resolvedImageHistory(const DImageHistory& history, bool mustBeAvailable) { DImageHistory h; foreach (const DImageHistory::Entry& e, history.entries()) { // Copy entry, without referredImages DImageHistory::Entry entry; entry.action = e.action; // resolve referredImages foreach (const HistoryImageId& id, e.referredImages) { QList<qlonglong> imageIds = resolveHistoryImageId(id); // append each image found in collection to referredImages foreach (qlonglong imageId, imageIds) { ImageInfo info(imageId); if (info.isNull()) { continue; } if (mustBeAvailable) { CollectionLocation location = CollectionManager::instance()->locationForAlbumRootId(info.albumRootId()); if (!location.isAvailable()) { continue; } } HistoryImageId newId = info.historyImageId(); newId.setType(id.m_type); entry.referredImages << newId; } } // add to history h.entries() << entry; }
ImageFiltersHistoryModel::ImageFiltersHistoryModel(QObject* const parent, const KUrl& url) : QAbstractItemModel(parent), d(new Private) { if (!url.isEmpty()) { //kDebug() << "Creating model with url" << url.toLocalFile(); d->rootItem = new ImageFiltersHistoryTreeItem(url.fileName()); d->lastUrl = url; DMetadata metadata(url.toLocalFile()); QString xml = metadata.getImageHistory(); DImageHistory h = DImageHistory::fromXml(xml); setupModelData(h.entries(), d->rootItem); } else { //kDebug() << "Creating empty model"; d->rootItem = new ImageFiltersHistoryTreeItem("Generic"); } }
void DImageHistoryTest::slotImageLoaded(const QString&, bool success) { QVERIFY(success); applyFilters1(); DImageHistory h = m_im->getImg()->getImageHistory(); h.adjustReferredImages(); for (int i=0; i<3; ++i) { qDebug() << i << h.entries().at(i).referredImages.size(); if (h.entries().at(i).referredImages.size()) { qDebug() << " " << i << h.entries().at(i).referredImages.first().m_type; } } m_loop.quit(); }
bool UndoManager::hasChanges() const { if (!isAtOrigin()) { return true; } else { DImageHistory currentHistory = d->core->getImageHistory(); DImageHistory initialHistory = d->core->getInitialImageHistory(); if (currentHistory == initialHistory) { return false; } else { return currentHistory.actionCount() > initialHistory.actionCount(); } } }
void VersionNameCreator::checkNeedNewVersion() { // First we check if we have any other files available. // The resolved initial history contains only referred files found in the collection // Note: The loaded file will have type Current kDebug() << m_resolvedInitialHistory.hasReferredImageOfType(HistoryImageId::Original) << m_resolvedInitialHistory.hasReferredImageOfType(HistoryImageId::Intermediate) << m_fromRaw << q->workspaceFileFormats().contains(m_loadedFile.format); if (!m_resolvedInitialHistory.hasReferredImageOfType(HistoryImageId::Original) && !m_resolvedInitialHistory.hasReferredImageOfType(HistoryImageId::Intermediate)) { m_newVersion = true; } // We check the loaded format: If it is not one of the workspace formats, or even raw, we need a new version else if (m_fromRaw || !q->workspaceFileFormats().contains(m_loadedFile.format)) { m_newVersion = true; } else { m_newVersion = false; } }
void FiltersHistoryWidget::setHistory(const DImageHistory& history) { d->model->setupModelData(history.entries()); }
void DImageHistoryTest::testDImg() { QDir imageDir(imagePath()); imageDir.setNameFilters(QStringList("*.jpg")); QList<QFileInfo> imageFiles = imageDir.entryInfoList(); IOFileSettings container; m_im->load(imageFiles.first().filePath(), &container); m_loop.exec(); DImageHistory history = m_im->getImg()->getImageHistory(); QCOMPARE(history.size(), 3); QCOMPARE(history.entries().first().referredImages.size(), 1); QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Current); QVERIFY(history.entries().last().referredImages.isEmpty()); m_im->saveAs(m_tempFile, &container, true, QString(), QString()); m_loop.exec(); history = m_im->getImg()->getImageHistory(); QCOMPARE(history.size(), 3); QCOMPARE(history.entries().first().referredImages.size(), 1); QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Current); QCOMPARE(history.entries().last().referredImages.size(), 1); QCOMPARE(history.entries().last().referredImages.first().m_type, HistoryImageId::Intermediate); m_im->switchToLastSaved(); history = m_im->getImg()->getImageHistory(); QCOMPARE(history.size(), 3); QCOMPARE(history.entries().first().referredImages.size(), 1); QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Original); QCOMPARE(history.entries().last().referredImages.size(), 1); QCOMPARE(history.entries().last().referredImages.first().m_type, HistoryImageId::Current); }