-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRetroCamera.cpp
119 lines (103 loc) · 2.93 KB
/
QRetroCamera.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#if QRETRO_HAVE_CAMERA
#include <QAbstractVideoSurface>
#include <QCamera>
#include <QVideoSurfaceFormat>
#endif
#include "QRetroCamera.h"
#if QRETRO_HAVE_CAMERA
bool QRetroCameraSurface::present(const QVideoFrame &frame)
{
auto copy = QVideoFrame(frame);
if (m_RawCb)
m_RawCb(reinterpret_cast<const uint32_t*>(copy.bits()),
static_cast<unsigned>(copy.width()),
static_cast<unsigned>(copy.height()),
static_cast<unsigned>(copy.bytesPerLine()));
return true;
}
QList<QVideoFrame::PixelFormat> QRetroCameraSurface::supportedPixelFormats(
QAbstractVideoBuffer::HandleType type) const
{
Q_UNUSED(type)
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32;
}
#endif
QRetroCamera::~QRetroCamera()
{
if (m_Initted && m_Callback.deinitialized)
m_Callback.deinitialized();
#if QRETRO_HAVE_CAMERA
delete m_Camera;
delete m_Surface;
#endif
}
void QRetroCamera::init(const retro_camera_callback* cb)
{
if (cb)
{
m_Callback = *cb;
#if QRETRO_HAVE_CAMERA
m_Camera = new QCamera();
#endif
setImage(QImage("://camera.png"));
m_Initted = true;
if (m_Callback.initialized)
m_Callback.initialized();
}
}
bool QRetroCamera::start(void)
{
#if QRETRO_HAVE_CAMERA
if (m_Camera && !m_Surface)
{
QVideoSurfaceFormat format(QSize(static_cast<int>(m_Callback.width), static_cast<int>(m_Callback.height)),
QVideoFrame::Format_RGB32,
/**
* @todo Support OpenGL texture
* m_Callback.frame_opengl_texture ? QAbstractVideoBuffer::GLTextureHandle :
* QAbstractVideoBuffer::NoHandle);
*/
QAbstractVideoBuffer::NoHandle);
m_Surface = new QRetroCameraSurface(nullptr);
m_Surface->start(format);
m_Camera->setViewfinder(m_Surface);
}
if (m_Surface)
{
m_Camera->start();
return true;
}
#endif
return true;
}
bool QRetroCamera::setImage(const QImage &image, bool quiet)
{
if (!image.isNull())
{
m_SpoofImage = image.scaled(static_cast<int>(m_Callback.width),
static_cast<int>(m_Callback.height));
if (!quiet)
m_Spoofing = true;
return true;
}
else
return false;
}
void QRetroCamera::stop(void)
{
#if QRETRO_HAVE_CAMERA
if (m_Camera)
m_Camera->stop();
#endif
}
void QRetroCamera::update(void)
{
if (m_Initted &&
!m_SpoofImage.isNull() &&
m_Spoofing &&
m_Callback.frame_raw_framebuffer)
m_Callback.frame_raw_framebuffer(reinterpret_cast<uint32_t*>(m_SpoofImage.bits()),
static_cast<unsigned>(m_SpoofImage.width()),
static_cast<unsigned>(m_SpoofImage.height()),
static_cast<unsigned>(m_SpoofImage.bytesPerLine()));
}