[libcamera-devel] [PATCH/RFC 07/11] qcam: Replace explicit DRM FourCCs with libcamera formats

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu May 28 13:11:37 CEST 2020


Hi Kieran,

On Thu, May 28, 2020 at 11:07:21AM +0100, Kieran Bingham wrote:
> On 22/05/2020 15:54, Laurent Pinchart wrote:
> > Use the new pixel format constants to replace usage of macros from
> > drm_fourcc.h.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > ---
> >  src/qcam/dng_writer.cpp       | 17 +++++++++--------
> >  src/qcam/format_converter.cpp | 36 ++++++++++++++++++-----------------
> >  src/qcam/viewfinder.cpp       | 10 ++++++----
> >  3 files changed, 34 insertions(+), 29 deletions(-)
> > 
> > diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
> > index cbd8bed3e6d0..1aa2eaa9a501 100644
> > --- a/src/qcam/dng_writer.cpp
> > +++ b/src/qcam/dng_writer.cpp
> > @@ -14,6 +14,7 @@
> >  #include <tiffio.h>
> >  
> >  #include <libcamera/control_ids.h>
> > +#include <libcamera/formats.h>
> >  
> >  using namespace libcamera;
> >  
> > @@ -83,49 +84,49 @@ void thumbScanlineSBGGRxxP(const FormatInfo &info, void *output,
> >  }
> >  
> >  static const std::map<PixelFormat, FormatInfo> formatInfo = {
> > -	{ PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SBGGR10_CSI2P, {
> >  		.bitsPerSample = 10,
> >  		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> >  		.packScanline = packScanlineSBGGR10P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SGBRG10, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SGBRG10_CSI2P, {
> >  		.bitsPerSample = 10,
> >  		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> >  		.packScanline = packScanlineSBGGR10P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SGRBG10, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SGRBG10_CSI2P, {
> >  		.bitsPerSample = 10,
> >  		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> >  		.packScanline = packScanlineSBGGR10P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SRGGB10, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SRGGB10_CSI2P, {
> >  		.bitsPerSample = 10,
> >  		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> >  		.packScanline = packScanlineSBGGR10P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SBGGR12, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SBGGR12_CSI2P, {
> >  		.bitsPerSample = 12,
> >  		.pattern = { CFAPatternBlue, CFAPatternGreen, CFAPatternGreen, CFAPatternRed },
> >  		.packScanline = packScanlineSBGGR12P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SGBRG12, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SGBRG12_CSI2P, {
> >  		.bitsPerSample = 12,
> >  		.pattern = { CFAPatternGreen, CFAPatternBlue, CFAPatternRed, CFAPatternGreen },
> >  		.packScanline = packScanlineSBGGR12P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SGRBG12, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SGRBG12_CSI2P, {
> >  		.bitsPerSample = 12,
> >  		.pattern = { CFAPatternGreen, CFAPatternRed, CFAPatternBlue, CFAPatternGreen },
> >  		.packScanline = packScanlineSBGGR12P,
> >  		.thumbScanline = thumbScanlineSBGGRxxP,
> >  	} },
> > -	{ PixelFormat(DRM_FORMAT_SRGGB12, MIPI_FORMAT_MOD_CSI2_PACKED), {
> > +	{ formats::SRGGB12_CSI2P, {
> >  		.bitsPerSample = 12,
> >  		.pattern = { CFAPatternRed, CFAPatternGreen, CFAPatternGreen, CFAPatternBlue },
> >  		.packScanline = packScanlineSBGGR12P,
> > diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp
> > index bf887ad446eb..4b9722d4ecf7 100644
> > --- a/src/qcam/format_converter.cpp
> > +++ b/src/qcam/format_converter.cpp
> > @@ -11,6 +11,8 @@
> >  
> >  #include <QImage>
> >  
> > +#include <libcamera/formats.h>
> > +
> >  #define RGBSHIFT		8
> >  #ifndef MAX
> >  #define MAX(a,b)		((a)>(b)?(a):(b))
> > @@ -29,79 +31,79 @@ int FormatConverter::configure(const libcamera::PixelFormat &format,
> >  			       const QSize &size)
> >  {
> >  	switch (format) {
> > -	case DRM_FORMAT_NV12:
> > +	case libcamera::formats::NV12:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 2;
> >  		vertSubSample_ = 2;
> >  		nvSwap_ = false;
> >  		break;
> > -	case DRM_FORMAT_NV21:
> > +	case libcamera::formats::NV21:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 2;
> >  		vertSubSample_ = 2;
> >  		nvSwap_ = true;
> >  		break;
> > -	case DRM_FORMAT_NV16:
> > +	case libcamera::formats::NV16:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 2;
> >  		vertSubSample_ = 1;
> >  		nvSwap_ = false;
> >  		break;
> > -	case DRM_FORMAT_NV61:
> > +	case libcamera::formats::NV61:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 2;
> >  		vertSubSample_ = 1;
> >  		nvSwap_ = true;
> >  		break;
> > -	case DRM_FORMAT_NV24:
> > +	case libcamera::formats::NV24:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 1;
> >  		vertSubSample_ = 1;
> >  		nvSwap_ = false;
> >  		break;
> > -	case DRM_FORMAT_NV42:
> > +	case libcamera::formats::NV42:
> >  		formatFamily_ = NV;
> >  		horzSubSample_ = 1;
> >  		vertSubSample_ = 1;
> >  		nvSwap_ = true;
> >  		break;
> >  
> > -	case DRM_FORMAT_RGB888:
> > +	case libcamera::formats::RGB888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 2;
> >  		g_pos_ = 1;
> >  		b_pos_ = 0;
> >  		bpp_ = 3;
> >  		break;
> > -	case DRM_FORMAT_BGR888:
> > +	case libcamera::formats::BGR888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 0;
> >  		g_pos_ = 1;
> >  		b_pos_ = 2;
> >  		bpp_ = 3;
> >  		break;
> > -	case DRM_FORMAT_ARGB8888:
> > +	case libcamera::formats::ARGB8888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 2;
> >  		g_pos_ = 1;
> >  		b_pos_ = 0;
> >  		bpp_ = 4;
> >  		break;
> > -	case DRM_FORMAT_RGBA8888:
> > +	case libcamera::formats::RGBA8888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 3;
> >  		g_pos_ = 2;
> >  		b_pos_ = 1;
> >  		bpp_ = 4;
> >  		break;
> > -	case DRM_FORMAT_ABGR8888:
> > +	case libcamera::formats::ABGR8888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 0;
> >  		g_pos_ = 1;
> >  		b_pos_ = 2;
> >  		bpp_ = 4;
> >  		break;
> > -	case DRM_FORMAT_BGRA8888:
> > +	case libcamera::formats::BGRA8888:
> >  		formatFamily_ = RGB;
> >  		r_pos_ = 1;
> >  		g_pos_ = 2;
> > @@ -109,28 +111,28 @@ int FormatConverter::configure(const libcamera::PixelFormat &format,
> >  		bpp_ = 4;
> >  		break;
> >  
> > -	case DRM_FORMAT_VYUY:
> > +	case libcamera::formats::VYUY:
> >  		formatFamily_ = YUV;
> >  		y_pos_ = 1;
> >  		cb_pos_ = 2;
> >  		break;
> > -	case DRM_FORMAT_YVYU:
> > +	case libcamera::formats::YVYU:
> >  		formatFamily_ = YUV;
> >  		y_pos_ = 0;
> >  		cb_pos_ = 3;
> >  		break;
> > -	case DRM_FORMAT_UYVY:
> > +	case libcamera::formats::UYVY:
> >  		formatFamily_ = YUV;
> >  		y_pos_ = 1;
> >  		cb_pos_ = 0;
> >  		break;
> > -	case DRM_FORMAT_YUYV:
> > +	case libcamera::formats::YUYV:
> >  		formatFamily_ = YUV;
> >  		y_pos_ = 0;
> >  		cb_pos_ = 1;
> >  		break;
> >  
> > -	case DRM_FORMAT_MJPEG:
> > +	case libcamera::formats::MJPEG:
> >  		formatFamily_ = MJPEG;
> >  		break;
> >  
> > diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
> > index 0d68f62ee6d7..ac83d7e6c397 100644
> > --- a/src/qcam/viewfinder.cpp
> > +++ b/src/qcam/viewfinder.cpp
> > @@ -17,18 +17,20 @@
> >  #include <QPainter>
> >  #include <QtDebug>
> >  
> > +#include <libcamera/formats.h>
> > +
> >  #include "format_converter.h"
> >  
> >  static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats
> >  {
> >  #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
> > -	{ libcamera::PixelFormat{ DRM_FORMAT_ABGR8888 }, QImage::Format_RGBA8888 },
> > +	{ libcamera::formats::ABGR8888, QImage::Format_RGBA8888 },
> >  #endif
> > -	{ libcamera::PixelFormat{ DRM_FORMAT_ARGB8888 }, QImage::Format_RGB32 },
> > +	{ libcamera::formats::ARGB8888, QImage::Format_RGB32 },
> >  #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
> > -	{ libcamera::PixelFormat{ DRM_FORMAT_BGR888 }, QImage::Format_BGR888 },
> > +	{ libcamera::formats::BGR888, QImage::Format_BGR888 },
> >  #endif
> > -	{ libcamera::PixelFormat{ DRM_FORMAT_RGB888 }, QImage::Format_RGB888 },
> > +	{ libcamera::formats::RGB888, QImage::Format_RGB888 },
> 
> Excepting the format swap necessary on BGR888/RGB888 in regards to the
> QImage formats, which has been identified after you created this patch:

I'll rebase this on top of the fix you've submitted, once you merge it.

> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> 
> >  };
> >  
> >  ViewFinder::ViewFinder(QWidget *parent)

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list