From ee21d1ccc7606df8300bfe094298176edae0b50b Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 8 Nov 2016 14:35:53 -0800 Subject: [PATCH] IT WORKSgit add -A! Mega amounts of cleanup to do now. --- interface/src/Application.cpp | 75 +++++++++++++++++++---------------- interface/src/Application.h | 1 + 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b59f02329b..9d88ebf116 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -176,6 +176,7 @@ using namespace std; static QTimer locationUpdateTimer; static QTimer identityPacketTimer; static QTimer pingTimer; +static QTimer animatedSnapshotTimer; static const int MAX_CONCURRENT_RESOURCE_DOWNLOADS = 16; @@ -5429,6 +5430,9 @@ void Application::toggleLogDialog() { } } +uint8_t _currentAnimatedSnapshotFrame; +GifWriter _animatedSnapshotGifWriter; + void Application::takeSnapshot(bool notify, const QString& format, float aspectRatio) { postLambdaEvent([notify, format, aspectRatio, this] { QMediaPlayer* player = new QMediaPlayer(); @@ -5441,55 +5445,56 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR if (!format.compare("still")) { path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); + emit DependencyManager::get()->snapshotTaken(path, notify); } else if (!format.compare("animated")) { - QImage frame; - GifWriter myGifWriter; char* cstr; - + connect(&animatedSnapshotTimer, &QTimer::timeout, this, &Application::animatedSnapshotTimerCb); + _currentAnimatedSnapshotFrame = 0; + // File path stuff path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); path.append(QDir::separator()); path.append("test.gif"); - string fname = path.toStdString(); cstr = new char[fname.size() + 1]; strcpy(cstr, fname.c_str()); - - - frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(400); - uint32_t frameNumBytes = frame.width() * frame.height() * 4; - - uint8_t* pixelArray = new uint8_t[frameNumBytes]; - uchar *bits; - - GifBegin(&myGifWriter, cstr, frame.width(), frame.height(), 50); - for (uint8_t itr = 0; itr < 30; itr++) - { - bits = frame.bits(); - for (uint32_t itr2 = 0; itr2 < frameNumBytes; itr2 += 4) - { - pixelArray[itr2 + 0] = (uint8_t)bits[itr2 + 0]; // R - pixelArray[itr2 + 1] = (uint8_t)bits[itr2 + 1]; // G - pixelArray[itr2 + 2] = (uint8_t)bits[itr2 + 2]; // B - pixelArray[itr2 + 3] = (uint8_t)bits[itr2 + 3]; // Alpha - } - - GifWriteFrame(&myGifWriter, pixelArray, frame.width(), frame.height(), 50); - usleep(USECS_PER_MSEC * 50); // 1/20 sec - // updateHeartbeat() while making the GIF so we don't scare the deadlock watchdog - updateHeartbeat(); - frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(400); - } - - delete[frameNumBytes] pixelArray; - GifEnd(&myGifWriter); + // Start the GIF + QImage frame = (getActiveDisplayPlugin()->getScreenshot(1.91)).scaledToWidth(500).convertToFormat(QImage::Format_RGBA8888); + GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), 5); + Application::animatedSnapshotTimerCb(); + animatedSnapshotTimer.start(50); } - - emit DependencyManager::get()->snapshotTaken(path, notify); }); } +void Application::animatedSnapshotTimerCb() +{ + if (_currentAnimatedSnapshotFrame == 30) + { + animatedSnapshotTimer.stop(); + GifEnd(&_animatedSnapshotGifWriter); + QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + path.append(QDir::separator()); + path.append("test.gif"); + emit DependencyManager::get()->snapshotTaken(path, false); + return; + } + + QImage frame = (getActiveDisplayPlugin()->getScreenshot(1.91)).scaledToWidth(500).convertToFormat(QImage::Format_RGBA8888); + uint32_t frameNumBytes = frame.width() * frame.height() * 4; + + uint8_t* pixelArray = new uint8_t[frameNumBytes]; + //uchar *bits; + //bits = frame.bits(); + //memcpy(pixelArray, (uint8_t*)bits, frameNumBytes); + + GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), 5); + _currentAnimatedSnapshotFrame++; + + delete[frameNumBytes] pixelArray; +} + void Application::shareSnapshot(const QString& path) { postLambdaEvent([path] { // not much to do here, everything is done in snapshot code... diff --git a/interface/src/Application.h b/interface/src/Application.h index d1150fb30f..6fd7c4f1b8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -267,6 +267,7 @@ public: float getAverageSimsPerSecond() const { return _simCounter.rate(); } void takeSnapshot(bool notify, const QString& format = "still", float aspectRatio = 0.0f); + void animatedSnapshotTimerCb(); void shareSnapshot(const QString& filename); model::SkyboxPointer getDefaultSkybox() const { return _defaultSkybox; }