Commit cf076ed3 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Timeline preview: when saving, store rendered chunks in a more clever list...

Timeline preview: when saving, store rendered chunks in a more clever list (like 0-1700 instead of listing each 0,25,50,75,... until 1700).
Will result in much smaller files.
Related to #1266
parent f23c89af
Pipeline #127121 passed with stage
in 7 minutes and 3 seconds
......@@ -811,20 +811,53 @@ void PreviewManager::removeOverlayTrack()
reconnectTrack();
}
QPair<QStringList, QStringList> PreviewManager::previewChunks() const
QPair<QStringList, QStringList> PreviewManager::previewChunks()
{
QStringList renderedChunks;
QStringList dirtyChunks;
for (const QVariant &frame : m_renderedChunks) {
renderedChunks << frame.toString();
}
std::sort(m_renderedChunks.begin(), m_renderedChunks.end());
const QStringList renderedChunks = getCompressedList(m_renderedChunks);
QMutexLocker lock(&m_dirtyMutex);
for (const QVariant &frame : m_dirtyChunks) {
dirtyChunks << frame.toString();
}
std::sort(m_dirtyChunks.begin(), m_dirtyChunks.end());
const QStringList dirtyChunks = getCompressedList(m_dirtyChunks);
lock.unlock();
return {renderedChunks, dirtyChunks};
}
const QStringList PreviewManager::getCompressedList(const QVariantList items) const
{
QStringList resultString;
int lastFrame = 0;
QString currentString;
for (const QVariant &frame : items) {
int current = frame.toInt();
if (current - 25 == lastFrame) {
lastFrame = current;
if (frame == items.last()) {
currentString.append(QString("-%1").arg(lastFrame));
resultString << currentString;
currentString.clear();
}
continue;
}
if (currentString.isEmpty()) {
currentString = frame.toString();
} else if (currentString == QString::number(lastFrame)) {
// Only one chunk, store it
resultString << currentString;
currentString = frame.toString();
} else {
// Range, store
currentString.append(QString("-%1").arg(lastFrame));
resultString << currentString;
currentString = frame.toString();
}
lastFrame = current;
}
if (!currentString.isEmpty()) {
resultString << currentString;
}
return resultString;
}
bool PreviewManager::hasOverlayTrack() const
{
return m_overlayTrack != nullptr;
......
......@@ -72,7 +72,7 @@ public:
/** @brief The current preview chunk being processed, -1 if none */
int workingPreview;
/** @brief Returns the list of existing chunks */
QPair<QStringList, QStringList> previewChunks() const;
QPair<QStringList, QStringList> previewChunks();
bool hasOverlayTrack() const;
bool hasPreviewTrack() const;
int addedTracks() const;
......@@ -115,6 +115,8 @@ private:
void enable();
/** @brief: Temporarily disable timeline preview track. */
void disable();
/** @brief: Get a compressed list of chunks, like: "0-500,525,575". */
const QStringList getCompressedList(const QVariantList items) const;
private slots:
/** @brief: To avoid filling the hard drive, remove preview undo history after 5 steps. */
......
......@@ -2463,10 +2463,28 @@ void TimelineController::loadPreview(const QString &chunks, const QString &dirty
QStringList dirtyList = dirty.split(QLatin1Char(','), Qt::SkipEmptyParts);
#endif
for (const QString &frame : qAsConst(chunksList)) {
renderedChunks << frame.toInt();
if (frame.contains(QLatin1Char('-'))) {
// Range, process
int start = frame.section(QLatin1Char('-'), 0, 0).toInt();
int end = frame.section(QLatin1Char('-'), 1, 1).toInt();
for (int i = start; i <= end; i+= 25) {
renderedChunks << i;
}
} else {
renderedChunks << frame.toInt();
}
}
for (const QString &frame : qAsConst(dirtyList)) {
dirtyChunks << frame.toInt();
if (frame.contains(QLatin1Char('-'))) {
// Range, process
int start = frame.section(QLatin1Char('-'), 0, 0).toInt();
int end = frame.section(QLatin1Char('-'), 1, 1).toInt();
for (int i = start; i <= end; i+= 25) {
dirtyChunks << i;
}
} else {
dirtyChunks << frame.toInt();
}
}
if ( m_disablePreview ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment