{"id":18900,"url":"https://patchwork.libcamera.org/api/1.1/patches/18900/?format=json","web_url":"https://patchwork.libcamera.org/patch/18900/","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":"<20230728133700.3713-3-david.plowman@raspberrypi.com>","date":"2023-07-28T13:36:59","name":"[libcamera-devel,2/3] ipa: rpi: agc: Filter exposures before dealing with digital gain","commit_ref":"84b6327789fcf5be37a990d5be27f305e8514621","pull_url":null,"state":"accepted","archived":false,"hash":"c34e4a061413ff0a516eddba2e7c1016609102d9","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18900/mbox/","series":[{"id":3993,"url":"https://patchwork.libcamera.org/api/1.1/series/3993/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3993","date":"2023-07-28T13:36:57","name":"Raspberry Pi AGC tidying","version":1,"mbox":"https://patchwork.libcamera.org/series/3993/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18900/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18900/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 CCEA7BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jul 2023 13:37:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87D99627F5;\n\tFri, 28 Jul 2023 15:37:07 +0200 (CEST)","from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2376D627E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jul 2023 15:37:04 +0200 (CEST)","by mail-wr1-x42e.google.com with SMTP id\n\tffacd0b85a97d-3178fa77b27so384573f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jul 2023 06:37:04 -0700 (PDT)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:2bce:64d6:1a5c:49a2])\n\tby smtp.gmail.com with ESMTPSA id\n\ti15-20020adffdcf000000b003145559a691sm4847758wrs.41.2023.07.28.06.37.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 28 Jul 2023 06:37:03 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690551427;\n\tbh=8RgkApAS1nLUlSyfKiNq5++HKh8PdG0ifshngX0bVO4=;\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=Aa/x+KXaeKlzB95BpDj25YuvAor9P+MxjpLcRkdJVAZB7VdZyq/YG/gXv03DUQVC3\n\taGffqZP9LjYmNhg/tkRMf45kYaTqohHve1pGJZXcXqrRp0cgpCbwGc1e8yMYyidAUZ\n\tr9XUHbVBk0XZ8HwuN0GIdmTSu1XCaun2/MXTGZF0HRYtfToTFYs67/5BLx30L3r90z\n\tjxmAKkvI+n+efel80g6FJsWcdMM4ySoiLn7LpWej3TdO5vpsDzeH0S9czEIL9Q60Tw\n\tdn6bXSgTQfsbdMpYXALyOggczhw+StWTU9yA4hp9Elnz68NL1sudZOVHWE7+TkJYGp\n\t3ouB/TLTboYOA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1690551423; x=1691156223;\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=cT9tTiTNC+0dc91UzzBi/jG1dsycuMB1SbT8keFJIxg=;\n\tb=YW/VLF3mop2QtRl8zu2MDGKo3G0nK9IWVGR+Uy/AdkmszD82mohAnzlfrVm2T4Il2p\n\tnz1dGENZ/IkD7XFT1x3x6+LiSgG5KIeGu7jJmFWjblvPjR36WCc05zcRkLCt6snLwCvu\n\tEWzkhYMUsAGubuTJ94BIQq/cRa76RnM1GbwA5Nx/64XPaoNTc4as0Cb6bSj+6l7mKWWa\n\tbKdqbVFKtxK7bxefdy4WaqiQpECX1PfAxpo5hMhOWeVHXPpOp+/xyGObe6GQwngPcael\n\tF+12PYXTdkD4w+N/y5jnTjD+4hPllori4IZ/aRy+0NoN173YPtjc0q5WqUM+eqrGcxAv\n\txudw=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"YW/VLF3m\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690551423; x=1691156223;\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=cT9tTiTNC+0dc91UzzBi/jG1dsycuMB1SbT8keFJIxg=;\n\tb=RxO6iYKKPYqDt8xAL/xBZMG1ifsbZc0KgTQmNA6Y3SzX6Xd1zZo/F2WOlcF/j516tP\n\tY1Ea7faVwJokKT281GLfFQLnf2XdBMBYLveBfxfz3e+0TewulYyPhVPz7rs8BzKHvLZM\n\tHIKmXAfaEOj3jYvbY7YCJGLkA0JzdZY3Lz99snhnM/INkxkj8ZxXCb0b9cD9AnOJYCdL\n\ta0B6iPwVcg6KVuiT5f8lKKJ/aXXhn4LvnkyzSwVyl/g/IiA4/na9FbyhdabB0B/Tjp7n\n\t3VDXBEXdG94s3aTkdoYdRTuhBE1oUkFoECpPuLMcIB/521jP+Yq87anua/ZZC/JEWlZu\n\tDsuw==","X-Gm-Message-State":"ABy/qLbI5i8JJ6isgA563MFTzza9xGXFz+jLT70n1V55eScb/5jmbNw9\n\tmK4b0kK0z2lGKr2l4dLi5AJCH1WBdoHdxb5AI3E=","X-Google-Smtp-Source":"APBJJlHtusRF9FezqKS4+whGmqwVV4LdvWwxbeZlCySKz0FdXeNK9918e/hA7pKDo5sJ+7H4Oa0bbA==","X-Received":"by 2002:a5d:4d8c:0:b0:317:6ada:b614 with SMTP id\n\tb12-20020a5d4d8c000000b003176adab614mr1965241wru.30.1690551423520; \n\tFri, 28 Jul 2023 06:37:03 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 28 Jul 2023 14:36:59 +0100","Message-Id":"<20230728133700.3713-3-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20230728133700.3713-1-david.plowman@raspberrypi.com>","References":"<20230728133700.3713-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/3] ipa: rpi: agc: Filter exposures\n\tbefore dealing with digital gain","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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"We now time-filter the exposure before sorting out how much digital\ngain is required. This is actually a little more natural and\nsimplifies the code.  It also prepares us for some future work where\nthis arrangement will be helpful.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/rpi/controller/rpi/agc.cpp | 30 +++++-------------------------\n src/ipa/rpi/controller/rpi/agc.h   |  2 +-\n 2 files changed, 6 insertions(+), 26 deletions(-)","diff":"diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\nindex e8526355..6087fc60 100644\n--- a/src/ipa/rpi/controller/rpi/agc.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc.cpp\n@@ -469,14 +469,14 @@ void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata)\n \tcomputeGain(stats, imageMetadata, gain, targetY);\n \t/* Now compute the target (final) exposure which we think we want. */\n \tcomputeTargetExposure(gain);\n+\t/* The results have to be filtered so as not to change too rapidly. */\n+\tfilterExposure();\n \t/*\n \t * Some of the exposure has to be applied as digital gain, so work out\n \t * what that is. This function also tells us whether it's decided to\n \t * \"desaturate\" the image more quickly.\n \t */\n \tbool desaturate = applyDigitalGain(gain, targetY);\n-\t/* The results have to be filtered so as not to change too rapidly. */\n-\tfilterExposure(desaturate);\n \t/*\n \t * The last thing is to divide up the exposure value into a shutter time\n \t * and analogue gain, according to the current exposure mode.\n@@ -757,12 +757,12 @@ bool Agc::applyDigitalGain(double gain, double targetY)\n \tif (desaturate)\n \t\tdg /= config_.fastReduceThreshold;\n \tLOG(RPiAgc, Debug) << \"Digital gain \" << dg << \" desaturate? \" << desaturate;\n-\ttarget_.totalExposureNoDG = target_.totalExposure / dg;\n-\tLOG(RPiAgc, Debug) << \"Target totalExposureNoDG \" << target_.totalExposureNoDG;\n+\tfiltered_.totalExposureNoDG = filtered_.totalExposure / dg;\n+\tLOG(RPiAgc, Debug) << \"Target totalExposureNoDG \" << filtered_.totalExposureNoDG;\n \treturn desaturate;\n }\n \n-void Agc::filterExposure(bool desaturate)\n+void Agc::filterExposure()\n {\n \tdouble speed = config_.speed;\n \t/*\n@@ -774,7 +774,6 @@ void Agc::filterExposure(bool desaturate)\n \t\tspeed = 1.0;\n \tif (!filtered_.totalExposure) {\n \t\tfiltered_.totalExposure = target_.totalExposure;\n-\t\tfiltered_.totalExposureNoDG = target_.totalExposureNoDG;\n \t} else {\n \t\t/*\n \t\t * If close to the result go faster, to save making so many\n@@ -785,26 +784,7 @@ void Agc::filterExposure(bool desaturate)\n \t\t\tspeed = sqrt(speed);\n \t\tfiltered_.totalExposure = speed * target_.totalExposure +\n \t\t\t\t\t  filtered_.totalExposure * (1.0 - speed);\n-\t\t/*\n-\t\t * When desaturing, take a big jump down in totalExposureNoDG,\n-\t\t * which we'll hide with digital gain.\n-\t\t */\n-\t\tif (desaturate)\n-\t\t\tfiltered_.totalExposureNoDG =\n-\t\t\t\ttarget_.totalExposureNoDG;\n-\t\telse\n-\t\t\tfiltered_.totalExposureNoDG =\n-\t\t\t\tspeed * target_.totalExposureNoDG +\n-\t\t\t\tfiltered_.totalExposureNoDG * (1.0 - speed);\n \t}\n-\t/*\n-\t * We can't let the totalExposureNoDG exposure deviate too far below the\n-\t * total exposure, as there might not be enough digital gain available\n-\t * in the ISP to hide it (which will cause nasty oscillation).\n-\t */\n-\tif (filtered_.totalExposureNoDG <\n-\t    filtered_.totalExposure * config_.fastReduceThreshold)\n-\t\tfiltered_.totalExposureNoDG = filtered_.totalExposure * config_.fastReduceThreshold;\n \tLOG(RPiAgc, Debug) << \"After filtering, totalExposure \" << filtered_.totalExposure\n \t\t\t   << \" no dg \" << filtered_.totalExposureNoDG;\n }\ndiff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h\nindex 939f9729..b7122de3 100644\n--- a/src/ipa/rpi/controller/rpi/agc.h\n+++ b/src/ipa/rpi/controller/rpi/agc.h\n@@ -93,8 +93,8 @@ private:\n \tvoid computeGain(StatisticsPtr &statistics, Metadata *imageMetadata,\n \t\t\t double &gain, double &targetY);\n \tvoid computeTargetExposure(double gain);\n+\tvoid filterExposure();\n \tbool applyDigitalGain(double gain, double targetY);\n-\tvoid filterExposure(bool desaturate);\n \tvoid divideUpExposure();\n \tvoid writeAndFinish(Metadata *imageMetadata, bool desaturate);\n \tlibcamera::utils::Duration limitShutter(libcamera::utils::Duration shutter);\n","prefixes":["libcamera-devel","2/3"]}