From patchwork Tue Nov 15 09:07:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17800 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 4982DBE08B for ; Tue, 15 Nov 2022 09:08:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D50ED63095; Tue, 15 Nov 2022 10:08:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1668503291; bh=YhIxN2di9TyNXMbx5fMifQcQb3B04ncA8Y/T2+CW3v4=; 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=CCWv0EP9062B61IIsx2KyAm+uQbFUkgLuS8wdUOz2OL5Ud85/0lN7ARgABnIS8Zd3 i9rn9Vq5NBDX4pp/MUOPn+Ck/Wa/l0dWhJhRHANAy1/SphyfhUZRQRwgQAzD5tiNBD wDR3JO1jIDA688xr2qhrlxEPSfSAVR05BeXZbzM74d170qjcAVwI3lZs7yEtaKjj8W wYt0Pb8fUmqEBj+pppKt1j/vajcc86XChHSFXgJXv/Zf4ijOwHOsfh/4A+n4R7nrUW +lJH6BWmTvm7B1jtagP2vKi8fQyX6tDukzLcFqL5Qi33dYoJ57DjdCaqtOxLPnvNcM ovZ5luZEJr2sg== Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5742B63089 for ; Tue, 15 Nov 2022 10:08:07 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="kc+I44dj"; dkim-atps=neutral Received: by mail-wr1-x434.google.com with SMTP id v1so23055638wrt.11 for ; Tue, 15 Nov 2022 01:08:07 -0800 (PST) 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=zdhz+1j/NkLDJJXH7usJMOs+Zyvf3jcELZrgcTTFIAE=; b=kc+I44djMYwTNTtT3Hb/KU8C6b4ZzYBMlVa6tZmuGyFTWtReRI6ZVZ5EVZG0bP88Nw EA6Kf1U3HWxAT2RRdtyk3xOGQ/D6+LYq0Mgi8YzjdoiInZTG9R3OZ53Ovme/hHTxmP/M szTzJbGnzMzLchnUZnV0jyWpzM8nHbkV5KcARJnTTqImUo/CZa+3O2wlKNn1r0xE1Orw ufPWRDysc6MwtMUqbIJueYlciwW+ZdvKBhTR5kgS1v04+SBB+MVW+DvCijO5D1AiQwYD 7iwDQbP1cHanc/e5yrFFTWhM4smz2Vp1whnveeKQ3GXT7r7komVOvJ2JGd9DFJaUngpF llBA== 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=zdhz+1j/NkLDJJXH7usJMOs+Zyvf3jcELZrgcTTFIAE=; b=QMVMC1gY3dXuqzu16z1liZr3qx2kfjKtbYm99KBlYKbRuRhaI44GD7ERbe3yKwQL4U D0SkqScccbeFV4cppsRPRVFkCwVy1DAOHdQ77eYx1ypNPOJsDw2/uuNv5tcZ+bjcQJ1D axX2La95dN1dkPqEYZmcUWLYQBeA8i6O4MO+ZqyLeefQ51OyrI/oqaZFKr3wZThAqSMu BZ6YWwVZRTyUnrXML1sq2kgbOotyW/hX4cYjiyh5dsce8li3d7cXKJD/bZqEZ0MVLygf evsJYSju0i9syftHJ88ltOzBFD31IrCkzGRSWMgKfdkntFlJzp/NUfpCGl4Xbc6HfpR7 9U5A== X-Gm-Message-State: ANoB5pkEBdXNLp3Qrz0cjOUU9Yrbo7povWeTQ78DkqrveA1AmHg3guxm EisaXO+7d9v4cFNoesrXAxvFNkUE1Ry9nA== X-Google-Smtp-Source: AA0mqf5eugk5u7ukkFVyUeihFIzhdvHrGdOdnr4AG/lLyy4jWWkcSCg9PDfnGUzH1zs9/IRfenwS3Q== X-Received: by 2002:adf:edc6:0:b0:236:6a28:eeda with SMTP id v6-20020adfedc6000000b002366a28eedamr9778463wro.315.1668503286518; Tue, 15 Nov 2022 01:08:06 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p25-20020a05600c1d9900b003c64c186206sm15143696wms.16.2022.11.15.01.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 01:08:05 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Nov 2022 09:07:55 +0000 Message-Id: <20221115090755.2921-9-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115090755.2921-1-naush@raspberrypi.com> References: <20221115090755.2921-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 8/8] 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 194171a8bc96..7904f2b696dd 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1028,6 +1028,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.delayContext]; + 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.