[libcamera-devel] [PATCH v2 7/7] libcamera: Switch PixelFormat to DRM FourCC values
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon Oct 28 12:02:08 CET 2019
From: Jacopo Mondi <jacopo at jmondi.org>
Use DRM FourCC values for the newly defined PixelFormat.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
src/libcamera/pipeline/ipu3/ipu3.cpp | 7 +++---
src/libcamera/pipeline/rkisp1/rkisp1.cpp | 25 ++++++++++----------
src/libcamera/pipeline/uvcvideo.cpp | 4 ++--
src/libcamera/pipeline/vimc.cpp | 15 ++++++------
src/libcamera/pixelformats.cpp | 6 +++--
src/qcam/format_converter.cpp | 30 ++++++++++++------------
test/camera/buffer_import.cpp | 17 ++++++++++----
7 files changed, 58 insertions(+), 46 deletions(-)
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 8d3ad568d16e..1c5fccf69428 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -10,6 +10,7 @@
#include <memory>
#include <vector>
+#include <linux/drm_fourcc.h>
#include <linux/media-bus-format.h>
#include <libcamera/camera.h>
@@ -249,7 +250,7 @@ IPU3CameraConfiguration::IPU3CameraConfiguration(Camera *camera,
void IPU3CameraConfiguration::adjustStream(StreamConfiguration &cfg, bool scale)
{
/* The only pixel format the driver supports is NV12. */
- cfg.pixelFormat = V4L2_PIX_FMT_NV12;
+ cfg.pixelFormat = DRM_FORMAT_NV12;
if (scale) {
/*
@@ -404,7 +405,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
StreamConfiguration cfg = {};
IPU3Stream *stream = nullptr;
- cfg.pixelFormat = V4L2_PIX_FMT_NV12;
+ cfg.pixelFormat = DRM_FORMAT_NV12;
switch (role) {
case StreamRole::StillCapture:
@@ -1121,7 +1122,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output,
return 0;
V4L2DeviceFormat outputFormat = {};
- outputFormat.fourcc = V4L2_PIX_FMT_NV12;
+ outputFormat.fourcc = dev->toV4L2Fourcc(DRM_FORMAT_NV12);
outputFormat.size = cfg.size;
outputFormat.planesCount = 2;
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 7a28b03b8d38..b21cf92435e7 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -11,6 +11,7 @@
#include <memory>
#include <queue>
+#include <linux/drm_fourcc.h>
#include <linux/media-bus-format.h>
#include <ipa/rkisp1.h>
@@ -434,14 +435,14 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera,
CameraConfiguration::Status RkISP1CameraConfiguration::validate()
{
static const std::array<unsigned int, 8> formats{
- V4L2_PIX_FMT_YUYV,
- V4L2_PIX_FMT_YVYU,
- V4L2_PIX_FMT_VYUY,
- V4L2_PIX_FMT_NV16,
- V4L2_PIX_FMT_NV61,
- V4L2_PIX_FMT_NV21,
- V4L2_PIX_FMT_NV12,
- V4L2_PIX_FMT_GREY,
+ DRM_FORMAT_YUYV,
+ DRM_FORMAT_YVYU,
+ DRM_FORMAT_VYUY,
+ DRM_FORMAT_NV16,
+ DRM_FORMAT_NV61,
+ DRM_FORMAT_NV21,
+ DRM_FORMAT_NV12,
+ /* \todo Add support for 8-bit greyscale to DRM formats */
};
const CameraSensor *sensor = data_->sensor_;
@@ -462,7 +463,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
if (std::find(formats.begin(), formats.end(), cfg.pixelFormat) ==
formats.end()) {
LOG(RkISP1, Debug) << "Adjusting format to NV12";
- cfg.pixelFormat = V4L2_PIX_FMT_NV12;
+ cfg.pixelFormat = DRM_FORMAT_NV12,
status = Adjusted;
}
@@ -541,7 +542,7 @@ CameraConfiguration *PipelineHandlerRkISP1::generateConfiguration(Camera *camera
return config;
StreamConfiguration cfg{};
- cfg.pixelFormat = V4L2_PIX_FMT_NV12;
+ cfg.pixelFormat = DRM_FORMAT_NV12;
cfg.size = data->sensor_->resolution();
config->addConfiguration(cfg);
@@ -623,7 +624,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
LOG(RkISP1, Debug) << "ISP output pad configured with " << format.toString();
V4L2DeviceFormat outputFormat = {};
- outputFormat.fourcc = cfg.pixelFormat;
+ outputFormat.fourcc = video_->toV4L2Fourcc(cfg.pixelFormat);
outputFormat.size = cfg.size;
outputFormat.planesCount = 2;
@@ -632,7 +633,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)
return ret;
if (outputFormat.size != cfg.size ||
- outputFormat.fourcc != cfg.pixelFormat) {
+ outputFormat.fourcc != video_->toV4L2Fourcc(cfg.pixelFormat)) {
LOG(RkISP1, Error)
<< "Unable to configure capture in " << cfg.toString();
return -EINVAL;
diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index fae0ffc4de30..45448d6f8c05 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -176,7 +176,7 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config)
int ret;
V4L2DeviceFormat format = {};
- format.fourcc = cfg.pixelFormat;
+ format.fourcc = data->video_->toV4L2Fourcc(cfg.pixelFormat);
format.size = cfg.size;
ret = data->video_->setFormat(&format);
@@ -184,7 +184,7 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config)
return ret;
if (format.size != cfg.size ||
- format.fourcc != cfg.pixelFormat)
+ format.fourcc != data->video_->toV4L2Fourcc(cfg.pixelFormat))
return -EINVAL;
cfg.setStream(&data->stream_);
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index c16ae4cb76b5..e6ab6a085824 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -10,6 +10,7 @@
#include <iomanip>
#include <tuple>
+#include <linux/drm_fourcc.h>
#include <linux/media-bus-format.h>
#include <ipa/ipa_interface.h>
@@ -106,9 +107,9 @@ private:
namespace {
constexpr std::array<unsigned int, 3> pixelformats{
- V4L2_PIX_FMT_BGR24,
- V4L2_PIX_FMT_RGB24,
- V4L2_PIX_FMT_ARGB32,
+ DRM_FORMAT_RGB888,
+ DRM_FORMAT_BGR888,
+ DRM_FORMAT_BGRA8888,
};
} /* namespace */
@@ -137,7 +138,7 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()
if (std::find(pixelformats.begin(), pixelformats.end(), cfg.pixelFormat) ==
pixelformats.end()) {
LOG(VIMC, Debug) << "Adjusting format to RGB24";
- cfg.pixelFormat = V4L2_PIX_FMT_RGB24;
+ cfg.pixelFormat = DRM_FORMAT_BGR888;
status = Adjusted;
}
@@ -186,7 +187,7 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,
StreamConfiguration cfg(formats.data());
- cfg.pixelFormat = V4L2_PIX_FMT_RGB24;
+ cfg.pixelFormat = DRM_FORMAT_BGR888;
cfg.size = { 1920, 1080 };
cfg.bufferCount = 4;
@@ -231,7 +232,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)
return ret;
V4L2DeviceFormat format = {};
- format.fourcc = cfg.pixelFormat;
+ format.fourcc = data->video_->toV4L2Fourcc(cfg.pixelFormat);
format.size = cfg.size;
ret = data->video_->setFormat(&format);
@@ -239,7 +240,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)
return ret;
if (format.size != cfg.size ||
- format.fourcc != cfg.pixelFormat)
+ format.fourcc != data->video_->toV4L2Fourcc(cfg.pixelFormat))
return -EINVAL;
/*
diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp
index 9377fb5e0749..c03335400b70 100644
--- a/src/libcamera/pixelformats.cpp
+++ b/src/libcamera/pixelformats.cpp
@@ -19,8 +19,10 @@ namespace libcamera {
* \brief libcamera image pixel format
*
* The PixelFormat type describes the format of images in the public libcamera
- * API. It stores a FourCC value in a 32-bit unsigned integer. The values are
- * defined in the Linux kernel V4L2 API (see linux/videodev2.h).
+ * API. It stores a FourCC value as a 32-bit unsigned integer. The values are
+ * defined in the Linux kernel DRM/KMS API (see linux/drm_fourcc.h).
+ *
+ * \todo Add support for format modifiers
*/
} /* namespace libcamera */
diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp
index 86b03b2cd84d..383d48223140 100644
--- a/src/qcam/format_converter.cpp
+++ b/src/qcam/format_converter.cpp
@@ -7,7 +7,7 @@
#include <errno.h>
-#include <linux/videodev2.h>
+#include <linux/drm_fourcc.h>
#include <QImage>
@@ -31,84 +31,84 @@ int FormatConverter::configure(unsigned int format, unsigned int width,
unsigned int height)
{
switch (format) {
- case V4L2_PIX_FMT_NV12:
+ case DRM_FORMAT_NV12:
formatFamily_ = NV;
horzSubSample_ = 2;
vertSubSample_ = 2;
nvSwap_ = false;
break;
- case V4L2_PIX_FMT_NV21:
+ case DRM_FORMAT_NV21:
formatFamily_ = NV;
horzSubSample_ = 2;
vertSubSample_ = 2;
nvSwap_ = true;
break;
- case V4L2_PIX_FMT_NV16:
+ case DRM_FORMAT_NV16:
formatFamily_ = NV;
horzSubSample_ = 2;
vertSubSample_ = 1;
nvSwap_ = false;
break;
- case V4L2_PIX_FMT_NV61:
+ case DRM_FORMAT_NV61:
formatFamily_ = NV;
horzSubSample_ = 2;
vertSubSample_ = 1;
nvSwap_ = true;
break;
- case V4L2_PIX_FMT_NV24:
+ case DRM_FORMAT_NV24:
formatFamily_ = NV;
horzSubSample_ = 1;
vertSubSample_ = 1;
nvSwap_ = false;
break;
- case V4L2_PIX_FMT_NV42:
+ case DRM_FORMAT_NV42:
formatFamily_ = NV;
horzSubSample_ = 1;
vertSubSample_ = 1;
nvSwap_ = true;
break;
- case V4L2_PIX_FMT_BGR24:
+ case DRM_FORMAT_RGB888:
formatFamily_ = RGB;
r_pos_ = 2;
g_pos_ = 1;
b_pos_ = 0;
bpp_ = 3;
break;
- case V4L2_PIX_FMT_RGB24:
+ case DRM_FORMAT_BGR888:
formatFamily_ = RGB;
r_pos_ = 0;
g_pos_ = 1;
b_pos_ = 2;
bpp_ = 3;
break;
- case V4L2_PIX_FMT_ARGB32:
+ case DRM_FORMAT_BGRA8888:
formatFamily_ = RGB;
r_pos_ = 1;
g_pos_ = 2;
b_pos_ = 3;
bpp_ = 4;
break;
- case V4L2_PIX_FMT_VYUY:
+ case DRM_FORMAT_VYUY:
formatFamily_ = YUV;
y_pos_ = 1;
cb_pos_ = 2;
break;
- case V4L2_PIX_FMT_YVYU:
+ case DRM_FORMAT_YVYU:
formatFamily_ = YUV;
y_pos_ = 0;
cb_pos_ = 3;
break;
- case V4L2_PIX_FMT_UYVY:
+ case DRM_FORMAT_UYVY:
formatFamily_ = YUV;
y_pos_ = 1;
cb_pos_ = 0;
break;
- case V4L2_PIX_FMT_YUYV:
+ case DRM_FORMAT_YUYV:
formatFamily_ = YUV;
y_pos_ = 0;
cb_pos_ = 1;
break;
- case V4L2_PIX_FMT_MJPEG:
+ case DRM_FORMAT_MJPEG:
formatFamily_ = MJPEG;
break;
default:
diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp
index 9cac19d8ce81..bbc5a25c4019 100644
--- a/test/camera/buffer_import.cpp
+++ b/test/camera/buffer_import.cpp
@@ -155,7 +155,16 @@ public:
}
bool done() const { return done_; }
- const V4L2DeviceFormat &format() const { return format_; }
+
+ PixelFormat format() const
+ {
+ return video_->toPixelFormat(format_.fourcc);
+ }
+
+ const Size &size() const
+ {
+ return format_.size;
+ }
Signal<uint64_t, int> requestReady;
@@ -314,11 +323,9 @@ protected:
return TestFail;
}
- const V4L2DeviceFormat &format = sink_.format();
-
StreamConfiguration &cfg = config->at(0);
- cfg.size = format.size;
- cfg.pixelFormat = format.fourcc;
+ cfg.size = sink_.size();
+ cfg.pixelFormat = sink_.format();
cfg.bufferCount = CAMERA_BUFFER_COUNT;
cfg.memoryType = ExternalMemory;
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list