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++

Allow iterating encoder frames multiple times

Carsten Hartenfels75706a1ac5f8
diff --git a/libs/ui/animation/KisMediaEncoderWrapper.cpp b/libs/ui/animation/KisMediaEncoderWrapper.cpp
index 67c8c95a61..2a2344dcd5 100644
--- a/libs/ui/animation/KisMediaEncoderWrapper.cpp
+++ b/libs/ui/animation/KisMediaEncoderWrapper.cpp
@@ -96,8 +96,12 @@ bool KisMediaEncoderRunnable::nextFrame(Frame &outFrame)
}
if (instances != 0) {
- m_outputFrameNo += instances;
- Q_EMIT sigProgressUpdated(m_outputFrameNo);
+ // GIF must spin through the input frames twice, once to generate a
+ // palette and then again to actually render the animated image. It
+ // sets the multiplier to 0.5 so that the progress bar shows values
+ // that make sense for the user, rather than reaching 100% halfway.
+ m_outputFrameNo += double(instances) * m_outputFrameNoMultiplier;
+ Q_EMIT sigProgressUpdated(int(m_outputFrameNo));
// If we're on the last frame, we can append the linger time.
if (fileIndex == lastIndex && m_needsLingerAfter) {
@@ -122,6 +126,14 @@ bool KisMediaEncoderRunnable::nextFrame(Frame &outFrame)
return false;
}
+void KisMediaEncoderRunnable::rewindFrames()
+{
+ m_inputTime = 0;
+ m_inputFileIndex = 0;
+ m_needsPreviewBefore = true;
+ m_needsLingerAfter = true;
+}
+
KisMediaEncoderRunnable::EncodeResult KisMediaEncoderRunnable::prepareAndEncode(QString &outErrorMessage)
{
if (m_cancel) {
diff --git a/libs/ui/animation/KisMediaEncoderWrapper.h b/libs/ui/animation/KisMediaEncoderWrapper.h
index 2e0a7126fc..062654d8bf 100644
--- a/libs/ui/animation/KisMediaEncoderWrapper.h
+++ b/libs/ui/animation/KisMediaEncoderWrapper.h
@@ -111,7 +111,13 @@ protected:
return m_cancel;
}
+ void setOutputFrameNoMultiplier(double outputFrameNoMultiplier)
+ {
+ m_outputFrameNoMultiplier = outputFrameNoMultiplier;
+ }
+
bool nextFrame(Frame &outFrame);
+ void rewindFrames();
private:
EncodeResult prepareAndEncode(QString &outErrorMessage);
@@ -119,7 +125,8 @@ private:
KisMediaEncoderWrapperSettings m_settings;
double m_inputTime = 0.0;
int m_inputFileIndex = 0;
- int m_outputFrameNo = 0;
+ double m_outputFrameNo = 0.0;
+ double m_outputFrameNoMultiplier = 1.0;
bool m_needsPreviewBefore = true;
bool m_needsLingerAfter = true;
bool m_cancel = false;