all repos — mgba @ 6ca3e9940dabc7e52697f177566f65626599396d

mGBA Game Boy Advance Emulator

Qt: Improve camera compatibility
Vicki Pfau vi@endrift.com
Fri, 28 Jul 2017 17:45:18 -0700
commit

6ca3e9940dabc7e52697f177566f65626599396d

parent

d1db97cf0c5a5861446aae0d88d934bcd4441b04

2 files changed, 30 insertions(+), 2 deletions(-)

jump to
M src/platform/qt/InputController.cppsrc/platform/qt/InputController.cpp

@@ -9,6 +9,7 @@ #include "ConfigController.h"

#include "GamepadAxisEvent.h" #include "GamepadButtonEvent.h" #include "InputProfile.h" +#include "LogController.h" #include <QApplication> #include <QTimer>

@@ -742,12 +743,17 @@ }

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 src/platform/qt/VideoDumper.cppsrc/platform/qt/VideoDumper.cpp

@@ -19,10 +19,26 @@ QVideoFrame mappedFrame(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 @@ list.append(QVideoFrame::Format_RGB24);

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; }