[libcamera-devel] qcam: viewfinder: Use correct DRM/QImage mappings

Message ID 20200526160644.154051-1-kieran.bingham@ideasonboard.com
State Accepted
Commit 16c5f44c690a1d7d31b2e150d6e916cc6a999119
Headers show
Series
  • [libcamera-devel] qcam: viewfinder: Use correct DRM/QImage mappings
Related show

Commit Message

Kieran Bingham May 26, 2020, 4:06 p.m. UTC
When the native pixel formats supported by QT were introduced, the
RGB/BGR formats were inverted.

Swap the BGR888 and RGB888 mappings accordingly.

Fixes: f890a57b7a06 ("qcam: viewfinder: Add support for more native formats")
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/qcam/viewfinder.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart May 26, 2020, 10:02 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Tue, May 26, 2020 at 05:06:44PM +0100, Kieran Bingham wrote:
> When the native pixel formats supported by QT were introduced, the

s/QT/Qt/

> RGB/BGR formats were inverted.

The Qt documentation isn't very clear, so let's make sure.

~/src/test/qt $ cat qimage.cpp
#include <QDebug>
#include <QImage>

int main()
{
        QImage image{ 640, 480, QImage::Format_RGB888 };
        image.fill(Qt::red);
        uchar *bits = image.bits();
        qInfo() << "(" << bits[0] << "," << bits[1] << "," << bits[2] << ")";
        return 0;
}

~/src/test/qt $ ./qimage
( 255 , 0 , 0 )

That's indeed DRM_FORMAT_BGR888, at least on little-endian machines.

> Swap the BGR888 and RGB888 mappings accordingly.
> 
> Fixes: f890a57b7a06 ("qcam: viewfinder: Add support for more native formats")
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/qcam/viewfinder.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
> index 0d68f62ee6d7..7a308f53f576 100644
> --- a/src/qcam/viewfinder.cpp
> +++ b/src/qcam/viewfinder.cpp
> @@ -26,9 +26,9 @@ static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats
>  #endif
>  	{ libcamera::PixelFormat{ DRM_FORMAT_ARGB8888 }, QImage::Format_RGB32 },
>  #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
> -	{ libcamera::PixelFormat{ DRM_FORMAT_BGR888 }, QImage::Format_BGR888 },
> +	{ libcamera::PixelFormat{ DRM_FORMAT_RGB888 }, QImage::Format_BGR888 },
>  #endif
> -	{ libcamera::PixelFormat{ DRM_FORMAT_RGB888 }, QImage::Format_RGB888 },
> +	{ libcamera::PixelFormat{ DRM_FORMAT_BGR888 }, QImage::Format_RGB888 },
>  };
>  
>  ViewFinder::ViewFinder(QWidget *parent)

Patch

diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
index 0d68f62ee6d7..7a308f53f576 100644
--- a/src/qcam/viewfinder.cpp
+++ b/src/qcam/viewfinder.cpp
@@ -26,9 +26,9 @@  static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats
 #endif
 	{ libcamera::PixelFormat{ DRM_FORMAT_ARGB8888 }, QImage::Format_RGB32 },
 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
-	{ libcamera::PixelFormat{ DRM_FORMAT_BGR888 }, QImage::Format_BGR888 },
+	{ libcamera::PixelFormat{ DRM_FORMAT_RGB888 }, QImage::Format_BGR888 },
 #endif
-	{ libcamera::PixelFormat{ DRM_FORMAT_RGB888 }, QImage::Format_RGB888 },
+	{ libcamera::PixelFormat{ DRM_FORMAT_BGR888 }, QImage::Format_RGB888 },
 };
 
 ViewFinder::ViewFinder(QWidget *parent)