From patchwork Mon Aug 25 11:46:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 24232 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 F2BBDBD87C for ; Mon, 25 Aug 2025 11:46:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1BCFB692ED; Mon, 25 Aug 2025 13:46:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H3QiD+L+"; 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 7D77B692CA for ; Mon, 25 Aug 2025 13:46:51 +0200 (CEST) Received: from neptunite.infra.iob (unknown [IPv6:2404:7a81:160:2100:39d7:37aa:64a2:5533]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A1512285; Mon, 25 Aug 2025 13:45:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1756122349; bh=8IQKnmlwbepxqvD//dDB7EyFkYjR45Rji9TZ4F3EMOk=; h=From:To:Cc:Subject:Date:From; b=H3QiD+L+HkgG2NNLLDPXF2/twHAPfVX7Vmk528nPLr9zi0PUEB7bDydX0UugZuLEd JdKRcrQk5n2VFjYNvVRbQU9RnIroyPY3SHt5QmNfRKDMElufUJUxmGEj8NWSjtntJZ 142hPSF0Hh3mmXcYbHzOY4+gx6DNnbKfB8gDA1G4= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH] utils: Add unary negation operation to Duration Date: Mon, 25 Aug 2025 20:46:42 +0900 Message-ID: <20250825114642.576534-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 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" In the near future we will add a SyncAdjustment control for adjusting the frame duration via the sync algorithm. This control needs to be able to take on a negative value, since the frame duration can be shortened in addition to being extended. While the control is an int, it would be convenient to be able to clamp it to frame duration limits, which are usually handled as utils::Duration values internally. To allow this using utils::Duration, add a unary negation operation to utils::Duration. Also add a test for the operator. Signed-off-by: Paul Elder Reviewed-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- include/libcamera/base/utils.h | 5 +++++ src/libcamera/base/utils.cpp | 6 ++++++ test/utils.cpp | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index f21c6dc016ec..cb8caaa9bacc 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -394,6 +394,11 @@ public: return c.count(); } + constexpr Duration operator-() const + { + return BaseDuration::operator-(); + } + explicit constexpr operator bool() const { return *this != BaseDuration::zero(); diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp index bcfc1941a92a..cb9fe0049c83 100644 --- a/src/libcamera/base/utils.cpp +++ b/src/libcamera/base/utils.cpp @@ -425,6 +425,12 @@ std::string toAscii(const std::string &str) * \return The tick count of the Duration expressed in \a Period */ +/** + * \fn Duration::operator-() + * \brief Negation operator to negate a \a Duration + * \return The duration, with the number of ticks negated + */ + /** * \fn Duration::operator bool() * \brief Boolean operator to test if a \a Duration holds a non-zero time value diff --git a/test/utils.cpp b/test/utils.cpp index d25475cb93b9..195fddc97d97 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -167,6 +167,12 @@ protected: return TestFail; } + exposure = 100ms; + if ((-exposure).get() != -100) { + cerr << "utils::Duration failed negation" << endl; + return TestFail; + } + return TestPass; }