From patchwork Thu Oct 6 13:17:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17544 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 63F64C327C for ; Thu, 6 Oct 2022 13:17:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1297C62CFD; Thu, 6 Oct 2022 15:17:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665062279; bh=J8lJ6PGCLvUfkjHvaRUY8NgDNAIkJP7WBkY+MQMcq8I=; 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=Jv+sKHNCnl/+nx+fuPdfxPLkye5KB8MK4wcNS8FLDrPAq/fSrtE/wrcXXLxUuZnho RYMsqqPjCe/BcBM+0WsYJ3ZurXYAdr2ce7GxtMRluwsejFHe4P1oITs1y34vvIcMDB Fbe9fEet3Kh9SqC4yDYVwkqBCIx+UK92Jxva+L+8lr117xkp56GYC3W5Wpp8H7EVlA 1YyiAYFT8FdG3TwxkmtqgepSf1/lNpGg3V/MQIe21pZ/JVjOUp8mKLuZeJSqvF7yqA Yss5kMymwwx0ANzGz7o7G5l25RlC+RLC+JNIGe/rr9Krozr1q2SzYu4ICNU++WO0Sl EZATOedYdNZpg== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 655C062CFC for ; Thu, 6 Oct 2022 15:17:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IoBqAW78"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id b4so2706252wrs.1 for ; Thu, 06 Oct 2022 06:17:56 -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=PPWqyUmpb6N+I4R6BCY7bFIr1oMEW/5912qbXTEqvGA=; b=IoBqAW78xokAioPc5hwwNIlFvNHhBidEGUcahce9LWhZPeFyrHp+f2idyxjARGjqqy CKGTWohS+0Qr07oCM5e34TUc8HZeBKn/25UJNnGkj1A4uc+eGUqeqETDljCbbjRlD5B2 YE0jXxwkJ58Fa1b9hG69jdugXAfzW7pYxk+QbCKz50BLecOp7+q8s80R9LOpz0jgfA7Q UrHZhQuqwyXmlFvwR47JlAFa1Mp5Mf7yRzwukraUU+bZ/3PVLna6JYFDWmQFrYF7oGIC fC1F8SvikrjlRsV7xLqDkpQch1hrWfwvKdQhqPqhY+FMLonm8l3q7MezD3Zl/6cv1x4a fOJA== 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=PPWqyUmpb6N+I4R6BCY7bFIr1oMEW/5912qbXTEqvGA=; b=VL7QKSHhHcn2PhFSTposLOK7lQYAFdF6A6h/+LH36JtuG0dlot83c3go/oEQNjcvOU tRDa/fGhTyiNkigI4wq2GQRCKwzXa+vbRDslBimmL57wRUxkMZAuFRsSxoN8/SO2s9dp bi7oayV9B8gtdToW+XTyO2jpW8W78e5EqwjXc0GGV35EVRg1fDxR0fOLfIyOzwD1yTrO 5bGEDiLOBVtw2wAyP2v0FrSMS0o6WzmAuyMWyShEuqAjU008vXDb+VY1ddVjy/tH/ltR 3SzmUCWdryVylKyh9kk0aAVZl2xJeEOCwaEP2CwMj9BxJA0gPg2QSysErB86G/N5NP7Q PBSQ== X-Gm-Message-State: ACrzQf3pEeEW5PNz1uXxVIe/FxkCxG2J8/VN8dows75CHw1u9Ztn58V6 eJXZ//EmlJNwglFBD7yTiW+kxI+954WEFw== X-Google-Smtp-Source: AMsMyM7sNUP2xsCd793PCCqrBYv2qOz2w95uLca9Ulf/o5qtWStsbcNt7KQSFokolkpaykR0usVWAw== X-Received: by 2002:a5d:4a01:0:b0:21d:8ce1:8b6d with SMTP id m1-20020a5d4a01000000b0021d8ce18b6dmr3180226wrq.718.1665062275548; Thu, 06 Oct 2022 06:17:55 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q18-20020a056000137200b0022cc7c32309sm17986049wrz.115.2022.10.06.06.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 06:17:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 6 Oct 2022 14:17:37 +0100 Message-Id: <20221006131744.5179-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006131744.5179-1-naush@raspberrypi.com> References: <20221006131744.5179-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/10] 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 Tested-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- 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/raspberrypi.cpp | 8 ++++---- 7 files changed, 30 insertions(+), 23 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 66d21e36ecd0..d86ff3878983 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; void getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay) const override; private: @@ -53,12 +53,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 std::max(minExposureLines, (exposure - 14.26us) / timePerLine); } -Duration CamHelperImx296::exposure(uint32_t exposureLines) const +Duration CamHelperImx296::exposure(uint32_t exposureLines, + [[maybe_unused]] const Duration lineLength) const { return std::max(minExposureLines, 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/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 "