From patchwork Fri Jul 28 13:36:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 18900 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 CCEA7BDC71 for ; Fri, 28 Jul 2023 13:37:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 87D99627F5; Fri, 28 Jul 2023 15:37:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690551427; bh=8RgkApAS1nLUlSyfKiNq5++HKh8PdG0ifshngX0bVO4=; 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=Aa/x+KXaeKlzB95BpDj25YuvAor9P+MxjpLcRkdJVAZB7VdZyq/YG/gXv03DUQVC3 aGffqZP9LjYmNhg/tkRMf45kYaTqohHve1pGJZXcXqrRp0cgpCbwGc1e8yMYyidAUZ r9XUHbVBk0XZ8HwuN0GIdmTSu1XCaun2/MXTGZF0HRYtfToTFYs67/5BLx30L3r90z jxmAKkvI+n+efel80g6FJsWcdMM4ySoiLn7LpWej3TdO5vpsDzeH0S9czEIL9Q60Tw dn6bXSgTQfsbdMpYXALyOggczhw+StWTU9yA4hp9Elnz68NL1sudZOVHWE7+TkJYGp 3ouB/TLTboYOA== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2376D627E6 for ; Fri, 28 Jul 2023 15:37:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="YW/VLF3m"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3178fa77b27so384573f8f.2 for ; Fri, 28 Jul 2023 06:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1690551423; x=1691156223; 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=cT9tTiTNC+0dc91UzzBi/jG1dsycuMB1SbT8keFJIxg=; b=YW/VLF3mop2QtRl8zu2MDGKo3G0nK9IWVGR+Uy/AdkmszD82mohAnzlfrVm2T4Il2p nz1dGENZ/IkD7XFT1x3x6+LiSgG5KIeGu7jJmFWjblvPjR36WCc05zcRkLCt6snLwCvu EWzkhYMUsAGubuTJ94BIQq/cRa76RnM1GbwA5Nx/64XPaoNTc4as0Cb6bSj+6l7mKWWa bKdqbVFKtxK7bxefdy4WaqiQpECX1PfAxpo5hMhOWeVHXPpOp+/xyGObe6GQwngPcael F+12PYXTdkD4w+N/y5jnTjD+4hPllori4IZ/aRy+0NoN173YPtjc0q5WqUM+eqrGcxAv xudw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690551423; x=1691156223; 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=cT9tTiTNC+0dc91UzzBi/jG1dsycuMB1SbT8keFJIxg=; b=RxO6iYKKPYqDt8xAL/xBZMG1ifsbZc0KgTQmNA6Y3SzX6Xd1zZo/F2WOlcF/j516tP Y1Ea7faVwJokKT281GLfFQLnf2XdBMBYLveBfxfz3e+0TewulYyPhVPz7rs8BzKHvLZM HIKmXAfaEOj3jYvbY7YCJGLkA0JzdZY3Lz99snhnM/INkxkj8ZxXCb0b9cD9AnOJYCdL a0B6iPwVcg6KVuiT5f8lKKJ/aXXhn4LvnkyzSwVyl/g/IiA4/na9FbyhdabB0B/Tjp7n 3VDXBEXdG94s3aTkdoYdRTuhBE1oUkFoECpPuLMcIB/521jP+Yq87anua/ZZC/JEWlZu Dsuw== X-Gm-Message-State: ABy/qLbI5i8JJ6isgA563MFTzza9xGXFz+jLT70n1V55eScb/5jmbNw9 mK4b0kK0z2lGKr2l4dLi5AJCH1WBdoHdxb5AI3E= X-Google-Smtp-Source: APBJJlHtusRF9FezqKS4+whGmqwVV4LdvWwxbeZlCySKz0FdXeNK9918e/hA7pKDo5sJ+7H4Oa0bbA== X-Received: by 2002:a5d:4d8c:0:b0:317:6ada:b614 with SMTP id b12-20020a5d4d8c000000b003176adab614mr1965241wru.30.1690551423520; Fri, 28 Jul 2023 06:37:03 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:2bce:64d6:1a5c:49a2]) by smtp.gmail.com with ESMTPSA id i15-20020adffdcf000000b003145559a691sm4847758wrs.41.2023.07.28.06.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 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 Subject: [libcamera-devel] [PATCH 2/3] ipa: rpi: agc: Filter exposures before dealing with digital gain 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: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We now time-filter the exposure before sorting out how much digital gain is required. This is actually a little more natural and simplifies the code. It also prepares us for some future work where this arrangement will be helpful. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/rpi/agc.cpp | 30 +++++------------------------- src/ipa/rpi/controller/rpi/agc.h | 2 +- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp index e8526355..6087fc60 100644 --- a/src/ipa/rpi/controller/rpi/agc.cpp +++ b/src/ipa/rpi/controller/rpi/agc.cpp @@ -469,14 +469,14 @@ void Agc::process(StatisticsPtr &stats, Metadata *imageMetadata) computeGain(stats, imageMetadata, gain, targetY); /* Now compute the target (final) exposure which we think we want. */ computeTargetExposure(gain); + /* The results have to be filtered so as not to change too rapidly. */ + filterExposure(); /* * Some of the exposure has to be applied as digital gain, so work out * what that is. This function also tells us whether it's decided to * "desaturate" the image more quickly. */ bool desaturate = applyDigitalGain(gain, targetY); - /* The results have to be filtered so as not to change too rapidly. */ - filterExposure(desaturate); /* * The last thing is to divide up the exposure value into a shutter time * and analogue gain, according to the current exposure mode. @@ -757,12 +757,12 @@ bool Agc::applyDigitalGain(double gain, double targetY) if (desaturate) dg /= config_.fastReduceThreshold; LOG(RPiAgc, Debug) << "Digital gain " << dg << " desaturate? " << desaturate; - target_.totalExposureNoDG = target_.totalExposure / dg; - LOG(RPiAgc, Debug) << "Target totalExposureNoDG " << target_.totalExposureNoDG; + filtered_.totalExposureNoDG = filtered_.totalExposure / dg; + LOG(RPiAgc, Debug) << "Target totalExposureNoDG " << filtered_.totalExposureNoDG; return desaturate; } -void Agc::filterExposure(bool desaturate) +void Agc::filterExposure() { double speed = config_.speed; /* @@ -774,7 +774,6 @@ void Agc::filterExposure(bool desaturate) speed = 1.0; if (!filtered_.totalExposure) { filtered_.totalExposure = target_.totalExposure; - filtered_.totalExposureNoDG = target_.totalExposureNoDG; } else { /* * If close to the result go faster, to save making so many @@ -785,26 +784,7 @@ void Agc::filterExposure(bool desaturate) speed = sqrt(speed); filtered_.totalExposure = speed * target_.totalExposure + filtered_.totalExposure * (1.0 - speed); - /* - * When desaturing, take a big jump down in totalExposureNoDG, - * which we'll hide with digital gain. - */ - if (desaturate) - filtered_.totalExposureNoDG = - target_.totalExposureNoDG; - else - filtered_.totalExposureNoDG = - speed * target_.totalExposureNoDG + - filtered_.totalExposureNoDG * (1.0 - speed); } - /* - * We can't let the totalExposureNoDG exposure deviate too far below the - * total exposure, as there might not be enough digital gain available - * in the ISP to hide it (which will cause nasty oscillation). - */ - if (filtered_.totalExposureNoDG < - filtered_.totalExposure * config_.fastReduceThreshold) - filtered_.totalExposureNoDG = filtered_.totalExposure * config_.fastReduceThreshold; LOG(RPiAgc, Debug) << "After filtering, totalExposure " << filtered_.totalExposure << " no dg " << filtered_.totalExposureNoDG; } diff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h index 939f9729..b7122de3 100644 --- a/src/ipa/rpi/controller/rpi/agc.h +++ b/src/ipa/rpi/controller/rpi/agc.h @@ -93,8 +93,8 @@ private: void computeGain(StatisticsPtr &statistics, Metadata *imageMetadata, double &gain, double &targetY); void computeTargetExposure(double gain); + void filterExposure(); bool applyDigitalGain(double gain, double targetY); - void filterExposure(bool desaturate); void divideUpExposure(); void writeAndFinish(Metadata *imageMetadata, bool desaturate); libcamera::utils::Duration limitShutter(libcamera::utils::Duration shutter);