{"id":17742,"url":"https://patchwork.libcamera.org/api/1.1/patches/17742/?format=json","web_url":"https://patchwork.libcamera.org/patch/17742/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221031114522.14215-8-naush@raspberrypi.com>","date":"2022-10-31T11:45:22","name":"[libcamera-devel,v5,7/7] ipa: raspberrypi: agc: Fix digital gain calculation for manual mode","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"342ab35de37e6524fef1b8522fbe63a33b83cae0","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17742/mbox/","series":[{"id":3590,"url":"https://patchwork.libcamera.org/api/1.1/series/3590/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3590","date":"2022-10-31T11:45:15","name":"Raspberry Pi AGC digital gain fixes","version":5,"mbox":"https://patchwork.libcamera.org/series/3590/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17742/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17742/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CEB71C3289\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Oct 2022 11:45:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3600763044;\n\tMon, 31 Oct 2022 12:45:41 +0100 (CET)","from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com\n\t[IPv6:2a00:1450:4864:20::42d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BE466304A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Oct 2022 12:45:34 +0100 (CET)","by mail-wr1-x42d.google.com with SMTP id y16so15541192wrt.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Oct 2022 04:45:34 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\th11-20020adff18b000000b0023677e1157fsm6936354wro.56.2022.10.31.04.45.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 31 Oct 2022 04:45:33 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1667216741;\n\tbh=YhIxN2di9TyNXMbx5fMifQcQb3B04ncA8Y/T2+CW3v4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=PlAf2+JMx1uQhSR6UDYm1U5uEas/v+hxpKKhh0DrYzGavFT5REsyVNBtoz7qaRxgc\n\tLzotytDHpMDFFcpT2QF6mi+7pxk6XPrTAHnqGHqudW8eF+gAvf+LvJswitkT1eNsjm\n\tY+nO+4r5DJE4i0bViAPc8b1B4QOTZlEp269wDdxkx3ZUfWrw8r8UYNjp/JumR6gmJY\n\tELjLy17oD6ua1eQnbFgv+C8u51bVgSiYL94gipg68usgLjngkFpnNrCiE//+Pggb1D\n\tj3mLVJpSRg6+lO5ZOjD0B0Bdr1PgjQ+rI5cu4kz5XUwGBFfKWL8dcbLzrArTNK6618\n\tnKDwIiQ0lnBBg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=zdhz+1j/NkLDJJXH7usJMOs+Zyvf3jcELZrgcTTFIAE=;\n\tb=SzHvhgnrmwkVeMJAnSqa49KEkX+Tgdo+9L821PlYWqGqNGzVimg5RNXlnR74OFc6Mz\n\tgqIALBJw29PnR3+3AMG2WIfnbUEHMAh8IO8awejn5Oy+giNdp4Pv7y7Y1p0NGZiwY5xG\n\t1+Xm/P0BBgwn9Zet4cNRUK1LUxxwouH409qwUR+ura16ZRc/hJ+kXqhz/hZx1d0zAKGm\n\tSbMeuYXo/0MLE3voYXOsnE40vEDQKiocc7XuUi6YLHUmx0qa8x/LEdMuqXhZ/tmVdFaG\n\t1wYvPkrVdWl+4Mi3akbe3BMJ1ayB8+pnz4rXKp5YpsQBwcpTmQOo8Qe9rgDWjh74Mvhi\n\tmwVQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"SzHvhgnr\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=zdhz+1j/NkLDJJXH7usJMOs+Zyvf3jcELZrgcTTFIAE=;\n\tb=BMYYjlkYWWkmC8HSUOkHVdSzSgyEi78CpqC5OmZnI/QUcY9OPX+A5tQggg15M0+BbC\n\tdQbFby5B7+AWzgVIInyF4vrUsPwEqcViZtwXXwSqCz9z/2Uuv1morZ+cv4eU40dqSmZm\n\tisDJwXMZYqfDAPKyXahGsMRxmY9p1vW8RSFWahjgp4G9u7ORoGFUMuV8DD/RlgA1rJ6x\n\tX/D/mGWnvIYkhdhoumzhU6/VE04R/wX+uv+zVoJt20dFReTgKNcMW/sGSnb6DW+/+ND7\n\tZQyWlujzsi4PZs1g+2sb/IyDyElNvGtVPxeoUl/1nKIoZulO2yPTUY+4odqPxQMsNc4B\n\tNddA==","X-Gm-Message-State":"ACrzQf1/YMOtLRgLguRwnnTZPJFaVhlMSeachVVZ5FayghByKGrkMglJ\n\thCUEEei5OE5pj9WxTwu1E0u0PQCpw8auRw==","X-Google-Smtp-Source":"AMsMyM5scar6dX258fobLOYECkBrPtOgSE8GPOmWrlEZr9x5PYXumD2thclZp+Ow+sIpbEFEYxShDw==","X-Received":"by 2002:a5d:698e:0:b0:236:4b95:17ff with SMTP id\n\tg14-20020a5d698e000000b002364b9517ffmr8087204wru.196.1667216733681; \n\tMon, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 7/7] ipa: raspberrypi: agc: Fix digital\n\tgain calculation for manual mode","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The digital gain calculation uses a total exposure value computed with the\ncurrent AGC state. However, this is wrong in the case of manual shutter/gain\ncontrols, as the total exposure value used must be the value computed when the\nAGC sent the manual shutter/gain controls to the pipeline handler to action.\n\nTo fix this, the IPA now adds the historical AgcStatus structure to the metadata\n(tagged with \"agc.delayed_status\"). This historical AgcStatus structure contains\nthe total exposure value calculated when the AGC sent the manual shutter/gain\ncontrols to the pipeline handler.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++++++--\n src/ipa/raspberrypi/raspberrypi.cpp        | 11 +++++++++++\n 2 files changed, 19 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex bd54a639d637..b18bd7b5b19e 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -408,6 +408,12 @@ void Agc::switchMode(CameraMode const &cameraMode,\n \n void Agc::prepare(Metadata *imageMetadata)\n {\n+\tDuration totalExposureValue = status_.totalExposureValue;\n+\tAgcStatus delayedStatus;\n+\n+\tif (!imageMetadata->get(\"agc.delayed_status\", delayedStatus))\n+\t\ttotalExposureValue = delayedStatus.totalExposureValue;\n+\n \tstatus_.digitalGain = 1.0;\n \tfetchAwbStatus(imageMetadata); /* always fetch it so that Process knows it's been done */\n \n@@ -418,8 +424,8 @@ void Agc::prepare(Metadata *imageMetadata)\n \t\t\tDuration actualExposure = deviceStatus.shutterSpeed *\n \t\t\t\t\t\t  deviceStatus.analogueGain;\n \t\t\tif (actualExposure) {\n-\t\t\t\tstatus_.digitalGain = status_.totalExposureValue / actualExposure;\n-\t\t\t\tLOG(RPiAgc, Debug) << \"Want total exposure \" << status_.totalExposureValue;\n+\t\t\t\tstatus_.digitalGain = totalExposureValue / actualExposure;\n+\t\t\t\tLOG(RPiAgc, Debug) << \"Want total exposure \" << totalExposureValue;\n \t\t\t\t/*\n \t\t\t\t * Never ask for a gain < 1.0, and also impose\n \t\t\t\t * some upper limit. Make it customisable?\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 194171a8bc96..7904f2b696dd 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -1028,6 +1028,17 @@ void IPARPi::prepareISP(const ISPConfig &data)\n \t\tembeddedBuffer = it->second.planes()[0];\n \t}\n \n+\t/*\n+\t * AGC wants to know the algorithm status from the time it actioned the\n+\t * sensor exposure/gain changes. So fetch it from the metadata list\n+\t * indexed by the IPA cookie returned, and put it in the current frame\n+\t * metadata.\n+\t */\n+\tAgcStatus agcStatus;\n+\tRPiController::Metadata &delayedMetadata = rpiMetadata_[data.delayContext];\n+\tif (!delayedMetadata.get<AgcStatus>(\"agc.status\", agcStatus))\n+\t\trpiMetadata.set(\"agc.delayed_status\", agcStatus);\n+\n \t/*\n \t * This may overwrite the DeviceStatus using values from the sensor\n \t * metadata, and may also do additional custom processing.\n","prefixes":["libcamera-devel","v5","7/7"]}