From patchwork Mon Sep 5 07:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17303 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 228D8C327D for ; Mon, 5 Sep 2022 07:40:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCB1062054; Mon, 5 Sep 2022 09:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662363611; bh=3D5mP/TcXrH/mVvjO0UQb80rXuYUzyT8+7a/q2SMD+0=; 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=RsEe7nDs+0zkW31eCEQFxzlXihxsfC9B+ptScrxo9YnIKpxjLechULX4LBFPlv6Cw 5ZTqD3bE1rap8rRJWLPkfv61ElQnVNSvyEXyU4/ITb0FafqUk1qOFzXG3peBIQgVtq 9jULVb+8bfcwL4N/Xtlfr1AlaruvqCOHyGZpKx4qkTJV6Ew8g/Wg5GWLzXdQ/FpqRn akYMhjVK+9iHKjDUu0QFiSytp30Ob6DkBI2mpOFJElbLVxXCCsoSZgxL9l7YsFPuWC SBjjdS+8zxoXjpmcXA2S02Tkh98uTQhcMcDs6g1838rt8iH9C4hvTRY02Hnfj4BvnW 11GJF6pupwz0Q== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6106362065 for ; Mon, 5 Sep 2022 09:40:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jsBT35t0"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id w5so10093961wrn.12 for ; Mon, 05 Sep 2022 00:40:10 -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=1Zzkg/UuOevXN4rX2S7SZgpXxqbkmqHLsiA2gpwjQi4=; b=jsBT35t0KA87kcyF6jlH/vJOqYEn1RJg8Wa1EfUCGylFDWWPEMmBO+TOIOaCLp4xrU kYKYRmNuDVWOQSNjTXpxZMODAWx6u8mOeKImIbpsL27XXBqKg4DYn7PUs2NsS/LeY3Ql kY7fUHweA2bQStPxlyItsBKLotd8HjCwpj1suhZDY9VmO5MJ2KzRQcQUG+qOZJrEVLyu qxcXy9Myxopgbqa6rPmOIvwh4E4K6L92IW6JfUCgJRIywM7ggh7wdgvQtiZ4VaAHNReT kn1hJYscOIZDpn98EZyaEmPRLkdaQkSSMPqilyMFQgKb3+u46NoyAd6rssqrfCc8gQCO rMzg== 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=1Zzkg/UuOevXN4rX2S7SZgpXxqbkmqHLsiA2gpwjQi4=; b=ydlHuM7c3USudfQhyXN9yX28sQNndwCR6CjDYau6y334skIOccl5ky6usZmF2ehTrZ lQx+bA/YDTL96H9U54OU240RNINNOZzsmuIS+PTq27lR3Xnh67221rJ5m4EpivH8MnFM 9vuPBiqyi2W2ETXKkYqG4DrmK0fyVcdIvmv4IDR/uUd+vc423y8Z3Kjahn9WHHFy2HnP 0TQw2VJYQ277w/WCIqVny4LMEJ/z9QZemGIZOkAsbgkIlk7amBJSoRY9p6RE6dLfXdn5 vTfwWEotSexuaooa/cSelZPezrdyrSXSvt+iyYimrRulP/EnOPA0PHEhX/23AxPaYfyt ckkg== X-Gm-Message-State: ACgBeo3qrmCr9G3ZUHQAofIDFh1MH6YJNBdpV36+wLF+Q2oYtXIW4DbR oKuJqOZrmFzb67U73ebrKeU4KTh7M+N5VPgK X-Google-Smtp-Source: AA6agR4xzg0gtgpYU/fT/47szjBEI43SDO+ibPHRoZfIEH5afo5ikE1Vro8mCv2Q1QAeiHDVOX/NVQ== X-Received: by 2002:adf:e112:0:b0:21d:7195:3a8d with SMTP id t18-20020adfe112000000b0021d71953a8dmr24437585wrz.371.1662363609820; Mon, 05 Sep 2022 00:40:09 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id v16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:40:08 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 08:39:56 +0100 Message-Id: <20220905073956.7342-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905073956.7342-1-naush@raspberrypi.com> References: <20220905073956.7342-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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.