mirror of https://github.com/mgba-emu/mgba.git
Qt: Improve QCamera support for 5.5+
This commit is contained in:
parent
cf15ea91d7
commit
ce9439031f
|
@ -84,9 +84,9 @@ struct mRTCSource {
|
|||
};
|
||||
|
||||
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 {
|
||||
|
|
|
@ -244,7 +244,7 @@ void GBMBCInit(struct GB* gb) {
|
|||
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 @@ void _GBPocketCamCapture(struct GBMemory* memory) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -87,16 +87,42 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
|
|||
#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 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
|
|||
#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();
|
||||
|
|
|
@ -138,6 +138,7 @@ private:
|
|||
InputController* p;
|
||||
QImage image;
|
||||
QImage resizedImage;
|
||||
unsigned w, h;
|
||||
} m_image;
|
||||
|
||||
#ifdef BUILD_QT_MULTIMEDIA
|
||||
|
|
|
@ -31,10 +31,10 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
|||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue