From patchwork Tue Jul 26 12:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16783 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 46F2FC3275 for ; Tue, 26 Jul 2022 12:46:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 001DE63317; Tue, 26 Jul 2022 14:46:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658839573; bh=M6ZE3o2fghoWtS4ji2W8K8UQeneQpm7E86273fbZMWM=; 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=29rk8gCUpxeW4X+CpFAYdRcadXGGvQYV4vCLieZLuaFqsSMHof97H8TCLSZMu5zYI jx4O3Ag3dCidcYrIIQRGizq4P4D9Y5g2G048VEZt0JT968QGUhEQrz9YV3cniF3ZdO +HQ/qaItghbJVIY3tLTX7bJv5zJjn/TyoOwwvrgVwfb51bdIRERvf+GZ47UjDWd2K2 yT5PpdS6ku9CYn/p4KGzGG9GvLHZiPdlRNcfAfapo6OdI1p8HEOtigK4lEYfTv/Eut CnjI9nmgP2LoKr7hpzg6MNeIDgySAhGYI3aIgeEsNmwR0fp/VahHYj4RxlvqoCYnbC opkeG41ffCc9g== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2414263311 for ; Tue, 26 Jul 2022 14:46:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mLwFFv6g"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id d8so19898152wrp.6 for ; Tue, 26 Jul 2022 05:46:07 -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=lJV82aXpXJtQQMSUEO7LLuOfWPbkgSr4e+cMhnX5w9s=; b=mLwFFv6gtsZAvycScGx8ZwQSR05r320PD+xNjcE2fidRhne7wHHjOiftfq/EFHWJiH rG6gDaX+1k8Rr9A/nVF14VWpcfZBehEw4hWHmQKdqO5JcbkF7UicFeW7banAs8iRQmGn 9Z7TsAOMEN5tVHYBjAxIzpsfEFyb5WyA0KkuSwUbDTzZTybhpRmtC9VxsQwKu+FilUzj Drv5s577eLYyqnn2VGJ9XtuUPTuti7Y9KSuXIMVf7HVmj3G4QaC2nxi7H6OPFW6LSpkC ovqaRspdVtiu8JgqZ1cQ2V8+FQiYz1R6jYob30ZP5ipZ2CSjJPTXLm9Ctv9p30bm38fy HdoA== 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=lJV82aXpXJtQQMSUEO7LLuOfWPbkgSr4e+cMhnX5w9s=; b=16K4ICkJsvUCyyHUvLZqoThiDtPOKR0EqHOebCIPo1IEBXCyWo0TSQek85LOoPWxzj ylM/g/+nNULVnm4XyR+ktKGo3vHMQgwfRX73EiYE/N2rv3FuQoPJFgXO85EiYnVSCzlV 9+iN61+XkZ8TheCE25w2a9db//2cuLmDO12zU80630cAdUVyUraE7nxJqY25bly07sCZ C9wTTsy3fpnEoSWtOqIJ5VuUC9Go0BxZHjVXTHweT/unTlpNxU/oAAzw6Rx9L2cgvKbR Xaz/AftEsdRPDX1t8BflCmeoaTSTGP4rPUfoJddZpk5tifStrDoMdMQgtrHCCWqm05RP HrVw== X-Gm-Message-State: AJIora9uLew0CJIIMWzWsUkJ75GYSu/j1IawKesrmYO4ycnqtqyJwM1s GnMLQYUltuTNBsKpagGpfy2rQjLH5nI2Eg== X-Google-Smtp-Source: AGRyM1vBKuYvS2eNQQ01eQ75wOxrcUGIx8tnnl0Ds2G9cNGAS2v3LAMK3UpAbEMBFdWlz/zbxsoZug== X-Received: by 2002:a05:6000:38c:b0:21e:b38d:6bad with SMTP id u12-20020a056000038c00b0021eb38d6badmr1078426wrf.130.1658839566452; Tue, 26 Jul 2022 05:46:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 05:46:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 13:45:42 +0100 Message-Id: <20220726124549.1646-11-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 10/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/[n|s]* 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/noise.cpp | 38 ++++++++--------- src/ipa/raspberrypi/controller/rpi/noise.hpp | 14 +++---- src/ipa/raspberrypi/controller/rpi/sdn.cpp | 36 ++++++++-------- src/ipa/raspberrypi/controller/rpi/sdn.hpp | 10 ++--- .../raspberrypi/controller/rpi/sharpen.cpp | 42 +++++++++---------- .../raspberrypi/controller/rpi/sharpen.hpp | 14 +++---- 6 files changed, 78 insertions(+), 76 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/noise.cpp b/src/ipa/raspberrypi/controller/rpi/noise.cpp index 63cad639f313..97b0fd05e9d3 100644 --- a/src/ipa/raspberrypi/controller/rpi/noise.cpp +++ b/src/ipa/raspberrypi/controller/rpi/noise.cpp @@ -22,55 +22,55 @@ LOG_DEFINE_CATEGORY(RPiNoise) #define NAME "rpi.noise" Noise::Noise(Controller *controller) - : Algorithm(controller), mode_factor_(1.0) + : Algorithm(controller), modeFactor_(1.0) { } -char const *Noise::Name() const +char const *Noise::name() const { return NAME; } -void Noise::SwitchMode(CameraMode const &camera_mode, +void Noise::switchMode(CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata) { // For example, we would expect a 2x2 binned mode to have a "noise // factor" of sqrt(2x2) = 2. (can't be less than one, right?) - mode_factor_ = std::max(1.0, camera_mode.noise_factor); + modeFactor_ = std::max(1.0, cameraMode.noiseFactor); } -void Noise::Read(boost::property_tree::ptree const ¶ms) +void Noise::read(boost::property_tree::ptree const ¶ms) { - reference_constant_ = params.get("reference_constant"); - reference_slope_ = params.get("reference_slope"); + referenceConstant_ = params.get("reference_constant"); + referenceSlope_ = params.get("reference_slope"); } -void Noise::Prepare(Metadata *image_metadata) +void Noise::prepare(Metadata *imageMetadata) { - struct DeviceStatus device_status; - device_status.analogue_gain = 1.0; // keep compiler calm - if (image_metadata->Get("device.status", device_status) == 0) { + struct DeviceStatus deviceStatus; + deviceStatus.analogueGain = 1.0; // keep compiler calm + if (imageMetadata->get("device.status", deviceStatus) == 0) { // There is a slight question as to exactly how the noise // profile, specifically the constant part of it, scales. For // now we assume it all scales the same, and we'll revisit this // if it proves substantially wrong. NOTE: we may also want to // make some adjustments based on the camera mode (such as // binning), if we knew how to discover it... - double factor = sqrt(device_status.analogue_gain) / mode_factor_; + double factor = sqrt(deviceStatus.analogueGain) / modeFactor_; struct NoiseStatus status; - status.noise_constant = reference_constant_ * factor; - status.noise_slope = reference_slope_ * factor; - image_metadata->Set("noise.status", status); + status.noiseConstant = referenceConstant_ * factor; + status.noiseSlope = referenceSlope_ * factor; + imageMetadata->set("noise.status", status); LOG(RPiNoise, Debug) - << "constant " << status.noise_constant - << " slope " << status.noise_slope; + << "constant " << status.noiseConstant + << " slope " << status.noiseSlope; } else LOG(RPiNoise, Warning) << " no metadata"; } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return new Noise(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/noise.hpp b/src/ipa/raspberrypi/controller/rpi/noise.hpp index 1c9de5c87d08..ed6ffe910e27 100644 --- a/src/ipa/raspberrypi/controller/rpi/noise.hpp +++ b/src/ipa/raspberrypi/controller/rpi/noise.hpp @@ -17,16 +17,16 @@ class Noise : public Algorithm { public: Noise(Controller *controller); - char const *Name() const override; - void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; - void Read(boost::property_tree::ptree const ¶ms) override; - void Prepare(Metadata *image_metadata) override; + char const *name() const override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; private: // the noise profile for analogue gain of 1.0 - double reference_constant_; - double reference_slope_; - double mode_factor_; + double referenceConstant_; + double referenceSlope_; + double modeFactor_; }; } // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index 9384550983e7..480da38dc068 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -27,49 +27,51 @@ Sdn::Sdn(Controller *controller) { } -char const *Sdn::Name() const +char const *Sdn::name() const { return NAME; } -void Sdn::Read(boost::property_tree::ptree const ¶ms) +void Sdn::read(boost::property_tree::ptree const ¶ms) { deviation_ = params.get("deviation", 3.2); strength_ = params.get("strength", 0.75); } -void Sdn::Initialise() {} +void Sdn::initialise() +{ +} -void Sdn::Prepare(Metadata *image_metadata) +void Sdn::prepare(Metadata *imageMetadata) { - struct NoiseStatus noise_status = {}; - noise_status.noise_slope = 3.0; // in case no metadata - if (image_metadata->Get("noise.status", noise_status) != 0) + struct NoiseStatus noiseStatus = {}; + noiseStatus.noiseSlope = 3.0; // in case no metadata + if (imageMetadata->get("noise.status", noiseStatus) != 0) LOG(RPiSdn, Warning) << "no noise profile found"; LOG(RPiSdn, Debug) - << "Noise profile: constant " << noise_status.noise_constant - << " slope " << noise_status.noise_slope; + << "Noise profile: constant " << noiseStatus.noiseConstant + << " slope " << noiseStatus.noiseSlope; struct DenoiseStatus status; - status.noise_constant = noise_status.noise_constant * deviation_; - status.noise_slope = noise_status.noise_slope * deviation_; + status.noiseConstant = noiseStatus.noiseConstant * deviation_; + status.noiseSlope = noiseStatus.noiseSlope * deviation_; status.strength = strength_; status.mode = static_cast>(mode_); - image_metadata->Set("denoise.status", status); + imageMetadata->set("denoise.status", status); LOG(RPiSdn, Debug) - << "programmed constant " << status.noise_constant - << " slope " << status.noise_slope + << "programmed constant " << status.noiseConstant + << " slope " << status.noiseSlope << " strength " << status.strength; } -void Sdn::SetMode(DenoiseMode mode) +void Sdn::setMode(DenoiseMode mode) { // We only distinguish between off and all other modes. mode_ = mode; } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Sdn(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.hpp b/src/ipa/raspberrypi/controller/rpi/sdn.hpp index 2371ce04163f..d9b18f296635 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.hpp @@ -17,11 +17,11 @@ class Sdn : public DenoiseAlgorithm { public: Sdn(Controller *controller = NULL); - char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; - void Initialise() override; - void Prepare(Metadata *image_metadata) override; - void SetMode(DenoiseMode mode) override; + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + void setMode(DenoiseMode mode) override; private: double deviation_; diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp index 18825a43867b..3fe62bc8a5cf 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp @@ -21,23 +21,23 @@ LOG_DEFINE_CATEGORY(RPiSharpen) #define NAME "rpi.sharpen" Sharpen::Sharpen(Controller *controller) - : SharpenAlgorithm(controller), user_strength_(1.0) + : SharpenAlgorithm(controller), userStrength_(1.0) { } -char const *Sharpen::Name() const +char const *Sharpen::name() const { return NAME; } -void Sharpen::SwitchMode(CameraMode const &camera_mode, +void Sharpen::switchMode(CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata) { // can't be less than one, right? - mode_factor_ = std::max(1.0, camera_mode.noise_factor); + modeFactor_ = std::max(1.0, cameraMode.noiseFactor); } -void Sharpen::Read(boost::property_tree::ptree const ¶ms) +void Sharpen::read(boost::property_tree::ptree const ¶ms) { threshold_ = params.get("threshold", 1.0); strength_ = params.get("strength", 1.0); @@ -48,38 +48,38 @@ void Sharpen::Read(boost::property_tree::ptree const ¶ms) << " limit " << limit_; } -void Sharpen::SetStrength(double strength) +void Sharpen::setStrength(double strength) { // Note that this function is how an application sets the overall // sharpening "strength". We call this the "user strength" field // as there already is a strength_ field - being an internal gain // parameter that gets passed to the ISP control code. Negative // values are not allowed - coerce them to zero (no sharpening). - user_strength_ = std::max(0.0, strength); + userStrength_ = std::max(0.0, strength); } -void Sharpen::Prepare(Metadata *image_metadata) +void Sharpen::prepare(Metadata *imageMetadata) { - // The user_strength_ affects the algorithm's internal gain directly, but + // The userStrength_ affects the algorithm's internal gain directly, but // we adjust the limit and threshold less aggressively. Using a sqrt // function is an arbitrary but gentle way of accomplishing this. - double user_strength_sqrt = sqrt(user_strength_); + double userStrengthSqrt = sqrt(userStrength_); struct SharpenStatus status; // Binned modes seem to need the sharpening toned down with this - // pipeline, thus we use the mode_factor here. Also avoid - // divide-by-zero with the user_strength_sqrt. - status.threshold = threshold_ * mode_factor_ / - std::max(0.01, user_strength_sqrt); - status.strength = strength_ / mode_factor_ * user_strength_; - status.limit = limit_ / mode_factor_ * user_strength_sqrt; - // Finally, report any application-supplied parameters that were used. - status.user_strength = user_strength_; - image_metadata->Set("sharpen.status", status); + // pipeline, thus we use the modeFactor_ here. Also avoid + // divide-by-zero with the userStrengthSqrt. + status.threshold = threshold_ * modeFactor_ / + std::max(0.01, userStrengthSqrt); + status.strength = strength_ / modeFactor_ * userStrength_; + status.limit = limit_ / modeFactor_ * userStrengthSqrt; + /* Finally, report any application-supplied parameters that were used. */ + status.userStrength = userStrength_; + imageMetadata->set("sharpen.status", status); } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return new Sharpen(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp index 13a076a86895..ced917f3c42b 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp @@ -17,18 +17,18 @@ class Sharpen : public SharpenAlgorithm { public: Sharpen(Controller *controller); - char const *Name() const override; - void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; - void Read(boost::property_tree::ptree const ¶ms) override; - void SetStrength(double strength) override; - void Prepare(Metadata *image_metadata) override; + char const *name() const override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void read(boost::property_tree::ptree const ¶ms) override; + void setStrength(double strength) override; + void prepare(Metadata *imageMetadata) override; private: double threshold_; double strength_; double limit_; - double mode_factor_; - double user_strength_; + double modeFactor_; + double userStrength_; }; } // namespace RPiController