mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:58:56 +02:00
Still unstable, but maybe better?
This commit is contained in:
parent
fc21cae904
commit
25471d9fae
2 changed files with 66 additions and 45 deletions
|
@ -5432,8 +5432,8 @@ void Application::toggleLogDialog() {
|
||||||
// The frame will take too long to pack, the timer slot will
|
// The frame will take too long to pack, the timer slot will
|
||||||
// not execute properly, and the GIF will appear sped-up.
|
// not execute properly, and the GIF will appear sped-up.
|
||||||
// This is unacceptable and is probably a blocker for release.
|
// This is unacceptable and is probably a blocker for release.
|
||||||
#define SNAPSNOT_ANIMATED_WIDTH (300)
|
#define SNAPSNOT_ANIMATED_WIDTH (400)
|
||||||
#define SNAPSNOT_ANIMATED_FRAMERATE_FPS (50) // This value should divide evenly into 100
|
#define SNAPSNOT_ANIMATED_FRAMERATE_FPS (25) // This value should divide evenly into 100
|
||||||
#define SNAPSNOT_ANIMATED_DURATION_SECS (3)
|
#define SNAPSNOT_ANIMATED_DURATION_SECS (3)
|
||||||
|
|
||||||
#define SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC (1000/SNAPSNOT_ANIMATED_FRAMERATE_FPS)
|
#define SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC (1000/SNAPSNOT_ANIMATED_FRAMERATE_FPS)
|
||||||
|
@ -5451,60 +5451,80 @@ void Application::takeSnapshot(bool notify, float aspectRatio) {
|
||||||
QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio));
|
QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio));
|
||||||
|
|
||||||
// If we're in the middle of capturing a GIF...
|
// If we're in the middle of capturing a GIF...
|
||||||
if (_currentAnimatedSnapshotFrame != 0)
|
if (_animatedSnapshotFirstFrameTimestamp != 0)
|
||||||
{
|
{
|
||||||
// Notify the window scripting interface that we've taken a Snapshot
|
// Notify the window scripting interface that we've taken a Snapshot
|
||||||
emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify);
|
emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(path, notify);
|
||||||
// Protect against clobbering it and return immediately.
|
// Protect against clobbering it and return immediately.
|
||||||
// (Perhaps with a "snapshot failed" message?
|
// (Perhaps with a "snapshot failed" message?
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Reset the current animated snapshot frame
|
||||||
|
qApp->_animatedSnapshotFirstFrameTimestamp = 0;
|
||||||
|
// Reset the current animated snapshot frame timestamp
|
||||||
|
qApp->_animatedSnapshotTimestamp = 0;
|
||||||
|
|
||||||
// Reset the current animated snapshot frame
|
// Change the extension of the future GIF saved snapshot file to "gif"
|
||||||
_currentAnimatedSnapshotFrame = 0;
|
qApp->_animatedSnapshotPath = path.replace("jpg", "gif");
|
||||||
|
|
||||||
// Change the extension of the future GIF saved snapshot file to "gif"
|
// Ensure the snapshot timer is Precise (attempted millisecond precision)
|
||||||
_animatedSnapshotPath = path.replace("jpg", "gif");
|
qApp->animatedSnapshotTimer.setTimerType(Qt::PreciseTimer);
|
||||||
|
|
||||||
// Ensure the snapshot timer is Precise (attempted millisecond precision)
|
// Connect the animatedSnapshotTimer QTimer to the lambda slot function
|
||||||
animatedSnapshotTimer.setTimerType(Qt::PreciseTimer);
|
connect(&(qApp->animatedSnapshotTimer), &QTimer::timeout, [=] {
|
||||||
|
// Get a screenshot from the display, then scale the screenshot down,
|
||||||
|
// then convert it to the image format the GIF library needs,
|
||||||
|
// then save all that to the QImage named "frame"
|
||||||
|
QImage frame(qApp->getActiveDisplayPlugin()->getScreenshot(aspectRatio));
|
||||||
|
frame = frame.scaledToWidth(SNAPSNOT_ANIMATED_WIDTH);
|
||||||
|
frame = frame.convertToFormat(QImage::Format_RGBA8888);
|
||||||
|
|
||||||
// Connect the animatedSnapshotTimer QTimer to the lambda slot function
|
// If this is the first frame...
|
||||||
connect(&(qApp->animatedSnapshotTimer), &QTimer::timeout, [=] {
|
if (qApp->_animatedSnapshotTimestamp == 0)
|
||||||
// Get a screenshot from the display, then scale the screenshot down,
|
{
|
||||||
// then convert it to the image format the GIF library needs,
|
// Write out the header and beginning of the GIF file
|
||||||
// then save all that to the QImage named "frame"
|
GifBegin(&(qApp->_animatedSnapshotGifWriter), qPrintable(qApp->_animatedSnapshotPath), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10);
|
||||||
QImage frame(qApp->getActiveDisplayPlugin()->getScreenshot(aspectRatio));
|
// Write the first to the gif
|
||||||
frame = frame.scaledToWidth(SNAPSNOT_ANIMATED_WIDTH).convertToFormat(QImage::Format_RGBA8888);
|
GifWriteFrame(&(qApp->_animatedSnapshotGifWriter),
|
||||||
|
(uint8_t*)frame.bits(),
|
||||||
|
frame.width(),
|
||||||
|
frame.height(),
|
||||||
|
SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10);
|
||||||
|
// Record the current frame timestamp
|
||||||
|
qApp->_animatedSnapshotTimestamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
qApp->_animatedSnapshotFirstFrameTimestamp = qApp->_animatedSnapshotTimestamp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Write the frame to the gif
|
||||||
|
GifWriteFrame(&(qApp->_animatedSnapshotGifWriter),
|
||||||
|
(uint8_t*)frame.bits(),
|
||||||
|
frame.width(),
|
||||||
|
frame.height(),
|
||||||
|
round(((float)(QDateTime::currentMSecsSinceEpoch() - qApp->_animatedSnapshotTimestamp)) / 10));
|
||||||
|
// Record the current frame timestamp
|
||||||
|
qApp->_animatedSnapshotTimestamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
|
||||||
// If this is the first frame...
|
// If that was the last frame...
|
||||||
if (qApp->_currentAnimatedSnapshotFrame == 0)
|
if ((qApp->_animatedSnapshotTimestamp - qApp->_animatedSnapshotFirstFrameTimestamp) >= (SNAPSNOT_ANIMATED_DURATION_SECS * 1000))
|
||||||
{
|
{
|
||||||
// Write out the header and beginning of the GIF file
|
// Reset the current frame timestamp
|
||||||
GifBegin(&(qApp->_animatedSnapshotGifWriter), qPrintable(qApp->_animatedSnapshotPath), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC / 10, 8, false);
|
qApp->_animatedSnapshotTimestamp = 0;
|
||||||
}
|
qApp->_animatedSnapshotFirstFrameTimestamp = 0;
|
||||||
|
// Write out the end of the GIF
|
||||||
|
GifEnd(&(qApp->_animatedSnapshotGifWriter));
|
||||||
|
// Notify the Window Scripting Interface that the snapshot was taken
|
||||||
|
emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(qApp->_animatedSnapshotPath, false);
|
||||||
|
// Stop the snapshot QTimer
|
||||||
|
qApp->animatedSnapshotTimer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Write the frame to the gif
|
// Start the animatedSnapshotTimer QTimer - argument for this is in milliseconds
|
||||||
GifWriteFrame(&(qApp->_animatedSnapshotGifWriter), (uint8_t*)frame.bits(), frame.width(), frame.height(), SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC/10, 8, false);
|
qApp->animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC);
|
||||||
// Increment the current snapshot frame count
|
}
|
||||||
qApp->_currentAnimatedSnapshotFrame++;
|
|
||||||
|
|
||||||
// If that was the last frame...
|
|
||||||
if (qApp->_currentAnimatedSnapshotFrame >= SNAPSNOT_ANIMATED_NUM_FRAMES)
|
|
||||||
{
|
|
||||||
// Reset the current frame number
|
|
||||||
qApp->_currentAnimatedSnapshotFrame = 0;
|
|
||||||
// Write out the end of the GIF
|
|
||||||
GifEnd(&(qApp->_animatedSnapshotGifWriter));
|
|
||||||
// Notify the Window Scripting Interface that the snapshot was taken
|
|
||||||
emit DependencyManager::get<WindowScriptingInterface>()->snapshotTaken(qApp->_animatedSnapshotPath, false);
|
|
||||||
// Stop the snapshot QTimer
|
|
||||||
qApp->animatedSnapshotTimer.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start the animatedSnapshotTimer QTimer - argument for this is in milliseconds
|
|
||||||
animatedSnapshotTimer.start(SNAPSNOT_ANIMATED_FRAME_DELAY_MSEC);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void Application::shareSnapshot(const QString& path) {
|
void Application::shareSnapshot(const QString& path) {
|
||||||
|
|
|
@ -613,7 +613,8 @@ private:
|
||||||
|
|
||||||
QTimer animatedSnapshotTimer;
|
QTimer animatedSnapshotTimer;
|
||||||
GifWriter _animatedSnapshotGifWriter;
|
GifWriter _animatedSnapshotGifWriter;
|
||||||
uint32_t _currentAnimatedSnapshotFrame { 0 };
|
quint64 _animatedSnapshotTimestamp{ 0 };
|
||||||
|
quint64 _animatedSnapshotFirstFrameTimestamp{ 0 };
|
||||||
QString _animatedSnapshotPath;
|
QString _animatedSnapshotPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue