diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index 9dbbb3aff..36afa1841 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -9,6 +9,7 @@ #include "GamepadAxisEvent.h" #include "GamepadButtonEvent.h" #include "InputProfile.h" +#include "LogController.h" #include #include @@ -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); diff --git a/src/platform/qt/VideoDumper.cpp b/src/platform/qt/VideoDumper.cpp index 373678ac6..ae4695a5a 100644 --- a/src/platform/qt/VideoDumper.cpp +++ b/src/platform/qt/VideoDumper.cpp @@ -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(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 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; }