cellCamera: add some more logging and fix some warnings

This commit is contained in:
Megamouse 2021-10-21 03:28:01 +02:00
parent f66b29f043
commit d161d8c545
2 changed files with 33 additions and 15 deletions

View File

@ -303,7 +303,13 @@ void qt_camera_handler::update_camera_settings()
QCameraViewfinderSettings settings;
// Set resolution if possible.
for (const QSize& resolution : m_camera->supportedViewfinderResolutions(settings))
const QList<QSize> 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",
settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
}
for (const QSize& resolution : resolutions)
{
if (m_width == resolution.width() && m_height == resolution.height())
{
@ -313,7 +319,13 @@ void qt_camera_handler::update_camera_settings()
}
// Set frame rate if possible.
for (const QCamera::FrameRateRange& frame_rate : m_camera->supportedViewfinderFrameRateRanges(settings))
const QList<QCamera::FrameRateRange> 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",
settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
}
for (const QCamera::FrameRateRange& frame_rate : frame_rate_ranges)
{
// Some cameras do not have an exact match, so let's approximate.
if (static_cast<qreal>(m_frame_rate) >= (frame_rate.maximumFrameRate - 0.5) && static_cast<qreal>(m_frame_rate) <= (frame_rate.maximumFrameRate + 0.5))
@ -326,7 +338,13 @@ void qt_camera_handler::update_camera_settings()
}
// Set pixel format if possible. (Unused for now, because formats differ between Qt and cell)
//for (const QVideoFrame::PixelFormat& pixel_format : m_camera->supportedViewfinderPixelFormats(settings))
const QList<QVideoFrame::PixelFormat> 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",
settings.maximumFrameRate(), settings.resolution().width(), settings.resolution().height(), static_cast<int>(settings.pixelFormat()));
}
//for (const QVideoFrame::PixelFormat& pixel_format : pixel_formats)
//{
// if (pixel_format matches m_format)
// {

View File

@ -131,11 +131,11 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
case CELL_CAMERA_RAW8: // The game seems to expect BGGR
{
// Let's use a very simple algorithm to convert the image to raw BGGR
const auto convert_to_bggr = [&image_buffer, &image](int y_begin, int y_end)
const auto convert_to_bggr = [&image_buffer, &image](u32 y_begin, u32 y_end)
{
for (int y = y_begin; y < std::min<int>(image_buffer.height, image.height()) && y < y_end; y++)
for (u32 y = y_begin; y < std::min<u32>(image_buffer.height, image.height()) && y < y_end; y++)
{
for (int x = 0; x < std::min<int>(image_buffer.width, image.width()); x++)
for (u32 x = 0; x < std::min<u32>(image_buffer.width, image.width()); x++)
{
u8& pixel = image_buffer.data[image_buffer.width * y + x];
const bool is_left_pixel = (x % 2) == 0;
@ -159,9 +159,9 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
// Use a multithreaded workload. The faster we get this done, the better.
constexpr u32 thread_count = 4;
const int lines_per_thread = std::ceil(image_buffer.height / static_cast<double>(thread_count));
int y_begin = 0;
int y_end = lines_per_thread;
const u32 lines_per_thread = std::ceil(image_buffer.height / static_cast<double>(thread_count));
u32 y_begin = 0;
u32 y_end = lines_per_thread;
QFutureSynchronizer<void> synchronizer;
for (u32 i = 0; i < thread_count; i++)
@ -178,7 +178,7 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
case CELL_CAMERA_V_Y1_U_Y0:
{
// Simple RGB to Y0_U_Y1_V conversion from stackoverflow.
const auto convert_to_yuv422 = [&image_buffer, &image, format = m_format](int y_begin, int y_end)
const auto convert_to_yuv422 = [&image_buffer, &image, format = m_format](u32 y_begin, u32 y_end)
{
constexpr int yuv_bytes_per_pixel = 2;
const int yuv_pitch = image_buffer.width * yuv_bytes_per_pixel;
@ -188,11 +188,11 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
const int y1_offset = (format == CELL_CAMERA_Y0_U_Y1_V) ? 2 : 1;
const int v_offset = (format == CELL_CAMERA_Y0_U_Y1_V) ? 3 : 0;
for (u32 y = y_begin; y < std::min<int>(image_buffer.height, image.height()) && y < y_end; y++)
for (u32 y = y_begin; y < std::min<u32>(image_buffer.height, image.height()) && y < y_end; y++)
{
uint8_t* yuv_row_ptr = &image_buffer.data[y * yuv_pitch];
for (u32 x = 0; x < std::min<int>(image_buffer.width, image.width()) - 1; x += 2)
for (u32 x = 0; x < std::min<u32>(image_buffer.width, image.width()) - 1; x += 2)
{
const QRgb pixel_1 = image.pixel(x, y);
const QRgb pixel_2 = image.pixel(x + 1, y);
@ -220,9 +220,9 @@ bool qt_camera_video_surface::present(const QVideoFrame& frame)
// Use a multithreaded workload. The faster we get this done, the better.
constexpr u32 thread_count = 4;
const int lines_per_thread = std::ceil(image_buffer.height / static_cast<double>(thread_count));
int y_begin = 0;
int y_end = lines_per_thread;
const u32 lines_per_thread = std::ceil(image_buffer.height / static_cast<double>(thread_count));
u32 y_begin = 0;
u32 y_end = lines_per_thread;
QFutureSynchronizer<void> synchronizer;
for (u32 i = 0; i < thread_count; i++)