From patchwork Tue Nov 24 16:58:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 29084 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 06D32C3355 for ; Tue, 24 Nov 2026 16:59:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5672B6A9CB; Tue, 24 Nov 2026 17:59:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tP0lDyOE"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A7E106A9C7 for ; Tue, 24 Nov 2026 17:59:00 +0100 (CET) Received: from [192.168.95.178] (mob-5-90-67-29.net.vodafone.it [5.90.67.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 83A43BE1; Tue, 24 Nov 2026 17:56:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795539387; bh=QL2+3JPTqvaQXjSTwqbO7n4B5o80ky20OJGjyXF/yFI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tP0lDyOEVRG54IW3X5hQAlN/GhNXqNo38DYOiewO7XlLiymPz9vBG5xIE4NpyuXgU a2PPSuchO+ekKH1XXMJb8w6EZbJaMEXEvHCUGhOS8DIr0jw9P4vVNKYSt2yNdYoK9u CrxusAO9QQAvmMquWLZ5uBb5chZii63DvF7Rwxg0= From: Jacopo Mondi Date: Tue, 24 Nov 2026 17:58:06 +0100 Subject: [PATCH v3 5/5] libipa: camera_sensor_helper: Add Mira016 MIME-Version: 1.0 Message-Id: <20261124-b4-mira016-v3-5-b71d2cf61889@ideasonboard.com> References: <20261124-b4-mira016-v3-0-b71d2cf61889@ideasonboard.com> In-Reply-To: <20261124-b4-mira016-v3-0-b71d2cf61889@ideasonboard.com> To: Philippe Baetens , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2509; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=QL2+3JPTqvaQXjSTwqbO7n4B5o80ky20OJGjyXF/yFI=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBrBcJEtxPKLhuT0pfhZgWkwnRiDXsqkwUutYYdy RT+Mf2FMNWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCawXCRAAKCRByNAaPFqFW PJWdD/9pKWmhiW6aWbBILaWVWEvkmX3gEi6S1PYrE/pPvBz9LSJW9cMwQuGtd/wVa9la7Y1ScE9 UVq2s38J3G9PwApHix/xxZz5hWIlTUyHUx6KJx5Yqjazv65AOMGS7uN5REEGABkRhf8iYMYW5gq wGcMBXP69VAsno0wRbU4dDmXeL5B41j3OyIAkKWhrJ3nr/0n6pURZqNgyIDNJy6wTmNWZ8QuCAA Se06EflSvUuujbnZQb6Y64Z3diGF+Zsfo6VP1lxm0htSzJTKF+nNwsgo+fOof6helDOu5pB/yxF 4Hd8BihYGJ1D+13Rn8WPkoWChrbOu0X4JP2d+/4BVEol2tpTNVV9wbiZrfElUg2HHm9SFJB/82H OdL/nXZ8HyZF9Egb9OQB6PAKihRaD7XfqvfMLqy1wPRjT7fiy6SlQOacicm9bpYKaqNEDuhaS5U 8ZVQNBgUYzNhQNHfNrl/kuXav7qeTIX1pJu39PSVSgFczAp8/FbE5nudd6GKK2RMrMaC8JUNNlq +MMKX2RndyMf740KpVYFIrlSXCyZqr5LO8VX4WRbU94/U3bckBfK8AEh+A6g5lTYk228lp7+W1x jcuEMMzFn6CepxMgwgYQAT3yAl5Byj+G20O6W8sb/aq0vksRTG+SrBPcBtkzaNfb/Ozzu3TgsYv EMFN56w+MNdzKcA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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" Add a camera sensor helper for the AMS-OSRAM Mira016 sensor. The sensor black level has been measured by averaging the pixel values while covering the lens. The analogue gain code is the gain in thousandths (1000 is 1x), and the driver computes the fine gain registers from it, rounding to: gain = 57 * 2^n / (ADC_GAIN + 21). the driver programs for a code, so the IPA knows the real gain. The gainCode() function returns the gain times 1000, and the gain() function computes the gain as the driver does, so the IPA knows the real applied gain. Signed-off-by: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index c5c8a447567f..7cb5e1c2004d 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -787,6 +787,49 @@ public: }; REGISTER_CAMERA_SENSOR_HELPER(CameraSensorHelperOv08x40, "ov08x40") +class CameraSensorHelperMira016 : public CameraSensorHelper +{ +public: + /* + * The driver's analogue gain code is the gain in thousandths (1000 is + * 1x), up to 16000 in 8-bit modes, 4000 in 10-bit modes and only 1000 + * in 12-bit modes. The driver rounds it to the nearest gain the fine + * gain registers give: + * + * gain = 57 * 2^n / (ADC_GAIN + 21) + * + * n is the octave of the gain (0 to 4) and ADC_GAIN is 21 to 63. Up to + * 4x the 8 and 10-bit modes give the same gains, so the conversion does + * not depend on the mode. + */ + CameraSensorHelperMira016() + { + blackLevel_ = 2048; + } + + uint32_t gainCode(double gain) const override + { + return std::max(std::lround(gain * 1000), 1000); + } + + double gain(uint32_t gainCode) const override + { + uint32_t code = std::clamp(gainCode, 1000, 16000); + uint32_t n = std::floor(std::log2(84.0 * static_cast(code) / + kAdcRampStep)); + + uint32_t num = kAdcRampStep << n; + int adcGain = ((num + code / 2) / code) - 21; + adcGain = std::clamp(adcGain, 0, 63); + + return static_cast(num) / (adcGain + 21) / 1000.0; + } + +private: + static constexpr unsigned int kAdcRampStep = 5700; +}; +REGISTER_CAMERA_SENSOR_HELPER(CameraSensorHelperMira016, "mira016") + class CameraSensorHelperMira220 : public CameraSensorHelper { public: