-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreviousframeoverlayeffect.cpp
More file actions
66 lines (54 loc) · 1.74 KB
/
previousframeoverlayeffect.cpp
File metadata and controls
66 lines (54 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "previousframeoverlayeffect.h"
#include <QPainter>
#include <iostream>
#include <QFile>
#include "settings.h"
PreviousFrameOverlayEffect::PreviousFrameOverlayEffect() :
_frameNeedsUpdate (false),
_mode (Mode::BLEND)
{
}
void PreviousFrameOverlayEffect::setPreviousFrame (const QString &filename)
{
_previousFrameFile = filename;
_frameNeedsUpdate = true;
}
void PreviousFrameOverlayEffect::setMode (Mode newMode)
{
_mode = newMode;
}
PreviousFrameOverlayEffect::Mode PreviousFrameOverlayEffect::getMode () const
{
return _mode;
}
void PreviousFrameOverlayEffect::draw(QPainter *painter)
{
if (_frameNeedsUpdate) {
bool loaded = false;
try {
loaded = _previousFrame.load (_previousFrameFile);
} catch (...) {
loaded = false;
}
if (!loaded) {
std::cerr << "Could not load the frame file!" << std::endl;
std::cerr << _previousFrameFile.toStdString() << std::endl;
}
_frameNeedsUpdate = false;
}
const QPixmap pixmap = sourcePixmap();
const QRect rect = pixmap.rect();
QImage overlaidImage (rect.width(), rect.height(), QImage::Format_ARGB32_Premultiplied);
QPainter overlaidPainter (&overlaidImage);
overlaidPainter.setCompositionMode(QPainter::CompositionMode_Source);
Settings settings;
int w = settings.Get("settings/imageWidth").toInt();
int h = settings.Get("settings/imageHeight").toInt();
if (_mode == Mode::BLEND) {
overlaidPainter.drawPixmap(0,0,w,h,pixmap);
overlaidPainter.setCompositionMode(QPainter::CompositionMode_Screen);
}
overlaidPainter.drawPixmap(0,0,w,h, _previousFrame);
overlaidPainter.end();
painter->drawImage(rect, overlaidImage);
}