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
5444 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));5444 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
5445 player->play();5445 player->play();
5446 5446
5447 GifWriter _animatedSnapshotGifWriter;
5448 uint8_t _currentAnimatedSnapshotFrame = 0;
5449 QString path;
5450 5447
5451 // If this is a still snapshot...5448 // If this is a still snapshot...
5452 if (!format.compare("still"))5449 if (!format.compare("still"))
5453 {5450 {
5454 // Get a screenshot and save it. and - this part of the code has been around for a while5451 // Get a screenshot and save it
5455 path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio));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);
5456 }5455 }
5457 // If this is an animated snapshot (GIF)...5456 // If this is an animated snapshot (GIF)...
5458 else if (!format.compare("animated"))5457 else if (!format.compare("animated"))
5459 {5458 {
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
5460 char* cstr;5463 char* cstr;
5461 // File path stuff5464 QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); // Get the desktop
5462 path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);5465 path.append(QDir::separator()); // Add the dir separator to the desktop location
5463 path.append(QDir::separator());5466 path.append("test.gif"); // Add "test.gif" to the path
5464 path.append("test.gif");5467 string fname = path.toStdString(); // Turn the QString into a regular string
5465 string fname = path.toStdString();5468 cstr = new char[fname.size() + 1]; // Create a new character array to hold the .GIF file location
5466 cstr = new char[fname.size() + 1];5469 strcpy(cstr, fname.c_str()); // Copy the string into a character array
5467 strcpy(cstr, fname.c_str());5470
5468 5471 // Connect the animatedSnapshotTimer QTimer to the lambda slot function
5469 connect(&animatedSnapshotTimer, &QTimer::timeout, [&] {5472 connect(&animatedSnapshotTimer, &QTimer::timeout, [&]() {
5473 // If this is the last frame...
5470 if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES)5474 if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES)
5471 {5475 {
5476 // Stop the snapshot QTimer
5472 animatedSnapshotTimer.stop();5477 animatedSnapshotTimer.stop();
5478 // Write out the end of the GIF
5473 GifEnd(&_animatedSnapshotGifWriter);5479 GifEnd(&_animatedSnapshotGifWriter);
5480 // Notify the Window Scripting Interface that the snapshot was taken
5474 emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false);5481 emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false);
5475 return;5482 return;
5476 }5483 }
5477 5484
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...
5479 if (_currentAnimatedSnapshotFrame == 0)5491 if (_currentAnimatedSnapshotFrame == 0)
5480 {5492 {
5493 // Write out the header and beginning of the GIF file
5481 GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);5494 GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);
5482 }5495 }
5483 5496
5497 // Write the frame to the gif
5484 GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);5498 GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY);
5499 // Increment the current snapshot frame count
5485 _currentAnimatedSnapshotFrame++;5500 _currentAnimatedSnapshotFrame++;
5486 });5501 });
5502
5503 // Start the animatedSnapshotTimer QTimer
5487 animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY * 10);5504 animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY * 10);
5488 }5505 }
5489
5490 // Notify the window scripting interface that we've taken a Snapshot
5491 emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify);
5492 });5506 });
5493}5507}
5494void Application::shareSnapshot(const QString& path) {5508void Application::shareSnapshot(const QString& path) {