From patchwork Mon Jul 25 13:46:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16760 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 8A4FCC3275 for ; Mon, 25 Jul 2022 13:46:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4243E63330; Mon, 25 Jul 2022 15:46:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658756816; bh=pXSwhZGprdXB9KdOExJ8lSQl05a52dfCQvtSQuAvAmQ=; 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=bjFW1HdkKTSbnNPNTDxdzg+S0q/ih9Nm/l8KvDkwkQkoXURF7T2ErUCwMDI096yyj wk15XZG3eAZAP6c4T5XvJr+JpX+iOX08f5ce+6RBq57VtStH7NGAVlOYSeXfTsX88Y s4FGevBn0Uuzchsjk+ibDyrsLHDOgns6QMIdc4baEhp9YJ6pmIGAAJeGPo9izvnrd1 joMU8FLbuWoWMoi465Oy+d7WK32zRgFAPffFnHUL12qCLyqg4Tij2vNJsqIFPjEO49 GuRfHz48lREcHxwY4WQGnOwiHAgQrz1absLllTE713GY6EsNXub9tWWJZGMs3T+gng RxzGT2UtIx1GQ== Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 513CB63313 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="SDlnia/o"; dkim-atps=neutral Received: by mail-wr1-x429.google.com with SMTP id u5so16045893wrm.4 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=W6u/ATJ6yiLSf3ATDzNuZopNLKM5bCUNGBjENPMY07w=; b=SDlnia/ohrY4Zkxm2iRqo62yHliXqDBmuPR+IlTLE0UTifJTOKtI1DwD6gBnAkGRYV dUfqsAGkCBlj8AU38iSMjOMSWKbwKxrNYDq1pYos+rUD3EfvvUap8PrsPVROhwkYopm0 nj68tN4S6F0qyfoqzGxVgdDxoVCJ8x5vlX/ngLYDOyVm4XXEeXzcedQ8YB3uM7hAhRMQ 0cHfi2HlA2/vH54BgJ4LEiGODvCrWaekLcbTZX40BwSjM062IJbGjHy+cHeY7nah38h2 eyocQ3zlIdZgzhs+lUuSLpKYoowM4LHQmZgPHRaf+tuAdznHj4ErWYpFqu5ZAHaJ1KBF IJAQ== 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=W6u/ATJ6yiLSf3ATDzNuZopNLKM5bCUNGBjENPMY07w=; b=6KN6bw0tHgzMVXgGYj9ZeMVdhSWuv0ocrwg0KmclI8gifOSgjEx44omKnpe5djZ6Q3 8WK3TK+Aa+CTPPMbEj0XuggenF/hybUJ7fcY+KjD514s6y3E5nndzv6K2mhPpR1yJ1Ry Y1Zr5YPqtHz/9F6v6yEC70Icyho2/8BvORGUPQR1hLPBBIwvNMyA2SVw4i5RjGi8RcJ6 EDhUDo9g67MJMH9nFAuPXBRZd5mhqlbIzg52hob9aI79r7oKMogBonJ5EzVNzcKTFgJY rS27WwmK3ACf3r8RvWdrdwkPCG/qS6oEn2rMsmXlbnzD3QQ6s1F2wMnmgD4NDtjjpp6Q Yd7g== X-Gm-Message-State: AJIora+gmYXPLC97XlSD3MPB2/Pejhla+iSguWuijecyrFAPJa6IrT2w BMavFTi4SQBzDLJ3CZ1UvGybzM3JPNx0hA== X-Google-Smtp-Source: AGRyM1u5tyCFVtkhrG97w2F8vPFlHoWh7nshpMl7DRmA+yNQSx/engIm56G3oGg4Z4diaR7jRevaAw== X-Received: by 2002:a5d:6c6f:0:b0:21d:cb1b:5776 with SMTP id r15-20020a5d6c6f000000b0021dcb1b5776mr7619108wrz.44.1658756809350; Mon, 25 Jul 2022 06:46:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 06:46:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 25 Jul 2022 14:46:32 +0100 Message-Id: <20220725134639.4572-9-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 08/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/[b|c|d]* 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 --- .../controller/rpi/black_level.cpp | 32 ++--- .../controller/rpi/black_level.hpp | 12 +- src/ipa/raspberrypi/controller/rpi/ccm.cpp | 84 +++++++------ src/ipa/raspberrypi/controller/rpi/ccm.hpp | 12 +- .../raspberrypi/controller/rpi/contrast.cpp | 118 +++++++++--------- .../raspberrypi/controller/rpi/contrast.hpp | 30 ++--- src/ipa/raspberrypi/controller/rpi/dpc.cpp | 18 +-- src/ipa/raspberrypi/controller/rpi/dpc.hpp | 6 +- 8 files changed, 155 insertions(+), 157 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.cpp b/src/ipa/raspberrypi/controller/rpi/black_level.cpp index 6b3497f13c19..695b3129dd93 100644 --- a/src/ipa/raspberrypi/controller/rpi/black_level.cpp +++ b/src/ipa/raspberrypi/controller/rpi/black_level.cpp @@ -26,38 +26,38 @@ BlackLevel::BlackLevel(Controller *controller) { } -char const *BlackLevel::Name() const +char const *BlackLevel::name() const { return NAME; } -void BlackLevel::Read(boost::property_tree::ptree const ¶ms) +void BlackLevel::read(boost::property_tree::ptree const ¶ms) { - uint16_t black_level = params.get( + uint16_t blackLevel = params.get( "black_level", 4096); // 64 in 10 bits scaled to 16 bits - black_level_r_ = params.get("black_level_r", black_level); - black_level_g_ = params.get("black_level_g", black_level); - black_level_b_ = params.get("black_level_b", black_level); + blackLevelR_ = params.get("black_level_r", blackLevel); + blackLevelG_ = params.get("black_level_g", blackLevel); + blackLevelB_ = params.get("black_level_b", blackLevel); LOG(RPiBlackLevel, Debug) - << " Read black levels red " << black_level_r_ - << " green " << black_level_g_ - << " blue " << black_level_b_; + << " Read black levels red " << blackLevelR_ + << " green " << blackLevelG_ + << " blue " << blackLevelB_; } -void BlackLevel::Prepare(Metadata *image_metadata) +void BlackLevel::prepare(Metadata *imageMetadata) { // Possibly we should think about doing this in a switch_mode or // something? struct BlackLevelStatus status; - status.black_level_r = black_level_r_; - status.black_level_g = black_level_g_; - status.black_level_b = black_level_b_; - image_metadata->Set("black_level.status", status); + status.black_level_r = blackLevelR_; + status.black_level_g = blackLevelG_; + status.black_level_b = blackLevelB_; + imageMetadata->set("black_level.status", status); } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return new BlackLevel(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.hpp b/src/ipa/raspberrypi/controller/rpi/black_level.hpp index 65ec4d0ed26c..0d74f6a4c49b 100644 --- a/src/ipa/raspberrypi/controller/rpi/black_level.hpp +++ b/src/ipa/raspberrypi/controller/rpi/black_level.hpp @@ -17,14 +17,14 @@ class BlackLevel : public Algorithm { public: BlackLevel(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: - double black_level_r_; - double black_level_g_; - double black_level_b_; + double blackLevelR_; + double blackLevelG_; + double blackLevelB_; }; } // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp index 821a4c7c98c5..24d8e5bd1fd8 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp @@ -37,7 +37,7 @@ Matrix::Matrix(double m0, double m1, double m2, double m3, double m4, double m5, m[0][0] = m0, m[0][1] = m1, m[0][2] = m2, m[1][0] = m3, m[1][1] = m4, m[1][2] = m5, m[2][0] = m6, m[2][1] = m7, m[2][2] = m8; } -void Matrix::Read(boost::property_tree::ptree const ¶ms) +void Matrix::read(boost::property_tree::ptree const ¶ms) { double *ptr = (double *)m; int n = 0; @@ -53,47 +53,49 @@ void Matrix::Read(boost::property_tree::ptree const ¶ms) Ccm::Ccm(Controller *controller) : CcmAlgorithm(controller), saturation_(1.0) {} -char const *Ccm::Name() const +char const *Ccm::name() const { return NAME; } -void Ccm::Read(boost::property_tree::ptree const ¶ms) +void Ccm::read(boost::property_tree::ptree const ¶ms) { if (params.get_child_optional("saturation")) - config_.saturation.Read(params.get_child("saturation")); + config_.saturation.read(params.get_child("saturation")); for (auto &p : params.get_child("ccms")) { - CtCcm ct_ccm; - ct_ccm.ct = p.second.get("ct"); - ct_ccm.ccm.Read(p.second.get_child("ccm")); + CtCcm ctCcm; + ctCcm.ct = p.second.get("ct"); + ctCcm.ccm.read(p.second.get_child("ccm")); if (!config_.ccms.empty() && - ct_ccm.ct <= config_.ccms.back().ct) + ctCcm.ct <= config_.ccms.back().ct) throw std::runtime_error( "Ccm: CCM not in increasing colour temperature order"); - config_.ccms.push_back(std::move(ct_ccm)); + config_.ccms.push_back(std::move(ctCcm)); } if (config_.ccms.empty()) throw std::runtime_error("Ccm: no CCMs specified"); } -void Ccm::SetSaturation(double saturation) +void Ccm::setSaturation(double saturation) { saturation_ = saturation; } -void Ccm::Initialise() {} +void Ccm::initialise() +{ +} template -static bool get_locked(Metadata *metadata, std::string const &tag, T &value) +static bool getLocked(Metadata *metadata, std::string const &tag, T &value) { - T *ptr = metadata->GetLocked(tag); + T *ptr = metadata->getLocked(tag); if (ptr == nullptr) return false; value = *ptr; return true; } -Matrix calculate_ccm(std::vector const &ccms, double ct) +Matrix calculateCcm(std::vector const &ccms, double ct) { if (ct <= ccms.front().ct) return ccms.front().ccm; @@ -109,7 +111,7 @@ Matrix calculate_ccm(std::vector const &ccms, double ct) } } -Matrix apply_saturation(Matrix const &ccm, double saturation) +Matrix applySaturation(Matrix const &ccm, double saturation) { Matrix RGB2Y(0.299, 0.587, 0.114, -0.169, -0.331, 0.500, 0.500, -0.419, -0.081); @@ -119,51 +121,51 @@ Matrix apply_saturation(Matrix const &ccm, double saturation) return Y2RGB * S * RGB2Y * ccm; } -void Ccm::Prepare(Metadata *image_metadata) +void Ccm::prepare(Metadata *imageMetadata) { - bool awb_ok = false, lux_ok = false; + bool awbOk = false, luxOk = false; struct AwbStatus awb = {}; - awb.temperature_K = 4000; // in case no metadata + awb.temperatureK = 4000; // in case no metadata struct LuxStatus lux = {}; lux.lux = 400; // in case no metadata { // grab mutex just once to get everything - std::lock_guard lock(*image_metadata); - awb_ok = get_locked(image_metadata, "awb.status", awb); - lux_ok = get_locked(image_metadata, "lux.status", lux); + std::lock_guard lock(*imageMetadata); + awbOk = getLocked(imageMetadata, "awb.status", awb); + luxOk = getLocked(imageMetadata, "lux.status", lux); } - if (!awb_ok) + if (!awbOk) LOG(RPiCcm, Warning) << "no colour temperature found"; - if (!lux_ok) + if (!luxOk) LOG(RPiCcm, Warning) << "no lux value found"; - Matrix ccm = calculate_ccm(config_.ccms, awb.temperature_K); + Matrix ccm = calculateCcm(config_.ccms, awb.temperatureK); double saturation = saturation_; - struct CcmStatus ccm_status; - ccm_status.saturation = saturation; - if (!config_.saturation.Empty()) - saturation *= config_.saturation.Eval( - config_.saturation.Domain().Clip(lux.lux)); - ccm = apply_saturation(ccm, saturation); + struct CcmStatus ccmStatus; + ccmStatus.saturation = saturation; + if (!config_.saturation.empty()) + saturation *= config_.saturation.eval( + config_.saturation.domain().clip(lux.lux)); + ccm = applySaturation(ccm, saturation); for (int j = 0; j < 3; j++) for (int i = 0; i < 3; i++) - ccm_status.matrix[j * 3 + i] = + ccmStatus.matrix[j * 3 + i] = std::max(-8.0, std::min(7.9999, ccm.m[j][i])); LOG(RPiCcm, Debug) - << "colour temperature " << awb.temperature_K << "K"; + << "colour temperature " << awb.temperatureK << "K"; LOG(RPiCcm, Debug) - << "CCM: " << ccm_status.matrix[0] << " " << ccm_status.matrix[1] - << " " << ccm_status.matrix[2] << " " - << ccm_status.matrix[3] << " " << ccm_status.matrix[4] - << " " << ccm_status.matrix[5] << " " - << ccm_status.matrix[6] << " " << ccm_status.matrix[7] - << " " << ccm_status.matrix[8]; - image_metadata->Set("ccm.status", ccm_status); + << "CCM: " << ccmStatus.matrix[0] << " " << ccmStatus.matrix[1] + << " " << ccmStatus.matrix[2] << " " + << ccmStatus.matrix[3] << " " << ccmStatus.matrix[4] + << " " << ccmStatus.matrix[5] << " " + << ccmStatus.matrix[6] << " " << ccmStatus.matrix[7] + << " " << ccmStatus.matrix[8]; + imageMetadata->set("ccm.status", ccmStatus); } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Ccm(controller); ; } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.hpp b/src/ipa/raspberrypi/controller/rpi/ccm.hpp index 330ed51fe398..4c4807b8a942 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.hpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.hpp @@ -20,7 +20,7 @@ struct Matrix { double m6, double m7, double m8); Matrix(); double m[3][3]; - void Read(boost::property_tree::ptree const ¶ms); + void read(boost::property_tree::ptree const ¶ms); }; static inline Matrix operator*(double d, Matrix const &m) { @@ -61,11 +61,11 @@ class Ccm : public CcmAlgorithm { public: Ccm(Controller *controller = NULL); - char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; - void SetSaturation(double saturation) override; - void Initialise() override; - void Prepare(Metadata *image_metadata) override; + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void setSaturation(double saturation) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; private: CcmConfig config_; diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index ae55aad56739..169837576678 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -31,40 +31,40 @@ Contrast::Contrast(Controller *controller) { } -char const *Contrast::Name() const +char const *Contrast::name() const { return NAME; } -void Contrast::Read(boost::property_tree::ptree const ¶ms) +void Contrast::read(boost::property_tree::ptree const ¶ms) { // enable adaptive enhancement by default - config_.ce_enable = params.get("ce_enable", 1); + config_.ceEnable = params.get("ce_enable", 1); // the point near the bottom of the histogram to move - config_.lo_histogram = params.get("lo_histogram", 0.01); + config_.loHistogram = params.get("lo_histogram", 0.01); // where in the range to try and move it to - config_.lo_level = params.get("lo_level", 0.015); + config_.loLevel = params.get("lo_level", 0.015); // but don't move by more than this - config_.lo_max = params.get("lo_max", 500); + config_.loMax = params.get("lo_max", 500); // equivalent values for the top of the histogram... - config_.hi_histogram = params.get("hi_histogram", 0.95); - config_.hi_level = params.get("hi_level", 0.95); - config_.hi_max = params.get("hi_max", 2000); - config_.gamma_curve.Read(params.get_child("gamma_curve")); + config_.hiHistogram = params.get("hi_histogram", 0.95); + config_.hiLevel = params.get("hi_level", 0.95); + config_.hiMax = params.get("hi_max", 2000); + config_.gammaCurve.read(params.get_child("gamma_curve")); } -void Contrast::SetBrightness(double brightness) +void Contrast::setBrightness(double brightness) { brightness_ = brightness; } -void Contrast::SetContrast(double contrast) +void Contrast::setContrast(double contrast) { contrast_ = contrast; } -static void fill_in_status(ContrastStatus &status, double brightness, - double contrast, Pwl &gamma_curve) +static void fillInStatus(ContrastStatus &status, double brightness, + double contrast, Pwl &gammaCurve) { status.brightness = brightness; status.contrast = contrast; @@ -73,104 +73,100 @@ static void fill_in_status(ContrastStatus &status, double brightness, : (i < 24 ? (i - 16) * 2048 + 16384 : (i - 24) * 4096 + 32768); status.points[i].x = x; - status.points[i].y = std::min(65535.0, gamma_curve.Eval(x)); + status.points[i].y = std::min(65535.0, gammaCurve.eval(x)); } status.points[CONTRAST_NUM_POINTS - 1].x = 65535; status.points[CONTRAST_NUM_POINTS - 1].y = 65535; } -void Contrast::Initialise() +void Contrast::initialise() { // Fill in some default values as Prepare will run before Process gets // called. - fill_in_status(status_, brightness_, contrast_, config_.gamma_curve); + fillInStatus(status_, brightness_, contrast_, config_.gammaCurve); } -void Contrast::Prepare(Metadata *image_metadata) +void Contrast::prepare(Metadata *imageMetadata) { std::unique_lock lock(mutex_); - image_metadata->Set("contrast.status", status_); + imageMetadata->set("contrast.status", status_); } -Pwl compute_stretch_curve(Histogram const &histogram, - ContrastConfig const &config) +Pwl computeStretchCurve(Histogram const &histogram, + ContrastConfig const &config) { Pwl enhance; - enhance.Append(0, 0); + enhance.append(0, 0); // If the start of the histogram is rather empty, try to pull it down a // bit. - double hist_lo = histogram.Quantile(config.lo_histogram) * - (65536 / NUM_HISTOGRAM_BINS); - double level_lo = config.lo_level * 65536; + double histLo = histogram.quantile(config.loHistogram) * + (65536 / NUM_HISTOGRAM_BINS); + double levelLo = config.loLevel * 65536; LOG(RPiContrast, Debug) - << "Move histogram point " << hist_lo << " to " << level_lo; - hist_lo = std::max( - level_lo, - std::min(65535.0, std::min(hist_lo, level_lo + config.lo_max))); + << "Move histogram point " << histLo << " to " << levelLo; + histLo = std::max(levelLo, + std::min(65535.0, std::min(histLo, levelLo + config.loMax))); LOG(RPiContrast, Debug) - << "Final values " << hist_lo << " -> " << level_lo; - enhance.Append(hist_lo, level_lo); + << "Final values " << histLo << " -> " << levelLo; + enhance.append(histLo, levelLo); // Keep the mid-point (median) in the same place, though, to limit the // apparent amount of global brightness shift. - double mid = histogram.Quantile(0.5) * (65536 / NUM_HISTOGRAM_BINS); - enhance.Append(mid, mid); + double mid = histogram.quantile(0.5) * (65536 / NUM_HISTOGRAM_BINS); + enhance.append(mid, mid); // If the top to the histogram is empty, try to pull the pixel values // there up. - double hist_hi = histogram.Quantile(config.hi_histogram) * - (65536 / NUM_HISTOGRAM_BINS); - double level_hi = config.hi_level * 65536; + double histHi = histogram.quantile(config.hiHistogram) * + (65536 / NUM_HISTOGRAM_BINS); + double levelHi = config.hiLevel * 65536; LOG(RPiContrast, Debug) - << "Move histogram point " << hist_hi << " to " << level_hi; - hist_hi = std::min( - level_hi, - std::max(0.0, std::max(hist_hi, level_hi - config.hi_max))); + << "Move histogram point " << histHi << " to " << levelHi; + histHi = std::min(levelHi, + std::max(0.0, std::max(histHi, levelHi - config.hiMax))); LOG(RPiContrast, Debug) - << "Final values " << hist_hi << " -> " << level_hi; - enhance.Append(hist_hi, level_hi); - enhance.Append(65535, 65535); + << "Final values " << histHi << " -> " << levelHi; + enhance.append(histHi, levelHi); + enhance.append(65535, 65535); return enhance; } -Pwl apply_manual_contrast(Pwl const &gamma_curve, double brightness, - double contrast) +Pwl applyManualContrast(Pwl const &gammaCurve, double brightness, + double contrast) { - Pwl new_gamma_curve; + Pwl newGammaCurve; LOG(RPiContrast, Debug) << "Manual brightness " << brightness << " contrast " << contrast; - gamma_curve.Map([&](double x, double y) { - new_gamma_curve.Append( + gammaCurve.map([&](double x, double y) { + newGammaCurve.append( x, std::max(0.0, std::min(65535.0, (y - 32768) * contrast + 32768 + brightness))); }); - return new_gamma_curve; + return newGammaCurve; } -void Contrast::Process(StatisticsPtr &stats, - [[maybe_unused]] Metadata *image_metadata) +void Contrast::process(StatisticsPtr &stats, + [[maybe_unused]] Metadata *imageMetadata) { Histogram histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS); // We look at the histogram and adjust the gamma curve in the following // ways: 1. Adjust the gamma curve so as to pull the start of the // histogram down, and possibly push the end up. - Pwl gamma_curve = config_.gamma_curve; - if (config_.ce_enable) { - if (config_.lo_max != 0 || config_.hi_max != 0) - gamma_curve = compute_stretch_curve(histogram, config_) - .Compose(gamma_curve); + Pwl gammaCurve = config_.gammaCurve; + if (config_.ceEnable) { + if (config_.loMax != 0 || config_.hiMax != 0) + gammaCurve = computeStretchCurve(histogram, config_).compose(gammaCurve); // We could apply other adjustments (e.g. partial equalisation) // based on the histogram...? } // 2. Finally apply any manually selected brightness/contrast // adjustment. if (brightness_ != 0 || contrast_ != 1.0) - gamma_curve = apply_manual_contrast(gamma_curve, brightness_, - contrast_); + gammaCurve = applyManualContrast(gammaCurve, brightness_, contrast_); // And fill in the status for output. Use more points towards the bottom // of the curve. ContrastStatus status; - fill_in_status(status, brightness_, contrast_, gamma_curve); + fillInStatus(status, brightness_, contrast_, gammaCurve); { std::unique_lock lock(mutex_); status_ = status; @@ -178,8 +174,8 @@ void Contrast::Process(StatisticsPtr &stats, } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Contrast(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp index 85624539a1da..5a6d530f63fd 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp @@ -17,27 +17,27 @@ namespace RPiController { // Back End AWB. struct ContrastConfig { - bool ce_enable; - double lo_histogram; - double lo_level; - double lo_max; - double hi_histogram; - double hi_level; - double hi_max; - Pwl gamma_curve; + bool ceEnable; + double loHistogram; + double loLevel; + double loMax; + double hiHistogram; + double hiLevel; + double hiMax; + Pwl gammaCurve; }; class Contrast : public ContrastAlgorithm { public: Contrast(Controller *controller = NULL); - char const *Name() const override; - void Read(boost::property_tree::ptree const ¶ms) override; - void SetBrightness(double brightness) override; - void SetContrast(double contrast) override; - void Initialise() override; - void Prepare(Metadata *image_metadata) override; - void Process(StatisticsPtr &stats, Metadata *image_metadata) override; + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void setBrightness(double brightness) override; + void setContrast(double contrast) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; private: ContrastConfig config_; diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.cpp b/src/ipa/raspberrypi/controller/rpi/dpc.cpp index 110f50560e76..42154cf300b8 100644 --- a/src/ipa/raspberrypi/controller/rpi/dpc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/dpc.cpp @@ -24,30 +24,30 @@ Dpc::Dpc(Controller *controller) { } -char const *Dpc::Name() const +char const *Dpc::name() const { return NAME; } -void Dpc::Read(boost::property_tree::ptree const ¶ms) +void Dpc::read(boost::property_tree::ptree const ¶ms) { config_.strength = params.get("strength", 1); if (config_.strength < 0 || config_.strength > 2) throw std::runtime_error("Dpc: bad strength value"); } -void Dpc::Prepare(Metadata *image_metadata) +void Dpc::prepare(Metadata *imageMetadata) { - DpcStatus dpc_status = {}; + DpcStatus dpcStatus = {}; // Should we vary this with lux level or analogue gain? TBD. - dpc_status.strength = config_.strength; - LOG(RPiDpc, Debug) << "strength " << dpc_status.strength; - image_metadata->Set("dpc.status", dpc_status); + dpcStatus.strength = config_.strength; + LOG(RPiDpc, Debug) << "strength " << dpcStatus.strength; + imageMetadata->set("dpc.status", dpcStatus); } // Register algorithm with the system. -static Algorithm *Create(Controller *controller) +static Algorithm *create(Controller *controller) { return (Algorithm *)new Dpc(controller); } -static RegisterAlgorithm reg(NAME, &Create); +static RegisterAlgorithm reg(NAME, &create); diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.hpp b/src/ipa/raspberrypi/controller/rpi/dpc.hpp index d90285c4eb56..039310cc8d05 100644 --- a/src/ipa/raspberrypi/controller/rpi/dpc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/dpc.hpp @@ -21,9 +21,9 @@ class Dpc : public Algorithm { public: Dpc(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: DpcConfig config_;