summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2021-12-10 14:44:19 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-12-13 11:29:01 +0200
commite86aed6166449189eaf1b7e9d734236797e3d0c3 (patch)
tree3fc1ae1b9aa912a70364bd4e58425caf90a38edd /include
parent96f990ea6c8c0e3dbcb6b1c6f379fcc341529ea8 (diff)
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 <david.plowman@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/v4l2_device.h8
1 files changed, 8 insertions, 0 deletions
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 <map>
#include <memory>
+#include <optional>
#include <vector>
#include <linux/videodev2.h>
@@ -18,6 +19,7 @@
#include <libcamera/base/span.h>
#include <libcamera/base/unique_fd.h>
+#include <libcamera/color_space.h>
#include <libcamera/controls.h>
namespace libcamera {
@@ -56,6 +58,12 @@ protected:
int fd() const { return fd_.get(); }
+ template<typename T>
+ static std::optional<ColorSpace> toColorSpace(const T &v4l2Format);
+
+ template<typename T>
+ static int fromColorSpace(const std::optional<ColorSpace> &colorSpace, T &v4l2Format);
+
private:
static ControlType v4l2CtrlType(uint32_t ctrlType);
static std::unique_ptr<ControlId> v4l2ControlId(const v4l2_query_ext_ctrl &ctrl);