[{"id":24875,"web_url":"https://patchwork.libcamera.org/comment/24875/","msgid":"<20220901033703.GE27075@pyrite.rasen.tech>","date":"2022-09-01T03:37:03","subject":"Re: [libcamera-devel] [PATCH v4 3/7] libcamera: v4l2_videodevice:\n\tImprove toColorSpace() readability","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"On Tue, Aug 30, 2022 at 01:17:21PM +0530, Umang Jain via libcamera-devel wrote:\n> Wrap V4L2Device::toColorspace() inside a private static member\n> function in V4L2VideoDevice class. It improves readability in\n> setting the colorspace for V4L2DeviceFormat.\n> \n> No functional changes intended.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  3 +++\n>  src/libcamera/v4l2_videodevice.cpp            | 19 +++++++++++--------\n>  2 files changed, 14 insertions(+), 8 deletions(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index ed98a284..d157a447 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -268,6 +268,9 @@ private:\n>  \n>  \tvoid watchdogExpired();\n>  \n> +\ttemplate<typename T>\n> +\tstatic std::optional<ColorSpace> toColorSpace(const T &v4l2Format);\n> +\n>  \tV4L2Capability caps_;\n>  \tV4L2DeviceFormat format_;\n>  \tconst PixelFormatInfo *formatInfo_;\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 0e3f5436..955e1508 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -914,6 +914,13 @@ int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n>  \treturn 0;\n>  }\n>  \n> +template<typename T>\n> +std::optional<ColorSpace> V4L2VideoDevice::toColorSpace(const T &v4l2Format)\n> +{\n> +\tV4L2PixelFormat fourcc{ v4l2Format.pixelformat };\n> +\treturn V4L2Device::toColorSpace(v4l2Format, PixelFormatInfo::info(fourcc).colourEncoding);\n> +}\n> +\n>  int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n>  {\n>  \tstruct v4l2_format v4l2Format = {};\n> @@ -931,8 +938,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 =\n> -\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\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> @@ -988,8 +994,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 =\n> -\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }\n> @@ -1013,8 +1018,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 =\n> -\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }\n> @@ -1056,8 +1060,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 =\n> -\t\ttoColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding);\n> +\tformat->colorSpace = toColorSpace(*pix);\n>  \n>  \treturn 0;\n>  }\n> -- \n> 2.37.2\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 BF684C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 Sep 2022 03:37:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E326E61FC7;\n\tThu,  1 Sep 2022 05:37:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D4F7161F9A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 Sep 2022 05:37:11 +0200 (CEST)","from pyrite.rasen.tech (unknown [50.228.9.220])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 65E35481;\n\tThu,  1 Sep 2022 05:37:09 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662003432;\n\tbh=iPnH5tnjPZb/QieLWpXfq8/bsFm1Xx5YaDBbNaH1Ut0=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=yNCJMx1LZvQzgU5AnvgdXmwNoA+NaHq+mbkLMMot8j1yoVUXrQJXLbN2U09s0xSDP\n\tNHCn9OgAzMXQ/NxgZQ8hWOrIl3BJp2MfqNOWwB2ahyIZtr6+epX+79tY1Kg+jrswvR\n\t+N+YJUt3lIq2XoYSdvo5ZdOeTXI4v8MWD4YsKMx9RszeAupvyUEREn/x+j2kiu6Xts\n\tjPOBskscLDypUQaV8NCh+ocbr5yhb6jmbh7yVgkTAeiYKoIGFBAaHy9BaKyL/UCdhz\n\tVlwlo4ooZfzjf2RAVerSSYMl04rUXLbuQc+3v5VqcQgcT+LWwgKuhQiRFe6DdUxSaZ\n\tB9Uf+Mr17PuOw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662003431;\n\tbh=iPnH5tnjPZb/QieLWpXfq8/bsFm1Xx5YaDBbNaH1Ut0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=aYGK4MbyW8jO9UkSz0b6Qeu091lB6Xn9e7QsSpzSsfy/u1s78ozDv/6cLAcr0m89H\n\tJPNRSXWz3M7i5xhNo/7kltLTbVfhSrMoNK2gEdMvMUdLcaoQ0mpTRn1Sq1p++d/zO4\n\tzxQRsBZMTD8Dei/BMH0d2fKpjGcrDAq4+xY9GbAo="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"aYGK4Mby\"; dkim-atps=neutral","Date":"Wed, 31 Aug 2022 23:37:03 -0400","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<20220901033703.GE27075@pyrite.rasen.tech>","References":"<20220830074725.1059643-1-umang.jain@ideasonboard.com>\n\t<20220830074725.1059643-4-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220830074725.1059643-4-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 3/7] libcamera: v4l2_videodevice:\n\tImprove toColorSpace() readability","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>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"rishikeshdonadkar@gmail.com, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]