Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAsyncAnimationFramesSavingRenderer.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include "kis_image.h"
10#include "kis_paint_device.h"
12#include "KisPart.h"
13#include "KisDocument.h"
14#include "kis_time_span.h"
15#include "kis_paint_layer.h"
16
17
19{
20 Private(KisImageSP image, const KisTimeSpan &_range, int _sequenceNumberingOffset, bool _onlyNeedsUniqueFrames, KisPropertiesConfigurationSP _exportConfiguration)
22 range(_range),
23 sequenceNumberingOffset(_sequenceNumberingOffset),
24 onlyNeedsUniqueFrames(_onlyNeedsUniqueFrames),
25 exportConfiguration(_exportConfiguration)
26 {
27
28 savingDoc->setInfiniteAutoSaveInterval();
29 savingDoc->setFileBatchMode(true);
30
31 KisImageSP savingImage = new KisImage(savingDoc->createUndoStore(),
32 image->bounds().width(),
33 image->bounds().height(),
34 image->colorSpace(),
35 QString());
36
37 savingImage->setResolution(image->xRes(), image->yRes());
38 savingDoc->setCurrentImage(savingImage);
39
40 KisPaintLayer* paintLayer = new KisPaintLayer(savingImage, "paint device", 255);
41 savingImage->addNode(paintLayer, savingImage->root(), KisLayerSP(0));
42
43 savingDevice = paintLayer->paintDevice();
44 }
45
46 QScopedPointer<KisDocument> savingDoc;
48
51
53
56
57 QByteArray outputMimeType;
59};
60
62 const QString &fileNamePrefix,
63 const QString &fileNameSuffix,
64 const QByteArray &outputMimeType,
65 const KisTimeSpan &range,
66 const int sequenceNumberingOffset,
67 const bool onlyNeedsUniqueFrames,
68 KisPropertiesConfigurationSP exportConfiguration)
69 : m_d(new Private(image, range, sequenceNumberingOffset, onlyNeedsUniqueFrames, exportConfiguration))
70{
71 m_d->filenamePrefix = fileNamePrefix;
72 m_d->filenameSuffix = fileNameSuffix;
73 m_d->outputMimeType = outputMimeType;
74
75 connect(this, SIGNAL(sigCompleteRegenerationInternal(int)), SLOT(notifyFrameCompleted(int)));
77}
78
79
80
81
85
87{
88 KisImageSP image = requestedImage();
89 if (!image) return;
90
93 return;
94 }
95
96 m_d->savingDevice->makeCloneFromRough(image->projection(), image->bounds());
97
99
100 QString frameNumber = QString("%1").arg(frame + m_d->sequenceNumberingOffset, 4, 10, QChar('0'));
101 QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix;
102
103 if (!m_d->savingDoc->exportDocumentSync(filename, m_d->outputMimeType, m_d->exportConfiguration)) {
105 }
106
107 //Get all identical frames to this one and either copy or symlink based on settings.
109 identicals &= m_d->range;
110 if( !m_d->onlyNeedsUniqueFrames && identicals.start() < identicals.end() ) {
111 for (int identicalFrame = (identicals.start() + 1); identicalFrame <= identicals.end(); identicalFrame++) {
112 QString identicalFrameNumber = QString("%1").arg(identicalFrame + m_d->sequenceNumberingOffset, 4, 10, QChar('0'));
113 QString identicalFrameName = m_d->filenamePrefix + identicalFrameNumber + m_d->filenameSuffix;
114
115 QFile::copy(filename, identicalFrameName);
116
117 /* This would be nice to do but sym-linking on windows isn't possible without
118 * way more other work to be done. This works on linux though!
119 *
120 * if (m_d->linkRedundantFrames) {
121 * QFile::link(filename, identicalFrameName);
122 * } else {
123 * QFile::copy(filename, identicalFrameName);
124 * }
125 */
126 }
127 }
128
129 if (status.isOk()) {
131 } else {
133 }
134}
135
137{
138 notifyFrameCancelled(frame, cancelReason);
139}
140
PythonPluginManager * instance
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void frameCancelledCallback(int frame, CancelReason cancelReason) override
frameCancelledCallback is called when the rendering of the frame was cancelled.
void sigCancelRegenerationInternal(int frame, KisAsyncAnimationRendererBase::CancelReason cancelReason)
void frameCompletedCallback(int frame, const KisRegion &requestedRegion) override
frameCompletedCallback is called by the renderer when a new frame becomes ready
KisAsyncAnimationFramesSavingRenderer(KisImageSP image, const QString &fileNamePrefix, const QString &fileNameSuffix, const QByteArray &outputMimeType, const KisTimeSpan &range, const int sequenceNumberingOffset, const bool onlyNeedsUniqueFrames, KisPropertiesConfigurationSP exportConfiguration)
void sigCompleteRegenerationInternal(int frame)
const KoColorSpace * colorSpace() const
KisPaintDeviceSP projection() const
double xRes() const
double yRes() const
QRect bounds() const override
void setResolution(double xres, double yres)
int start() const
static KisTimeSpan calculateIdenticalFramesRecursive(const KisNode *node, int time)
int end() const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
KisDocument * createDocument(QList< KisNodeSP > nodes, KisImageSP srcImage, const QRect &copiedBounds)
Private(KisImageSP image, const KisTimeSpan &_range, int _sequenceNumberingOffset, bool _onlyNeedsUniqueFrames, KisPropertiesConfigurationSP _exportConfiguration)
void notifyFrameCancelled(int frame, KisAsyncAnimationRendererBase::CancelReason cancelReason)
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
KisPaintDeviceSP paintDevice