From 62879c44840f66a9854ab3938412b97828154d7f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 2 Oct 2022 19:43:57 +0200 Subject: [PATCH] add support for UYVY format (FaceTime camera) --- src/frontend/qt_sdl/CameraManager.cpp | 32 +++++++++++++++++++++++++++ src/frontend/qt_sdl/CameraManager.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/frontend/qt_sdl/CameraManager.cpp b/src/frontend/qt_sdl/CameraManager.cpp index d2cb1e58..19cf8d4d 100644 --- a/src/frontend/qt_sdl/CameraManager.cpp +++ b/src/frontend/qt_sdl/CameraManager.cpp @@ -47,6 +47,10 @@ void CameraFrameDumper::present(const QVideoFrame& _frame) cam->feedFrame((u32*)frame.bits(0), frame.width(), frame.height(), frame.pixelFormat() == QVideoFrameFormat::Format_YUYV); break; + case QVideoFrameFormat::Format_UYVY: + cam->feedFrame_UYVY((u32*)frame.bits(0), frame.width(), frame.height()); + break; + case QVideoFrameFormat::Format_NV12: cam->feedFrame_NV12((u8*)frame.bits(0), (u8*)frame.bits(1), frame.width(), frame.height()); break; @@ -80,6 +84,10 @@ bool CameraFrameDumper::present(const QVideoFrame& _frame) cam->feedFrame((u32*)frame.bits(0), frame.width(), frame.height(), frame.pixelFormat() == QVideoFrame::Format_YUYV); break; + case QVideoFrame::Format_UYVY: + cam->feedFrame_UYVY((u32*)frame.bits(0), frame.width(), frame.height()); + break; + case QVideoFrame::Format_NV12: cam->feedFrame_NV12((u8*)frame.bits(0), (u8*)frame.bits(1), frame.width(), frame.height()); break; @@ -96,6 +104,7 @@ QList CameraFrameDumper::supportedPixelFormats(QAbstra ret.append(QVideoFrame::Format_RGB32); ret.append(QVideoFrame::Format_YUYV); + ret.append(QVideoFrame::Format_UYVY); ret.append(QVideoFrame::Format_NV12); return ret; @@ -209,6 +218,7 @@ void CameraManager::init() for (const QCameraFormat& item : supported) { if (item.pixelFormat() != QVideoFrameFormat::Format_YUYV && + item.pixelFormat() != QVideoFrameFormat::Format_UYVY && item.pixelFormat() != QVideoFrameFormat::Format_NV12 && item.pixelFormat() != QVideoFrameFormat::Format_XRGB8888) continue; @@ -252,6 +262,7 @@ void CameraManager::init() for (const QCameraViewfinderSettings& item : supported) { if (item.pixelFormat() != QVideoFrame::Format_YUYV && + item.pixelFormat() != QVideoFrame::Format_UYVY && item.pixelFormat() != QVideoFrame::Format_NV12 && item.pixelFormat() != QVideoFrame::Format_RGB32) continue; @@ -417,6 +428,27 @@ void CameraManager::feedFrame(u32* frame, int width, int height, bool yuv) frameMutex.unlock(); } +void CameraManager::feedFrame_UYVY(u32* frame, int width, int height) +{ + for (int y = 0; y < frameHeight; y++) + { + int sy = (y * height) / frameHeight; + + for (int x = 0; x < frameWidth; x+=2) + { + int sx = (x * width) / frameWidth; + + u32 val = frame[((sy*width) + sx) >> 1]; + + val = ((val & 0xFF00FF00) >> 8) | ((val & 0x00FF00FF) << 8); + + tempFrameBuffer[((y*frameWidth) + x) >> 1] = val; + } + } + + feedFrame(tempFrameBuffer, frameWidth, frameHeight, true); +} + void CameraManager::feedFrame_NV12(u8* planeY, u8* planeUV, int width, int height) { for (int y = 0; y < frameHeight; y++) diff --git a/src/frontend/qt_sdl/CameraManager.h b/src/frontend/qt_sdl/CameraManager.h index 36e8565d..6743d19e 100644 --- a/src/frontend/qt_sdl/CameraManager.h +++ b/src/frontend/qt_sdl/CameraManager.h @@ -92,6 +92,7 @@ public: void captureFrame(u32* frame, int width, int height, bool yuv); void feedFrame(u32* frame, int width, int height, bool yuv); + void feedFrame_UYVY(u32* frame, int width, int height); void feedFrame_NV12(u8* planeY, u8* planeUV, int width, int height); signals: