From patchwork Mon Jul 25 13:46:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16761 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 19A7AC3275 for ; Mon, 25 Jul 2022 13:46:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CBF2263337; Mon, 25 Jul 2022 15:46:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658756817; bh=WHnM8TPLzraBE43FpWqrh7uVJNUI/so3kLJP5VUTziw=; 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=Kvlpi0qa0EV5Xnwas8GnsLcKHJ+CuuyubbdnuFZEjb9nYUi1y+iTFrWyqjKOFHiFT vugOdEpx9mkzJ7niMU7LXaQ2gfJRrCIv1PbTU3g40edvxS//r5paUg+gnu/0RgpZO3 rFHltLUh3h8ClxQH8h0Uj8JRL3sO1h96BJ6c1dV83gl0y8LhTVYpRkT9a9bAETpIRQ NWGUeOflCz4vTwRXarkSYGBSMYUZzyX7n8ZF5G0yd9084E42cSB6PAP+5BZ3dVNIHV QQY2uTo6uMLn7UfvTtVLpbyES3bFs2PZH+4Ik1+273XhjOeJkoLES30jwm0mtASRnk 9ahv5ynIsJauA== Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB1D963312 for ; Mon, 25 Jul 2022 15:46:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="NEOZjNGH"; dkim-atps=neutral Received: by mail-wm1-x32f.google.com with SMTP id c22so6845293wmr.2 for ; Mon, 25 Jul 2022 06:46:50 -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=mRuHQylAIUqDyu1vrkwOYAhAxvgWIUxwRbLiL3bvAI8=; b=NEOZjNGHMFoz6TiYEpTgNrOx0Vik+5lZMa00R2Leqfwk0ykv03CNcVXVfCHwNeP8p1 lRDdGKqBxD1t9dn4TGl1FVqH2Rx1lpXg2bWBVWv1KfZmTcw3aXdUU9CsKV21PTtu6uQl Ie8M7bYgWvnn7vuPSXDDj0sYqDSIWFTQC3bHI3llE5NC8mKsE0Fr9AyTHDLEzIbcEWt9 m31qDyj5Xg2lbdSdW6//w5gHgMMhTzC7hh3+YwXo8hBvOQIkGtKPQLGlcBaWFgELEAQH tckHDHxz66esbQgPWs7cx0VuVbKKL1svGkgGo/5Z03pUe1/J/RvATjzxdbVK1eMXWjvb FK+w== 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=mRuHQylAIUqDyu1vrkwOYAhAxvgWIUxwRbLiL3bvAI8=; b=fvf5IajvisystJEF2NEyKami6jMr/q+v5ZaJFBKnGc6iZjcCj7/BD5XL9f/rziz2UV Q4rlNXXK5kV869rlWxlOcWP9X2O8tkYgfyzjQtJRGTeL4ba3k70pniNZ5y3YovofR3dJ yKQ1dS7FQ6+Bamx/1/2qH9VtQ/I46f2NBnNs4pjkESQrr/LhyoguKCpN3Ad2zxFzkv0s 8SlXQx8gEAJGLfRkm1JdNT0xGdItUQ+mFQju/CD1sV45IWcaThG/VB1+35n/1F249Jac VkPKRvtVbjKw+Ar5rq0gXpyApSZiLn1RLg8lkqDjodaq7+vXXMZ7Hd2NcT7Ca+uRxavZ Jp3w== X-Gm-Message-State: AJIora9Zcg1oEVKSsEuYHr98TQAOhyjqiQ0viEaeEVpcXRbazAZT0kmA xvbrrKZSD01jWu0OD9bqfllRrBniUAhLtA== X-Google-Smtp-Source: AGRyM1u3lcLEwK6iLhV0e6baSc1lNAFSq9ZISY4FH7VviGQCWVQC/XLjUK2zJhFsga/RdsRjlH1MlA== X-Received: by 2002:a05:600c:17d5:b0:3a3:576:21ba with SMTP id y21-20020a05600c17d500b003a3057621bamr8390541wmo.176.1658756810036; Mon, 25 Jul 2022 06:46:50 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c225400b003a32167b8d4sm18054320wmm.13.2022.07.25.06.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 06:46:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 25 Jul 2022 14:46:33 +0100 Message-Id: <20220725134639.4572-10-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220725134639.4572-1-naush@raspberrypi.com> References: <20220725134639.4572-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/15] 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..10654fbba94a 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..98cfd0ac8bd0 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_; };