Qt: Improve QCamera support for 5.5+
Vicki Pfau vi@endrift.com
Wed, 26 Jul 2017 14:40:06 -0700
5 files changed,
39 insertions(+),
13 deletions(-)
M
include/mgba/core/interface.h
→
include/mgba/core/interface.h
@@ -84,9 +84,9 @@ bool (*deserialize)(struct mRTCSource*, const struct mStateExtdataItem*);
}; struct mImageSource { - void (*startRequestImage)(struct mImageSource*); + void (*startRequestImage)(struct mImageSource*, unsigned w, unsigned h); void (*stopRequestImage)(struct mImageSource*); - void (*requestImage)(struct mImageSource*, unsigned w, unsigned h, const uint32_t** buffer, size_t* stride); + void (*requestImage)(struct mImageSource*, const uint32_t** buffer, size_t* stride); }; enum mRTCGenericType {
M
src/gb/mbc.c
→
src/gb/mbc.c
@@ -244,7 +244,7 @@ case GB_POCKETCAM:
gb->memory.mbcWrite = _GBPocketCam; gb->memory.mbcRead = _GBPocketCamRead; if (gb->memory.cam && gb->memory.cam->startRequestImage) { - gb->memory.cam->startRequestImage(gb->memory.cam); + gb->memory.cam->startRequestImage(gb->memory.cam, GBCAM_WIDTH, GBCAM_HEIGHT); } break; }@@ -793,7 +793,7 @@ return;
} const uint32_t* image = NULL; size_t stride; - memory->cam->requestImage(memory->cam, GBCAM_WIDTH, GBCAM_HEIGHT, &image, &stride); + memory->cam->requestImage(memory->cam, &image, &stride); if (!image) { return; }
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -87,16 +87,42 @@ setLuminanceLevel(0);
#endif m_image.p = this; - m_image.startRequestImage = [](mImageSource* context) { + m_image.startRequestImage = [](mImageSource* context, unsigned w, unsigned h) { InputControllerImage* image = static_cast<InputControllerImage*>(context); + image->w = w; + image->h = h; if (image->image.isNull()) { image->image.load(":/res/no-cam.png"); } + image->resizedImage = image->image.scaled(w, h, Qt::KeepAspectRatioByExpanding); #ifdef BUILD_QT_MULTIMEDIA if (image->p->m_config->getQtOption("cameraDriver").toInt() == static_cast<int>(CameraDriver::QT_MULTIMEDIA)) { if (!image->p->m_camera) { image->p->m_camera = new QCamera; } +#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) + QCameraViewfinderSettings settings; + QSize size(1920, 1080); + auto cameraRes = image->p->m_camera->supportedViewfinderResolutions(settings); + for (auto& cameraSize : cameraRes) { + if (cameraSize.width() < w || cameraSize.height() < h) { + continue; + } + if (cameraSize.width() <= size.width() && cameraSize.height() <= size.height()) { + size = cameraSize; + } + } + settings.setResolution(size); + auto cameraFormats = image->p->m_camera->supportedViewfinderPixelFormats(settings); + auto goodFormats = image->p->m_videoDumper.supportedPixelFormats(); + for (auto& format : goodFormats) { + if (cameraFormats.contains(format)) { + settings.setPixelFormat(format); + break; + } + } + image->p->m_camera->setViewfinderSettings(settings); +#endif image->p->m_camera->setViewfinder(&image->p->m_videoDumper); image->p->m_camera->start(); }@@ -113,17 +139,16 @@ }
#endif }; - m_image.requestImage = [](mImageSource* context, unsigned w, unsigned h, const uint32_t** buffer, size_t* stride) { + m_image.requestImage = [](mImageSource* context, const uint32_t** buffer, size_t* stride) { InputControllerImage* image = static_cast<InputControllerImage*>(context); - image->resizedImage = image->image.scaled(w, h, Qt::KeepAspectRatioByExpanding); image->resizedImage = image->resizedImage.convertToFormat(QImage::Format_RGB32); const uint32_t* bits = reinterpret_cast<const uint32_t*>(image->resizedImage.constBits()); QSize size = image->resizedImage.size(); - if (size.width() > w) { - bits += (size.width() - w) / 2; + if (size.width() > image->w) { + bits += (size.width() - image->w) / 2; } - if (size.height() > h) { - bits += ((size.height() - h) / 2) * size.width(); + if (size.height() > image->h) { + bits += ((size.height() - image->h) / 2) * size.width(); } *buffer = bits; *stride = size.width();
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -138,6 +138,7 @@ struct InputControllerImage : mImageSource {
InputController* p; QImage image; QImage resizedImage; + unsigned w, h; } m_image; #ifdef BUILD_QT_MULTIMEDIA
M
src/platform/qt/VideoDumper.cpp
→
src/platform/qt/VideoDumper.cpp
@@ -31,10 +31,10 @@ }
QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const { QList<QVideoFrame::PixelFormat> list; - list.append(QVideoFrame::Format_ARGB32); - list.append(QVideoFrame::Format_ARGB32_Premultiplied); list.append(QVideoFrame::Format_RGB32); + list.append(QVideoFrame::Format_ARGB32); list.append(QVideoFrame::Format_RGB24); + list.append(QVideoFrame::Format_ARGB32_Premultiplied); list.append(QVideoFrame::Format_RGB565); list.append(QVideoFrame::Format_RGB555); return list;