From patchwork Tue Dec 21 23:44:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15209 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 629DCBE080 for ; Tue, 21 Dec 2021 23:45:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3A48608F9; Wed, 22 Dec 2021 00:45:01 +0100 (CET) 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="b/qFjn+N"; 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 7D90760223 for ; Wed, 22 Dec 2021 00:44:59 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D6873894; Wed, 22 Dec 2021 00:44:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1640130299; bh=j2Cz2yqgW9fXPJHtjHMZi04wZDdEnoEJt3StdzKXNRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/qFjn+NJUGoud8qi6jL6xs/h3HR2YPczfVaxhn7gV63dfNR99EFy+KEKPcTX5BIP M6p9ACeyI9OajB8Tj/FBtFx4Q/vi8oCcE61D71P4SQraKzqsNukvnGTCjfO/mZWayg sk7Qu6rVlBhMV5X6zlZ0iVCu7F6k7ZnUeD+aC+ao= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Dec 2021 01:44:48 +0200 Message-Id: <20211221234448.21944-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211219232714.11427-4-laurent.pinchart@ideasonboard.com> References: <20211219232714.11427-4-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1.1 3/4] ipa: raspberrypi: Add camera helper for Sony IMX296 sensor 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" From: Naushir Patuck The Sony IMX296 sensor has an exponential gain model, and adds a fixed 14.26µs offset to the exposure time expressed in line units. Signed-off-by: Naushir Patuck Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham --- Changes since v1: - Drop metadata support --- src/ipa/raspberrypi/cam_helper_imx296.cpp | 69 +++++++++++++++++++++++ src/ipa/raspberrypi/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 src/ipa/raspberrypi/cam_helper_imx296.cpp base-commit: 8ff5a8d548eee7c2cb14b355867debdb29e75419 prerequisite-patch-id: 94059e3f2e08c8ed4c077cd3fbc9ab5f6a43cbe5 prerequisite-patch-id: c4afb92de814501d8e0b6f9daa967be862351ed8 diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp new file mode 100644 index 000000000000..a1a771cb96d5 --- /dev/null +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Limited + * + * cam_helper_imx296.cpp - Camera helper for IMX296 sensor + */ + +#include +#include +#include + +#include "cam_helper.hpp" + +using namespace RPiController; +using libcamera::utils::Duration; +using namespace std::literals::chrono_literals; + +class CamHelperImx296 : public CamHelper +{ +public: + CamHelperImx296(); + uint32_t GainCode(double gain) const override; + double Gain(uint32_t gain_code) const override; + uint32_t ExposureLines(Duration exposure) const override; + Duration Exposure(uint32_t exposure_lines) const override; + +private: + static constexpr uint32_t maxGainCode = 239; + static constexpr Duration timePerLine = 550.0 / 37.125e6 * 1.0s; + + /* + * Smallest difference between the frame length and integration time, + * in units of lines. + */ + static constexpr int frameIntegrationDiff = 4; +}; + +CamHelperImx296::CamHelperImx296() + : CamHelper(nullptr, frameIntegrationDiff) +{ +} + +uint32_t CamHelperImx296::GainCode(double gain) const +{ + uint32_t code = 20 * std::log10(gain) * 10; + return std::min(code, maxGainCode); +} + +double CamHelperImx296::Gain(uint32_t gain_code) const +{ + return std::pow(10.0, gain_code / 200.0); +} + +uint32_t CamHelperImx296::ExposureLines(Duration exposure) const +{ + return (exposure - 14.26us) / timePerLine; +} + +Duration CamHelperImx296::Exposure(uint32_t exposure_lines) const +{ + return exposure_lines * timePerLine + 14.26us; +} + +static CamHelper *Create() +{ + return new CamHelperImx296(); +} + +static RegisterCamHelper reg("imx296", &Create); diff --git a/src/ipa/raspberrypi/meson.build b/src/ipa/raspberrypi/meson.build index 176055f42248..32897e07dad9 100644 --- a/src/ipa/raspberrypi/meson.build +++ b/src/ipa/raspberrypi/meson.build @@ -21,6 +21,7 @@ rpi_ipa_sources = files([ 'cam_helper_ov5647.cpp', 'cam_helper_imx219.cpp', 'cam_helper_imx290.cpp', + 'cam_helper_imx296.cpp', 'cam_helper_imx477.cpp', 'cam_helper_imx519.cpp', 'cam_helper_ov9281.cpp',