From patchwork Thu Oct 27 11:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 17701 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 74D38BD16B for ; Thu, 27 Oct 2022 11:40:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D955A62F87; Thu, 27 Oct 2022 13:40:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666870809; bh=7DtEcKB6Y/vYDPtigNOGHOhe5G1W2wRl8cLenLRqCe0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=4QbdXtQ6zOSLQquGau0O3ZFKABDr7pFt/MByuYw0Ph8/pzXPFD854bC5zJzAuKOWs F9T33GjnrRpFUDvVxhYVBoZSVfin4pkEyrZLfiU7+wAv68wUi6VU0+Tbv1g+hFiUfP /Z0ZcIZv7a/FW+ub1LaURwnk5q9Cy/2qLUPCnDTtUjjo+5GLiIKHuBUDuEA9NOyiqB 1ZyuQ0HccYRcJc7jen8gZ5ORHEYSQHx7ykECMhaXEb7w3+EkvssrNCi0B6UYStQJNO s7xtJ6qEgNTCoQNIzzUabZBc2SyyhYsEi8ZYlEICp3wNmzE9pShn85lAn83R9MAAuF 1rLC4miL7JU/w== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A36C962F0C for ; Thu, 27 Oct 2022 13:40:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="U86QPiKZ"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id a14so1698070wru.5 for ; Thu, 27 Oct 2022 04:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+Ulk/1RYgIvbf97P4QQS65Z/beEG23xHntTXv82ASJw=; b=U86QPiKZxm5QeYhsXqrS4GFLkBwWD3s2xswmHy61b8iYY/LlWrA5kEflexSsryMtKx 4lnvaWYPJm5sGD0jeXujcEs0DLtLzgAlPRuStqvstbIwsytO73x2EHaYL0LzTb9ArSlg XLxF2naublomU/Trynhe5T3iNeQB++/cPMdZjfLCxDyWeIvXe8WVu/25MRgAWQ58aThY f7NuHRB4z5UvUzQsXe3BsC8Np/EG7L8b3XrxfhyyNhulJf7879PLUp4iCZWX77XPZGcQ jwn56/Sh/J+OK/YxUpCmMGjsL50+nw5m10Chkc9UbS/akLf3MqRuhKpGVGximpZxY/4Y cvew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+Ulk/1RYgIvbf97P4QQS65Z/beEG23xHntTXv82ASJw=; b=28w7N+KmSM5n6Jg/7N8+Q83ADKU+5oxgCRDUOscTALdn3vUtJS8UsiWuMkQoZ9H+mf iKvQcZQownp8wlDqS2IY/tNuZDklbH4W4j6CmqfBc/tOroHJumuH/jakgRSCu6D+Sk3h x2GE/oX5HSPZeTyicCpHmVGumZNKMn+2ZO7DtgzDQ6zXyy0m6a7Xu62cS8VcB7iQnmoG BiI8RqevtE2KdlmgznQGmtb6seSTS30Z529pBWCk0IfTogef5e9Q8D2VpBHPpiyrrSgM N8GSIFUe5afMmJr/TBx7Vqmvt4As4HroUXGEI1sLPuP6mVtOZwAwsM56I8xDZP0CGHVn WnPg== X-Gm-Message-State: ACrzQf05Ifo7x56B+eopMIgcJC8yO8sN+ndxVdxrjKk8W85vsUii2gGH +XIeWzQuU4dut8Za8Q0Wd+d0wpiHrYvqMg== X-Google-Smtp-Source: AMsMyM5u7cAPb943J/e3IAI7RGi7RHMpDPt6g7bgOejo9r1IJZ5jwme6RrvL+H+tMCe26Qk0epdGrQ== X-Received: by 2002:a5d:6dc2:0:b0:236:5107:f5ba with SMTP id d2-20020a5d6dc2000000b002365107f5bamr22399648wrz.522.1666870807906; Thu, 27 Oct 2022 04:40:07 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id g23-20020a7bc4d7000000b003b3307fb98fsm1253529wmk.24.2022.10.27.04.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 04:40:07 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 27 Oct 2022 12:39:56 +0100 Message-Id: <20221027113956.7854-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: raspberrypi: awb: Update colour temperature whenever manual gains change 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" Previously we only did this when the system starts (on the first switch_mode). Now we do it whenever the manual colour gains are updated. To facilitate this, this R/B vs. colour temperature inverse functions are stored persistently in the AwbConfig. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 24 +++++++++------------- src/ipa/raspberrypi/controller/rpi/awb.h | 3 ++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index 2b88c3b0..8d8ddf09 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -104,6 +104,9 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) ret = readCtCurve(ctR, ctB, params["ct_curve"]); if (ret) return ret; + /* We will want the inverse functions of these too. */ + ctRInverse = ctR.inverse(); + ctBInverse = ctB.inverse(); } if (params.contains("priors")) { @@ -174,7 +177,6 @@ Awb::Awb(Controller *controller) asyncAbort_ = asyncStart_ = asyncStarted_ = asyncFinished_ = false; mode_ = nullptr; manualR_ = manualB_ = 0.0; - firstSwitchMode_ = true; asyncThread_ = std::thread(std::bind(&Awb::asyncFunc, this)); } @@ -270,27 +272,21 @@ void Awb::setManualGains(double manualR, double manualB) syncResults_.gainR = prevSyncResults_.gainR = manualR_; syncResults_.gainG = prevSyncResults_.gainG = 1.0; syncResults_.gainB = prevSyncResults_.gainB = manualB_; + if (config_.bayes) { + /* Also estimate the best corresponding colour temperature from the curves. */ + double ctR = config_.ctRInverse.eval(config_.ctRInverse.domain().clip(1 / manualR_)); + double ctB = config_.ctBInverse.eval(config_.ctBInverse.domain().clip(1 / manualB_)); + prevSyncResults_.temperatureK = (ctR + ctB) / 2; + syncResults_.temperatureK = prevSyncResults_.temperatureK; + } } } void Awb::switchMode([[maybe_unused]] CameraMode const &cameraMode, Metadata *metadata) { - /* - * On the first mode switch we'll have no meaningful colour - * temperature, so try to dead reckon one if in manual mode. - */ - if (!isAutoEnabled() && firstSwitchMode_ && config_.bayes) { - Pwl ctRInverse = config_.ctR.inverse(); - Pwl ctBInverse = config_.ctB.inverse(); - double ctR = ctRInverse.eval(ctRInverse.domain().clip(1 / manualR_)); - double ctB = ctBInverse.eval(ctBInverse.domain().clip(1 / manualB_)); - prevSyncResults_.temperatureK = (ctR + ctB) / 2; - syncResults_.temperatureK = prevSyncResults_.temperatureK; - } /* Let other algorithms know the current white balance values. */ metadata->set("awb.status", prevSyncResults_); - firstSwitchMode_ = false; } bool Awb::isAutoEnabled() const diff --git a/src/ipa/raspberrypi/controller/rpi/awb.h b/src/ipa/raspberrypi/controller/rpi/awb.h index cb4cfd1b..30acd89d 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.h +++ b/src/ipa/raspberrypi/controller/rpi/awb.h @@ -42,6 +42,8 @@ struct AwbConfig { bool fast; /* "fast" mode uses a 16x16 rather than 32x32 grid */ Pwl ctR; /* function maps CT to r (= R/G) */ Pwl ctB; /* function maps CT to b (= B/G) */ + Pwl ctRInverse; /* inverse of ctR */ + Pwl ctBInverse; /* inverse of ctB */ /* table of illuminant priors at different lux levels */ std::vector priors; /* AWB "modes" (determines the search range) */ @@ -168,7 +170,6 @@ private: double manualR_; /* manual b setting */ double manualB_; - bool firstSwitchMode_; /* is this the first call to SwitchMode? */ }; static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b)