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++
Fix recorder export when some frames are missing
Luna Lovecraft38120db7fc72
diff --git a/plugins/dockers/recorder/CMakeLists.txt b/plugins/dockers/recorder/CMakeLists.txtindex ec8b62102a..140b6737f1 100644--- a/plugins/dockers/recorder/CMakeLists.txt+++ b/plugins/dockers/recorder/CMakeLists.txt@@ -14,6 +14,7 @@ set(KRITA_RECORDERDOCKER_SOURCESrecorder_directory_cleaner.cpprecorderdocker.cpprecorderdocker_dock.cpp+ recorder_export_preprocessor.cpp)set(KRITA_RECORDERDOCKER_UISdiff --git a/plugins/dockers/recorder/recorder_export.cpp b/plugins/dockers/recorder/recorder_export.cppindex 534dd18185..7fb2787515 100644--- a/plugins/dockers/recorder/recorder_export.cpp+++ b/plugins/dockers/recorder/recorder_export.cpp@@ -5,6 +5,7 @@*/#include "recorder_export.h"+#include "recorder_export_preprocessor.h"#include "ui_recorder_export.h"#include "recorder_export_config.h"#include "recorder_export_settings.h"@@ -67,6 +68,7 @@ public:QScopedPointer<Ui::RecorderExport> ui;RecorderExportSettings *settings;+ QScopedPointer<RecorderExportPreprocessor> preprocessor;QScopedPointer<Exporter> exporter;RecorderDirectoryCleaner *cleaner = nullptr;@@ -79,6 +81,7 @@ public:: q(q_ptr), ui(new Ui::RecorderExport), settings(q_ptr->settings)+ , preprocessor(new RecorderExportPreprocessor(settings->inputDirectory, settings->format)){}@@ -283,6 +286,9 @@ public:{Q_ASSERT(exporter == nullptr);+ preprocessor->updateSettings(settings->inputDirectory, settings->format);+ preprocessor->doPreprocessing();+#ifndef Q_OS_ANDROID// We don't do this again on Android, it's mind-bogglingly slow.updateFrameInfo();diff --git a/plugins/dockers/recorder/recorder_export_preprocessor.cpp b/plugins/dockers/recorder/recorder_export_preprocessor.cppnew file mode 100644index 0000000000..967d5c8023--- /dev/null+++ b/plugins/dockers/recorder/recorder_export_preprocessor.cpp@@ -0,0 +1,107 @@+/*+ * SPDX-FileCopyrightText: 2026 Luna Lovecraft <[email protected]>+ *+ * SPDX-License-Identifier: GPL-3.0-or-later+ */++#include "recorder_export_preprocessor.h"+#include "recorder_const.h"+#include "recorder_format.h"+#include <QRegularExpression>+#include <algorithm>++struct RecorderExportPreprocessor::Private {+ QDir directory;+ RecorderFormat format;++ Private(QDir directory, RecorderFormat format)+ : directory(directory)+ , format(format)+ {+ }++ ~Private()+ {+ }+};++RecorderExportPreprocessor::RecorderExportPreprocessor(QDir directory, RecorderFormat format)+ : d(new Private(directory, format))+{+}++RecorderExportPreprocessor::~RecorderExportPreprocessor()+{+}++void RecorderExportPreprocessor::updateSettings(QDir directory, RecorderFormat format)+{+ d->directory = directory;+ d->format = format;+}++// Double check that the files are sequential and have no holes, if there are any, fill them in+void RecorderExportPreprocessor::doPreprocessing()+{+ if (!d->directory.exists()) {+ return;+ }++ QStringList fileNames = d->directory.entryList({"*." % RecorderFormatInfo::fileExtension(d->format)});++ QRegularExpression fileRegex = RecorderConst::snapshotFilePatternFor(RecorderFormatInfo::fileExtension(d->format));+ QHash<int, QString> files;+ QVector<int> indecies;++ Q_FOREACH (QString file, fileNames) {+ QRegularExpressionMatch match = fileRegex.match(file);++ if (match.hasMatch()) {+ int index = match.captured(1).toInt();+ files.insert(index, file);+ indecies.push_back(index);+ }+ }++ // It should be sorted, but just in case+ std::sort(indecies.begin(), indecies.end());++ QHash<int, int> holes;+ int prevIndex = 0;++ for (auto it = indecies.begin(); it != indecies.end(); ++it) {+ int curIndex = *it;+ int diff = curIndex - prevIndex;++ if (diff > 1) {+ holes.insert(curIndex, diff - 1);+ }++ prevIndex = curIndex;+ }++ // No holes, so we don't need to do anything+ if (holes.isEmpty()) {+ return;+ }++ int offset = 0;+ for (auto it = indecies.begin(); it != indecies.end(); ++it) {+ int ind = *it;++ if (holes.contains(ind)) {+ offset += holes[ind];+ }++ if (offset == 0) {+ continue;+ }++ QString oldName = files[ind];+ QString newName = QString("%2.%3").arg(QString("%1").arg(ind - offset, 7, 10, QLatin1Char('0')),+ RecorderFormatInfo::fileExtension(d->format));++ // Hopefully nothing should go wrong+ d->directory.rename(oldName, newName);+ }+}diff --git a/plugins/dockers/recorder/recorder_export_preprocessor.h b/plugins/dockers/recorder/recorder_export_preprocessor.hnew file mode 100644index 0000000000..4b41a299bf--- /dev/null+++ b/plugins/dockers/recorder/recorder_export_preprocessor.h@@ -0,0 +1,29 @@+/*+ * SPDX-FileCopyrightText: 2026 Luna Lovecraft <[email protected]>+ *+ * SPDX-License-Identifier: GPL-3.0-or-later+ */++#ifndef KRITA_RECORDER_EXPORT_PREPROCESSOR_H+#define KRITA_RECORDER_EXPORT_PREPROCESSOR_H++#include "recorder_format.h"+#include <QDir>+#include <QScopedPointer>++class RecorderExportPreprocessor+{+public:+ RecorderExportPreprocessor(QDir directory, RecorderFormat format);+ ~RecorderExportPreprocessor();++ void updateSettings(QDir directory, RecorderFormat format);++ void doPreprocessing();++private:+ struct Private;+ QScopedPointer<Private> d;+};++#endif