cellCamera: support all formats and set RGB32 if possible

This commit is contained in:
Megamouse 2021-10-22 00:48:31 +02:00
parent d161d8c545
commit 60d35e17ac
2 changed files with 64 additions and 20 deletions

View File

@ -306,7 +306,7 @@ void qt_camera_handler::update_camera_settings()
const QList<QSize> resolutions = m_camera->supportedViewfinderResolutions(settings); const QList<QSize> resolutions = m_camera->supportedViewfinderResolutions(settings);
if (resolutions.isEmpty()) 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<int>(settings.pixelFormat())); settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
} }
for (const QSize& resolution : resolutions) for (const QSize& resolution : resolutions)
@ -322,7 +322,7 @@ void qt_camera_handler::update_camera_settings()
const QList<QCamera::FrameRateRange> frame_rate_ranges = m_camera->supportedViewfinderFrameRateRanges(settings); const QList<QCamera::FrameRateRange> frame_rate_ranges = m_camera->supportedViewfinderFrameRateRanges(settings);
if (frame_rate_ranges.isEmpty()) 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<int>(settings.pixelFormat())); settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
} }
for (const QCamera::FrameRateRange& frame_rate : frame_rate_ranges) for (const QCamera::FrameRateRange& frame_rate : frame_rate_ranges)
@ -341,23 +341,31 @@ void qt_camera_handler::update_camera_settings()
const QList<QVideoFrame::PixelFormat> pixel_formats = m_camera->supportedViewfinderPixelFormats(settings); const QList<QVideoFrame::PixelFormat> pixel_formats = m_camera->supportedViewfinderPixelFormats(settings);
if (pixel_formats.isEmpty()) 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<int>(settings.pixelFormat())); settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
} }
//for (const QVideoFrame::PixelFormat& pixel_format : pixel_formats) for (const QVideoFrame::PixelFormat& pixel_format : pixel_formats)
//{ {
// if (pixel_format matches m_format) if (pixel_format == QVideoFrame::Format_RGB32)
// { {
// settings.setPixelFormat(pixel_format); settings.setPixelFormat(pixel_format);
// break; break;
// } }
//} }
camera_log.notice("Setting view finder settings: frame_rate=%f, width=%d, height=%d, pixel_format=%d", if (m_camera->supportedViewfinderSettings(settings).isEmpty())
settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat())); {
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<int>(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<int>(settings.pixelFormat()));
// Apply settings. // Apply settings.
m_camera->setViewfinderSettings(settings); m_camera->setViewfinderSettings(settings);
}
} }
// Update video surface if possible // Update video surface if possible

View File

@ -32,11 +32,43 @@ QList<QVideoFrame::PixelFormat> qt_camera_video_surface::supportedPixelFormats(Q
{ {
Q_UNUSED(type) Q_UNUSED(type)
// Let's only allow RGB formats for now // Support all cameras
QList<QVideoFrame::PixelFormat> result; QList<QVideoFrame::PixelFormat> result;
result result
<< QVideoFrame::Format_ARGB32
<< QVideoFrame::Format_ARGB32_Premultiplied
<< QVideoFrame::Format_RGB32 << 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; return result;
} }
@ -56,10 +88,14 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
return false; return false;
} }
// Create shallow copy // Get image. This usually also converts the image to ARGB32.
QImage image(tmp.bits(), tmp.width(), tmp.height(), tmp.bytesPerLine(), QVideoFrame::imageFormatFromPixelFormat(tmp.pixelFormat())); QImage image = frame.image();
if (!image.isNull()) if (image.isNull())
{
camera_log.warning("Image is invalid: pixel_format=%d, format=%d", static_cast<int>(tmp.pixelFormat()), static_cast<int>(QVideoFrame::imageFormatFromPixelFormat(tmp.pixelFormat())));
}
else
{ {
// Scale image if necessary // Scale image if necessary
if (m_width > 0 && m_height > 0 && m_width != image.width() && m_height != image.height()) if (m_width > 0 && m_height > 0 && m_width != image.width() && m_height != image.height())