{"id":14429,"url":"https://patchwork.libcamera.org/api/1.1/patches/14429/?format=json","web_url":"https://patchwork.libcamera.org/patch/14429/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20211029132343.1629-6-david.plowman@raspberrypi.com>","date":"2021-10-29T13:23:41","name":"[libcamera-devel,v4,5/7] libcamera: Support passing ColorSpaces to V4L2 subdevices","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"cf475a5c64d7b10ca6030e5512b74ded71ddeea2","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14429/mbox/","series":[{"id":2682,"url":"https://patchwork.libcamera.org/api/1.1/series/2682/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2682","date":"2021-10-29T13:23:36","name":"Colour spaces","version":4,"mbox":"https://patchwork.libcamera.org/series/2682/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14429/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14429/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 12EF8C324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Oct 2021 13:23:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C40B4600C1;\n\tFri, 29 Oct 2021 15:23:57 +0200 (CEST)","from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A230600C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 15:23:50 +0200 (CEST)","by mail-wr1-x430.google.com with SMTP id k7so16079919wrd.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Oct 2021 06:23:50 -0700 (PDT)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:1ce1:9965:4328:89c4])\n\tby smtp.gmail.com with ESMTPSA id\n\tl7sm111934wrf.31.2021.10.29.06.23.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 29 Oct 2021 06:23:49 -0700 (PDT)"],"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=\"owcw/i51\"; 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=TE3X+BIbROe2GXpvAy5L/7MmT1/6LP/Ws9oGo2jUKTo=;\n\tb=owcw/i51upm6ZwpDvExzATk5iZtbINRGC9wxXDRQYahdQQ2XZrgCNa6bLmDUR49SNF\n\tyM59+Lx6Uu6PEYa/GrTvyCg5M8Xvaw55UDQzgaEaqKezv+MMCBxz8p08bkZCa/DJ78U1\n\tQ9W7EBK+twiCfqZ6Bf+1iroz7YlJlPr02Qv44GGFuYpW3gbk5JKyHLyJTrhV6+Im6Zh0\n\t6Arz9Bdji1soh8s8oGnSYnt3o/hBgE233InTQvCyknW7hIpQhRQKq4MpbA2FYLgd+M9k\n\tZlydMJ7uOhJHxZYCTlzNGy/j8NE65pyfN6yCYaEgjrMPQEClt2DJsKJuaYeZAGCJ8pVj\n\tvzrw==","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=TE3X+BIbROe2GXpvAy5L/7MmT1/6LP/Ws9oGo2jUKTo=;\n\tb=67Mj/c+q/3NUXYnM5q82E+qIwBUTI4frv3xMdLInB+DFD+J7qVnPmg4/0jsxVs/Z69\n\tgMNLnWGhXdCoVT3V5FvAj+mK6Z7L95pIwD/WuxBWOEef5xnzo8sdfdhzpqYIRHhSfTwX\n\tRRqwlcZ+fLCFfY88bwQik11ptT8sMrRy2424co7gCOf/oowrPdPi52an36yM2ugnfmVd\n\tWU7Q1noVcEG4vGwBvAo0vSSKCv4fnlQEakzzSnvGCNsICE56a/C9a7q1/oLBwnKTUtSx\n\tEXYM0OALf2lT6eBuGFdDglwZ3QPe6gj5Jup1d7HbSk13bScd7biRrpz2mtunZUxQ07f/\n\thF/g==","X-Gm-Message-State":"AOAM530M/cbRX+vnvZxO/hJBSoIthB9ecMhBC1dk7+3hZWORgts4lJTL\n\t2gcPOi9Q7YLFWlw9xMflz5/oIob7RK0wDg==","X-Google-Smtp-Source":"ABdhPJz6oAkmAgoi165clRRQZiE21Yn4BdFBMQYVVsBrenZWqeUHBUy8KgFk5c9xMXL0kVMRJli4/w==","X-Received":"by 2002:a5d:64a3:: with SMTP id\n\tm3mr14393053wrp.393.1635513829496; \n\tFri, 29 Oct 2021 06:23:49 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 29 Oct 2021 14:23:41 +0100","Message-Id":"<20211029132343.1629-6-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20211029132343.1629-1-david.plowman@raspberrypi.com>","References":"<20211029132343.1629-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 5/7] libcamera: Support passing\n\tColorSpaces to V4L2 subdevices","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 V4L2Subdevice.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/internal/v4l2_subdevice.h |  2 ++\n src/libcamera/camera_sensor.cpp             |  1 +\n src/libcamera/v4l2_subdevice.cpp            | 37 ++++++++++++++++++++-\n 3 files changed, 39 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\nindex 97b89fb9..f3ab8454 100644\n--- a/include/libcamera/internal/v4l2_subdevice.h\n+++ b/include/libcamera/internal/v4l2_subdevice.h\n@@ -14,6 +14,7 @@\n #include <libcamera/base/class.h>\n #include <libcamera/base/log.h>\n \n+#include <libcamera/color_space.h>\n #include <libcamera/geometry.h>\n \n #include \"libcamera/internal/formats.h\"\n@@ -27,6 +28,7 @@ class MediaDevice;\n struct V4L2SubdeviceFormat {\n \tuint32_t mbus_code;\n \tSize size;\n+\tColorSpace colorSpace;\n \n \tconst std::string toString() const;\n \tuint8_t bitsPerPixel() const;\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 9fdb8c09..6fcd1c1d 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -613,6 +613,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu\n \tV4L2SubdeviceFormat format{\n \t\t.mbus_code = bestCode,\n \t\t.size = *bestSize,\n+\t\t.colorSpace = ColorSpace::Raw,\n \t};\n \n \treturn format;\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 023e2328..8896e9b0 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -168,6 +168,18 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n  * \\brief The image size in pixels\n  */\n \n+/**\n+ * \\var V4L2SubdeviceFormat::colorSpace\n+ * \\brief The color space of the pixels\n+ *\n+ * When setting or trying a format, passing in \"Undefined\" fields in the\n+ * ColorSpace is not recommended because the driver will then make an\n+ * arbitrary choice of its own. Choices made by the driver will be\n+ * passed back in the normal way, though note that \"Undefined\" values can\n+ * be returned if the device has chosen something that the ColorSpace\n+ * cannot represent.\n+ */\n+\n /**\n  * \\brief Assemble and return a string describing the format\n  * \\return A string describing the V4L2SubdeviceFormat\n@@ -400,6 +412,12 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \tformat->size.height = subdevFmt.format.height;\n \tformat->mbus_code = subdevFmt.format.code;\n \n+\tformat->colorSpace = toColorSpace(subdevFmt.format);\n+\tif (!format->colorSpace.isFullyDefined())\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Retrieved undefined color space: \"\n+\t\t\t<< format->colorSpace.toString();\n+\n \treturn 0;\n }\n \n@@ -418,6 +436,11 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \t\t\t     Whence whence)\n {\n+\tif (!format->colorSpace.isFullyDefined())\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Trying to set undefined color space: \"\n+\t\t\t<< format->colorSpace.toString();\n+\n \tstruct v4l2_subdev_format subdevFmt = {};\n \tsubdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE\n \t\t\t: V4L2_SUBDEV_FORMAT_TRY;\n@@ -427,7 +450,13 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \tsubdevFmt.format.code = format->mbus_code;\n \tsubdevFmt.format.field = V4L2_FIELD_NONE;\n \n-\tint ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n+\tint ret = fromColorSpace(format->colorSpace, subdevFmt.format);\n+\tif (ret < 0)\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Setting color space unrecognised by V4L2: \"\n+\t\t\t<< format->colorSpace.toString();\n+\n+\tret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n \t\t\t<< \"Unable to set format on pad \" << pad\n@@ -439,6 +468,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \tformat->size.height = subdevFmt.format.height;\n \tformat->mbus_code = subdevFmt.format.code;\n \n+\tformat->colorSpace = toColorSpace(subdevFmt.format);\n+\tif (!format->colorSpace.isFullyDefined())\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Undefined color space has been set: \"\n+\t\t\t<< format->colorSpace.toString();\n+\n \treturn 0;\n }\n \n","prefixes":["libcamera-devel","v4","5/7"]}