{"id":14462,"url":"https://patchwork.libcamera.org/api/1.1/patches/14462/?format=json","web_url":"https://patchwork.libcamera.org/patch/14462/","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":"<20211104135805.5269-6-david.plowman@raspberrypi.com>","date":"2021-11-04T13:58:03","name":"[libcamera-devel,v5,5/7] libcamera: Support passing ColorSpaces to V4L2 subdevices","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f801429a80c0edadf814a76b273462007ab65d4b","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/14462/mbox/","series":[{"id":2691,"url":"https://patchwork.libcamera.org/api/1.1/series/2691/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2691","date":"2021-11-04T13:57:58","name":"Colour spaces","version":5,"mbox":"https://patchwork.libcamera.org/series/2691/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14462/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14462/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 6EB00C324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Nov 2021 13:58:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 202BB6034F;\n\tThu,  4 Nov 2021 14:58:32 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 04E7460352\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Nov 2021 14:58:26 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id y196so4588360wmc.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 04 Nov 2021 06:58:26 -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\ti20sm2264736wmq.41.2021.11.04.06.58.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 04 Nov 2021 06:58:25 -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=\"T893C1jc\"; 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=HsQlhHnuhc87TaSXhA5f4OVRdGAu3zIVZXBgg53nXBM=;\n\tb=T893C1jc5/OBi28MfxZnXec0O+Ab2vOFs58ObSFvTaOiWxjS1oMrF0LIiVPRyV1gda\n\tEzEgQL4IoDZv8llqkwqmk5Xz1JKerfnUVlfZhd6Xdub5ssMnV7YPpxnlejJ1P9ZPSgz3\n\tKoKSE8X+/tLpU01/+Kj7IhF7hOQbqyGsbScpmYmel9otED6xd+o7mizJc6tYt5A5prPZ\n\tSqvFVBsaFhMpO+QtSxQIAWP73L+Kpi8+OPCJ41wKcnq2hyWvYkjLn6P7uKrq9y4e80vb\n\t3K2+iMHRE6tB5lOzbOZuvIW5LllvPnvHmXxLUPysORy4vTMnA+Q9PMEZMV3LYxj/v2sb\n\tPTyw==","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=HsQlhHnuhc87TaSXhA5f4OVRdGAu3zIVZXBgg53nXBM=;\n\tb=OMaeaXue+FcZIwd3Ru5pjWFAjpk6rNlITpQmFba+rIB8qAFB+Q0XgjjtslyD3EeiUB\n\tF+XxYHrFK2NL2SUq5JHLitwrLSAjdLxfLpgGvgAfiTXD+C75RttI2kBHthYLoFyWyLUu\n\t2tIiiyXxGqnvA5ZPIP3CQx5xPvuf/Lr+rDIhKNw6DYP41/O97Ksbq9dTqs/Imj5XEyPM\n\toFFwNGUBvFVCGgMjthPHZm410Dpeg/Wve+OWCrzSYzb4vEBIz9wqmR26elXXya85NmjA\n\td5IojsRGQRRGSXSJ3VGA+GULzTDLFRmixwZ7QzXbswlZDmpvR/zdtn3Hfu9qGIW49P0U\n\tr+mw==","X-Gm-Message-State":"AOAM532DobuI3T7iDGxTLTe3LtTuE+mMdXLRGqVGd8qJW57Jusl3YdGH\n\tEINuc0zv2reEumEmxXUua0E5HHQqIPhmdQ==","X-Google-Smtp-Source":"ABdhPJzyTMWuCyBZkFT84bCCTS1nrqpBrpkj+fb7d4leHwdHbMiRmkWuOZQaYRpMcGHluEtUgKr0Jg==","X-Received":"by 2002:a7b:c744:: with SMTP id w4mr18525399wmk.50.1636034305546;\n\tThu, 04 Nov 2021 06:58:25 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  4 Nov 2021 13:58:03 +0000","Message-Id":"<20211104135805.5269-6-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20211104135805.5269-1-david.plowman@raspberrypi.com>","References":"<20211104135805.5269-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 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            | 42 ++++++++++++++++++++-\n 3 files changed, 44 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..b348170f 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,17 @@ 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+\t/*\n+\t * This warning can be ignored on metadata pads. These are normally\n+\t * pads other than zero.\n+\t * \\todo find a way to detect metadata pads and ignore them\n+\t */\n+\tif (!format->colorSpace.isFullyDefined())\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Retrieved undefined color space on pad \" << pad\n+\t\t\t<< \": \" << format->colorSpace.toString();\n+\n \treturn 0;\n }\n \n@@ -418,6 +441,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 +455,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 +473,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","v5","5/7"]}