[{"id":21629,"web_url":"https://patchwork.libcamera.org/comment/21629/","msgid":"<Ya9hlcVa3TK2Xn/o@pendragon.ideasonboard.com>","date":"2021-12-07T13:28:53","subject":"Re: [libcamera-devel] [PATCH v9 4/8] libcamera: Support passing\n\tColorSpaces to V4L2 video devices","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Mon, Dec 06, 2021 at 10:50:27AM +0000, David Plowman wrote:\n> The ColorSpace from the StreamConfiguration is now handled\n> appropriately in the V4L2VideoDevice.\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>  src/libcamera/v4l2_videodevice.cpp            | 32 +++++++++++++++++++\n>  2 files changed, 34 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 9b2ec3af..6a507a51 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -21,6 +21,7 @@\n>  #include <libcamera/base/signal.h>\n>  #include <libcamera/base/unique_fd.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\nMissing #include <optional> (in v4l2_device.h too)\n\n>  \n>  \tstd::array<Plane, 3> planes;\n>  \tunsigned int planesCount = 0;\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index b4b89e27..80a8c8e4 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -383,6 +383,21 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>   * that identifies the image format pixel encoding scheme.\n>   */\n>  \n> +/**\n> + * \\var V4L2DeviceFormat::colorSpace\n> + * \\brief The color space of the pixels\n> + *\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\nI'm not used to std::optional, it seems to be an elegant way to handle\nthis.\n\n> + * After being set, this value should contain the color space that\n> + * was actually used. If this value is unset, then the color space chosen\n> + * by the driver could not be represented by the ColorSpace class (and\n> + * should probably be added).\n> + *\n> + * It is up to the pipeline handler or application to check if the\n> + * resulting color space is acceptable.\n> + */\n> +\n>  /**\n>   * \\var V4L2DeviceFormat::planes\n>   * \\brief The per-plane memory size information\n> @@ -871,6 +886,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n>  \tformat->size.height = pix->height;\n>  \tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = pix->num_planes;\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n>  \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n> @@ -893,6 +909,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\nShould this be moved to fromColorSpace(), or do you expect valid use\ncases for calling it on a color space that can't be represented in V4L2\nwithout printing a message ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  \tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>  \n>  \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n> @@ -920,6 +942,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>  \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n>  \t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n>  \t}\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }\n> @@ -943,6 +966,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }\n> @@ -959,6 +983,13 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\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> @@ -977,6 +1008,7 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }","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 929BFBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Dec 2021 13:29:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E9C360872;\n\tTue,  7 Dec 2021 14:29:24 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 335F860592\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Dec 2021 14:29:23 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 84AFD556;\n\tTue,  7 Dec 2021 14:29:22 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"PDP86tne\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638883762;\n\tbh=KYcCM6SK5eh0Y1Pte2aUQ2jzSTq4an5w/TLwPVZHGJA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PDP86tneaPfr8Mxb97Bcw9O3Ms1Qy4dmb0gbW/22xGq1nny5zkUbUi7RN5vhsKjWt\n\thhsJ1T9w7/qgBBQCHY9gJa4uUcPmeowBqG1SJ0rdGukUUtTxAZ1EdNHM8hDSym3Mnq\n\tESSyvtBUFEJrlOeL46yMTr81MOOIyy4cNqG9PPXw=","Date":"Tue, 7 Dec 2021 15:28:53 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<Ya9hlcVa3TK2Xn/o@pendragon.ideasonboard.com>","References":"<20211206105032.13876-1-david.plowman@raspberrypi.com>\n\t<20211206105032.13876-5-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211206105032.13876-5-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v9 4/8] 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>","Cc":"tfiga@google.com, libcamera-devel@lists.libcamera.org,\n\thverkuil-cisco@xs4all.nl","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]