From 912c9db1c183a3052242f0feb0c4355f945f06ae Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 8 Nov 2016 10:51:04 -0800 Subject: [PATCH] More progress. Corrupted output GIF. --- interface/src/Application.cpp | 40 ++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a7140403ca..61b0af63c5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5436,15 +5436,19 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); player->play(); - //QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); + QString path; - //if (!format.compare("animated")) - //{ + if (!format.compare("still")) + { + path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); + } + else if (!format.compare("animated")) + { QImage frame; GifWriter myGifWriter; char* cstr; - QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); path.append(QDir::separator()); path.append("test.gif"); @@ -5452,20 +5456,36 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR cstr = new char[fname.size() + 1]; strcpy(cstr, fname.c_str()); - GifBegin(&myGifWriter, cstr, 1, 1, 0); - uint8_t test[4] = { 0xFF, 0x00, 0x00, 0x00 }; + frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(500); + qDebug() << "image format: " << frame.format(); + uint8_t frameNumBytes = frame.width() * frame.height() * 4; + uint8_t* pixelArray = new uint8_t[frameNumBytes]; + uchar *bits; + + GifBegin(&myGifWriter, cstr, frame.width(), frame.height(), 0); for (uint8_t itr = 0; itr < 30; itr++) { - test[0] = 0xFF / (itr + 1); - //frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(500); + bits = frame.bits(); + for (uint8_t itr2 = 0; itr2 < frameNumBytes; itr2 += 4) + { + pixelArray[itr2 + 3] = (uint8_t)bits[itr2]; + pixelArray[itr2 + 0] = (uint8_t)bits[itr2 + 1]; + pixelArray[itr2 + 1] = (uint8_t)bits[itr2 + 2]; + pixelArray[itr2 + 2] = (uint8_t)bits[itr2 + 3]; + } - GifWriteFrame(&myGifWriter, test, 1, 1, 0); + GifWriteFrame(&myGifWriter, pixelArray, frame.width(), frame.height(), 0); + 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(500); } + delete[frameNumBytes] pixelArray; GifEnd(&myGifWriter); - //} + } emit DependencyManager::get()->snapshotTaken(path, notify); });