{"id":10954,"url":"https://patchwork.libcamera.org/api/patches/10954/?format=json","web_url":"https://patchwork.libcamera.org/patch/10954/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210122102211.12768-4-david.plowman@raspberrypi.com>","date":"2021-01-22T10:22:09","name":"[libcamera-devel,3/5] ipa: raspberrypi: awb: Replace Raspberry Pi debug with libcamera debug","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"03943b0f0479048a0b236efb956ed1f32ec3163c","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/10954/mbox/","series":[{"id":1597,"url":"https://patchwork.libcamera.org/api/series/1597/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1597","date":"2021-01-22T10:22:06","name":"Remove Raspberry Pi logging","version":1,"mbox":"https://patchwork.libcamera.org/series/1597/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10954/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10954/checks/","tags":{},"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 EB233BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Jan 2021 10:22:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A386C68244;\n\tFri, 22 Jan 2021 11:22:28 +0100 (CET)","from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com\n\t[IPv6:2a00:1450:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C46A968232\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jan 2021 11:22:26 +0100 (CET)","by mail-wr1-x42a.google.com with SMTP id a12so4546978wrv.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jan 2021 02:22:26 -0800 (PST)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tp15sm11469221wrt.15.2021.01.22.02.22.25\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 22 Jan 2021 02:22:25 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"JsI6qv6W\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=zb3NETcE7o4MJ7BSr2BjfXSGp5ODCyGLNCbIC2n8h1M=;\n\tb=JsI6qv6W/nsQiCM6z8FLjsmaz8urpnVjPVV+AjT7FvmjRqr9hq66oj74jhtPrDiPyN\n\thhHf84e+Tpt95oyt+j/4mZfe5BVtLDrMPR7Q6nbIG/KGlU7/3Q0Z341GekAo5mPD7S6P\n\tZmof0w42w/KHiY6slCdADlyDMrM5HYW3o2+zvP0rj/Xd92ia8Ia9upF0PhN7CCJW1Bpq\n\tGF9ZC99luYty8K2DaWPjqeT4xPEc2GXxZjDTZO2ygZTJFh5D2yMcmMqbbWvD7Itjjgk2\n\tXgRxG28xwFe4kfQ9sPsBFwZMTVKG0+Y9p/WIfX/gddOFp5NJsc1aXa1Dw3/TFjLmoH5F\n\tvd6A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=zb3NETcE7o4MJ7BSr2BjfXSGp5ODCyGLNCbIC2n8h1M=;\n\tb=Hu62QzdCeU5wyBUoUvwCU/lSNPzvutk8JCq0Hd9PWh8SDkXblhET1u/iSVs5hLaGuN\n\tOYqnq0ITh7sWgFOl8iHxhnyQMUYlbym0hy3hyl4rQwfPKQQqR9Bm+es25eoNY30NNuW7\n\tb9RPCt+PrjpGcC5RcthOvq1nX57x5m7mDnD1yA5ac5/jcpRpzMeZU2nteLv8HCkFA8HF\n\t6mCNfTng97U6lrEPsXnIoWNFXWfdX5BdgnltsMcuQPmbtHhTMw8MSBfLrsWeAcwUORDD\n\toYIfN8rKgqhZzO+3qwkJ8m1GBz9FufrKhG6husfjXG4GxOOAMKsIDKWyXkxJpk7XpigS\n\tVMmQ==","X-Gm-Message-State":"AOAM532IcjvVCR4SJ/oDW7/eEX53mK2XUKM8vV8WXZ5gaS7AARNTGd0Z\n\tVWddxTf7oamklwp+TvX5I7tuQfcqtVmS0b5g","X-Google-Smtp-Source":"ABdhPJwycL+cV+BjhJpbVzZWuLQw/w2lpfRpPKhioOtJO1rK75cnCCztSDOTs+wQHx9CeJ9D11ZSGQ==","X-Received":"by 2002:adf:edc8:: with SMTP id v8mr3713385wro.374.1611310946012;\n\tFri, 22 Jan 2021 02:22:26 -0800 (PST)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 22 Jan 2021 10:22:09 +0000","Message-Id":"<20210122102211.12768-4-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20210122102211.12768-1-david.plowman@raspberrypi.com>","References":"<20210122102211.12768-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 3/5] ipa: raspberrypi: awb: Replace\n\tRaspberry Pi debug with libcamera debug","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>","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>"},"content":"Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/awb.cpp | 92 +++++++++++-----------\n 1 file changed, 47 insertions(+), 45 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp\nindex f66c2b29..34f3644b 100644\n--- a/src/ipa/raspberrypi/controller/rpi/awb.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp\n@@ -5,12 +5,16 @@\n  * awb.cpp - AWB control algorithm\n  */\n \n-#include \"../logging.hpp\"\n+#include \"libcamera/internal/log.h\"\n+\n #include \"../lux_status.h\"\n \n #include \"awb.hpp\"\n \n using namespace RPiController;\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(RPiAwb)\n \n #define NAME \"rpi.awb\"\n \n@@ -58,7 +62,7 @@ static void read_ct_curve(Pwl &ct_r, Pwl &ct_b,\n \n void AwbConfig::Read(boost::property_tree::ptree const &params)\n {\n-\tRPI_LOG(\"AwbConfig\");\n+\tLOG(RPiAwb, Debug) << \"AwbConfig\";\n \tbayes = params.get<int>(\"bayes\", 1);\n \tframe_period = params.get<uint16_t>(\"frame_period\", 10);\n \tstartup_frames = params.get<uint16_t>(\"startup_frames\", 10);\n@@ -104,8 +108,7 @@ void AwbConfig::Read(boost::property_tree::ptree const &params)\n \tif (bayes) {\n \t\tif (ct_r.Empty() || ct_b.Empty() || priors.empty() ||\n \t\t    default_mode == nullptr) {\n-\t\t\tRPI_WARN(\n-\t\t\t\t\"Bayesian AWB mis-configured - switch to Grey method\");\n+\t\t\tLOG(RPiAwb, Warning) << \"Bayesian AWB mis-configured - switch to Grey method\";\n \t\t\tbayes = false;\n \t\t}\n \t}\n@@ -220,7 +223,7 @@ void Awb::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,\n \n void Awb::fetchAsyncResults()\n {\n-\tRPI_LOG(\"Fetch AWB results\");\n+\tLOG(RPiAwb, Debug) << \"Fetch AWB results\";\n \tasync_finished_ = false;\n \tasync_started_ = false;\n \tsync_results_ = async_results_;\n@@ -229,7 +232,7 @@ void Awb::fetchAsyncResults()\n void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name,\n \t\t       double lux)\n {\n-\tRPI_LOG(\"Starting AWB thread\");\n+\tLOG(RPiAwb, Debug) << \"Starting AWB thread\";\n \t// this makes a new reference which belongs to the asynchronous thread\n \tstatistics_ = stats;\n \t// store the mode as it could technically change\n@@ -254,11 +257,11 @@ void Awb::Prepare(Metadata *image_metadata)\n \tdouble speed = frame_count_ < (int)config_.startup_frames\n \t\t\t       ? 1.0\n \t\t\t       : config_.speed;\n-\tRPI_LOG(\"Awb: frame_count \" << frame_count_ << \" speed \" << speed);\n+\tLOG(RPiAwb, Debug) << \"Awb: frame_count \" << frame_count_ << \" speed \" << speed;\n \t{\n \t\tstd::unique_lock<std::mutex> lock(mutex_);\n \t\tif (async_started_ && async_finished_) {\n-\t\t\tRPI_LOG(\"AWB thread finished\");\n+\t\t\tLOG(RPiAwb, Debug) << \"AWB thread finished\";\n \t\t\tfetchAsyncResults();\n \t\t}\n \t}\n@@ -275,9 +278,9 @@ void Awb::Prepare(Metadata *image_metadata)\n \tprev_sync_results_.gain_b = speed * sync_results_.gain_b +\n \t\t\t\t    (1.0 - speed) * prev_sync_results_.gain_b;\n \timage_metadata->Set(\"awb.status\", prev_sync_results_);\n-\tRPI_LOG(\"Using AWB gains r \" << prev_sync_results_.gain_r << \" g \"\n-\t\t\t\t     << prev_sync_results_.gain_g << \" b \"\n-\t\t\t\t     << prev_sync_results_.gain_b);\n+\tLOG(RPiAwb, Debug) << \"Using AWB gains r \" << prev_sync_results_.gain_r << \" g \"\n+\t\t\t   << prev_sync_results_.gain_g << \" b \"\n+\t\t\t   << prev_sync_results_.gain_b;\n }\n \n void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata)\n@@ -287,7 +290,7 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata)\n \t\tframe_phase_++;\n \tif (frame_count2_ < (int)config_.startup_frames)\n \t\tframe_count2_++;\n-\tRPI_LOG(\"Awb: frame_phase \" << frame_phase_);\n+\tLOG(RPiAwb, Debug) << \"Awb: frame_phase \" << frame_phase_;\n \tif (frame_phase_ >= (int)config_.frame_period ||\n \t    frame_count2_ < (int)config_.startup_frames) {\n \t\t// Update any settings and any image metadata that we need.\n@@ -299,12 +302,12 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata)\n \t\tstruct LuxStatus lux_status = {};\n \t\tlux_status.lux = 400; // in case no metadata\n \t\tif (image_metadata->Get(\"lux.status\", lux_status) != 0)\n-\t\t\tRPI_LOG(\"No lux metadata found\");\n-\t\tRPI_LOG(\"Awb lux value is \" << lux_status.lux);\n+\t\t\tLOG(RPiAwb, Debug) << \"No lux metadata found\";\n+\t\tLOG(RPiAwb, Debug) << \"Awb lux value is \" << lux_status.lux;\n \n \t\tstd::unique_lock<std::mutex> lock(mutex_);\n \t\tif (async_started_ == false) {\n-\t\t\tRPI_LOG(\"AWB thread starting\");\n+\t\t\tLOG(RPiAwb, Debug) << \"AWB thread starting\";\n \t\t\trestartAsync(stats, mode_name, lux_status.lux);\n \t\t}\n \t}\n@@ -375,7 +378,7 @@ double Awb::computeDelta2Sum(double gain_r, double gain_b)\n \t\tdouble delta_r = gain_r * z.R - 1 - config_.whitepoint_r;\n \t\tdouble delta_b = gain_b * z.B - 1 - config_.whitepoint_b;\n \t\tdouble delta2 = delta_r * delta_r + delta_b * delta_b;\n-\t\t//RPI_LOG(\"delta_r \" << delta_r << \" delta_b \" << delta_b << \" delta2 \" << delta2);\n+\t\t//LOG(RPiAwb, Debug) << \"delta_r \" << delta_r << \" delta_b \" << delta_b << \" delta2 \" << delta2;\n \t\tdelta2 = std::min(delta2, config_.delta_limit);\n \t\tdelta2_sum += delta2;\n \t}\n@@ -438,10 +441,10 @@ double Awb::coarseSearch(Pwl const &prior)\n \t\tdouble prior_log_likelihood =\n \t\t\tprior.Eval(prior.Domain().Clip(t));\n \t\tdouble final_log_likelihood = delta2_sum - prior_log_likelihood;\n-\t\tRPI_LOG(\"t: \" << t << \" gain_r \" << gain_r << \" gain_b \"\n-\t\t\t      << gain_b << \" delta2_sum \" << delta2_sum\n-\t\t\t      << \" prior \" << prior_log_likelihood << \" final \"\n-\t\t\t      << final_log_likelihood);\n+\t\tLOG(RPiAwb, Debug) << \"t: \" << t << \" gain_r \" << gain_r << \" gain_b \"\n+\t\t\t\t   << gain_b << \" delta2_sum \" << delta2_sum\n+\t\t\t\t   << \" prior \" << prior_log_likelihood << \" final \"\n+\t\t\t\t   << final_log_likelihood;\n \t\tpoints_.push_back(Pwl::Point(t, final_log_likelihood));\n \t\tif (points_.back().y < points_[best_point].y)\n \t\t\tbest_point = points_.size() - 1;\n@@ -452,7 +455,7 @@ double Awb::coarseSearch(Pwl const &prior)\n \t\t\t     mode_->ct_hi);\n \t}\n \tt = points_[best_point].x;\n-\tRPI_LOG(\"Coarse search found CT \" << t);\n+\tLOG(RPiAwb, Debug) << \"Coarse search found CT \" << t;\n \t// We have the best point of the search, but refine it with a quadratic\n \t// interpolation around its neighbours.\n \tif (points_.size() > 2) {\n@@ -461,8 +464,8 @@ double Awb::coarseSearch(Pwl const &prior)\n \t\tt = interpolate_quadatric(points_[best_point - 1],\n \t\t\t\t\t  points_[best_point],\n \t\t\t\t\t  points_[best_point + 1]);\n-\t\tRPI_LOG(\"After quadratic refinement, coarse search has CT \"\n-\t\t\t<< t);\n+\t\tLOG(RPiAwb, Debug) << \"After quadratic refinement, coarse search has CT \"\n+\t\t\t\t   << t;\n \t}\n \treturn t;\n }\n@@ -514,8 +517,8 @@ void Awb::fineSearch(double &t, double &r, double &b, Pwl const &prior)\n \t\t\tdouble gain_r = 1 / r_test, gain_b = 1 / b_test;\n \t\t\tdouble delta2_sum = computeDelta2Sum(gain_r, gain_b);\n \t\t\tpoints[j].y = delta2_sum - prior_log_likelihood;\n-\t\t\tRPI_LOG(\"At t \" << t_test << \" r \" << r_test << \" b \"\n-\t\t\t\t\t<< b_test << \": \" << points[j].y);\n+\t\t\tLOG(RPiAwb, Debug) << \"At t \" << t_test << \" r \" << r_test << \" b \"\n+\t\t\t\t\t   << b_test << \": \" << points[j].y;\n \t\t\tif (points[j].y < points[best_point].y)\n \t\t\t\tbest_point = j;\n \t\t}\n@@ -532,17 +535,16 @@ void Awb::fineSearch(double &t, double &r, double &b, Pwl const &prior)\n \t\tdouble gain_r = 1 / r_test, gain_b = 1 / b_test;\n \t\tdouble delta2_sum = computeDelta2Sum(gain_r, gain_b);\n \t\tdouble final_log_likelihood = delta2_sum - prior_log_likelihood;\n-\t\tRPI_LOG(\"Finally \"\n-\t\t\t<< t_test << \" r \" << r_test << \" b \" << b_test << \": \"\n-\t\t\t<< final_log_likelihood\n-\t\t\t<< (final_log_likelihood < best_log_likelihood ? \" BEST\"\n-\t\t\t\t\t\t\t\t       : \"\"));\n+\t\tLOG(RPiAwb, Debug) << \"Finally \"\n+\t\t\t\t   << t_test << \" r \" << r_test << \" b \" << b_test << \": \"\n+\t\t\t\t   << final_log_likelihood\n+\t\t\t\t   << (final_log_likelihood < best_log_likelihood ? \" BEST\" : \"\");\n \t\tif (best_t == 0 || final_log_likelihood < best_log_likelihood)\n \t\t\tbest_log_likelihood = final_log_likelihood,\n \t\t\tbest_t = t_test, best_r = r_test, best_b = b_test;\n \t}\n \tt = best_t, r = best_r, b = best_b;\n-\tRPI_LOG(\"Fine search found t \" << t << \" r \" << r << \" b \" << b);\n+\tLOG(RPiAwb, Debug) << \"Fine search found t \" << t << \" r \" << r << \" b \" << b;\n }\n \n void Awb::awbBayes()\n@@ -556,13 +558,13 @@ void Awb::awbBayes()\n \tPwl prior = interpolatePrior();\n \tprior *= zones_.size() / (double)(AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y);\n \tprior.Map([](double x, double y) {\n-\t\tRPI_LOG(\"(\" << x << \",\" << y << \")\");\n+\t\tLOG(RPiAwb, Debug) << \"(\" << x << \",\" << y << \")\";\n \t});\n \tdouble t = coarseSearch(prior);\n \tdouble r = config_.ct_r.Eval(t);\n \tdouble b = config_.ct_b.Eval(t);\n-\tRPI_LOG(\"After coarse search: r \" << r << \" b \" << b << \" (gains r \"\n-\t\t\t\t\t  << 1 / r << \" b \" << 1 / b << \")\");\n+\tLOG(RPiAwb, Debug) << \"After coarse search: r \" << r << \" b \" << b << \" (gains r \"\n+\t\t\t   << 1 / r << \" b \" << 1 / b << \")\";\n \t// Not entirely sure how to handle the fine search yet. Mostly the\n \t// estimated CT is already good enough, but the fine search allows us to\n \t// wander transverely off the CT curve. Under some illuminants, where\n@@ -570,8 +572,8 @@ void Awb::awbBayes()\n \t// though I probably need more real datasets before deciding exactly how\n \t// this should be controlled and tuned.\n \tfineSearch(t, r, b, prior);\n-\tRPI_LOG(\"After fine search: r \" << r << \" b \" << b << \" (gains r \"\n-\t\t\t\t\t<< 1 / r << \" b \" << 1 / b << \")\");\n+\tLOG(RPiAwb, Debug) << \"After fine search: r \" << r << \" b \" << b << \" (gains r \"\n+\t\t\t   << 1 / r << \" b \" << 1 / b << \")\";\n \t// Write results out for the main thread to pick up. Remember to adjust\n \t// the gains from the ones that the \"canonical sensor\" would require to\n \t// the ones needed by *this* sensor.\n@@ -583,7 +585,7 @@ void Awb::awbBayes()\n \n void Awb::awbGrey()\n {\n-\tRPI_LOG(\"Grey world AWB\");\n+\tLOG(RPiAwb, Debug) << \"Grey world AWB\";\n \t// Make a separate list of the derivatives for each of red and blue, so\n \t// that we can sort them to exclude the extreme gains.  We could\n \t// consider some variations, such as normalising all the zones first, or\n@@ -620,21 +622,21 @@ void Awb::doAwb()\n \t\tasync_results_.gain_r = manual_r_;\n \t\tasync_results_.gain_g = 1.0;\n \t\tasync_results_.gain_b = manual_b_;\n-\t\tRPI_LOG(\"Using manual white balance: gain_r \"\n-\t\t\t<< async_results_.gain_r << \" gain_b \"\n-\t\t\t<< async_results_.gain_b);\n+\t\tLOG(RPiAwb, Debug) << \"Using manual white balance: gain_r \"\n+\t\t\t\t   << async_results_.gain_r << \" gain_b \"\n+\t\t\t\t   << async_results_.gain_b;\n \t} else {\n \t\tprepareStats();\n-\t\tRPI_LOG(\"Valid zones: \" << zones_.size());\n+\t\tLOG(RPiAwb, Debug) << \"Valid zones: \" << zones_.size();\n \t\tif (zones_.size() > config_.min_regions) {\n \t\t\tif (config_.bayes)\n \t\t\t\tawbBayes();\n \t\t\telse\n \t\t\t\tawbGrey();\n-\t\t\tRPI_LOG(\"CT found is \"\n-\t\t\t\t<< async_results_.temperature_K\n-\t\t\t\t<< \" with gains r \" << async_results_.gain_r\n-\t\t\t\t<< \" and b \" << async_results_.gain_b);\n+\t\t\tLOG(RPiAwb, Debug) << \"CT found is \"\n+\t\t\t\t\t   << async_results_.temperature_K\n+\t\t\t\t\t   << \" with gains r \" << async_results_.gain_r\n+\t\t\t\t\t   << \" and b \" << async_results_.gain_b;\n \t\t}\n \t}\n }\n","prefixes":["libcamera-devel","3/5"]}