{"id":14461,"url":"https://patchwork.libcamera.org/api/1.1/patches/14461/?format=json","web_url":"https://patchwork.libcamera.org/patch/14461/","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-5-david.plowman@raspberrypi.com>","date":"2021-11-04T13:58:02","name":"[libcamera-devel,v5,4/7] libcamera: Support passing ColorSpaces to V4L2 video devices","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"99f912e6377bc8e54c18349f7bac7f3b0d8351d9","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/14461/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/14461/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14461/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 B5B83BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Nov 2021 13:58:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 881AD6035A;\n\tThu,  4 Nov 2021 14:58:30 +0100 (CET)","from mail-wm1-x333.google.com (mail-wm1-x333.google.com\n\t[IPv6:2a00:1450:4864:20::333])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B2D960128\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Nov 2021 14:58:25 +0100 (CET)","by mail-wm1-x333.google.com with SMTP id 71so4582649wma.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 04 Nov 2021 06:58:25 -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:24 -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=\"V7ZvxNWY\"; 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=3jzpKNdq0T31XWyv1nf4OXskRk3Z5TSZ2eDhnU9oflA=;\n\tb=V7ZvxNWYv7bvytBs0LTt6iJYfCSxBzkfz4Gn5fwjKGlY0Vxxen1TM/+oG0xg+oodfR\n\tYYrTOaMvZlDOEHvKct8gdRA/jHYtQlQ3PiSkArTpeB7lNfnkheQl/Za7XD5aTMUo0vCN\n\tDTveOzUnwAzzrqSwaiAornxVtveK2Znr6J54kY41Z6zQy64quMdiVKdj5zBpqqcyLDAH\n\t8gWoMInxK1FR3d1i1T6Q7OKl32IgNIPmM2884ogJz/4m5vw3axAoY4V8vy5Jdnq6PMb+\n\tGHo4Mh6H2AkZU8gwNLXvhB+GH0uTkXseew3/cL9cQxCtGfRyT6VYc+ntig679/z3ix7X\n\ttkmA==","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=3jzpKNdq0T31XWyv1nf4OXskRk3Z5TSZ2eDhnU9oflA=;\n\tb=18GZPUbmXAu7DDsTJ0FGaXqltXvh5CaLrzvVlXgDvKW4zWL7WS3GyK2vg2qRGcOIUA\n\txyGPvDcZlqLz4NfQ7Cwqsh6GXyhnjRMTee4y7kM6/IMnANp0xedob+Dw1G3Pp38ZQnlZ\n\tSA1jG0K47ygintxQ5FW6r3TGrQ7amPE8HeP/OIgyJCych/exL+LmreuCuJTX1VxPwS4M\n\tai8icteELQiG5DanykjHQ4ilmdV1lRXztOa0XVU5fIuIFGz8v2EciueUv4I72XThgaQA\n\tnQ0nrvNsiT9jxC9dL2/WDJQVVGzbLFkIbAauyC+rOY4RTaio8fQRKBF2sTbk6y3gYUWD\n\thXjQ==","X-Gm-Message-State":"AOAM531vx33g1RvGRrZPnoOy4cRUzQub0/EvkRXv+3xFRkHlTGMgxy7s\n\tN8WuW0VAQ93YZwP6dyFK4ueUq4x7gDMvyQ==","X-Google-Smtp-Source":"ABdhPJwggjpHIsmc27LmIE3HKfohyY2/t2WTjnEN2iZnhQdbyTBZ3OqgK41YjT1S3Qi52pHrRJbizQ==","X-Received":"by 2002:a7b:c441:: with SMTP id l1mr22800343wmi.69.1636034304932;\n\tThu, 04 Nov 2021 06:58:24 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  4 Nov 2021 13:58:02 +0000","Message-Id":"<20211104135805.5269-5-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 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            | 67 +++++++++++++++++--\n 2 files changed, 65 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex a1c458e4..6ca749c1 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+\tColorSpace 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..ccf3d28c 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -370,17 +370,29 @@ 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+ * When setting or trying a format, passing in \"Undefined\" fields in the\n+ * ColorSpace is not permitted 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+ * class cannot represent.\n  */\n \n /**\n@@ -879,6 +891,12 @@ 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.isFullyDefined())\n+\t\tLOG(V4L2, Warning)\n+\t\t\t<< \"Retrieved undefined color space: \"\n+\t\t\t<< format->colorSpace.toString();\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 +911,11 @@ 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.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 \tv4l2Format.type = bufferType_;\n \tpix->width = format->size.width;\n \tpix->height = format->size.height;\n@@ -900,6 +923,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<< format->colorSpace.toString();\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 +957,12 @@ 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.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@@ -951,6 +986,12 @@ 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.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@@ -960,12 +1001,24 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n \tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n \tint ret;\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 \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<< format->colorSpace.toString();\n+\n \tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n@@ -985,6 +1038,12 @@ 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.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","4/7"]}