[{"id":25134,"web_url":"https://patchwork.libcamera.org/comment/25134/","msgid":"<20220927092204.kxk2fvaabo6bspun@uno.localdomain>","date":"2022-09-27T09:22:04","subject":"Re: [libcamera-devel] [PATCH v5 32/33] ipa: rkisp1: awb: Freeze AWB\n\twhen means are too small","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Tue, Sep 27, 2022 at 05:36:41AM +0300, Laurent Pinchart via libcamera-devel wrote:\n> When the RGB means are too small, gains and color temperature can't be\n> meaningfully calculated. Freeze the AWB in that case, using the\n> previously calculated values.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n\n> ---\n>  src/ipa/rkisp1/algorithms/awb.cpp | 17 ++++++++++++++++-\n>  src/ipa/rkisp1/ipa_context.cpp    |  3 +++\n>  src/ipa/rkisp1/ipa_context.h      |  1 +\n>  3 files changed, 20 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index a3066fbb1994..eb32cd722071 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -31,6 +31,9 @@ namespace ipa::rkisp1::algorithms {\n>\n>  LOG_DEFINE_CATEGORY(RkISP1Awb)\n>\n> +/* Minimum mean value below which AWB can't operate. */\n> +constexpr double kMeanMinThreshold = 2.0;\n> +\n>  Awb::Awb()\n>  \t: rgbMode_(false)\n>  {\n> @@ -263,7 +266,17 @@ void Awb::process(IPAContext &context,\n>  \tgreenMean /= frameContext.awb.gains.green;\n>  \tblueMean /= frameContext.awb.gains.blue;\n>\n> -\tframeContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);\n> +\t/*\n> +\t * If the means are too small we don't have enough information to\n> +\t * meaningfully calculate gains. Freeze the algorithm in that case.\n> +\t */\n> +\tif (redMean < kMeanMinThreshold && greenMean < kMeanMinThreshold &&\n> +\t    blueMean < kMeanMinThreshold) {\n> +\t\tframeContext.awb.temperatureK = activeState.awb.temperatureK;\n> +\t\treturn;\n> +\t}\n> +\n> +\tactiveState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);\n>\n>  \t/*\n>  \t * Estimate the red and blue gains to apply in a grey world. The green\n> @@ -290,6 +303,8 @@ void Awb::process(IPAContext &context,\n>  \tactiveState.awb.gains.automatic.blue = blueGain;\n>  \tactiveState.awb.gains.automatic.green = 1.0;\n>\n> +\tframeContext.awb.temperatureK = activeState.awb.temperatureK;\n> +\n>  \tLOG(RkISP1Awb, Debug) << std::showpoint\n>  \t\t<< \"Means [\" << redMean << \", \" << greenMean << \", \" << blueMean\n>  \t\t<< \"], gains [\" << activeState.awb.gains.automatic.red << \", \"\n> diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\n> index 2126ed1d0acb..b00dc29c1713 100644\n> --- a/src/ipa/rkisp1/ipa_context.cpp\n> +++ b/src/ipa/rkisp1/ipa_context.cpp\n> @@ -156,6 +156,9 @@ namespace libcamera::ipa::rkisp1 {\n>   * \\var IPAActiveState::awb.gains.automatic.blue\n>   * \\brief Automatic white balance gain for B channel\n>   *\n> + * \\var IPAActiveState::awb.temperatureK\n> + * \\brief Estimated color temperature\n> + *\n>   * \\var IPAActiveState::awb.autoEnabled\n>   * \\brief Whether the Auto White Balance algorithm is enabled\n>   */\n> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\n> index d0692f872960..0677c8c35d73 100644\n> --- a/src/ipa/rkisp1/ipa_context.h\n> +++ b/src/ipa/rkisp1/ipa_context.h\n> @@ -69,6 +69,7 @@ struct IPAActiveState {\n>  \t\t\t} automatic;\n>  \t\t} gains;\n>\n> +\t\tunsigned int temperatureK;\n>  \t\tbool autoEnabled;\n>  \t} awb;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","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 7F579C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Sep 2022 09:22:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4C2126226F;\n\tTue, 27 Sep 2022 11:22:07 +0200 (CEST)","from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5522C61F7B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Sep 2022 11:22:06 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id D1A491BF206;\n\tTue, 27 Sep 2022 09:22:05 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664270527;\n\tbh=CwU/kAK26zKRO/pZTj6FpCG+oaAeuIDvI5lquNDGAfE=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=uchG7uE81yDDhDvciookbdbQZw/8cFGlHS4s4zDN1zh9EZHPjCODhl5DgZ2h31ySn\n\tFEYRUBihi1o5lt4P6HKl+IugzlWau7iRrvvz5ieGsV6h8G3rZHDCYvHkxucJYYJQxg\n\tFFXr3aIOsfaGnfr/nzc6lIv13P/AlKLg1eegI2eLG+g1H3/LDWMIyH7KCt33pEG7g7\n\tmnV7glJyahkJse8uwvqAvElFJSAVpKUwJSrvZEyFZjtg7pjuWNBpOWf0vUuopTRJXO\n\tYjhgvesxSw1XW6FjE6RMlntM3ru0oWGFLK6c1RnavhVyUAHkwSlaNchPW+EVbi6sA/\n\tMVcjWXwOg4xrA==","Date":"Tue, 27 Sep 2022 11:22:04 +0200","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220927092204.kxk2fvaabo6bspun@uno.localdomain>","References":"<20220927023642.12341-1-laurent.pinchart@ideasonboard.com>\n\t<20220927023642.12341-33-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220927023642.12341-33-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v5 32/33] ipa: rkisp1: awb: Freeze AWB\n\twhen means are too small","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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]