From patchwork Mon Oct 31 11:45:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17742 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 CEB71C3289 for ; Mon, 31 Oct 2022 11:45:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3600763044; Mon, 31 Oct 2022 12:45:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667216741; 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=PlAf2+JMx1uQhSR6UDYm1U5uEas/v+hxpKKhh0DrYzGavFT5REsyVNBtoz7qaRxgc LzotytDHpMDFFcpT2QF6mi+7pxk6XPrTAHnqGHqudW8eF+gAvf+LvJswitkT1eNsjm Y+nO+4r5DJE4i0bViAPc8b1B4QOTZlEp269wDdxkx3ZUfWrw8r8UYNjp/JumR6gmJY ELjLy17oD6ua1eQnbFgv+C8u51bVgSiYL94gipg68usgLjngkFpnNrCiE//+Pggb1D j3mLVJpSRg6+lO5ZOjD0B0Bdr1PgjQ+rI5cu4kz5XUwGBFfKWL8dcbLzrArTNK6618 nKDwIiQ0lnBBg== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BE466304A for ; Mon, 31 Oct 2022 12:45:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SzHvhgnr"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id y16so15541192wrt.12 for ; Mon, 31 Oct 2022 04:45:34 -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=zdhz+1j/NkLDJJXH7usJMOs+Zyvf3jcELZrgcTTFIAE=; b=SzHvhgnrmwkVeMJAnSqa49KEkX+Tgdo+9L821PlYWqGqNGzVimg5RNXlnR74OFc6Mz gqIALBJw29PnR3+3AMG2WIfnbUEHMAh8IO8awejn5Oy+giNdp4Pv7y7Y1p0NGZiwY5xG 1+Xm/P0BBgwn9Zet4cNRUK1LUxxwouH409qwUR+ura16ZRc/hJ+kXqhz/hZx1d0zAKGm SbMeuYXo/0MLE3voYXOsnE40vEDQKiocc7XuUi6YLHUmx0qa8x/LEdMuqXhZ/tmVdFaG 1wYvPkrVdWl+4Mi3akbe3BMJ1ayB8+pnz4rXKp5YpsQBwcpTmQOo8Qe9rgDWjh74Mvhi mwVQ== 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=BMYYjlkYWWkmC8HSUOkHVdSzSgyEi78CpqC5OmZnI/QUcY9OPX+A5tQggg15M0+BbC dQbFby5B7+AWzgVIInyF4vrUsPwEqcViZtwXXwSqCz9z/2Uuv1morZ+cv4eU40dqSmZm isDJwXMZYqfDAPKyXahGsMRxmY9p1vW8RSFWahjgp4G9u7ORoGFUMuV8DD/RlgA1rJ6x X/D/mGWnvIYkhdhoumzhU6/VE04R/wX+uv+zVoJt20dFReTgKNcMW/sGSnb6DW+/+ND7 ZQyWlujzsi4PZs1g+2sb/IyDyElNvGtVPxeoUl/1nKIoZulO2yPTUY+4odqPxQMsNc4B NddA== X-Gm-Message-State: ACrzQf1/YMOtLRgLguRwnnTZPJFaVhlMSeachVVZ5FayghByKGrkMglJ hCUEEei5OE5pj9WxTwu1E0u0PQCpw8auRw== X-Google-Smtp-Source: AMsMyM5scar6dX258fobLOYECkBrPtOgSE8GPOmWrlEZr9x5PYXumD2thclZp+Ow+sIpbEFEYxShDw== X-Received: by 2002:a5d:698e:0:b0:236:4b95:17ff with SMTP id g14-20020a5d698e000000b002364b9517ffmr8087204wru.196.1667216733681; Mon, 31 Oct 2022 04:45:33 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id h11-20020adff18b000000b0023677e1157fsm6936354wro.56.2022.10.31.04.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 04:45:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 31 Oct 2022 11:45:22 +0000 Message-Id: <20221031114522.14215-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221031114522.14215-1-naush@raspberrypi.com> References: <20221031114522.14215-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 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.