From e86aed6166449189eaf1b7e9d734236797e3d0c3 Mon Sep 17 00:00:00 2001 From: David Plowman Date: Fri, 10 Dec 2021 14:44:19 +0000 Subject: libcamera: video_device: Convert between ColorSpace class and V4L2 formats Add functions to the V4L2Device class to convert to and from libcamera ColorSpace. These functions are added to the base V4L2Device class so that they can be shared both by the video device class and subdevices. With the ColorSpace class, the color space and related other fields are stored together, corresponding to a number of fields in the various different V4L2 format structures. Template functions are therefore a convenient implementation, and we must explicitly instantiate the templates that will be needed. Note that unset color spaces are converted to requests for the device's "default" color space. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- include/libcamera/internal/v4l2_device.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 8886b750..a52a5f2c 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -18,6 +19,7 @@ #include #include +#include #include namespace libcamera { @@ -56,6 +58,12 @@ protected: int fd() const { return fd_.get(); } + template + static std::optional toColorSpace(const T &v4l2Format); + + template + static int fromColorSpace(const std::optional &colorSpace, T &v4l2Format); + private: static ControlType v4l2CtrlType(uint32_t ctrlType); static std::unique_ptr v4l2ControlId(const v4l2_query_ext_ctrl &ctrl); -- cgit v1.2.1