Commit de5dcc38 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Connect the render dialog to the animation exporter

This also adds an offset parameter for when you want to renumber
frames from a given startpoint on exporting.
parent 6bf5a581
...@@ -232,13 +232,14 @@ void KisAnimationExporter::frameReadyToSave() ...@@ -232,13 +232,14 @@ void KisAnimationExporter::frameReadyToSave()
struct KisAnimationExportSaver::Private struct KisAnimationExportSaver::Private
{ {
Private(KisDocument *document, int fromTime, int toTime) Private(KisDocument *document, int fromTime, int toTime, int _sequenceNumberingOffset)
: document(document), : document(document)
image(document->image()), , image(document->image())
firstFrame(fromTime), , firstFrame(fromTime)
lastFrame(toTime), , lastFrame(toTime)
tmpDoc(KisPart::instance()->createDocument()), , sequenceNumberingOffset(_sequenceNumberingOffset)
exporter(document, fromTime, toTime) , tmpDoc(KisPart::instance()->createDocument())
, exporter(document, fromTime, toTime)
{ {
tmpDoc->setAutoSave(0); tmpDoc->setAutoSave(0);
...@@ -263,6 +264,7 @@ struct KisAnimationExportSaver::Private ...@@ -263,6 +264,7 @@ struct KisAnimationExportSaver::Private
KisImageWSP image; KisImageWSP image;
int firstFrame; int firstFrame;
int lastFrame; int lastFrame;
int sequenceNumberingOffset;
QScopedPointer<KisDocument> tmpDoc; QScopedPointer<KisDocument> tmpDoc;
KisImageSP tmpImage; KisImageSP tmpImage;
...@@ -274,8 +276,8 @@ struct KisAnimationExportSaver::Private ...@@ -274,8 +276,8 @@ struct KisAnimationExportSaver::Private
QString filenameSuffix; QString filenameSuffix;
}; };
KisAnimationExportSaver::KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime) KisAnimationExportSaver::KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime, int sequenceNumberingOffset)
: m_d(new Private(document, fromTime, toTime)) : m_d(new Private(document, fromTime, toTime, sequenceNumberingOffset))
{ {
int baseLength = baseFilename.lastIndexOf("."); int baseLength = baseFilename.lastIndexOf(".");
if (baseLength > -1) { if (baseLength > -1) {
...@@ -307,8 +309,8 @@ KisImportExportFilter::ConversionStatus KisAnimationExportSaver::saveFrameCallba ...@@ -307,8 +309,8 @@ KisImportExportFilter::ConversionStatus KisAnimationExportSaver::saveFrameCallba
KisImportExportFilter::ConversionStatus status = KisImportExportFilter::ConversionStatus status =
KisImportExportFilter::OK; KisImportExportFilter::OK;
QString frameNumber = QString("%1").arg(time, 4, 10, QChar('0')); QString frameNumber = QString("%1").arg(time + m_d->sequenceNumberingOffset, 4, 10, QChar('0'));
QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix; QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix;
QRect rc = m_d->image->bounds(); QRect rc = m_d->image->bounds();
KisPainter::copyAreaOptimized(rc.topLeft(), frame, m_d->tmpDevice, rc); KisPainter::copyAreaOptimized(rc.topLeft(), frame, m_d->tmpDevice, rc);
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
class KisDocument; class KisDocument;
/**
* @brief The KisAnimationExporterUI class
*/
class KRITAUI_EXPORT KisAnimationExporterUI : public QObject class KRITAUI_EXPORT KisAnimationExporterUI : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -35,7 +38,7 @@ class KRITAUI_EXPORT KisAnimationExporterUI : public QObject ...@@ -35,7 +38,7 @@ class KRITAUI_EXPORT KisAnimationExporterUI : public QObject
public: public:
KisAnimationExporterUI(QWidget *parent); KisAnimationExporterUI(QWidget *parent);
~KisAnimationExporterUI(); virtual ~KisAnimationExporterUI();
KisImportExportFilter::ConversionStatus exportSequence(KisDocument *document); KisImportExportFilter::ConversionStatus exportSequence(KisDocument *document);
private: private:
...@@ -43,6 +46,9 @@ private: ...@@ -43,6 +46,9 @@ private:
QScopedPointer<Private> m_d; QScopedPointer<Private> m_d;
}; };
/**
* @brief The KisAnimationExporter class
*/
class KRITAUI_EXPORT KisAnimationExporter : public QObject class KRITAUI_EXPORT KisAnimationExporter : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -71,11 +77,14 @@ private: ...@@ -71,11 +77,14 @@ private:
QScopedPointer<Private> m_d; QScopedPointer<Private> m_d;
}; };
/**
* @brief The KisAnimationExportSaver class
*/
class KRITAUI_EXPORT KisAnimationExportSaver : public QObject class KRITAUI_EXPORT KisAnimationExportSaver : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime); KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime, int sequenceNumberingOffset = 0);
~KisAnimationExportSaver(); ~KisAnimationExportSaver();
KisImportExportFilter::ConversionStatus exportAnimation(); KisImportExportFilter::ConversionStatus exportAnimation();
......
...@@ -29,7 +29,10 @@ ...@@ -29,7 +29,10 @@
#include <kis_image_animation_interface.h> #include <kis_image_animation_interface.h>
#include <kis_properties_configuration.h> #include <kis_properties_configuration.h>
#include "DlgAnimationRenderer.h" #include "DlgAnimationRenderer.h"
#include <kis_config.h>
#include <kis_animation_exporter.h>
#include <KisDocument.h>
#include <KisMimeDatabase.h>
K_PLUGIN_FACTORY_WITH_JSON(AnimaterionRendererFactory, "kritaanimationrenderer.json", registerPlugin<AnimaterionRenderer>();) K_PLUGIN_FACTORY_WITH_JSON(AnimaterionRendererFactory, "kritaanimationrenderer.json", registerPlugin<AnimaterionRenderer>();)
...@@ -54,6 +57,7 @@ AnimaterionRenderer::~AnimaterionRenderer() ...@@ -54,6 +57,7 @@ AnimaterionRenderer::~AnimaterionRenderer()
void AnimaterionRenderer::slotRenderAnimation() void AnimaterionRenderer::slotRenderAnimation()
{ {
KisImageWSP image = m_view->image(); KisImageWSP image = m_view->image();
KisDocument *doc = m_view->document();
if (!image) return; if (!image) return;
if (!image->animationInterface()->hasAnimation()) return; if (!image->animationInterface()->hasAnimation()) return;
...@@ -62,8 +66,17 @@ void AnimaterionRenderer::slotRenderAnimation() ...@@ -62,8 +66,17 @@ void AnimaterionRenderer::slotRenderAnimation()
dlgAnimaterionRenderer.setCaption(i18n("Render Animation")); dlgAnimaterionRenderer.setCaption(i18n("Render Animation"));
if (dlgAnimaterionRenderer.exec() == QDialog::Accepted) { if (dlgAnimaterionRenderer.exec() == QDialog::Accepted) {
KisPropertiesConfigurationSP sequencecfg = dlgAnimaterionRenderer.getSequenceConfiguration();
KisConfig kisConfig;
kisConfig.setExportConfiguration("IMAGESEQUENCE", *sequencecfg.data());
QString mimetype = sequencecfg->getString("mimetype");
QString extension = KisMimeDatabase::suffixesForMimeType(mimetype).first();
QString baseFileName = QString("%1/%2.%3").arg(sequencecfg->getString("directory"))
.arg(sequencecfg->getString("basename"))
.arg(extension);
KisAnimationExportSaver exporter(doc, baseFileName, sequencecfg->getInt("first_frame"), sequencecfg->getInt("last_frame"), sequencecfg->getInt("sequence_start"));
bool success = exporter.exportAnimation();
Q_ASSERT(success);
} }
} }
......
...@@ -123,6 +123,7 @@ KisPropertiesConfigurationSP DlgAnimaterionRenderer::getSequenceConfiguration() ...@@ -123,6 +123,7 @@ KisPropertiesConfigurationSP DlgAnimaterionRenderer::getSequenceConfiguration()
cfg->setProperty("first_frame", m_page->intStart->value()); cfg->setProperty("first_frame", m_page->intStart->value());
cfg->setProperty("last_frame", m_page->intEnd->value()); cfg->setProperty("last_frame", m_page->intEnd->value());
cfg->setProperty("sequence_start", m_page->sequenceStart->value()); cfg->setProperty("sequence_start", m_page->sequenceStart->value());
cfg->setProperty("mimetype", m_page->cmbMimetype->currentData().toString());
return cfg; return cfg;
} }
......
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