From patchwork Mon Oct 3 08:39:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17490 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 20BE0C3285 for ; Mon, 3 Oct 2022 08:40:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3A7E62CE7; Mon, 3 Oct 2022 10:40:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664786402; bh=D+O3A92GH+pY7AyNAjsM9mtZeLOyaplKIjW+yl5Z+/Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QbFV2BFSj8xhrjotiP3z34pd9j45YURUMqwx+/bbCAXRwz7wFNp3swRe5g8vYeSAz BeLRK+Jl29LxSvXA5Fu8c2yFGtwizHkvLVuBgLo1Ovnm2eN+I9ml6uzGREVcNvzUq7 DAl4QqaAjtHgKuTCOEkeVsV0PYL1duIIRrRmrIygRZsuOzDxROrzL6G+9Joo/parS5 xAE3kHbHS0mFaXXP9Ja2feMYY/wtK67787dUleG11Vpvj3n50LFoOWgyuuVqyuWO3P wjdKg1bk5UdeRQTPBvFETWn6oHx31/K2wPnAuv7ewChP/aEdYMUhfJs5sy5tGwVeZB spjneakH8ICSg== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18E0161F74 for ; Mon, 3 Oct 2022 10:40:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Cbf0RYlE"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id n35-20020a05600c502300b003b4924c6868so6731728wmr.1 for ; Mon, 03 Oct 2022 01:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=tlMV8G5wGt0Z/9WlSigS1mH/aBSMhPPT2FEqWU+4Qx4=; b=Cbf0RYlErHLSczlpGUKVLhA5msEwM1YWEDFrclBsaN5z1j+3MwJfQan7/EHWoqMn2N sH35PXT6NWb+xWz4CldjYvT1Y8x1SYl1TAZ3xT5YkY6OAIPSf17Ucj+V6C+O/8IBJlvK bOeLqp602SQFYuMoEmhFpLLrOcxHsxNrw91B2Zl8qwiYWFC4tjtReZuOswGKjwLKMEwR K2zkxlDOpUrmGUKKkUuvN9YXBlAkNpJLkMg+7PBvCwSRzXom8C7rYwm4CJPjudfqq6zn p2/loEgFPKt0kskSPzGC2IHo/CfIOaFA8Kn9skEiVALe/y5w83cCHsVF4V/HyTlfOkCt p/zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=tlMV8G5wGt0Z/9WlSigS1mH/aBSMhPPT2FEqWU+4Qx4=; b=SHscvuMtGBJLOyv1gZCAjird0eD8a7t7dh4zxXbVRan0NicXpZ4rPh+c4064eR8i7z xNQ/XMDMrQTOpTnK5ZIEZCe7EcIH3QDMaT5fwjnw2EmUGROWXIFmyvBrCn8259vde+NA dBGAB0xae8dP7QUGAx6H2i4mvlKpuMRseTogJuxOUijrZIx9x41JEI/in/sDBfvxRAAa XCOtaohN3KcYewh7WVu944uQ1qQzu95TDCEnzS4aSwqzx3GfaqeGyo8CDzNJJwdC8reA 38NEz6lgWHVzQjDwPthY8vUZuuTJL3ofxRWnv/FbcWs/FDOlBq9oTSGudvCenNzsZBSb GGbQ== X-Gm-Message-State: ACrzQf3v0LvpYVDtRXHm0gtD9iUxcdGYwtDP87g63Q2dF693GgmqSJmX +qs4Q0D0WaSZkpHR0h4V4itebgdduTgi6A== X-Google-Smtp-Source: AMsMyM4ziDz6LBKzGH4NjxC0DFzwaF13IpUOtmhsm0A4lvtx1TMjOs6ZpLire2IkH8Ry+gbYj9IRtQ== X-Received: by 2002:a05:600c:4e15:b0:3b4:a621:b54e with SMTP id b21-20020a05600c4e1500b003b4a621b54emr6057678wmq.47.1664786399287; Mon, 03 Oct 2022 01:39:59 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i13-20020a5d55cd000000b0022ae59d472esm8922787wrw.112.2022.10.03.01.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 01:39:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 3 Oct 2022 09:39:29 +0100 Message-Id: <20221003083934.31629-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221003083934.31629-1-naush@raspberrypi.com> References: <20221003083934.31629-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/9] ipa: raspberrypi: Pass lineLength into the CamHelper API 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: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Update CamHelper::exposureLines() and CamHelper::exposure() to take a line length duration parameter for use in the exposure calculations. For now, only use the minimum line length for all the calculations to match the existing IPA behavior. Signed-off-by: Naushir Patuck --- src/ipa/raspberrypi/cam_helper.cpp | 12 ++++++------ src/ipa/raspberrypi/cam_helper.h | 6 ++++-- src/ipa/raspberrypi/cam_helper_imx219.cpp | 3 ++- src/ipa/raspberrypi/cam_helper_imx296.cpp | 10 ++++++---- src/ipa/raspberrypi/cam_helper_imx477.cpp | 7 ++++--- src/ipa/raspberrypi/cam_helper_imx519.cpp | 7 ++++--- src/ipa/raspberrypi/controller/camera_mode.h | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 8 ++++---- 8 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index 42251ba29682..fd3527b94501 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -61,16 +61,16 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, { } -uint32_t CamHelper::exposureLines(const Duration exposure) const +uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const { assert(initialized_); - return exposure / mode_.minLineLength; + return exposure / lineLength; } -Duration CamHelper::exposure(uint32_t exposureLines) const +Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const { assert(initialized_); - return exposureLines * mode_.minLineLength; + return exposureLines * lineLength; } uint32_t CamHelper::getVBlanking(Duration &exposure, @@ -78,7 +78,7 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, Duration maxFrameDuration) const { uint32_t frameLengthMin, frameLengthMax, vblank; - uint32_t exposureLines = CamHelper::exposureLines(exposure); + uint32_t exposureLines = CamHelper::exposureLines(exposure, mode_.minLineLength); assert(initialized_); @@ -94,7 +94,7 @@ uint32_t CamHelper::getVBlanking(Duration &exposure, * re-calculate if it has been clipped. */ exposureLines = std::min(frameLengthMax - frameIntegrationDiff_, exposureLines); - exposure = CamHelper::exposure(exposureLines); + exposure = CamHelper::exposure(exposureLines, mode_.minLineLength); /* Limit the vblank to the range allowed by the frame length limits. */ vblank = std::clamp(exposureLines + frameIntegrationDiff_, diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h index 70d62719da86..9b5e602689f3 100644 --- a/src/ipa/raspberrypi/cam_helper.h +++ b/src/ipa/raspberrypi/cam_helper.h @@ -78,8 +78,10 @@ public: virtual void prepare(libcamera::Span buffer, Metadata &metadata); virtual void process(StatisticsPtr &stats, Metadata &metadata); - virtual uint32_t exposureLines(libcamera::utils::Duration exposure) const; - virtual libcamera::utils::Duration exposure(uint32_t exposureLines) const; + virtual uint32_t exposureLines(const libcamera::utils::Duration exposure, + const libcamera::utils::Duration lineLength) const; + virtual libcamera::utils::Duration exposure(uint32_t exposureLines, + const libcamera::utils::Duration lineLength) const; virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, libcamera::utils::Duration minFrameDuration, libcamera::utils::Duration maxFrameDuration) const; diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 7ded07a213cd..98a3b31956ec 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -94,7 +94,8 @@ void CamHelperImx219::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp index ab1d157aaf45..74361ffe7cc2 100644 --- a/src/ipa/raspberrypi/cam_helper_imx296.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -21,8 +21,8 @@ public: CamHelperImx296(); uint32_t gainCode(double gain) const override; double gain(uint32_t gainCode) const override; - uint32_t exposureLines(Duration exposure) const override; - Duration exposure(uint32_t exposureLines) const override; + uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override; + Duration exposure(uint32_t exposureLines, const Duration lineLength) const override; private: static constexpr uint32_t maxGainCode = 239; @@ -51,12 +51,14 @@ double CamHelperImx296::gain(uint32_t gainCode) const return std::pow(10.0, gainCode / 200.0); } -uint32_t CamHelperImx296::exposureLines(Duration exposure) const +uint32_t CamHelperImx296::exposureLines(const Duration exposure, + [[maybe_unused]] const Duration lineLength) const { return (exposure - 14.26us) / timePerLine; } -Duration CamHelperImx296::exposure(uint32_t exposureLines) const +Duration CamHelperImx296::exposure(uint32_t exposureLines, + [[maybe_unused]] const Duration lineLength) const { return exposureLines * timePerLine + 14.26us; } diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index aa306d6661c6..71529bdd3034 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -144,9 +144,9 @@ uint32_t CamHelperImx477::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx477::exposureLines(exposure); + exposureLines = CamHelperImx477::exposureLines(exposure, mode_.minLineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx477::exposure(exposureLines); + exposure = CamHelperImx477::exposure(exposureLines, mode_.minLineLength); } return frameLength - mode_.height; @@ -170,7 +170,8 @@ void CamHelperImx477::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); deviceStatus.sensorTemperature = std::clamp(registers.at(temperatureReg), -20, 80); diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index 54e104e7659a..2c120dad1680 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -144,9 +144,9 @@ uint32_t CamHelperImx519::getVBlanking(Duration &exposure, if (shift) { /* Account for any rounding in the scaled frame length value. */ frameLength <<= shift; - exposureLines = CamHelperImx519::exposureLines(exposure); + exposureLines = CamHelperImx519::exposureLines(exposure, mode_.minLineLength); exposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff); - exposure = CamHelperImx519::exposure(exposureLines); + exposure = CamHelperImx519::exposure(exposureLines, mode_.minLineLength); } return frameLength - mode_.height; @@ -170,7 +170,8 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap ®isters, { DeviceStatus deviceStatus; - deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg)); + deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg), + mode_.minLineLength); deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg)); deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg); diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h index b7e73aae4698..cda6ac4e200a 100644 --- a/src/ipa/raspberrypi/controller/camera_mode.h +++ b/src/ipa/raspberrypi/controller/camera_mode.h @@ -31,7 +31,7 @@ struct CameraMode { double scaleX, scaleY; /* scaling of the noise compared to the native sensor mode */ double noiseFactor; - /* line time */ + /* minimum and maximum line times */ libcamera::utils::Duration minLineLength, maxLineLength; /* any camera transform *not* reflected already in the camera tuning */ libcamera::Transform transform; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 67326bcf4a14..13807f4d47f7 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -477,7 +477,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const uint32_t exposureMin = sensorCtrls_.at(V4L2_CID_EXPOSURE).min().get(); ctrlMap[&controls::ExposureTime] = - ControlInfo(static_cast(helper_->exposure(exposureMin).get()), + ControlInfo(static_cast(helper_->exposure(exposureMin, mode_.minLineLength).get()), static_cast(maxShutter.get())); result->controlInfo = ControlInfoMap(std::move(ctrlMap), controls::controls); @@ -550,7 +550,7 @@ void IPARPi::reportMetadata() deviceStatus->shutterSpeed.get()); libcameraMetadata_.set(controls::AnalogueGain, deviceStatus->analogueGain); libcameraMetadata_.set(controls::FrameDuration, - helper_->exposure(deviceStatus->frameLength).get()); + helper_->exposure(deviceStatus->frameLength, mode_.minLineLength).get()); if (deviceStatus->sensorTemperature) libcameraMetadata_.set(controls::SensorTemperature, *deviceStatus->sensorTemperature); } @@ -1106,7 +1106,7 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls) int32_t gainCode = sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get(); int32_t vblank = sensorControls.get(V4L2_CID_VBLANK).get(); - deviceStatus.shutterSpeed = helper_->exposure(exposureLines); + deviceStatus.shutterSpeed = helper_->exposure(exposureLines, mode_.minLineLength); deviceStatus.analogueGain = helper_->gain(gainCode); deviceStatus.frameLength = mode_.height + vblank; @@ -1198,7 +1198,7 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) /* getVBlanking might clip exposure time to the fps limits. */ Duration exposure = agcStatus->shutterTime; int32_t vblanking = helper_->getVBlanking(exposure, minFrameDuration_, maxFrameDuration_); - int32_t exposureLines = helper_->exposureLines(exposure); + int32_t exposureLines = helper_->exposureLines(exposure, mode_.minLineLength); LOG(IPARPI, Debug) << "Applying AGC Exposure: " << exposure << " (Shutter lines: " << exposureLines << ", AGC requested "