Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Save tail frames as a seprate list of frames

Luna Lovecraftae618dd760cc
diff --git a/plugins/dockers/recorder/recorder_export.cpp b/plugins/dockers/recorder/recorder_export.cpp
index 69a7825fc3..7613504315 100644
--- a/plugins/dockers/recorder/recorder_export.cpp
+++ b/plugins/dockers/recorder/recorder_export.cpp
@@ -336,8 +336,6 @@ public:
void cleanupExporter()
{
- preprocessor->undoPreprocessing();
-
if (exporter) {
exporter->reset();
exporter.reset();
diff --git a/plugins/dockers/recorder/recorder_export_preprocessor.cpp b/plugins/dockers/recorder/recorder_export_preprocessor.cpp
index 1038ddd772..550c4a38b9 100644
--- a/plugins/dockers/recorder/recorder_export_preprocessor.cpp
+++ b/plugins/dockers/recorder/recorder_export_preprocessor.cpp
@@ -25,29 +25,45 @@ struct RecorderExportPreprocessor::Private {
{
}
- void processTail()
+ void getTail()
{
if (!directory.exists())
return;
- Q_FOREACH (QString file, directory.entryList({"*-tail.*"})) {
- QString oldFile = file;
- directory.rename(oldFile, file.remove("-tail"));
+ const QString filename = "tail";
- tails.append(file);
+ QFile file(directory.filePath(filename));
+
+ if (!file.exists()) {
+ return;
+ }
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ return;
}
+
+ tails.clear();
+ QDataStream out(&file);
+ out >> tails;
}
- void restoreTail()
+ void saveTail()
{
if (!directory.exists())
return;
- Q_FOREACH (QString tail, tails) {
- QString oldName = tail;
- directory.rename(oldName, tail.replace(".", "-tail."));
+ const QString filename = "tail";
+
+ QFile file(directory.filePath(filename));
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ return;
}
+ QDataStream out(&file);
+ out << tails;
+
+ file.close();
tails.clear();
}
};
@@ -74,7 +90,7 @@ void RecorderExportPreprocessor::doPreprocessing()
return;
}
- d->processTail();
+ d->getTail();
QStringList fileNames = d->directory.entryList({"*." % RecorderFormatInfo::fileExtension(d->format)});
@@ -141,10 +157,8 @@ void RecorderExportPreprocessor::doPreprocessing()
d->directory.rename(oldName, newName);
}
- d->tails = new_tails;
-}
-
-void RecorderExportPreprocessor::undoPreprocessing()
-{
- d->restoreTail();
+ if (d->tails != new_tails) {
+ d->tails = new_tails;
+ d->saveTail();
+ }
}
diff --git a/plugins/dockers/recorder/recorder_export_preprocessor.h b/plugins/dockers/recorder/recorder_export_preprocessor.h
index faa6be0e40..464aa14ea6 100644
--- a/plugins/dockers/recorder/recorder_export_preprocessor.h
+++ b/plugins/dockers/recorder/recorder_export_preprocessor.h
@@ -19,11 +19,8 @@ public:
void updateSettings(QDir directory, RecorderFormat format);
- /// Renames tail frames, checks if there are no holes in the frames, and shifts the files to fill them
+ /// Checks if there are no holes in the frames, and shifts the files to fill them
void doPreprocessing();
-
- /// Restores tail frames, doesn't actually undo `doPreprocessing()`
- void undoPreprocessing();
private:
struct Private;
QScopedPointer<Private> d;
diff --git a/plugins/dockers/recorder/recorder_writer.cpp b/plugins/dockers/recorder/recorder_writer.cpp
index d9b50edb6b..3939f48a50 100644
--- a/plugins/dockers/recorder/recorder_writer.cpp
+++ b/plugins/dockers/recorder/recorder_writer.cpp
@@ -44,6 +44,15 @@ namespace
"KritaShape/KisToolRectangle",
"KritaShape/KisToolEllipse",
}; // disable recorder when toggled to one of these tools and activated tool(left button pressed on canvas).
+
+ static QString filePathForIndex(int index, QString directory, RecorderFormat format )
+ {
+ QString fileName = QString("%1").arg(index, 7, 10, QLatin1Char('0'));
+
+ return QString("%1%2.%3").arg(directory,
+ fileName,
+ RecorderFormatInfo::fileExtension(format));
+ }
}
bool ThreadCounter::set(int value)
@@ -302,7 +311,7 @@ RecorderWriter::~RecorderWriter()
delete d;
}
-bool RecorderWriter::onCaptureImageImpl(int index, bool tail, QRect region, KisPaintDevice* device)
+bool RecorderWriter::onCaptureImageImpl(int index, QRect region, KisPaintDevice *device)
{
d->captureImage(region, device);
@@ -314,7 +323,7 @@ bool RecorderWriter::onCaptureImageImpl(int index, bool tail, QRect region, KisP
d->partIndex = index;
- return d->writeFrame(tail);
+ return d->writeFrame();
}
bool RecorderWriter::isActive()
@@ -335,7 +344,7 @@ void RecorderWriter::onCaptureImage(int writerId, int index, QVector<QRect> regi
bool framesWrittens = true;
Q_FOREACH (QRect region, regions) {
- framesWrittens &= onCaptureImageImpl(index, tail, region, device.data());
+ framesWrittens &= onCaptureImageImpl(index, region, device.data());
index++;
}
@@ -443,7 +452,7 @@ public:
for (auto &el : writerPool) {
el.thread->quit();
el.thread->wait(RecorderConst::waitThreadTimeoutMs);
- disconnect(q, SIGNAL(startCapturing(int, int, bool, QVector<QRect>, KisPaintDeviceSP)), el.writer.get(), SLOT(onCaptureImage(int, int, bool, QVector<QRect>, KisPaintDeviceSP)));
+ disconnect(q, SIGNAL(startCapturing(int, int, QVector<QRect>, KisPaintDeviceSP)), el.writer.get(), SLOT(onCaptureImage(int, int, QVector<QRect>, KisPaintDeviceSP)));
disconnect(el.writer.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
if (el.thread->isRunning())
{
@@ -487,7 +496,7 @@ public:
auto writerPtr = writerPool[newWorkerId].writer;
auto threadPtr = writerPool[newWorkerId].thread;
threadPtr->setObjectName(QString("Krita-Recorder-WriterPool#%1").arg(newWorkerId));
- connect(q, SIGNAL(startCapturing(int, int, bool, QVector<QRect>, KisPaintDeviceSP)), writerPtr.get(), SLOT(onCaptureImage(int, int, bool, QVector<QRect>, KisPaintDeviceSP)));
+ connect(q, SIGNAL(startCapturing(int, int, QVector<QRect>, KisPaintDeviceSP)), writerPtr.get(), SLOT(onCaptureImage(int, int, QVector<QRect>, KisPaintDeviceSP)));
connect(writerPtr.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
writerPtr->moveToThread(threadPtr.get());
threadPtr->start(QThread::IdlePriority);
@@ -858,20 +867,76 @@ void RecorderWriterManager::tryRestoreRegion()
void RecorderWriterManager::saveState()
{
saveRegion();
+
// Capture some tail frames, but only if we're zoomed in, and if some frames were captured
- if (d->oldRegion != d->canvas->image()->bounds() && d->oldRegion != QRect(-1, -1, -1, -1)) {
- d->captureTail = true;
- onTimer();
+ const QString filename = "tail";
+
+ if (d->oldRegion == d->canvas->image()->bounds() || d->oldRegion == QRect(-1, -1, -1, -1)) {
+ return;
}
+
+ int beginIndex = d->partIndex + 1;
+
+ d->captureTail = true;
+ onTimer();
+
+ int endIndex = d->partIndex;
+
+ QStringList fileNames;
+
+ for (int i = beginIndex; i <= endIndex; i++) {
+ fileNames.push_back(filePathForIndex(i, "", d->settings.format));
+ }
+
+ QFile file(d->outputDir.filePath(filename));
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ return;
+ }
+
+ QDataStream out(&file);
+ out << fileNames;
+
+ file.close();
}
void RecorderWriterManager::restoreState()
{
tryRestoreRegion();
+
// Remove all tail frames
- if(d->outputDir.exists()) {
- Q_FOREACH (QString f, d->outputDir.entryList({"*-tail.*"}, QDir::Files)) {
- d->outputDir.remove(f);
- }
+ const QString filename = "tail";
+
+ QStringList fileNames;
+
+ QFile file(d->outputDir.filePath(filename));
+
+ if (!file.exists()) {
+ return;
+ }
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ return;
+ }
+
+ QDataStream out(&file);
+ out >> fileNames;
+
+ file.close();
+ d->outputDir.remove(filename);
+
+ Q_FOREACH (QString name, fileNames) {
+ d->outputDir.remove(name);
+ }
+
+ // Move the frame index back
+ QRegularExpression fileRegex =
+ RecorderConst::snapshotFilePatternFor(RecorderFormatInfo::fileExtension(d->settings.format));
+
+ QRegularExpressionMatch match = fileRegex.match(fileNames.first());
+
+ if (match.hasMatch()) {
+ int index = match.captured(1).toInt();
+ d->partIndex = index - 1;
}
}
diff --git a/plugins/dockers/recorder/recorder_writer.h b/plugins/dockers/recorder/recorder_writer.h
index 1cb0d5b76c..624401fc48 100644
--- a/plugins/dockers/recorder/recorder_writer.h
+++ b/plugins/dockers/recorder/recorder_writer.h
@@ -91,10 +91,10 @@ Q_SIGNALS:
void capturingDone(int writerId, bool success);
public Q_SLOTS:
- void onCaptureImage(int writerId, int index, bool tail, QVector<QRect> regions, KisPaintDeviceSP device);
+ void onCaptureImage(int writerId, int index, QVector<QRect> regions, KisPaintDeviceSP device);
private:
- bool onCaptureImageImpl(int index, bool tail, QRect region, KisPaintDevice* device);
+ bool onCaptureImageImpl(int index, QRect region, KisPaintDevice* device);
private:
class Private;
@@ -159,7 +159,7 @@ Q_SIGNALS:
void lowPerformanceWarning();
void recorderStopWarning();
- void startCapturing(int writerId, int index, bool tail, QVector<QRect> regions, KisPaintDeviceSP device);
+ void startCapturing(int writerId, int index, QVector<QRect> regions, KisPaintDeviceSP device);
private Q_SLOTS:
void onTimer();