[{"id":14226,"web_url":"https://patchwork.libcamera.org/comment/14226/","msgid":"<X9PjMShSjsqGSLxb@pendragon.ideasonboard.com>","date":"2020-12-11T21:22:57","subject":"Re: [libcamera-devel] [PATCH v3 5/6] src: ipa: raspberrypi:\n\tEstimate the colour temerature if starting with fixed colour gains","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Tue, Dec 08, 2020 at 08:44:40PM +0000, David Plowman wrote:\n> When the AWB is started from \"cold\" with fixed colour gains, we try to\n> estimate the colour temperature this corresponds to (if a calibrated\n> CT curve was supplied). When fixed colour gains are set after the AWB\n> has been running, we leave the CT estimate alone, as the one we have\n> is probably sensible.\n> \n> This estimated colour is passed out in the metadata for other\n> algorithms - notably ALSC - to use.\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/ipa/raspberrypi/controller/rpi/alsc.cpp |  6 +++++-\n>  src/ipa/raspberrypi/controller/rpi/awb.cpp  | 14 ++++++++++++++\n>  src/ipa/raspberrypi/controller/rpi/awb.hpp  |  1 +\n>  3 files changed, 20 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n> index 183a0c95..c354c985 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n> @@ -146,6 +146,7 @@ void Alsc::Read(boost::property_tree::ptree const &params)\n>  \tconfig_.threshold = params.get<double>(\"threshold\", 1e-3);\n>  }\n>  \n> +static double get_ct(Metadata *metadata, double default_ct);\n>  static void get_cal_table(double ct,\n>  \t\t\t  std::vector<AlscCalibration> const &calibrations,\n>  \t\t\t  double cal_table[XY]);\n> @@ -210,6 +211,9 @@ void Alsc::SwitchMode(CameraMode const &camera_mode,\n>  \t// change.\n>  \tbool reset_tables = first_time_ || compare_modes(camera_mode_, camera_mode);\n>  \n> +\t// Believe the colour temperature from the AWB, if there is one.\n> +\tct_ = get_ct(metadata, ct_);\n> +\n>  \t// Ensure the other thread isn't running while we do this.\n>  \twaitForAysncThread();\n>  \n> @@ -254,7 +258,7 @@ void Alsc::fetchAsyncResults()\n>  \tmemcpy(sync_results_, async_results_, sizeof(sync_results_));\n>  }\n>  \n> -static double get_ct(Metadata *metadata, double default_ct)\n> +double get_ct(Metadata *metadata, double default_ct)\n\nIs this required ? I see there are other internal functions that are\nforward-declared as static and then defined as non-static. I thus won't\nmodify this when applying, but if it's not needed, a patch on top to\naddress all the occurrences could be nice. Bonus points if the functions\ncan be reordered to avoid statuc declarations.\n\n>  {\n>  \tAwbStatus awb_status;\n>  \tawb_status.temperature_K = default_ct; // in case nothing found\n> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp\n> index 10600f75..f66c2b29 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp\n> @@ -19,6 +19,9 @@ using namespace RPiController;\n>  \n>  const double Awb::RGB::INVALID = -1.0;\n>  \n> +// todo - the locking in this algorithm needs some tidying up as has been done\n> +// elsewhere (ALSC and AGC).\n> +\n>  void AwbMode::Read(boost::property_tree::ptree const &params)\n>  {\n>  \tct_lo = params.get<double>(\"lo\");\n> @@ -121,6 +124,7 @@ Awb::Awb(Controller *controller)\n>  \tasync_abort_ = async_start_ = async_started_ = async_finished_ = false;\n>  \tmode_ = nullptr;\n>  \tmanual_r_ = manual_b_ = 0.0;\n> +\tfirst_switch_mode_ = true;\n>  \tasync_thread_ = std::thread(std::bind(&Awb::asyncFunc, this));\n>  }\n>  \n> @@ -199,9 +203,19 @@ void Awb::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n>  \t\tprev_sync_results_.gain_r = manual_r_;\n>  \t\tprev_sync_results_.gain_g = 1.0;\n>  \t\tprev_sync_results_.gain_b = manual_b_;\n> +\t\t// If we're starting up for the first time, try and\n> +\t\t// \"dead reckon\" the corresponding colour temperature.\n> +\t\tif (first_switch_mode_ && config_.bayes) {\n> +\t\t\tPwl ct_r_inverse = config_.ct_r.Inverse();\n> +\t\t\tPwl ct_b_inverse = config_.ct_b.Inverse();\n> +\t\t\tdouble ct_r = ct_r_inverse.Eval(ct_r_inverse.Domain().Clip(1 / manual_r_));\n> +\t\t\tdouble ct_b = ct_b_inverse.Eval(ct_b_inverse.Domain().Clip(1 / manual_b_));\n> +\t\t\tprev_sync_results_.temperature_K = (ct_r + ct_b) / 2;\n> +\t\t}\n>  \t\tsync_results_ = prev_sync_results_;\n>  \t}\n>  \tmetadata->Set(\"awb.status\", prev_sync_results_);\n> +\tfirst_switch_mode_ = false;\n>  }\n>  \n>  void Awb::fetchAsyncResults()\n> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp\n> index 6fc045ce..83b81498 100644\n> --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp\n> +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp\n> @@ -159,6 +159,7 @@ private:\n>  \tdouble manual_r_;\n>  \t// manual b setting\n>  \tdouble manual_b_;\n> +\tbool first_switch_mode_; // is this the first call to SwitchMode?\n>  };\n>  \n>  static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b)","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 3596ABD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 11 Dec 2020 21:23:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B0AF56358C;\n\tFri, 11 Dec 2020 22:23:04 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 25302608A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Dec 2020 22:23:03 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9D03399;\n\tFri, 11 Dec 2020 22:23:02 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tXTFYMce\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607721782;\n\tbh=wHjcNF/HzXeatODn7Q844ABpLRZA1xlcKFQUxPeUIDo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tXTFYMceW9LpcvHuOgy7vgL7ALd9eKiP8RrSpVndUEIMSMWTGWYNcK1lpul7qqYJ7\n\t+w7qP41FJi530NkofQoZC1CiDveFi7YSFp2x1iWcOcv7AMS9OcGXww+MosnRZiKyD9\n\t2QvQWx8H//rOPEbUitxMmKBVtg105zXxeuMXhMWs=","Date":"Fri, 11 Dec 2020 23:22:57 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<X9PjMShSjsqGSLxb@pendragon.ideasonboard.com>","References":"<20201208204441.9356-1-david.plowman@raspberrypi.com>\n\t<20201208204441.9356-6-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201208204441.9356-6-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v3 5/6] src: ipa: raspberrypi:\n\tEstimate 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":"<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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]