mirror of https://github.com/mgba-emu/mgba.git
Qt: Improve camera compatibility
This commit is contained in:
parent
d1db97cf0c
commit
6ca3e9940d
|
@ -9,6 +9,7 @@
|
|||
#include "GamepadAxisEvent.h"
|
||||
#include "GamepadButtonEvent.h"
|
||||
#include "InputProfile.h"
|
||||
#include "LogController.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
|
@ -742,13 +743,18 @@ void InputController::setupCam() {
|
|||
settings.setResolution(size);
|
||||
auto cameraFormats = m_camera->supportedViewfinderPixelFormats(settings);
|
||||
auto goodFormats = m_videoDumper.supportedPixelFormats();
|
||||
bool goodFormatFound = false;
|
||||
for (auto& goodFormat : goodFormats) {
|
||||
if (cameraFormats.contains(goodFormat)) {
|
||||
settings.setPixelFormat(goodFormat);
|
||||
format = goodFormat;
|
||||
goodFormatFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!goodFormatFound) {
|
||||
LOG(QT, WARN) << "Could not find a valid camera format!";
|
||||
}
|
||||
m_camera->setViewfinderSettings(settings);
|
||||
#endif
|
||||
m_camera->setCaptureMode(QCamera::CaptureVideo);
|
||||
|
|
|
@ -19,10 +19,26 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
|||
if (!mappedFrame.map(QAbstractVideoBuffer::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(mappedFrame.pixelFormat());
|
||||
QVideoFrame::PixelFormat vFormat = mappedFrame.pixelFormat();
|
||||
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||
bool swap = false;
|
||||
if (format == QImage::Format_Invalid) {
|
||||
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
||||
format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||
if (format == QImage::Format_ARGB32) {
|
||||
format = QImage::Format_RGBA8888;
|
||||
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
||||
format = QImage::Format_RGBA8888_Premultiplied;
|
||||
}
|
||||
swap = true;
|
||||
}
|
||||
uchar* bits = mappedFrame.bits();
|
||||
QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
|
||||
image = image.copy(); // Create a deep copy of the bits
|
||||
if (swap) {
|
||||
image = image.rgbSwapped();
|
||||
} else {
|
||||
image = image.copy(); // Create a deep copy of the bits
|
||||
}
|
||||
mappedFrame.unmap();
|
||||
emit imageAvailable(image);
|
||||
return true;
|
||||
|
@ -36,5 +52,11 @@ QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVide
|
|||
list.append(QVideoFrame::Format_ARGB32_Premultiplied);
|
||||
list.append(QVideoFrame::Format_RGB565);
|
||||
list.append(QVideoFrame::Format_RGB555);
|
||||
list.append(QVideoFrame::Format_BGR32);
|
||||
list.append(QVideoFrame::Format_BGRA32);
|
||||
list.append(QVideoFrame::Format_BGR24);
|
||||
list.append(QVideoFrame::Format_BGRA32_Premultiplied);
|
||||
list.append(QVideoFrame::Format_BGR565);
|
||||
list.append(QVideoFrame::Format_BGR555);
|
||||
return list;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue