Showing the changes to interface/src/Application.cpp (1 of 3 files). Show all
Unified · Split
| @@ -5430,9 +5430,7 @@ void Application::toggleLogDialog() { · 5429 unmodified lines | ||
| 5430 | 5430 | } |
| 5431 | 5431 | } |
| 5432 | 5432 | |
| 5433 | −uint8_t _currentAnimatedSnapshotFrame; | |
| 5434 | −GifWriter _animatedSnapshotGifWriter; | |
| 5435 | −#define SNAPSNOT_ANIMATED_WIDTH (640) | |
| 5433 | +#define SNAPSNOT_ANIMATED_WIDTH (900) | |
| 5436 | 5434 | #define SNAPSNOT_ANIMATED_FRAMERATE_FPS (20) |
| 5437 | 5435 | #define SNAPSNOT_ANIMATED_FRAME_DELAY (100/SNAPSNOT_ANIMATED_FRAMERATE_FPS) |
| 5438 | 5436 | #define SNAPSNOT_ANIMATED_DURATION_SECS (3) |
| @@ -5446,6 +5444,8 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR · 7 unmodified lines | ||
| 5446 | 5444 | player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); |
| 5447 | 5445 | player->play(); |
| 5448 | 5446 | |
| 5447 | + GifWriter _animatedSnapshotGifWriter; | |
| 5448 | + uint8_t _currentAnimatedSnapshotFrame; | |
| 5449 | 5449 | QString path; |
| 5450 | 5450 | |
| 5451 | 5451 | // If this is a still snapshot... |
| @@ -5460,7 +5460,6 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR · 8 unmodified lines | ||
| 5460 | 5460 | else if (!format.compare("animated")) |
| 5461 | 5461 | { |
| 5462 | 5462 | char* cstr; |
| 5463 | − connect(&animatedSnapshotTimer, &QTimer::timeout, this, &Application::animatedSnapshotTimerCb); | |
| 5464 | 5463 | _currentAnimatedSnapshotFrame = 0; |
| 5465 | 5464 | // File path stuff |
| 5466 | 5465 | path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); |
| @@ -5469,38 +5468,33 @@ void Application::takeSnapshot(bool notify, const QString& format, float aspectR · 2 unmodified lines | ||
| 5469 | 5468 | string fname = path.toStdString(); |
| 5470 | 5469 | cstr = new char[fname.size() + 1]; |
| 5471 | 5470 | strcpy(cstr, fname.c_str()); |
| 5472 | − // Start the GIF | |
| 5473 | − QImage frame = (getActiveDisplayPlugin()->getScreenshot(1.91)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888); | |
| 5474 | − GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); | |
| 5475 | − Application::animatedSnapshotTimerCb(); | |
| 5476 | − animatedSnapshotTimer.start(50); | |
| 5477 | − } | |
| 5478 | − }); | |
| 5479 | −} | |
| 5480 | 5471 | |
| 5481 | −void Application::animatedSnapshotTimerCb() | |
| 5482 | −{ | |
| 5483 | − if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES) | |
| 5484 | − { | |
| 5485 | − animatedSnapshotTimer.stop(); | |
| 5486 | − GifEnd(&_animatedSnapshotGifWriter); | |
| 5487 | − QString path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | |
| 5488 | − path.append(QDir::separator()); | |
| 5489 | − path.append("test.gif"); | |
| 5490 | − emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false); | |
| 5491 | − return; | |
| 5492 | − } | |
| 5472 | + connect(&animatedSnapshotTimer, &QTimer::timeout, this, [&] { | |
| 5473 | + if (_currentAnimatedSnapshotFrame == SNAPSNOT_ANIMATED_NUM_FRAMES) | |
| 5474 | + { | |
| 5475 | + animatedSnapshotTimer.stop(); | |
| 5476 | + GifEnd(&_animatedSnapshotGifWriter); | |
| 5477 | + emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, false); | |
| 5478 | + return; | |
| 5479 | + } | |
| 5493 | 5480 | |
| 5494 | − QImage frame = (getActiveDisplayPlugin()->getScreenshot(1.91)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888); | |
| 5495 | − uint32_t frameNumBytes = frame.width() * frame.height() * 4; | |
| 5496 | − uint8_t* pixelArray = new uint8_t[frameNumBytes]; | |
| 5481 | + QImage frame = (getActiveDisplayPlugin()->getScreenshot(aspectRatio)).scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888); | |
| 5482 | + if (_currentAnimatedSnapshotFrame == 0) | |
| 5483 | + { | |
| 5484 | + GifBegin(&_animatedSnapshotGifWriter, cstr, frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); | |
| 5485 | + } | |
| 5486 | + uint32_t frameNumBytes = frame.width() * frame.height() * 4; | |
| 5487 | + uint8_t* pixelArray = new uint8_t[frameNumBytes]; | |
| 5497 | 5488 | |
| 5498 | − GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); | |
| 5499 | − _currentAnimatedSnapshotFrame++; | |
| 5489 | + GifWriteFrame(&_animatedSnapshotGifWriter, (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY); | |
| 5490 | + _currentAnimatedSnapshotFrame++; | |
| 5500 | 5491 | |
| 5501 | − delete[frameNumBytes] pixelArray; | |
| 5492 | + delete[frameNumBytes] pixelArray; | |
| 5493 | + }); | |
| 5494 | + animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY * 10); | |
| 5495 | + } | |
| 5496 | + }); | |
| 5502 | 5497 | } |
| 5503 | − | |
| 5504 | 5498 | void Application::shareSnapshot(const QString& path) { |
| 5505 | 5499 | postLambdaEvent([path] { |
| 5506 | 5500 | // not much to do here, everything is done in snapshot code... |