{"id":14629,"url":"https://patchwork.libcamera.org/api/patches/14629/?format=json","web_url":"https://patchwork.libcamera.org/patch/14629/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211118151933.15627-5-david.plowman@raspberrypi.com>","date":"2021-11-18T15:19:30","name":"[libcamera-devel,v6,4/7] libcamera: Support passing ColorSpaces to V4L2 video devices","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"545a66ac6d8063474e91ad8edff88c0d06a71bc3","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14629/mbox/","series":[{"id":2726,"url":"https://patchwork.libcamera.org/api/series/2726/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2726","date":"2021-11-18T15:19:26","name":"Colour spaces","version":6,"mbox":"https://patchwork.libcamera.org/series/2726/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14629/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14629/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 067B9BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Nov 2021 15:20:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B02C4603C2;\n\tThu, 18 Nov 2021 16:20:35 +0100 (CET)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A693860376\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Nov 2021 16:20:28 +0100 (CET)","by mail-wr1-x436.google.com with SMTP id b12so12253134wrh.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Nov 2021 07:20:28 -0800 (PST)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:1ce1:9965:4328:89c4])\n\tby smtp.gmail.com with ESMTPSA id\n\tp12sm147367wro.33.2021.11.18.07.20.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 18 Nov 2021 07:20:27 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"LcZPmmT5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=XLKHkKrG/UEEcs/2bX824fXCZkEOH3339Y2W5nVKFIg=;\n\tb=LcZPmmT5guaAKEXzQ9fr6NSMmhzsdY2a5/AEvAT4QW6WUJseA/Vm670ie0EPCrQwdb\n\tC1dXc6kzL6bIYIIgc14dhKnqyd39pHdwlR3dSTljznj5U0PC/Xo1ChN8NvHwNy/9fvUX\n\tzqnrHdEkezHNExAo1ZqApaJTMSLM3P0EEjdDirob7Q6RjfsM4leR9MO4M7CctwXwjNCM\n\tQsdntB3j+PupVNLMKRnj8EJlAgH29g35e6Ib4BAQ88QnlG6/O3U5x5ipf69YuzifpMcg\n\t6k5vfk5mccMwR4EW0Go7retcZZYl++tmuxBfhxQH2ntUsmICX9lmFRQSRqs1sBknyu2+\n\tmWjg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=XLKHkKrG/UEEcs/2bX824fXCZkEOH3339Y2W5nVKFIg=;\n\tb=gWkRC/gY2pXuRaDqqASDO9ohOCtKDRhsVTIq9FyHjkauKzoEbdE5kJcJ8vwV/tUFy7\n\tlysh7CNFYyu13xUFiqhmIkMjea3pWemciQhYbj9s2VZGBl63C6IhpdcgiNanzBlB2Roi\n\tQRUVZN5mpEnoalQQjNx4ILSobVxFDPUeFZkIueuuSIfyTL59vVeMYN7B9IC6+wDt3xnC\n\t0M4R0ds3BZA3/xBuG3A6Xs44roRr+EuLwnOU2xitPLrAvGPWi4C9SWIto9V0IabQ/qwc\n\tMZR+5i354e9vjbM+u0UYDpgHxJnR5KXPpxVfym42Ll3Wfr2BU0qjRxKm2/MDvgG70du+\n\taF+A==","X-Gm-Message-State":"AOAM530SD163Joi5aWi4u38JEk0fL23jcFZqMhOlxf5a1QNz5nJ5N/YQ\n\tN8MNJJHTu/FnBGLnmnYTg5NxwQ==","X-Google-Smtp-Source":"ABdhPJxS7qv7lBYa7xwgcTVMyjpOQbcxYZpAYia/uJ97C0TYwe4JsZefwRB1zWiAb6uohDvoX7rj7Q==","X-Received":"by 2002:a5d:6152:: with SMTP id\n\ty18mr32364355wrt.271.1637248828146; \n\tThu, 18 Nov 2021 07:20:28 -0800 (PST)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com,\n\thverkuil-cisco@xs4all.nl, tfiga@google.com, jacopo@jmondi.org,\n\tnaush@raspberrypi.com, libcamera-devel@lists.libcamera.org","Date":"Thu, 18 Nov 2021 15:19:30 +0000","Message-Id":"<20211118151933.15627-5-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20211118151933.15627-1-david.plowman@raspberrypi.com>","References":"<20211118151933.15627-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 4/7] libcamera: Support passing\n\tColorSpaces to V4L2 video devices","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The ColorSpace from the StreamConfiguration is now handled\nappropriately in the V4L2VideoDevice.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/internal/v4l2_videodevice.h |  2 +\n src/libcamera/v4l2_videodevice.cpp            | 53 +++++++++++++++++--\n 2 files changed, 51 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex a1c458e4..00bc50e7 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -20,6 +20,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/signal.h>\n \n+#include <libcamera/color_space.h>\n #include <libcamera/framebuffer.h>\n #include <libcamera/geometry.h>\n #include <libcamera/pixel_format.h>\n@@ -167,6 +168,7 @@ public:\n \n \tV4L2PixelFormat fourcc;\n \tSize size;\n+\tstd::optional<ColorSpace> colorSpace;\n \n \tstd::array<Plane, 3> planes;\n \tunsigned int planesCount = 0;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 4f04212d..e03ff8b5 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -370,17 +370,27 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n  * \\brief The plane line stride (in bytes)\n  */\n \n+/**\n+ * \\var V4L2DeviceFormat::fourcc\n+ * \\brief The fourcc code describing the pixel encoding scheme\n+ *\n+ * The fourcc code, as defined by the V4L2 API with the V4L2_PIX_FMT_* macros,\n+ * that identifies the image format pixel encoding scheme.\n+ */\n+\n /**\n  * \\var V4L2DeviceFormat::size\n  * \\brief The image size in pixels\n  */\n \n /**\n- * \\var V4L2DeviceFormat::fourcc\n- * \\brief The fourcc code describing the pixel encoding scheme\n+ * \\var V4L2DeviceFormat::colorSpace\n+ * \\brief The color space of the pixels\n  *\n- * The fourcc code, as defined by the V4L2 API with the V4L2_PIX_FMT_* macros,\n- * that identifies the image format pixel encoding scheme.\n+ * The color space of the image. When setting the format this may be\n+ * unset, in which case the driver gets to use its default color space.\n+ * After being set, this value should contain the color space that the\n+ * was actually used.\n  */\n \n /**\n@@ -879,6 +889,10 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n \tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n \tformat->planesCount = pix->num_planes;\n \n+\tformat->colorSpace = toColorSpace(*pix);\n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Error) << \"Retrieved unrecognised color space\";\n+\n \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n \t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n@@ -893,6 +907,9 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n \tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n \tint ret;\n \n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Warning) << \"Setting undefined color space\";\n+\n \tv4l2Format.type = bufferType_;\n \tpix->width = format->size.width;\n \tpix->height = format->size.height;\n@@ -900,6 +917,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n \tpix->num_planes = format->planesCount;\n \tpix->field = V4L2_FIELD_NONE;\n \n+\tret = fromColorSpace(format->colorSpace, *pix);\n+\tif (ret < 0)\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Setting color space unrecognised by V4L2: \"\n+\t\t\t<< ColorSpace::toString(format->colorSpace);\n+\n \tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n \n \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n@@ -928,6 +951,10 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n \t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n \t}\n \n+\tformat->colorSpace = toColorSpace(*pix);\n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Warning) << \"Unrecognised color space has been set\";\n+\n \treturn 0;\n }\n \n@@ -951,6 +978,10 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n \tformat->planes[0].bpl = pix->bytesperline;\n \tformat->planes[0].size = pix->sizeimage;\n \n+\tformat->colorSpace = toColorSpace(*pix);\n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Error) << \"Retrieved unrecognised color space\";\n+\n \treturn 0;\n }\n \n@@ -960,12 +991,22 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n \tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n \tint ret;\n \n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Error) << \"Trying to set unrecognised color space\";\n+\n \tv4l2Format.type = bufferType_;\n \tpix->width = format->size.width;\n \tpix->height = format->size.height;\n \tpix->pixelformat = format->fourcc;\n \tpix->bytesperline = format->planes[0].bpl;\n \tpix->field = V4L2_FIELD_NONE;\n+\n+\tret = fromColorSpace(format->colorSpace, *pix);\n+\tif (ret < 0)\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Set color space unrecognised by V4L2: \"\n+\t\t\t<< ColorSpace::toString(format->colorSpace);\n+\n \tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n@@ -985,6 +1026,10 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n \tformat->planes[0].bpl = pix->bytesperline;\n \tformat->planes[0].size = pix->sizeimage;\n \n+\tformat->colorSpace = toColorSpace(*pix);\n+\tif (!format->colorSpace)\n+\t\tLOG(V4L2, Error) << \"Undefined color space has been set\";\n+\n \treturn 0;\n }\n \n","prefixes":["libcamera-devel","v6","4/7"]}