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()
struct KisAnimationExportSaver::Private
{
Private(KisDocument *document, int fromTime, int toTime)
: document(document),
image(document->image()),
firstFrame(fromTime),
lastFrame(toTime),
tmpDoc(KisPart::instance()->createDocument()),
exporter(document, fromTime, toTime)
Private(KisDocument *document, int fromTime, int toTime, int _sequenceNumberingOffset)
: document(document)
, image(document->image())
, firstFrame(fromTime)
, lastFrame(toTime)
, sequenceNumberingOffset(_sequenceNumberingOffset)
, tmpDoc(KisPart::instance()->createDocument())
, exporter(document, fromTime, toTime)
{
tmpDoc->setAutoSave(0);
......@@ -263,6 +264,7 @@ struct KisAnimationExportSaver::Private
KisImageWSP image;
int firstFrame;
int lastFrame;
int sequenceNumberingOffset;
QScopedPointer<KisDocument> tmpDoc;
KisImageSP tmpImage;
......@@ -274,8 +276,8 @@ struct KisAnimationExportSaver::Private
QString filenameSuffix;
};
KisAnimationExportSaver::KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime)
: m_d(new Private(document, fromTime, toTime))
KisAnimationExportSaver::KisAnimationExportSaver(KisDocument *document, const QString &baseFilename, int fromTime, int toTime, int sequenceNumberingOffset)
: m_d(new Private(document, fromTime, toTime, sequenceNumberingOffset))
{
int baseLength = baseFilename.lastIndexOf(".");
if (baseLength > -1) {
......@@ -307,8 +309,8 @@ KisImportExportFilter::ConversionStatus KisAnimationExportSaver::saveFrameCallba
KisImportExportFilter::ConversionStatus status =
KisImportExportFilter::OK;
QString frameNumber = QString("%1").arg(time, 4, 10, QChar('0'));
QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix;
QString frameNumber = QString("%1").arg(time + m_d->sequenceNumberingOffset, 4, 10, QChar('0'));
QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix;
QRect rc = m_d->image->bounds();
KisPainter::copyAreaOptimized(rc.topLeft(), frame, m_d->tmpDevice, rc);
......
......@@ -28,6 +28,9 @@
class KisDocument;
/**
* @brief The KisAnimationExporterUI class
*/
class KRITAUI_EXPORT KisAnimationExporterUI : public QObject
{
Q_OBJECT
......@@ -35,7 +38,7 @@ class KRITAUI_EXPORT KisAnimationExporterUI : public QObject
public:
KisAnimationExporterUI(QWidget *parent);
~KisAnimationExporterUI();
virtual ~KisAnimationExporterUI();
KisImportExportFilter::ConversionStatus exportSequence(KisDocument *document);
private:
......@@ -43,6 +46,9 @@ private:
QScopedPointer<Private> m_d;
};
/**
* @brief The KisAnimationExporter class
*/
class KRITAUI_EXPORT KisAnimationExporter : public QObject
{
Q_OBJECT
......@@ -71,11 +77,14 @@ private:
QScopedPointer<Private> m_d;
};
/**
* @brief The KisAnimationExportSaver class
*/
class KRITAUI_EXPORT KisAnimationExportSaver : public QObject
{
Q_OBJECT
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();
KisImportExportFilter::ConversionStatus exportAnimation();
......
......@@ -29,7 +29,10 @@
#include <kis_image_animation_interface.h>
#include <kis_properties_configuration.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>();)
......@@ -54,6 +57,7 @@ AnimaterionRenderer::~AnimaterionRenderer()
void AnimaterionRenderer::slotRenderAnimation()
{
KisImageWSP image = m_view->image();
KisDocument *doc = m_view->document();
if (!image) return;
if (!image->animationInterface()->hasAnimation()) return;
......@@ -62,8 +66,17 @@ void AnimaterionRenderer::slotRenderAnimation()
dlgAnimaterionRenderer.setCaption(i18n("Render Animation"));
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()
cfg->setProperty("first_frame", m_page->intStart->value());
cfg->setProperty("last_frame", m_page->intEnd->value());
cfg->setProperty("sequence_start", m_page->sequenceStart->value());
cfg->setProperty("mimetype", m_page->cmbMimetype->currentData().toString());
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