History

Comments - still crashing...

Zach Fox committed 10 years ago

Commit e656a441 parent 1912ab11 file · +32 −18Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+32−18
@@ -5444,51 +5444,65 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR · 5443 unmodified lines
54445444 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
54455445 player->play();
54465446
5447− GifWriter _animatedSnapshotGifWriter;
5448− uint8_t _currentAnimatedSnapshotFrame = 0;
5449− QString path;
54505447
54515448 // If this is a still snapshot...
54525449 if (!format.compare("still"))
54535450 {
5454− // Get a screenshot and save it. and - this part of the code has been around for a while
5455− path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio));
5451+ // Get a screenshot and save it
5452+ QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio));
5453+ // Notify the window scripting interface that we've taken a Snapshot
5454+ emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify);
54565455 }
54575456 // If this is an animated snapshot (GIF)...
54585457 else if (!format.compare("animated"))
54595458 {
5459+ GifWriter _animatedSnapshotGifWriter;
5460+ uint8_t _currentAnimatedSnapshotFrame = 0;
5461+ // File path stuff -- lots of this is temporary
5462+ // until I figure out how to save the .GIF to the same location as the still .JPG
54605463 char* cstr;
5461− // File path stuff
5462− path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
5463− path.append(QDir::separator());
5464− path.append("test.gif");
5465− string fname = path.toStdString();
5466− cstr = new char[fname.size() + 1];
5467− strcpy(cstr, fname.c_str());
5468−
5469− connect(&animatedSnapshotTimer, &QTimer::timeout, [&] {
5464+ QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); // Get the desktop
5465+ path.append(QDir::separator()); // Add the dir separator to the desktop location
5466+ path.append("test.gif"); // Add "test.gif" to the path
5467+ string fname = path.toStdString(); // Turn the QString into a regular string
5468+ cstr = new char[fname.size() + 1]; // Create a new character array to hold the .GIF file location
5469+ strcpy(cstr, fname.c_str()); // Copy the string into a character array
5470+
5471+ // Connect the animatedSnapshotTimer QTimer to the lambda slot function
5472+ connect(&animatedSnapshotTimer, &QTimer::timeout, [&]() {
5473+ // If this is the last frame...
54705474 if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES)
54715475 {
5476+ // Stop the snapshot QTimer
54725477 animatedSnapshotTimer.stop();
5478+ // Write out the end of the GIF
54735479 GifEnd(&_animatedSnapshotGifWriter);
5480+ // Notify the Window Scripting Interface that the snapshot was taken
54745481 emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false);
54755482 return;
54765483 }
54775484
5478− QImage frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888);
5485+ // Get a screenshot from the display, then scale the screenshot down,
5486+ // then convert it to the image format the GIF library needs,
5487+ // then save all that to the QImage named "frame"
5488+ QImage frame = (qApp->getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888);
5489+
5490+ // If this is the first frame...
54795491 if (_currentAnimatedSnapshotFrame == 0)
54805492 {
5493+ // Write out the header and beginning of the GIF file
54815494 GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);
54825495 }
54835496
5497+ // Write the frame to the gif
54845498 GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);
5499+ // Increment the current snapshot frame count
54855500 _currentAnimatedSnapshotFrame++;
54865501 });
5502+
5503+ // Start the animatedSnapshotTimer QTimer
54875504 animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY * 10);
54885505 }
5489−
5490− // Notify the window scripting interface that we've taken a Snapshot
5491− emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify);
54925506 });
54935507 }
54945508 void Application::shareSnapshot(const QString& path) {