From patchwork Sat Aug 22 20:00:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9368 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 95609BD87C for ; Sat, 22 Aug 2020 20:01:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BD11C62710; Sat, 22 Aug 2020 22:01:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="C4QDNlkt"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4955E61EA0 for ; Sat, 22 Aug 2020 22:01:01 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D947929E for ; Sat, 22 Aug 2020 22:01:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1598126461; bh=/CKj5S48tCgLx9e/ISDOPZmfFLiqUjHaY7h7dtMEeSk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C4QDNlktvKV3K7iiTR5/SKKQgYSemwb4bxDLsQEQTaZqxL3pgZ7XWQIwVBTYeyVmG up3wW/bP59DmKwL/PL1Qo1ek2mbl3zGOwHf0eSvIQsAOg/OOH2ZUOAj9R6YCaunube 372NAup0PyLmdncz+/NArMkMsFJErDk6cirLtjHg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 22 Aug 2020 23:00:34 +0300 Message-Id: <20200822200037.20892-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200822200037.20892-1-laurent.pinchart@ideasonboard.com> References: <20200822200037.20892-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] libcamera: Replace utils::clamp() with std::clamp() 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" Now that libcamera uses C++17, the C++ standard library provides std::clamp(). Drop our custom utils::clamp() function. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- include/libcamera/internal/utils.h | 7 ------- src/ipa/rkisp1/rkisp1.cpp | 11 +++++------ src/libcamera/pipeline/ipu3/imgu.cpp | 3 ++- src/libcamera/pipeline/ipu3/ipu3.cpp | 12 ++++++------ src/libcamera/pipeline/vimc/vimc.cpp | 2 +- src/libcamera/utils.cpp | 8 -------- 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h index 45cd6f120c51..a1b644b0345b 100644 --- a/include/libcamera/internal/utils.h +++ b/include/libcamera/internal/utils.h @@ -65,13 +65,6 @@ unsigned int set_overlap(InputIt1 first1, InputIt1 last1, return count; } -/* C++11 doesn't provide std::clamp */ -template -const T& clamp(const T& v, const T& lo, const T& hi) -{ - return std::max(lo, std::min(v, hi)); -} - using clock = std::chrono::steady_clock; using duration = std::chrono::steady_clock::duration; using time_point = std::chrono::steady_clock::time_point; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 4bb1627342fd..3a1c50c4add0 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -24,7 +24,6 @@ #include #include "libcamera/internal/log.h" -#include "libcamera/internal/utils.h" namespace libcamera { @@ -234,13 +233,13 @@ void IPARkISP1::updateStatistics(unsigned int frame, double exposure; exposure = factor * exposure_ * gain_ / minGain_; - exposure_ = utils::clamp((uint64_t)exposure, - minExposure_, - maxExposure_); + exposure_ = std::clamp((uint64_t)exposure, + minExposure_, + maxExposure_); exposure = exposure / exposure_ * minGain_; - gain_ = utils::clamp((uint64_t)exposure, - minGain_, maxGain_); + gain_ = std::clamp((uint64_t)exposure, + minGain_, maxGain_); setControls(frame + 1); } diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index eb829e096561..a4d74a62f69a 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -7,6 +7,7 @@ #include "imgu.h" +#include #include #include @@ -129,7 +130,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc if (!isSameRatio(pipe->input, gdc)) { float estIFHeight = (iif.width * gdc.height) / static_cast(gdc.width); - estIFHeight = utils::clamp(estIFHeight, minIFHeight, iif.height); + estIFHeight = std::clamp(estIFHeight, minIFHeight, iif.height); bool found = false; ifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H); diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 019e50b8f444..2d881fe28f98 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -240,15 +240,15 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() unsigned int limit; limit = utils::alignDown(cio2Configuration_.size.width - 1, IMGU_OUTPUT_WIDTH_MARGIN); - cfg->size.width = utils::clamp(cfg->size.width, - IMGU_OUTPUT_MIN_SIZE.width, - limit); + cfg->size.width = std::clamp(cfg->size.width, + IMGU_OUTPUT_MIN_SIZE.width, + limit); limit = utils::alignDown(cio2Configuration_.size.height - 1, IMGU_OUTPUT_HEIGHT_MARGIN); - cfg->size.height = utils::clamp(cfg->size.height, - IMGU_OUTPUT_MIN_SIZE.height, - limit); + cfg->size.height = std::clamp(cfg->size.height, + IMGU_OUTPUT_MIN_SIZE.height, + limit); cfg->size.alignDownTo(IMGU_OUTPUT_WIDTH_ALIGN, IMGU_OUTPUT_HEIGHT_ALIGN); diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index cf244f11f242..7e237650b448 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -360,7 +360,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request) } int32_t value = lroundf(it.second.get() * 128 + offset); - controls.set(cid, utils::clamp(value, 0, 255)); + controls.set(cid, std::clamp(value, 0, 255)); } for (const auto &ctrl : controls) diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 615df46ac142..a5232902191e 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -146,14 +146,6 @@ std::string dirname(const std::string &path) * \return The number of elements in the intersection of the two ranges */ -/** - * \fn libcamera::utils::clamp(const T& v, const T& lo, const T& hi) - * \param[in] v The value to clamp - * \param[in] lo The lower boundary to clamp v to - * \param[in] hi The higher boundary to clamp v to - * \return lo if v is less than lo, hi if v is greater than hi, otherwise v - */ - /** * \typedef clock * \brief The libcamera clock (monotonic)