From patchwork Tue Jul 26 12:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16782 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 3F036C3275 for ; Tue, 26 Jul 2022 12:46:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCCA063331; Tue, 26 Jul 2022 14:46:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658839569; bh=MrGiF9VO/RPYTur3ZPQxhi3q2+T9zGx+WewZhBx/N3s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=a4+ickVICypJXCb/umvS1DmqeihKbSw+bxaArgA1ULO7slyLL7AprC1pHdVC3Sohd uht+Tn3ie1l9xqS6AMwgvGKNIA9nxiJ622AgoTYpA5+ebXgD1tdkw3x/cKDT46uv0H tUeGB2rqKUr7bvi6o88Rltd/zwxewsxVPIcQQagSBOV3WjZXdKqAW8Da4FfEqk1IAR Z4MgkpdCoN53uVybIWMyL35qr2dB+S0UgL2VzJKGuHh3FOZnd/g2D7NILZjdOTKtMD x3g0ZktwHP6ipw8teq1wEDJ7YO0x2xhe3cClNOtGzhkIvW32ms5YjwcvBY6NQvBU18 7GnQnVL7w1x0A== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 401916331D for ; Tue, 26 Jul 2022 14:46:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="UPMOmb+0"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id r1-20020a05600c35c100b003a326685e7cso778148wmq.1 for ; Tue, 26 Jul 2022 05:46:06 -0700 (PDT) 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=h53DiA/UCvKsJUis2lWATuAAfe37Smke2YjB7DNAO+E=; b=UPMOmb+0h1IaBB25MTVD4TOW9NyHcblnCEbbT5nCXdzV4CtIaSxhbl0aZEq9OoX08E KXS+9DcEEfvt5xTkq8rNIPtUoE/VYx5p7L1FMxH/k8qJuG3x2s2qlGcOoh0nnz1tghwE nMLRoJnZ4p0ghsX7dKEYElNPdXZKHE1eaycF4LlM2Jc6qC0ePaEbD8jgxW5R2YIqODv2 wBmwSZT2okyf/wCjydno+cGp7Qxtj7PoUxB0Jw3gJyxX77KcSnGz+hDN2M9QyPdi5jIh BvPCfH9L5Y+J/RX0cq7dsPP79nRrxfc6Q5G/a6g6oUy83KNQQnEBOjXWJisbzlIO1kl0 +Y5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h53DiA/UCvKsJUis2lWATuAAfe37Smke2YjB7DNAO+E=; b=J5P8pzcClcyyly3lZj9Y3t42VWiMwjLE6zRje5hjaw94vusufQT5LBXKJF5QSUYWvi fDS3UxcKQ7v5Zd+F1NqmwdecOEbfxjSPt9vqtTmBCNwGkZhwkhOUQJT8U0LhVFVVwmbg Rdqko+yJGOynTm9JmHnF2mlzgu8sDU/Y6+qG/mUutdw5FzXo0Yg6UTrAo8SHSL8awg2D jnhSRb0NizPR8lITpVr18GksGuRpYxzOcX3nuEFiS7dnf30NJm3dbo/sl+C0RLGvB7VN /rXsuq5reXRsm1ElNecdJG99Gw0zHmhoNaC83n2ZXtXEfKb66dMfQGTnqDueJJZESvlP 2WPA== X-Gm-Message-State: AJIora+vgcpsA5RRL80tKYw4D7ifgzUa23M2i06dY/xki+UfSadNYgem yJ7/T2cfy0mVEBV2YyVVok9B9+OnPZzkjw== X-Google-Smtp-Source: AGRyM1t+Pxr3VPnIXeJegdx14gPG+rYDf2iEgBmlEUCPKjSq53K1JafokmFyh/W/QRF8BySARhtvKA== X-Received: by 2002:a05:600c:4e0d:b0:3a3:bc7:e9ec with SMTP id b13-20020a05600c4e0d00b003a30bc7e9ecmr25186916wmq.167.1658839565280; Tue, 26 Jul 2022 05:46:05 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id y17-20020adfd091000000b0021e87ec980bsm5948460wrh.84.2022.07.26.05.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 05:46:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 13:45:41 +0100 Message-Id: <20220726124549.1646-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220726124549.1646-1-naush@raspberrypi.com> References: <20220726124549.1646-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/17] DNI: ipa: raspberrypi: Code refactoring to match style guidelines 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Refactor the source files src/ipa/raspberrypi/controller/rps/[f|g|l]* to match the recommended formatting guidelines for the libcamera project. The vast majority of changes in this commit comprise of switching from snake_case to CamelCase, and starting class member functions with a lower case character. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/focus.cpp | 14 ++-- src/ipa/raspberrypi/controller/rpi/focus.hpp | 4 +- src/ipa/raspberrypi/controller/rpi/geq.cpp | 48 +++++++------- src/ipa/raspberrypi/controller/rpi/geq.hpp | 6 +- src/ipa/raspberrypi/controller/rpi/lux.cpp | 70 ++++++++++---------- src/ipa/raspberrypi/controller/rpi/lux.hpp | 22 +++--- 6 files changed, 81 insertions(+), 83 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp index a87ec802b964..90f36e58f28c 100644 --- a/src/ipa/raspberrypi/controller/rpi/focus.cpp +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp @@ -23,28 +23,28 @@ Focus::Focus(Controller *controller) { } -char const *Focus::Name() const +char const *Focus::name() const { return NAME; } -void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata) +void Focus::process(StatisticsPtr &stats, Metadata *imageMetadata) { FocusStatus status; unsigned int i; for (i = 0; i < FOCUS_REGIONS; i++) - status.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000; + status.focusMeasures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000; status.num = i; - image_metadata->Set("focus.status", status); + imageMetadata->set("focus.status", status); LOG(RPiFocus, Debug) << "Focus contrast measure: " - << (status.focus_measures[5] + status.focus_measures[6]) / 10; + << (status.focusMeasures[5] + status.focusMeasures[6]) / 10; } /* Register algorithm with the system. */ -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return new Focus(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp index 131b1d0f2fbf..a9207eb3cc23 100644 --- a/src/ipa/raspberrypi/controller/rpi/focus.hpp +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp @@ -21,8 +21,8 @@ class Focus : public Algorithm { public: Focus(Controller *controller); - char const *Name() const override; - void Process(StatisticsPtr &stats, Metadata *image_metadata) override; + char const *name() const override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; }; } /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/geq.cpp b/src/ipa/raspberrypi/controller/rpi/geq.cpp index 4530cb75792c..0da5efdf3d3d 100644 --- a/src/ipa/raspberrypi/controller/rpi/geq.cpp +++ b/src/ipa/raspberrypi/controller/rpi/geq.cpp @@ -28,54 +28,52 @@ Geq::Geq(Controller *controller) { } -char const *Geq::Name() const +char const *Geq::name() const { return NAME; } -void Geq::Read(boost::property_tree::ptree const ¶ms) +void Geq::read(boost::property_tree::ptree const ¶ms) { config_.offset = params.get("offset", 0); config_.slope = params.get("slope", 0.0); if (config_.slope < 0.0 || config_.slope >= 1.0) throw std::runtime_error("Geq: bad slope value"); if (params.get_child_optional("strength")) - config_.strength.Read(params.get_child("strength")); + config_.strength.read(params.get_child("strength")); } -void Geq::Prepare(Metadata *image_metadata) +void Geq::prepare(Metadata *imageMetadata) { - LuxStatus lux_status = {}; - lux_status.lux = 400; - if (image_metadata->Get("lux.status", lux_status)) + LuxStatus luxStatus = {}; + luxStatus.lux = 400; + if (imageMetadata->get("lux.status", luxStatus)) LOG(RPiGeq, Warning) << "no lux data found"; - DeviceStatus device_status; - device_status.analogue_gain = 1.0; // in case not found - if (image_metadata->Get("device.status", device_status)) + DeviceStatus deviceStatus; + deviceStatus.analogueGain = 1.0; // in case not found + if (imageMetadata->get("device.status", deviceStatus)) LOG(RPiGeq, Warning) << "no device metadata - use analogue gain of 1x"; - GeqStatus geq_status = {}; - double strength = - config_.strength.Empty() + GeqStatus geqStatus = {}; + double strength = config_.strength.empty() ? 1.0 - : config_.strength.Eval(config_.strength.Domain().Clip( - lux_status.lux)); - strength *= device_status.analogue_gain; + : config_.strength.eval(config_.strength.domain().clip(luxStatus.lux)); + strength *= deviceStatus.analogueGain; double offset = config_.offset * strength; double slope = config_.slope * strength; - geq_status.offset = std::min(65535.0, std::max(0.0, offset)); - geq_status.slope = std::min(.99999, std::max(0.0, slope)); + geqStatus.offset = std::min(65535.0, std::max(0.0, offset)); + geqStatus.slope = std::min(.99999, std::max(0.0, slope)); LOG(RPiGeq, Debug) - << "offset " << geq_status.offset << " slope " - << geq_status.slope << " (analogue gain " - << device_status.analogue_gain << " lux " - << lux_status.lux << ")"; - image_metadata->Set("geq.status", geq_status); + << "offset " << geqStatus.offset << " slope " + << geqStatus.slope << " (analogue gain " + << deviceStatus.analogueGain << " lux " + << luxStatus.lux << ")"; + imageMetadata->set("geq.status", geqStatus); } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Geq(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/geq.hpp b/src/ipa/raspberrypi/controller/rpi/geq.hpp index 8ba3046b2a2b..bdbc55b2e2d9 100644 --- a/src/ipa/raspberrypi/controller/rpi/geq.hpp +++ b/src/ipa/raspberrypi/controller/rpi/geq.hpp @@ -23,9 +23,9 @@ class Geq : public Algorithm { public: Geq(Controller *controller); - char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; - void Prepare(Metadata *image_metadata) override; + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; private: GeqConfig config_; diff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp index 4d145b6ff0e9..739a3d533874 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.cpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp @@ -31,74 +31,74 @@ Lux::Lux(Controller *controller) status_.lux = 400; } -char const *Lux::Name() const +char const *Lux::name() const { return NAME; } -void Lux::Read(boost::property_tree::ptree const ¶ms) +void Lux::read(boost::property_tree::ptree const ¶ms) { - reference_shutter_speed_ = + referenceShutterSpeed_ = params.get("reference_shutter_speed") * 1.0us; - reference_gain_ = params.get("reference_gain"); - reference_aperture_ = params.get("reference_aperture", 1.0); - reference_Y_ = params.get("reference_Y"); - reference_lux_ = params.get("reference_lux"); - current_aperture_ = reference_aperture_; + referenceGain_ = params.get("reference_gain"); + referenceAperture_ = params.get("reference_aperture", 1.0); + referenceY_ = params.get("reference_Y"); + referenceLux_ = params.get("reference_lux"); + currentAperture_ = referenceAperture_; } -void Lux::SetCurrentAperture(double aperture) +void Lux::setCurrentAperture(double aperture) { - current_aperture_ = aperture; + currentAperture_ = aperture; } -void Lux::Prepare(Metadata *image_metadata) +void Lux::prepare(Metadata *imageMetadata) { std::unique_lock lock(mutex_); - image_metadata->Set("lux.status", status_); + imageMetadata->set("lux.status", status_); } -void Lux::Process(StatisticsPtr &stats, Metadata *image_metadata) +void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata) { - DeviceStatus device_status; - if (image_metadata->Get("device.status", device_status) == 0) { - double current_gain = device_status.analogue_gain; - double current_aperture = device_status.aperture.value_or(current_aperture_); + DeviceStatus deviceStatus; + if (imageMetadata->get("device.status", deviceStatus) == 0) { + double currentGain = deviceStatus.analogueGain; + double currentAperture = deviceStatus.aperture.value_or(currentAperture_); uint64_t sum = 0; uint32_t num = 0; uint32_t *bin = stats->hist[0].g_hist; - const int num_bins = sizeof(stats->hist[0].g_hist) / - sizeof(stats->hist[0].g_hist[0]); - for (int i = 0; i < num_bins; i++) + const int numBins = sizeof(stats->hist[0].g_hist) / + sizeof(stats->hist[0].g_hist[0]); + for (int i = 0; i < numBins; i++) sum += bin[i] * (uint64_t)i, num += bin[i]; // add .5 to reflect the mid-points of bins - double current_Y = sum / (double)num + .5; - double gain_ratio = reference_gain_ / current_gain; - double shutter_speed_ratio = - reference_shutter_speed_ / device_status.shutter_speed; - double aperture_ratio = reference_aperture_ / current_aperture; - double Y_ratio = current_Y * (65536 / num_bins) / reference_Y_; - double estimated_lux = shutter_speed_ratio * gain_ratio * - aperture_ratio * aperture_ratio * - Y_ratio * reference_lux_; + double currentY = sum / (double)num + .5; + double gainRatio = referenceGain_ / currentGain; + double shutterSpeedRatio = + referenceShutterSpeed_ / deviceStatus.shutterSpeed; + double apertureRatio = referenceAperture_ / currentAperture; + double yRatio = currentY * (65536 / numBins) / referenceY_; + double estimatedLux = shutterSpeedRatio * gainRatio * + apertureRatio * apertureRatio * + yRatio * referenceLux_; LuxStatus status; - status.lux = estimated_lux; - status.aperture = current_aperture; - LOG(RPiLux, Debug) << ": estimated lux " << estimated_lux; + status.lux = estimatedLux; + status.aperture = currentAperture; + LOG(RPiLux, Debug) << ": estimated lux " << estimatedLux; { std::unique_lock lock(mutex_); status_ = status; } // Overwrite the metadata here as well, so that downstream // algorithms get the latest value. - image_metadata->Set("lux.status", status); + imageMetadata->set("lux.status", status); } else LOG(RPiLux, Warning) << ": no device metadata"; } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Lux(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp index 3ebd35d1e382..bd49a409d402 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp @@ -21,21 +21,21 @@ class Lux : public Algorithm { public: Lux(Controller *controller); - char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; - void Prepare(Metadata *image_metadata) override; - void Process(StatisticsPtr &stats, Metadata *image_metadata) override; - void SetCurrentAperture(double aperture); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + void setCurrentAperture(double aperture); private: // These values define the conditions of the reference image, against // which we compare the new image. - libcamera::utils::Duration reference_shutter_speed_; - double reference_gain_; - double reference_aperture_; // units of 1/f - double reference_Y_; // out of 65536 - double reference_lux_; - double current_aperture_; + libcamera::utils::Duration referenceShutterSpeed_; + double referenceGain_; + double referenceAperture_; // units of 1/f + double referenceY_; // out of 65536 + double referenceLux_; + double currentAperture_; LuxStatus status_; std::mutex mutex_; };