From patchwork Wed Oct 19 09:01:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17632 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 42B3AC3285 for ; Wed, 19 Oct 2022 09:01:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C0D2E62E58; Wed, 19 Oct 2022 11:01:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666170087; bh=/6GhMhetbOE+yc09yQxkOk8kZ5IJvoL23EuHpX7OmxE=; 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=ggKxW1RMVvTDOuEItjnRAUUgYY4A9GSX3+3Bzb87f5RbrlYmcFFKB4Az5Zh4qXaUm PmK6gM/VQRGcVBI+sM3jbwTil8MeKhPGI/AehQHia/abOkWWCd/O2+eD6wkUAyiSFe FjmGRHdEfgfTNY7HGssY6Gb7nT3P0bhiMcixuBGtJGNiiIvbH+rskOXDIXS3bR6fgW d4vW8dCvlThcIRw/4bYjhToDuHdZQDysp4vJGNnkerxrECgnywqw7g06E92K97tVkJ CZfEnVorjCumEri67vgrVyskn5pWq9evyEjon4eMmeqHMVG/1dnkPx5WeXdzZ94i/s ASYpTSSXKVurg== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5ED5F62E46 for ; Wed, 19 Oct 2022 11:01:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="E0HutGw/"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id j7so28002922wrr.3 for ; Wed, 19 Oct 2022 02:01:24 -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 :message-id:reply-to; bh=Ti3vLKdKN85OxloaVfMzj8nn2D6wytryKDydft3JQig=; b=E0HutGw/ZZpDkjzo3R5CnjJ8lzl/WJc9vZIuxe2ouUZwlTg0e35zISBm99RAzcbtiq ETtTGBRxGGtqakbpdYoDkcik49gmQ/Hxy7J8u9PSRR+l9Wpsbb/dob89AvMZqWhRaFa3 XlKZP3iniiJLYIQj7YKYzCsDbbQbvy4GpJw05NtFyJ/R9poHYa3edAhnOYQeMdHU1CVi nIOUketKPvvatO1PjpKtI+m2RrDpqhnEnUGXNqEtuYg/jOAnG1g3rgtUS2bSk5+Vz0tU moAIxlx5U+HhEQCGxXIbHj4TO+uunAOG3PwRKErcYanfiuiY2aDn4XX05FAsba/tdnr8 aVfg== 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:message-id:reply-to; bh=Ti3vLKdKN85OxloaVfMzj8nn2D6wytryKDydft3JQig=; b=PHzwHcPkxnDbgfhIifhskBsL7TLzXNEP8PCUev/8GDLCffF9s+v007jWdeJFzmJoLv UDXCyti7Na19/1SAn8Nwsiu7xx5nlkAD4p1nhvTOkIcmBKZzUwE5QKgV552dNG7qFE6d vRuBJZdAE+VqNbo21QcY2V3EaQYDU2nK4lSDtcMoM6IfqJ48Zc3GydFMgCLtI0OE98qq wTXdAvFoPHgjeJ6992AgPWxRn1vr7Ex+eOoa5IJnru+1ngRrzSJX0n054dRdpoSq/ANX eF6/k3qvwoT0DW4iGGJ75k/gCbGSIHhRWdnJ/9yRWr+KpAzOSgHCmP8++G7FI5i8PAOe zCbg== X-Gm-Message-State: ACrzQf0XJbHLP6592eJFyy/bD6uHAb7XHBG7z4iKIFG6VjAxyfQRAZX9 q5f1/VdN9hn4Xc8Tf2q0O6KOqJhT8+RfYQ== X-Google-Smtp-Source: AMsMyM7iuAQ/AxrLObElWL/I9hep7QaegpDEU1Vo3U399KIeqj9FRgAaYaCKiyQ47stcfBIyBLNKCA== X-Received: by 2002:a5d:64a8:0:b0:22e:409f:a3cb with SMTP id m8-20020a5d64a8000000b0022e409fa3cbmr4285667wrp.168.1666170083803; Wed, 19 Oct 2022 02:01:23 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r9-20020a05600c458900b003b47b913901sm1017595wmo.1.2022.10.19.02.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 02:01:23 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 10:01:07 +0100 Message-Id: <20221019090107.19975-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019090107.19975-1-naush@raspberrypi.com> References: <20221019090107.19975-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/7] ipa: raspberrypi: agc: Fix digital gain calculation for manual mode 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" The digital gain calculation uses a total exposure value computed with the current AGC state. However, this is wrong in the case of manual shutter/gain controls, as the total exposure value used must be the value computed when the AGC sent the manual shutter/gain controls to the pipeline handler to action. To fix this, the IPA now adds the historical AgcStatus structure to the metadata (tagged with "agc.delayed_status"). This historical AgcStatus structure contains the total exposure value calculated when the AGC sent the manual shutter/gain controls to the pipeline handler. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++++++-- src/ipa/raspberrypi/raspberrypi.cpp | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index bd54a639d637..b18bd7b5b19e 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -408,6 +408,12 @@ void Agc::switchMode(CameraMode const &cameraMode, void Agc::prepare(Metadata *imageMetadata) { + Duration totalExposureValue = status_.totalExposureValue; + AgcStatus delayedStatus; + + if (!imageMetadata->get("agc.delayed_status", delayedStatus)) + totalExposureValue = delayedStatus.totalExposureValue; + status_.digitalGain = 1.0; fetchAwbStatus(imageMetadata); /* always fetch it so that Process knows it's been done */ @@ -418,8 +424,8 @@ void Agc::prepare(Metadata *imageMetadata) Duration actualExposure = deviceStatus.shutterSpeed * deviceStatus.analogueGain; if (actualExposure) { - status_.digitalGain = status_.totalExposureValue / actualExposure; - LOG(RPiAgc, Debug) << "Want total exposure " << status_.totalExposureValue; + status_.digitalGain = totalExposureValue / actualExposure; + LOG(RPiAgc, Debug) << "Want total exposure " << totalExposureValue; /* * Never ask for a gain < 1.0, and also impose * some upper limit. Make it customisable? diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index aed8f68aded9..983745fcad98 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1029,6 +1029,17 @@ void IPARPi::prepareISP(const ISPConfig &data) embeddedBuffer = it->second.planes()[0]; } + /* + * AGC wants to know the algorithm status from the time it actioned the + * sensor exposure/gain changes. So fetch it from the metadata list + * indexed by the IPA cookie returned, and put it in the current frame + * metadata. + */ + AgcStatus agcStatus; + RPiController::Metadata &delayedMetadata = rpiMetadata_[data.delayCookie]; + if (!delayedMetadata.get("agc.status", agcStatus)) + rpiMetadata.set("agc.delayed_status", agcStatus); + /* * This may overwrite the DeviceStatus using values from the sensor * metadata, and may also do additional custom processing.