From patchwork Sun Feb 25 16:43:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19536 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 A7853BD160 for ; Sun, 25 Feb 2024 16:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE1D16286B; Sun, 25 Feb 2024 17:43:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Y/Uo833n"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8730661CA1 for ; Sun, 25 Feb 2024 17:43:46 +0100 (CET) Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA8234E6 for ; Sun, 25 Feb 2024 17:43:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708879415; bh=d9h1gzUILf4BFiEHLiU/dEI9YPfQTYnYHJYYLNTcW8M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Y/Uo833n9VTxiXOjhUUBzBq5bfqg5eKVd+06uLGzwPuCdzI0Os9oYpk3iQPks1XGz J+g9Tt6NxlqVx6bBod6AnADkckETOGj9TfW+c/BDiqmeueaLS+jH5NkpAyRKE7nglQ KpUdWfcPmJB4PIHwQj1DgK6GVUlef7IH2sB+l890= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 1/2] libcamera: utils: Add to_underlying() helper function Date: Sun, 25 Feb 2024 18:43:46 +0200 Message-ID: <20240225164348.10073-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225164348.10073-1-laurent.pinchart@ideasonboard.com> References: <20240225164348.10073-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" C++23 has a std::to_underlying() helper function that converts an enumeration value to its underlying type. Add a compatible implementation to the libcamera::utils namespace. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/base/utils.h | 6 ++++++ src/libcamera/base/utils.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 37d9af609ec7..922e4dfaf9fa 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -369,6 +369,12 @@ decltype(auto) abs_diff(const T &a, const T &b) double strtod(const char *__restrict nptr, char **__restrict endptr); +template +constexpr std::underlying_type_t to_underlying(Enum e) noexcept +{ + return static_cast>(e); +} + } /* namespace utils */ #ifndef __DOXYGEN__ diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp index 3b73b442260a..2f4c3177ac13 100644 --- a/src/libcamera/base/utils.cpp +++ b/src/libcamera/base/utils.cpp @@ -521,6 +521,16 @@ double strtod(const char *__restrict nptr, char **__restrict endptr) #endif } +/** + * \fn to_underlying(Enum e) + * \brief Convert an enumeration to its underlygin type + * \param[in] e Enumeration value to convert + * + * This function is equivalent to the C++23 std::to_underlying(). + * + * \return The value of e converted to its underlying type + */ + } /* namespace utils */ #ifndef __DOXYGEN__ From patchwork Sun Feb 25 16:43:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19537 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 A3D45BD160 for ; Sun, 25 Feb 2024 16:43:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5703762865; Sun, 25 Feb 2024 17:43:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qCVtiqfr"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1887C61CA1 for ; Sun, 25 Feb 2024 17:43:48 +0100 (CET) Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 364EA4E6 for ; Sun, 25 Feb 2024 17:43:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708879417; bh=9DQ/QJLS/r5TGcwuNFIFsbzRr4Jo65LM9kI6MEw4Png=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qCVtiqfroOOxnjjBQtsH2Irm/nfLVsMrKOpm5eNEdyT1mBGWx6hGacYYptObJip3G +g1sL1tgFu7bBGmZVJ7U4vOmdn8/QKGnc2DdrZO6Bm7Qgt2KZQ08Tbsg+k7R905yNQ rFXs3aNJXFv4BDIU9OS9J9/TK14esDmT/wX8ukZc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/2] libcamera: Use utils::to_underlying() Date: Sun, 25 Feb 2024 18:43:47 +0200 Message-ID: <20240225164348.10073-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225164348.10073-1-laurent.pinchart@ideasonboard.com> References: <20240225164348.10073-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace manual implementations of the utils::to_underlying() helper with calls to the function. Signed-off-by: Laurent Pinchart --- src/ipa/rpi/controller/rpi/sdn.cpp | 3 ++- src/libcamera/pipeline/rpi/common/rpi_stream.h | 10 +++------- src/libcamera/stream.cpp | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/sdn.cpp b/src/ipa/rpi/controller/rpi/sdn.cpp index 6743919e6b36..2f777dd725e2 100644 --- a/src/ipa/rpi/controller/rpi/sdn.cpp +++ b/src/ipa/rpi/controller/rpi/sdn.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "../denoise_status.h" #include "../noise_status.h" @@ -60,7 +61,7 @@ void Sdn::prepare(Metadata *imageMetadata) status.noiseConstant = noiseStatus.noiseConstant * deviation_; status.noiseSlope = noiseStatus.noiseSlope * deviation_; status.strength = strength_; - status.mode = static_cast>(mode_); + status.mode = utils::to_underlying(mode_); imageMetadata->set("denoise.status", status); LOG(RPiSdn, Debug) << "programmed constant " << status.noiseConstant diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index fc2bdfe25d4a..48ed41abea01 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -14,6 +14,7 @@ #include #include +#include #include @@ -180,19 +181,14 @@ private: template class Device : public std::array { -private: - constexpr auto index(E e) const noexcept - { - return static_cast>(e); - } public: Stream &operator[](E e) { - return std::array::operator[](index(e)); + return std::array::operator[](utils::to_underlying(e)); } const Stream &operator[](E e) const { - return std::array::operator[](index(e)); + return std::array::operator[](utils::to_underlying(e)); } }; diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index f3e00ead5ac6..540a428eacdd 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -433,7 +433,7 @@ std::ostream &operator<<(std::ostream &out, StreamRole role) "Viewfinder", }; - out << names[static_cast>(role)]; + out << names[utils::to_underlying(role)]; return out; }