From 60d35e17acd06ba16443769d783cee77559d88df Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 22 Oct 2021 00:48:31 +0200 Subject: [PATCH] cellCamera: support all formats and set RGB32 if possible --- rpcs3/rpcs3qt/qt_camera_handler.cpp | 38 +++++++++++-------- rpcs3/rpcs3qt/qt_camera_video_surface.cpp | 46 ++++++++++++++++++++--- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/rpcs3/rpcs3qt/qt_camera_handler.cpp b/rpcs3/rpcs3qt/qt_camera_handler.cpp index ae84fa2817..8f65bf5176 100644 --- a/rpcs3/rpcs3qt/qt_camera_handler.cpp +++ b/rpcs3/rpcs3qt/qt_camera_handler.cpp @@ -306,7 +306,7 @@ void qt_camera_handler::update_camera_settings() const QList resolutions = m_camera->supportedViewfinderResolutions(settings); if (resolutions.isEmpty()) { - camera_log.error("No resolution available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", + camera_log.warning("No resolution available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); } for (const QSize& resolution : resolutions) @@ -322,7 +322,7 @@ void qt_camera_handler::update_camera_settings() const QList frame_rate_ranges = m_camera->supportedViewfinderFrameRateRanges(settings); if (frame_rate_ranges.isEmpty()) { - camera_log.error("No frame rate available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", + camera_log.warning("No frame rate available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); } for (const QCamera::FrameRateRange& frame_rate : frame_rate_ranges) @@ -341,23 +341,31 @@ void qt_camera_handler::update_camera_settings() const QList pixel_formats = m_camera->supportedViewfinderPixelFormats(settings); if (pixel_formats.isEmpty()) { - camera_log.error("No pixel format available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", + camera_log.warning("No pixel format available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); } - //for (const QVideoFrame::PixelFormat& pixel_format : pixel_formats) - //{ - // if (pixel_format matches m_format) - // { - // settings.setPixelFormat(pixel_format); - // break; - // } - //} + for (const QVideoFrame::PixelFormat& pixel_format : pixel_formats) + { + if (pixel_format == QVideoFrame::Format_RGB32) + { + settings.setPixelFormat(pixel_format); + break; + } + } - camera_log.notice("Setting view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", - settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); + if (m_camera->supportedViewfinderSettings(settings).isEmpty()) + { + camera_log.warning("No camera setting available for the view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", + settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); + } + else + { + camera_log.notice("Setting view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", + settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast(settings.pixelFormat())); - // Apply settings. - m_camera->setViewfinderSettings(settings); + // Apply settings. + m_camera->setViewfinderSettings(settings); + } } // Update video surface if possible diff --git a/rpcs3/rpcs3qt/qt_camera_video_surface.cpp b/rpcs3/rpcs3qt/qt_camera_video_surface.cpp index f19d5ddab2..8e82741d2e 100644 --- a/rpcs3/rpcs3qt/qt_camera_video_surface.cpp +++ b/rpcs3/rpcs3qt/qt_camera_video_surface.cpp @@ -32,11 +32,43 @@ QList qt_camera_video_surface::supportedPixelFormats(Q { Q_UNUSED(type) - // Let's only allow RGB formats for now + // Support all cameras QList result; result + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_RGB24; + << QVideoFrame::Format_RGB24 + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_RGB555 + << QVideoFrame::Format_ARGB8565_Premultiplied + << QVideoFrame::Format_BGRA32 + << QVideoFrame::Format_BGRA32_Premultiplied + << QVideoFrame::Format_BGR32 + << QVideoFrame::Format_BGR24 + << QVideoFrame::Format_BGR565 + << QVideoFrame::Format_BGR555 + << QVideoFrame::Format_BGRA5658_Premultiplied + << QVideoFrame::Format_AYUV444 + << QVideoFrame::Format_AYUV444_Premultiplied + << QVideoFrame::Format_YUV444 + << QVideoFrame::Format_YUV420P + << QVideoFrame::Format_YV12 + << QVideoFrame::Format_UYVY + << QVideoFrame::Format_YUYV + << QVideoFrame::Format_NV12 + << QVideoFrame::Format_NV21 + << QVideoFrame::Format_IMC1 + << QVideoFrame::Format_IMC2 + << QVideoFrame::Format_IMC3 + << QVideoFrame::Format_IMC4 + << QVideoFrame::Format_Y8 + << QVideoFrame::Format_Y16 + << QVideoFrame::Format_Jpeg + << QVideoFrame::Format_CameraRaw + << QVideoFrame::Format_AdobeDng + << QVideoFrame::Format_ABGR32 + << QVideoFrame::Format_YUV422P; return result; } @@ -56,10 +88,14 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame) return false; } - // Create shallow copy - QImage image(tmp.bits(), tmp.width(), tmp.height(), tmp.bytesPerLine(), QVideoFrame::imageFormatFromPixelFormat(tmp.pixelFormat())); + // Get image. This usually also converts the image to ARGB32. + QImage image = frame.image(); - if (!image.isNull()) + if (image.isNull()) + { + camera_log.warning("Image is invalid: pixel_format=%d, format=%d", static_cast(tmp.pixelFormat()), static_cast(QVideoFrame::imageFormatFromPixelFormat(tmp.pixelFormat()))); + } + else { // Scale image if necessary if (m_width > 0 && m_height > 0 && m_width != image.width() && m_height != image.height())