diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp --- a/libs/ui/KisApplication.cpp +++ b/libs/ui/KisApplication.cpp @@ -95,6 +95,9 @@ #include "widgets/KisScreenColorPicker.h" #include "KisDlgInternalColorSelector.h" +#include +#include + namespace { const QTime appStartTime(QTime::currentTime()); } @@ -386,12 +389,13 @@ const bool doNewImage = args.doNewImage(); const bool doTemplate = args.doTemplate(); const bool exportAs = args.exportAs(); + const bool exportAnimation = args.exportAnimation(); const QString exportFileName = args.exportFileName(); - d->batchRun = (exportAs || !exportFileName.isEmpty()); - const bool needsMainWindow = !exportAs; + d->batchRun = (exportAs || exportAnimation || !exportFileName.isEmpty()); + const bool needsMainWindow = (!exportAs && !exportAnimation); // only show the mainWindow when no command-line mode option is passed - bool showmainWindow = !exportAs; // would be !batchRun; + bool showmainWindow = (!exportAs && !exportAnimation); // would be !batchRun; const bool showSplashScreen = !d->batchRun && qEnvironmentVariableIsEmpty("NOSPLASH"); if (showSplashScreen && d->splashScreen) { @@ -545,6 +549,34 @@ } QTimer::singleShot(0, this, SLOT(quit())); } + else if (exportAnimation) { + KisDocument *doc = kisPart->createDocument(); + doc->setFileBatchMode(d->batchRun); + doc->openUrl(QUrl::fromLocalFile(fileName)); + qApp->processEvents(); // For vector layers to be updated + + if (!doc->image()->animationInterface()->hasAnimation()) { + errKrita << "This file has no animation." << endl; + QTimer::singleShot(0, this, SLOT(quit())); + return 1; + } + + doc->setFileBatchMode(true); + int sequenceStart = 0; + + KisAsyncAnimationFramesSaveDialog exporter(doc->image(), + doc->image()->animationInterface()->fullClipRange(), + exportFileName, + sequenceStart, + 0); + exporter.setBatchMode(d->batchRun); + KisAsyncAnimationFramesSaveDialog::Result result = + exporter.regenerateRange(0); + if (result == KisAsyncAnimationFramesSaveDialog::RenderFailed) { + errKrita << i18n("Failed to render animation frames!") << endl; + } + QTimer::singleShot(0, this, SLOT(quit())); + } else if (d->mainWindow) { if (fileName.endsWith(".bundle")) { d->mainWindow->installBundle(fileName); diff --git a/libs/ui/KisApplicationArguments.h b/libs/ui/KisApplicationArguments.h --- a/libs/ui/KisApplicationArguments.h +++ b/libs/ui/KisApplicationArguments.h @@ -46,6 +46,7 @@ int dpiY() const; bool doTemplate() const; bool exportAs() const; + bool exportAnimation() const; QString exportFileName() const; QString workspace() const; QString windowLayout() const; diff --git a/libs/ui/KisApplicationArguments.cpp b/libs/ui/KisApplicationArguments.cpp --- a/libs/ui/KisApplicationArguments.cpp +++ b/libs/ui/KisApplicationArguments.cpp @@ -43,6 +43,7 @@ int dpiY {72}; bool doTemplate {false}; bool exportAs {false}; + bool exportAnimation {false}; QString exportFileName; QString workspace; QString windowLayout; @@ -98,6 +99,7 @@ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("fullscreen"), i18n("Start Krita in full-screen mode"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("dpi"), i18n("Override display DPI"), QLatin1String("dpiX,dpiY"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export"), i18n("Export to the given filename and exit"))); + parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export-animation"), i18n("Export animation to the given filename and exit"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export-filename"), i18n("Filename for export"), QLatin1String("filename"))); parser.addPositionalArgument(QLatin1String("[file(s)]"), i18n("File(s) or URL(s) to open")); parser.process(app); @@ -140,6 +142,7 @@ d->session = parser.value("load-session"); d->doTemplate = parser.isSet("template"); d->exportAs = parser.isSet("export"); + d->exportAnimation = parser.isSet("export-animation"); d->canvasOnly = parser.isSet("canvasonly"); d->noSplash = parser.isSet("nosplash"); d->fullScreen = parser.isSet("fullscreen"); @@ -282,6 +285,11 @@ return d->exportAs; } +bool KisApplicationArguments::exportAnimation() const +{ + return d->exportAnimation; +} + QString KisApplicationArguments::exportFileName() const { return d->exportFileName;