From patchwork Mon Sep 26 09:57: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: 17404 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 1582EBD16B for ; Mon, 26 Sep 2022 09:58:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B74F562264; Mon, 26 Sep 2022 11:58:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664186296; bh=lWX/rkuLsVjrzcRtKwbMiibWwShPlxC4AofWEXu6Um8=; 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=ROYdOxa6DQ1Qz/Vl+F/DolGwvBY307ZeIJa2yJKQMKHd33u//5omx4TTRAhjTJCUE Zz5k6yV4wOjRHEMaJ4eVpY3I6l+jjp5JRfCAKyLARmJ3z3COiKOzNtX4mhRXmAY+CD 3POqDBr1zlCSitWtwhQDNxcnnn5i7nM6CODhFnbiMFKBGZvZksgAUmWiQdoG4Jr4p1 zvWf9hPSrpzCorj1uZyBiSMZO4Z8Cl4dpkTJk/ffF3z9W8wO2lFh5fsUCsbuX33iUO SQJDPSMzs7fdRY+PhkHr81Kjtn20Y+vci/kRXqg3oKdwI6s9T2RS3aC/j6CGrDSjE9 I3ZtM3rAeefmA== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0B0B62260 for ; Mon, 26 Sep 2022 11:58:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LkvvOlav"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id o5so4120291wms.1 for ; Mon, 26 Sep 2022 02:58:14 -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=tnUgZJUKUkP6fVcpYTtvEJuRHxAYGbHl5Vo84ysJuZ0=; b=LkvvOlavcUaz5TBUmbgk9ugD0KrkhgERaHS0RABX9TiPq8O3Fhg1c7EitCONhdtzVN +aDKHT1WS7+O5q/Ovv6qdh8WjnaXVuv6FTtewFn715MEIUyNu4CZlwhDqstqQtlcPfxp ILkYcj5DOwJKJ4++k+ueoxnZcBPypKJ5KGwU5kEBblRAWnN5reWpdZftqCYUrhwyySVc Jl5Z+FZ8QdrDj40LYRNHPgEa+PpYyaI6RMYWfdsaYF8g4A6R4xPEqnwywK4I+y4hoiXf y95dKoCutTeSuiIR6noLzE9/1YWUI8UE9SY9EOwv7dpe0fTHmTBvbdBaWdvrsgpJryo8 OO3Q== 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=tnUgZJUKUkP6fVcpYTtvEJuRHxAYGbHl5Vo84ysJuZ0=; b=RupjxvxRWv1WpQE3k51TzLBgg9QGRPJjSbioh+hXucS7ocLcZzJ3ffQSbGWSBCJoDU lmav/M0eXbtt0KfIUekrB/v1QyuKeAsgzdHA/TQaqOFKOgFVYmS4SGGuXJb2Ie69nmVy jgPsny3foBoXRL5rAIXxJGu1TxuubFRsrrx8Hhz0g4C66Xb5IwlCUI2AHBN0Ay89Yxbe 7NlY5DoqyMNNFa6rgXf21hcrTvCKabKhKZY8usBdZXedlXEgiGDI2sI6zQpA25Eu93QW MyI3pR++AeYxmQCQzunXbzD+c0Bewo2fBUPiOJxeAHPpnUSOz7LR/C8Txw6YRFtP8bBf YBNg== X-Gm-Message-State: ACrzQf2JasWxJBOHjZ1wtLKKcw5idLdcVeevM75zB1x2bJSAFBqTRjmQ INi6FIJr8pVCAXbscT6IdTWKe/4BDDDp5AoY X-Google-Smtp-Source: AMsMyM4+3yet6Bj+D9suthFGcX1HkjdmmE1SRwF/ndrIDy21hrsw+JsTp4G0/qfVb4qOCqJubb+ufA== X-Received: by 2002:a7b:c392:0:b0:3b4:acef:3523 with SMTP id s18-20020a7bc392000000b003b4acef3523mr14843407wmj.37.1664186294440; Mon, 26 Sep 2022 02:58:14 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:58:13 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 26 Sep 2022 10:57:37 +0100 Message-Id: <20220926095737.30506-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220926095737.30506-1-naush@raspberrypi.com> References: <20220926095737.30506-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 --- 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 0e80ef9c7b95..bc438e99eff6 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1025,6 +1025,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.ipaCookie]; + 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.