summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2021-12-10 14:44:20 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-12-13 11:29:01 +0200
commit3e520cadf18ac53eed0fc98fb1d58368ef80a61d (patch)
tree8a7bac56c6490f725c23a35d6d1c8827c0659b72
parente86aed6166449189eaf1b7e9d734236797e3d0c3 (diff)
libcamera: video_device: Support passing ColorSpaces to V4L2 video devices
The ColorSpace from the StreamConfiguration is now handled appropriately in the V4L2VideoDevice. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--include/libcamera/internal/v4l2_videodevice.h3
-rw-r--r--src/libcamera/v4l2_videodevice.cpp22
2 files changed, 25 insertions, 0 deletions
diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
index 9b2ec3af..2d2ccc47 100644
--- a/include/libcamera/internal/v4l2_videodevice.h
+++ b/include/libcamera/internal/v4l2_videodevice.h
@@ -10,6 +10,7 @@
#include <array>
#include <atomic>
#include <memory>
+#include <optional>
#include <stdint.h>
#include <string>
#include <vector>
@@ -21,6 +22,7 @@
#include <libcamera/base/signal.h>
#include <libcamera/base/unique_fd.h>
+#include <libcamera/color_space.h>
#include <libcamera/framebuffer.h>
#include <libcamera/geometry.h>
#include <libcamera/pixel_format.h>
@@ -167,6 +169,7 @@ public:
V4L2PixelFormat fourcc;
Size size;
+ std::optional<ColorSpace> colorSpace;
std::array<Plane, 3> planes;
unsigned int planesCount = 0;
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index b4b89e27..5f36ee20 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -384,6 +384,21 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const
*/
/**
+ * \var V4L2DeviceFormat::colorSpace
+ * \brief The color space of the pixels
+ *
+ * The color space of the image. When setting the format this may be
+ * unset, in which case the driver gets to use its default color space.
+ * After being set, this value should contain the color space that
+ * was actually used. If this value is unset, then the color space chosen
+ * by the driver could not be represented by the ColorSpace class (and
+ * should probably be added).
+ *
+ * It is up to the pipeline handler or application to check if the
+ * resulting color space is acceptable.
+ */
+
+/**
* \var V4L2DeviceFormat::planes
* \brief The per-plane memory size information
*
@@ -871,6 +886,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)
format->size.height = pix->height;
format->fourcc = V4L2PixelFormat(pix->pixelformat);
format->planesCount = pix->num_planes;
+ format->colorSpace = toColorSpace(*pix);
for (unsigned int i = 0; i < format->planesCount; ++i) {
format->planes[i].bpl = pix->plane_fmt[i].bytesperline;
@@ -892,6 +908,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)
pix->pixelformat = format->fourcc;
pix->num_planes = format->planesCount;
pix->field = V4L2_FIELD_NONE;
+ fromColorSpace(format->colorSpace, *pix);
ASSERT(pix->num_planes <= std::size(pix->plane_fmt));
@@ -920,6 +937,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)
format->planes[i].bpl = pix->plane_fmt[i].bytesperline;
format->planes[i].size = pix->plane_fmt[i].sizeimage;
}
+ format->colorSpace = toColorSpace(*pix);
return 0;
}
@@ -943,6 +961,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)
format->planesCount = 1;
format->planes[0].bpl = pix->bytesperline;
format->planes[0].size = pix->sizeimage;
+ format->colorSpace = toColorSpace(*pix);
return 0;
}
@@ -959,6 +978,8 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)
pix->pixelformat = format->fourcc;
pix->bytesperline = format->planes[0].bpl;
pix->field = V4L2_FIELD_NONE;
+ fromColorSpace(format->colorSpace, *pix);
+
ret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);
if (ret) {
LOG(V4L2, Error)
@@ -977,6 +998,7 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)
format->planesCount = 1;
format->planes[0].bpl = pix->bytesperline;
format->planes[0].size = pix->sizeimage;
+ format->colorSpace = toColorSpace(*pix);
return 0;
}