From patchwork Fri Jan 22 10:22:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10953 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 56E84BD808 for ; Fri, 22 Jan 2021 10:22:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26E3F68245; Fri, 22 Jan 2021 11:22:28 +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="Jd4QQug1"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C01AE6823E for ; Fri, 22 Jan 2021 11:22:25 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id 7so4559776wrz.0 for ; Fri, 22 Jan 2021 02:22:25 -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=BVpqEkyfRSBU5rwlFMvrdOl3XxcNgdfc+RDlkGm4n4o=; b=Jd4QQug1SdAGd4xyjMqA3IYl2PE3WjbmO2jx8PbIbhnbZpwXCubQNfRTvrDpquoqvs CoZUcJ3UGsgwbg15wlwmaMY2YltagEPKdApXNQ5J/BKB3JXyAg8TKf8BHSG0S6Miv4bA mSgJHRTzWD4D3CkPg2dZdK4P5eC7UhAk9wYBQVkPrm2fhV5tRMpEx7X/2YQwXGI3nhGG XivnzEphtp3ppDRqR6dlV/IMgZGGEBBs4yz23u3488J6Z2xhnhGLYeOi9+/1MTfBOyrE 2czAP+XusQ26WEKH+6fhtNzWq0w0xZJfp9o5ImeM6/hJYSHwxIkFDLhg99t+N2fc/BQ2 A4iw== 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=BVpqEkyfRSBU5rwlFMvrdOl3XxcNgdfc+RDlkGm4n4o=; b=mXur+gq8tlSHpdjtW8jB0Ehma64MXXgSV7T7wGdtkLLZNUm20nekmk2ImL9LNI6IZL Z214LEjukU6Zqzmdstzontu3MtknZ5GtIp1uOx/AfDyZ9Q4hzGhTNYXIDO/c2WrnRggO uovlzdgsUHw33DHvsKWT0en2fdJSLgeQMHGlyM8Qhp7GyF+NdwWLVKlde5ZuK86weqFV A3RHBR1Gl55Frfo0pV9aIV7VgTUNQjn8YNUxj1816vPEkeGwJhh1vAG+i5Ic+LOb3fa0 rJlSdNua0Z2cByglICSNMdA/4valRu+bexs1Bx5bZj9KDBYLfqibnm7smk5OZ+styn5z zwOg== X-Gm-Message-State: AOAM530qz5n2a9lFUHoaCNHIEw0cTcNvqYk/br3qbfJeriCyCz7Pgkh8 0MikYTgVaD6kU2gwm+w7VzjuviRtKwcH/p5g X-Google-Smtp-Source: ABdhPJwx2wr8BX9HW7FhyeclcOY2QGBMJjwH5lZ6PVRuQrHY0bT4hVxTcuIlM+b6o5dhXhk7WUHLzA== X-Received: by 2002:adf:e610:: with SMTP id p16mr3711421wrm.169.1611310945096; Fri, 22 Jan 2021 02:22:25 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id p15sm11469221wrt.15.2021.01.22.02.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 02:22:24 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jan 2021 10:22:08 +0000 Message-Id: <20210122102211.12768-3-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 2/5] ipa: raspberrypi: alsc: Replace Raspberry Pi debug with libcamera debug 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" Signed-off-by: David Plowman --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 59 +++++++++++---------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index c354c985..4777238c 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -6,12 +6,17 @@ */ #include +#include "libcamera/internal/log.h" + #include "../awb_status.h" #include "alsc.hpp" // Raspberry Pi ALSC (Auto Lens Shading Correction) algorithm. using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiAlsc) #define NAME "rpi.alsc" @@ -110,15 +115,15 @@ static void read_calibrations(std::vector &calibrations, "Alsc: too few values for ct " + std::to_string(ct) + " in " + name); calibrations.push_back(calibration); - RPI_LOG("Read " << name << " calibration for ct " - << ct); + LOG(RPiAlsc, Debug) << "Read " << name << " calibration for ct " + << ct; } } } void Alsc::Read(boost::property_tree::ptree const ¶ms) { - RPI_LOG("Alsc"); + LOG(RPiAlsc, Debug) << "Alsc"; config_.frame_period = params.get("frame_period", 12); config_.startup_frames = params.get("startup_frames", 10); config_.speed = params.get("speed", 0.05); @@ -139,7 +144,7 @@ void Alsc::Read(boost::property_tree::ptree const ¶ms) read_lut(config_.luminance_lut, params.get_child("luminance_lut")); else - RPI_WARN("Alsc: no luminance table - assume unity everywhere"); + LOG(RPiAlsc, Warning) << "Alsc: no luminance table - assume unity everywhere"; read_calibrations(config_.calibrations_Cr, params, "calibrations_Cr"); read_calibrations(config_.calibrations_Cb, params, "calibrations_Cb"); config_.default_ct = params.get("default_ct", 4500.0); @@ -164,7 +169,7 @@ static void add_luminance_to_tables(double results[3][Y][X], void Alsc::Initialise() { - RPI_LOG("Alsc"); + LOG(RPiAlsc, Debug) << "Alsc"; frame_count2_ = frame_count_ = frame_phase_ = 0; first_time_ = true; ct_ = config_.default_ct; @@ -252,7 +257,7 @@ void Alsc::SwitchMode(CameraMode const &camera_mode, void Alsc::fetchAsyncResults() { - RPI_LOG("Fetch ALSC results"); + LOG(RPiAlsc, Debug) << "Fetch ALSC results"; async_finished_ = false; async_started_ = false; memcpy(sync_results_, async_results_, sizeof(sync_results_)); @@ -263,11 +268,11 @@ double get_ct(Metadata *metadata, double default_ct) AwbStatus awb_status; awb_status.temperature_K = default_ct; // in case nothing found if (metadata->Get("awb.status", awb_status) != 0) - RPI_WARN("Alsc: no AWB results found, using " - << awb_status.temperature_K); + LOG(RPiAlsc, Warning) << "Alsc: no AWB results found, using " + << awb_status.temperature_K; else - RPI_LOG("Alsc: AWB results found, using " - << awb_status.temperature_K); + LOG(RPiAlsc, Debug) << "Alsc: AWB results found, using " + << awb_status.temperature_K; return awb_status.temperature_K; } @@ -289,7 +294,7 @@ static void copy_stats(bcm2835_isp_stats_region regions[XY], StatisticsPtr &stat void Alsc::restartAsync(StatisticsPtr &stats, Metadata *image_metadata) { - RPI_LOG("Starting ALSC thread"); + LOG(RPiAlsc, Debug) << "Starting ALSC thread"; // Get the current colour temperature. It's all we need from the // metadata. Default to the last CT value (which could be the default). ct_ = get_ct(image_metadata, ct_); @@ -297,7 +302,7 @@ void Alsc::restartAsync(StatisticsPtr &stats, Metadata *image_metadata) // the LSC table that the pipeline applied to them. AlscStatus alsc_status; if (image_metadata->Get("alsc.status", alsc_status) != 0) { - RPI_WARN("No ALSC status found for applied gains!"); + LOG(RPiAlsc, Warning) << "No ALSC status found for applied gains!"; for (int y = 0; y < Y; y++) for (int x = 0; x < X; x++) { alsc_status.r[y][x] = 1.0; @@ -324,11 +329,11 @@ void Alsc::Prepare(Metadata *image_metadata) double speed = frame_count_ < (int)config_.startup_frames ? 1.0 : config_.speed; - RPI_LOG("Alsc: frame_count " << frame_count_ << " speed " << speed); + LOG(RPiAlsc, Debug) << "Alsc: frame_count " << frame_count_ << " speed " << speed; { std::unique_lock lock(mutex_); if (async_started_ && async_finished_) { - RPI_LOG("ALSC thread finished"); + LOG(RPiAlsc, Debug) << "ALSC thread finished"; fetchAsyncResults(); } } @@ -354,11 +359,11 @@ void Alsc::Process(StatisticsPtr &stats, Metadata *image_metadata) frame_phase_++; if (frame_count2_ < (int)config_.startup_frames) frame_count2_++; - RPI_LOG("Alsc: frame_phase " << frame_phase_); + LOG(RPiAlsc, Debug) << "Alsc: frame_phase " << frame_phase_; if (frame_phase_ >= (int)config_.frame_period || frame_count2_ < (int)config_.startup_frames) { if (async_started_ == false) { - RPI_LOG("ALSC thread starting"); + LOG(RPiAlsc, Debug) << "ALSC thread starting"; restartAsync(stats, image_metadata); } } @@ -391,25 +396,25 @@ void get_cal_table(double ct, std::vector const &calibrations, if (calibrations.empty()) { for (int i = 0; i < XY; i++) cal_table[i] = 1.0; - RPI_LOG("Alsc: no calibrations found"); + LOG(RPiAlsc, Debug) << "Alsc: no calibrations found"; } else if (ct <= calibrations.front().ct) { memcpy(cal_table, calibrations.front().table, XY * sizeof(double)); - RPI_LOG("Alsc: using calibration for " - << calibrations.front().ct); + LOG(RPiAlsc, Debug) << "Alsc: using calibration for " + << calibrations.front().ct; } else if (ct >= calibrations.back().ct) { memcpy(cal_table, calibrations.back().table, XY * sizeof(double)); - RPI_LOG("Alsc: using calibration for " - << calibrations.front().ct); + LOG(RPiAlsc, Debug) << "Alsc: using calibration for " + << calibrations.front().ct; } else { int idx = 0; while (ct > calibrations[idx + 1].ct) idx++; double ct0 = calibrations[idx].ct, ct1 = calibrations[idx + 1].ct; - RPI_LOG("Alsc: ct is " << ct << ", interpolating between " - << ct0 << " and " << ct1); + LOG(RPiAlsc, Debug) << "Alsc: ct is " << ct << ", interpolating between " + << ct0 << " and " << ct1; for (int i = 0; i < XY; i++) cal_table[i] = (calibrations[idx].table[i] * (ct1 - ct) + @@ -660,15 +665,15 @@ static void run_matrix_iterations(double const C[XY], double lambda[XY], for (int i = 0; i < n_iter; i++) { double max_diff = fabs(gauss_seidel2_SOR(M, omega, lambda)); if (max_diff < threshold) { - RPI_LOG("Stop after " << i + 1 << " iterations"); + LOG(RPiAlsc, Debug) << "Stop after " << i + 1 << " iterations"; break; } // this happens very occasionally (so make a note), though // doesn't seem to matter if (max_diff > last_max_diff) - RPI_LOG("Iteration " << i << ": max_diff gone up " - << last_max_diff << " to " - << max_diff); + LOG(RPiAlsc, Debug) << "Iteration " << i << ": max_diff gone up " + << last_max_diff << " to " + << max_diff; last_max_diff = max_diff; } // We're going to normalise the lambdas so the smallest is 1. Not sure