From f041cdf09509c99686eb819f76c5dd81e7d57d74 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 26 Nov 2020 18:43:42 +0100 Subject: [PATCH] pipewire: Support BGRA It's not supported by QImage, so we need to do it ourselves by swapping the B and the R. --- framebuffers/pipewire/pw_framebuffer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framebuffers/pipewire/pw_framebuffer.cpp b/framebuffers/pipewire/pw_framebuffer.cpp index d909a631..5be74cc5 100644 --- a/framebuffers/pipewire/pw_framebuffer.cpp +++ b/framebuffers/pipewire/pw_framebuffer.cpp @@ -777,7 +777,14 @@ void PWFrameBuffer::Private::handleFrame(pw_buffer *pwBuffer) cleanup(); #if PW_CHECK_VERSION(0, 2, 90) - if (videoFormat->format != SPA_VIDEO_FORMAT_RGB) { + if (videoFormat->format == SPA_VIDEO_FORMAT_BGRA || videoFormat->format == SPA_VIDEO_FORMAT_BGRx) { + for (uint y = 0; y < videoFormat->size.height; y++) { + for (uint x = 0; x < videoFormat->size.width; x++) { + uint offset = y * spaBuffer->datas->chunk->stride + x * 4; + std::swap(q->fb[offset], q->fb[offset + 2]); + } + } + } else if (videoFormat->format != SPA_VIDEO_FORMAT_RGB) { const QImage::Format format = videoFormat->format == SPA_VIDEO_FORMAT_BGR ? QImage::Format_BGR888 : videoFormat->format == SPA_VIDEO_FORMAT_RGBx ? QImage::Format_RGBX8888 : QImage::Format_RGB32;