From patchwork Mon Aug 29 16:37:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17230 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 973D7C3272 for ; Mon, 29 Aug 2022 16:38:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CE4361FCB; Mon, 29 Aug 2022 18:38:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661791090; bh=acK2S0GxZrfhSb3ahOQmVL+wQKOTvIggEMmTpEK2VcY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iRyZV8WpNfhmYwAJfMgk20GBtPfD0lC/xr6w98X2LS6ec9GdYVgba/zfAaFzmSGnm t2eXe+A9nHGF6Z8GGpLaLdDDq5cM8sMfqeXFoqX7euqynEA5S1dw8SGTUlDoVRe8OU 5oNkQa2vGstu7u+NPLEQ2cIM/Alumfs+NcPopDNRXHTvdtvMDWTj9+UqQwFy+ZXJ9r H3QCazHgY8y2h7vp1T6wPXBCelGP+WAq3zLvYwLxO9RQz0o/Mm624DhS+0AT01HTbF K6tSDvoH6lxvcc8CNvlmQj8PiHxm9PS8qZwTo33zd6qw1IdQx+aYz15YxVRId4Ncio 5lQJjE+LNeAVg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1D0FB61FBA for ; Mon, 29 Aug 2022 18:38:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gmLarNg7"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [IPv6:2401:4900:1f3f:1548:78ac:4a3:edc3:c28a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1780B8BD; Mon, 29 Aug 2022 18:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661791086; bh=acK2S0GxZrfhSb3ahOQmVL+wQKOTvIggEMmTpEK2VcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gmLarNg7PoGl2P/wIKobnpPw9NLYstOuruyoy/gllwp7j+kWs/9IAxYgCqTnsNf0l y9X4Vm0H3IfoH8EEVoewtveT5AXW4+vVFJWP+gcgCi2SS87iPNhq+sKg5ul8uHZoaq fcw/TxlyXUzRbkCetawA43oTaSmi+jel6uw9sX8g= To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Aug 2022 22:07:38 +0530 Message-Id: <20220829163742.1006102-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829163742.1006102-1-umang.jain@ideasonboard.com> References: <20220829163742.1006102-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/7] libcamera: v4l2_videodevice: Improve toColorSpace() readability X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Abstract out usage of V4L2Device::toColorspace() to a separate namespace. Since it is separated out in an unnamed namespace, the V4L2Device::toColorSpace() function needs to made public. This is not an issue since V4L2Device is an internal class. No functional changes intended. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_device.h | 14 +++++++------- src/libcamera/v4l2_videodevice.cpp | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 75304be1..606332e1 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -49,6 +49,13 @@ public: void updateControlInfo(); + template + static std::optional toColorSpace(const T &v4l2Format, + PixelFormatInfo::ColourEncoding colourEncoding); + + template + static int fromColorSpace(const std::optional &colorSpace, T &v4l2Format); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); @@ -60,13 +67,6 @@ protected: int fd() const { return fd_.get(); } - template - static std::optional toColorSpace(const T &v4l2Format, - PixelFormatInfo::ColourEncoding colourEncoding); - - template - static int fromColorSpace(const std::optional &colorSpace, T &v4l2Format); - private: static ControlType v4l2CtrlType(uint32_t ctrlType); static std::unique_ptr v4l2ControlId(const v4l2_query_ext_ctrl &ctrl); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 0e3f5436..b443253d 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -914,6 +914,17 @@ int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set) return 0; } +namespace { + +template +std::optional getColorSpace(const T &v4l2Format) +{ + V4L2PixelFormat fourcc{ v4l2Format.pixelformat }; + return V4L2Device::toColorSpace(v4l2Format, PixelFormatInfo::info(fourcc).colourEncoding); +} + +} /* namespace */ + int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) { struct v4l2_format v4l2Format = {}; @@ -931,8 +942,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) format->size.height = pix->height; format->fourcc = V4L2PixelFormat(pix->pixelformat); format->planesCount = pix->num_planes; - format->colorSpace = - toColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding); + format->colorSpace = getColorSpace(*pix); for (unsigned int i = 0; i < format->planesCount; ++i) { format->planes[i].bpl = pix->plane_fmt[i].bytesperline; @@ -988,8 +998,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) format->planes[i].bpl = pix->plane_fmt[i].bytesperline; format->planes[i].size = pix->plane_fmt[i].sizeimage; } - format->colorSpace = - toColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding); + format->colorSpace = getColorSpace(*pix); return 0; } @@ -1013,8 +1022,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format) format->planesCount = 1; format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; - format->colorSpace = - toColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding); + format->colorSpace = getColorSpace(*pix); return 0; } @@ -1056,8 +1064,7 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) format->planesCount = 1; format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; - format->colorSpace = - toColorSpace(*pix, PixelFormatInfo::info(format->fourcc).colourEncoding); + format->colorSpace = getColorSpace(*pix); return 0; }