From patchwork Mon Dec 7 18:01:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10602 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 27E43BDB1F for ; Mon, 7 Dec 2020 18:02:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E46C767E6E; Mon, 7 Dec 2020 19:02:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KRr9JXfA"; dkim-atps=neutral Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DE5B067E6A for ; Mon, 7 Dec 2020 19:02:29 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id qw4so20755662ejb.12 for ; Mon, 07 Dec 2020 10:02:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G9+1znq3c+n3y5z8pFtYQXOK6+AKuOXoD46Dro7MZM4=; b=KRr9JXfA3C64ODwJG1OsKNn+ZZn6M1N7mN37MuYy+CNCNNcePeZHVpd7XEmzn4Fdkw 2S7fKANjyCMzQg6428XLJml2laVXghh1R6/J4BQWpVqWjMzoLjvtVIZubv8+pB1WN2Dd NiLpm6XXfGU5QtqMZd6oi7mEtBIZk3hEztEQsRJf73GYuM9H0tUPTv8bOiskWdIpkIQE jgwHuMVmKk/q8NXxCJCCI892UyiuTKK7VTSo4V5MBXEf5EMB+nN8c9YnobQwTwExrIVp DJP/l4A6giMkQomoT+7IjyEvHQ5aWjMNQo5Ow7Lh/aFu7iSVDBFvMw7PKtlsyNmaPBkZ PNdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G9+1znq3c+n3y5z8pFtYQXOK6+AKuOXoD46Dro7MZM4=; b=hbDMYuiuPSEWQnwqS3+mAh9MgklayWLUKDjrdlB2j6VKnIy5kcI3wMTM46dtX4zUrw txDK9AcDcuIaYjX0JlbR+WCTO3MXJF1YPJmVMi6T4Knut8Wjw+uffTvcaBAm4yBMdpkC YcTtH9rfq0rt9ob0bUHnj+6FpZppEmD5C9cIUR5ZNDg9mUCX4nwJktAQ33BFkp5exVp/ XttMzt4XyhZcwEtd36IP4n6BM211sfnCBITswLnhItQrtuXGklj0Qy+AhCFP9C+eD3E6 D5tCaR9OHjwIwtKitDRTTHy2XFXsyJg2lw64mPR0CN8V7lxnOhD93uJIzpmSWWcwCewP jVbw== X-Gm-Message-State: AOAM531NXfY5eO9IvgJ0+uUGDvoJ5jkVfLxbasobDhmcO7v1vpnj0hqj fo+vNlGCePEayOo0AZm0kGUSdyK4PbjFfuQf X-Google-Smtp-Source: ABdhPJwKZyTcfZk46eP/Sf4LotnxOG1chpgWOgfKBQKnN6lG3IIoXT1uO9OO0BA74go+J743d2ofLQ== X-Received: by 2002:a17:906:7b82:: with SMTP id s2mr19718554ejo.435.1607364149228; Mon, 07 Dec 2020 10:02:29 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id be6sm14657977edb.29.2020.12.07.10.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 10:02:25 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 18:01:20 +0000 Message-Id: <20201207180121.6374-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201207180121.6374-1-david.plowman@raspberrypi.com> References: <20201207180121.6374-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/6] src: ipa: raspberrypi: Estimate the colour temerature if starting with fixed colour gains 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the AWB is started from "cold" with fixed colour gains, we try to estimate the colour temperature this corresponds to (if a calibrated CT curve was supplied). When fixed colour gains are set after the AWB has been running, we leave the CT estimate alone, as the one we have is probably sensible. This estimated colour is passed out in the metadata for other algorithms - notably ALSC - to use. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 6 +++++- src/ipa/raspberrypi/controller/rpi/awb.cpp | 14 ++++++++++++++ src/ipa/raspberrypi/controller/rpi/awb.hpp | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 183a0c95..c354c985 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -146,6 +146,7 @@ void Alsc::Read(boost::property_tree::ptree const ¶ms) config_.threshold = params.get("threshold", 1e-3); } +static double get_ct(Metadata *metadata, double default_ct); static void get_cal_table(double ct, std::vector const &calibrations, double cal_table[XY]); @@ -210,6 +211,9 @@ void Alsc::SwitchMode(CameraMode const &camera_mode, // change. bool reset_tables = first_time_ || compare_modes(camera_mode_, camera_mode); + // Believe the colour temperature from the AWB, if there is one. + ct_ = get_ct(metadata, ct_); + // Ensure the other thread isn't running while we do this. waitForAysncThread(); @@ -254,7 +258,7 @@ void Alsc::fetchAsyncResults() memcpy(sync_results_, async_results_, sizeof(sync_results_)); } -static double get_ct(Metadata *metadata, double default_ct) +double get_ct(Metadata *metadata, double default_ct) { AwbStatus awb_status; awb_status.temperature_K = default_ct; // in case nothing found diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index 6b359ac5..2266c07b 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -19,6 +19,9 @@ using namespace RPiController; const double Awb::RGB::INVALID = -1.0; +// todo - the locking in this algorithm needs some tidying up as has been done +// elsewhere (ALSC and AGC). + void AwbMode::Read(boost::property_tree::ptree const ¶ms) { ct_lo = params.get("lo"); @@ -121,6 +124,7 @@ Awb::Awb(Controller *controller) async_abort_ = async_start_ = async_started_ = async_finished_ = false; mode_ = nullptr; manual_r_ = manual_b_ = 0.0; + first_switch_mode_ = true; async_thread_ = std::thread(std::bind(&Awb::asyncFunc, this)); } @@ -201,9 +205,19 @@ void Awb::SwitchMode([[maybe_unused]] CameraMode const &camera_mode, prev_sync_results_.gain_r = manual_r_; prev_sync_results_.gain_g = 1.0; prev_sync_results_.gain_b = manual_b_; + // If we're starting up for the first time, try and + // "dead reckon" the corresponding colour temperature. + if (first_switch_mode_ && config_.bayes) { + Pwl ct_r_inverse = std::move(config_.ct_r.Inverse()); + Pwl ct_b_inverse = std::move(config_.ct_b.Inverse()); + double ct_r = ct_r_inverse.Eval(ct_r_inverse.Domain().Clip(1 / manual_r_)); + double ct_b = ct_b_inverse.Eval(ct_b_inverse.Domain().Clip(1 / manual_b_)); + prev_sync_results_.temperature_K = (ct_r + ct_b) / 2; + } sync_results_ = prev_sync_results_; } metadata->Set("awb.status", prev_sync_results_); + first_switch_mode_ = false; } void Awb::fetchAsyncResults() diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp index d86b9598..8525af32 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp @@ -159,6 +159,7 @@ private: double manual_r_; // manual b setting double manual_b_; + bool first_switch_mode_; // is this the first call to SwitchMode? }; static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b)