mirror of https://github.com/mgba-emu/mgba.git
Qt: Improve camera initialization
This commit is contained in:
parent
7b59e620f1
commit
03aed12d28
1
CHANGES
1
CHANGES
|
@ -24,6 +24,7 @@ Misc:
|
||||||
- Debugger: Add breakpoint and watchpoint listing
|
- Debugger: Add breakpoint and watchpoint listing
|
||||||
- Qt: Add missing HEVC NVENC option (fixes mgba.io/i/1323)
|
- Qt: Add missing HEVC NVENC option (fixes mgba.io/i/1323)
|
||||||
- LR35902: Support PC-relative opcode decoding
|
- LR35902: Support PC-relative opcode decoding
|
||||||
|
- Qt: Improve camera initialization
|
||||||
|
|
||||||
0.7.1: (2019-02-24)
|
0.7.1: (2019-02-24)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -725,12 +725,23 @@ void InputController::setupCam() {
|
||||||
#ifdef BUILD_QT_MULTIMEDIA
|
#ifdef BUILD_QT_MULTIMEDIA
|
||||||
if (!m_camera) {
|
if (!m_camera) {
|
||||||
m_camera = std::make_unique<QCamera>();
|
m_camera = std::make_unique<QCamera>();
|
||||||
|
connect(m_camera.get(), &QCamera::statusChanged, this, &InputController::prepareCamSettings);
|
||||||
}
|
}
|
||||||
QVideoFrame::PixelFormat format(QVideoFrame::Format_RGB32);
|
m_camera->setCaptureMode(QCamera::CaptureVideo);
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
|
m_camera->setViewfinder(&m_videoDumper);
|
||||||
m_camera->load();
|
m_camera->load();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_QT_MULTIMEDIA
|
||||||
|
void InputController::prepareCamSettings(QCamera::Status status) {
|
||||||
|
if (status != QCamera::LoadedStatus || m_camera->state() == QCamera::ActiveState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
|
||||||
|
QVideoFrame::PixelFormat format(QVideoFrame::Format_RGB32);
|
||||||
QCameraViewfinderSettings settings;
|
QCameraViewfinderSettings settings;
|
||||||
QSize size(1920, 1080);
|
QSize size(1280, 720);
|
||||||
auto cameraRes = m_camera->supportedViewfinderResolutions(settings);
|
auto cameraRes = m_camera->supportedViewfinderResolutions(settings);
|
||||||
for (auto& cameraSize : cameraRes) {
|
for (auto& cameraSize : cameraRes) {
|
||||||
if (cameraSize.width() < m_image.w || cameraSize.height() < m_image.h) {
|
if (cameraSize.width() < m_image.w || cameraSize.height() < m_image.h) {
|
||||||
|
@ -741,10 +752,11 @@ void InputController::setupCam() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.setResolution(size);
|
settings.setResolution(size);
|
||||||
|
|
||||||
auto cameraFormats = m_camera->supportedViewfinderPixelFormats(settings);
|
auto cameraFormats = m_camera->supportedViewfinderPixelFormats(settings);
|
||||||
auto goodFormats = m_videoDumper.supportedPixelFormats();
|
auto goodFormats = m_videoDumper.supportedPixelFormats();
|
||||||
bool goodFormatFound = false;
|
bool goodFormatFound = false;
|
||||||
for (auto& goodFormat : goodFormats) {
|
for (const auto& goodFormat : goodFormats) {
|
||||||
if (cameraFormats.contains(goodFormat)) {
|
if (cameraFormats.contains(goodFormat)) {
|
||||||
settings.setPixelFormat(goodFormat);
|
settings.setPixelFormat(goodFormat);
|
||||||
format = goodFormat;
|
format = goodFormat;
|
||||||
|
@ -754,20 +766,20 @@ void InputController::setupCam() {
|
||||||
}
|
}
|
||||||
if (!goodFormatFound) {
|
if (!goodFormatFound) {
|
||||||
LOG(QT, WARN) << "Could not find a valid camera format!";
|
LOG(QT, WARN) << "Could not find a valid camera format!";
|
||||||
|
for (const auto& format : cameraFormats) {
|
||||||
|
LOG(QT, WARN) << "Camera supported format: " << QString::number(format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_camera->setViewfinderSettings(settings);
|
m_camera->setViewfinderSettings(settings);
|
||||||
#endif
|
#endif
|
||||||
m_camera->setCaptureMode(QCamera::CaptureVideo);
|
|
||||||
m_camera->setViewfinder(&m_videoDumper);
|
|
||||||
m_camera->start();
|
m_camera->start();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void InputController::teardownCam() {
|
void InputController::teardownCam() {
|
||||||
#ifdef BUILD_QT_MULTIMEDIA
|
#ifdef BUILD_QT_MULTIMEDIA
|
||||||
if (m_camera) {
|
if (m_camera) {
|
||||||
m_camera->stop();
|
m_camera->stop();
|
||||||
m_camera.reset();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,12 @@
|
||||||
|
|
||||||
#ifdef BUILD_QT_MULTIMEDIA
|
#ifdef BUILD_QT_MULTIMEDIA
|
||||||
#include "VideoDumper.h"
|
#include "VideoDumper.h"
|
||||||
|
#include <QCamera>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct mRotationSource;
|
struct mRotationSource;
|
||||||
struct mRumble;
|
struct mRumble;
|
||||||
|
|
||||||
class QCamera;
|
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
class ConfigController;
|
class ConfigController;
|
||||||
|
@ -124,6 +123,9 @@ public slots:
|
||||||
void setCamImage(const QImage& image);
|
void setCamImage(const QImage& image);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
#ifdef BUILD_QT_MULTIMEDIA
|
||||||
|
void prepareCamSettings(QCamera::Status);
|
||||||
|
#endif
|
||||||
void setupCam();
|
void setupCam();
|
||||||
void teardownCam();
|
void teardownCam();
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,18 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
||||||
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||||
bool swap = false;
|
bool swap = false;
|
||||||
if (format == QImage::Format_Invalid) {
|
if (format == QImage::Format_Invalid) {
|
||||||
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
if (vFormat < QVideoFrame::Format_BGRA5658_Premultiplied) {
|
||||||
format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
||||||
if (format == QImage::Format_ARGB32) {
|
format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||||
format = QImage::Format_RGBA8888;
|
if (format == QImage::Format_ARGB32) {
|
||||||
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
format = QImage::Format_RGBA8888;
|
||||||
format = QImage::Format_RGBA8888_Premultiplied;
|
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
||||||
|
format = QImage::Format_RGBA8888_Premultiplied;
|
||||||
|
}
|
||||||
|
swap = true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
swap = true;
|
|
||||||
}
|
}
|
||||||
uchar* bits = mappedFrame.bits();
|
uchar* bits = mappedFrame.bits();
|
||||||
QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
|
QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
|
||||||
|
|
Loading…
Reference in New Issue