From 0bf8fa23d91ae9bc46a45a4a2d8d12061e54c742 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 11 Jan 2020 15:48:43 +0100 Subject: Skip same frames --- gui/basewindow.cc | 14 +++++++++----- gui/fpgaviewwidget.cc | 19 ++++++++++++------- gui/fpgaviewwidget.h | 4 +++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 0bfc59a3..7f767c58 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "designwidget.h" @@ -400,11 +401,14 @@ void BaseMainWindow::saveMovie() QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!dir.isEmpty()) { bool ok; - int frames = QInputDialog::getInt(this, "Skip frames", tr("Frames to skip (1 frame = 50ms):"), 5, 0, 1000, - 1, &ok); - if (ok) - fpgaView->movieStart(dir, frames); - else + int frames = + QInputDialog::getInt(this, "Recording", tr("Frames to skip (1 frame = 50ms):"), 5, 0, 1000, 1, &ok); + if (ok) { + QMessageBox::StandardButton reply = + QMessageBox::question(this, "Recording", "Skip identical frames ?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + fpgaView->movieStart(dir, frames, (reply == QMessageBox::Yes)); + } else actionMovie->setChecked(false); } else actionMovie->setChecked(false); diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 8730c9d9..f1494452 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -329,14 +329,17 @@ void FPGAViewWidget::paintGL() if (movieCounter == currentFrameSkip) { QMutexLocker lock(&rendererArgsLock_); movieCounter = 0; - currentMovieFrame++; - QImage image = grabFramebuffer(); - QString number = QString("movie_%1.png").arg(currentMovieFrame, 5, 10, QChar('0')); + if (!movieSkipSame || movieLastImage != image) { + currentMovieFrame++; + + QString number = QString("movie_%1.png").arg(currentMovieFrame, 5, 10, QChar('0')); - QFileInfo fileName = QFileInfo(QDir(movieDir), number); - QImageWriter imageWriter(fileName.absoluteFilePath(), "png"); - imageWriter.write(image); + QFileInfo fileName = QFileInfo(QDir(movieDir), number); + QImageWriter imageWriter(fileName.absoluteFilePath(), "png"); + imageWriter.write(image); + movieLastImage = image; + } } else { movieCounter++; } @@ -599,9 +602,11 @@ void FPGAViewWidget::renderLines(void) } } -void FPGAViewWidget::movieStart(QString dir, long frameSkip) +void FPGAViewWidget::movieStart(QString dir, long frameSkip, bool skipSame) { QMutexLocker locker(&rendererArgsLock_); + movieLastImage = QImage(); + movieSkipSame = skipSame; movieDir = dir; currentMovieFrame = 0; movieCounter = 0; diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 7f99408e..9f670cb0 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -120,7 +120,7 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions void zoomSelected(); void zoomOutbound(); void enableDisableDecals(bool bels, bool wires, bool pips, bool groups); - void movieStart(QString dir, long frameSkip); + void movieStart(QString dir, long frameSkip, bool skipSame); void movieStop(); Q_SIGNALS: void clickedBel(BelId bel, bool add); @@ -133,6 +133,8 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions long currentFrameSkip; long movieCounter; bool movieSaving; + bool movieSkipSame; + QImage movieLastImage; const float zoomNear_ = 0.05f; // do not zoom closer than this float zoomFar_ = 10.0f; // do not zoom further than this const float zoomLvl1_ = 1.0f; -- cgit v1.2.3