From patchwork Tue Jul 26 12:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16781 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 21292C3275 for ; Tue, 26 Jul 2022 12:46:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B28536331C; Tue, 26 Jul 2022 14:46:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658839568; bh=QO35yZnt0woM4gUBa9xZXM+Scv1x9CAVfUHOAqb6VHI=; 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=1kM2SVIMIb2hl0xaJOAjk9wmiGOPFdqvsopWJkbN/TC8iw0Bs4MiKN0n86YxiY3Zb qhO6iHBdhO6i8QFNXKEuwL6q7mpjJ+9fgCWzP4ShI1rnXwHjxuTQASX39c9WekT0Oc Z+834kmItU5X2Suy6JLJRFeFsDL+9AHSg1FcFHvuoMEIlH/2BBQob1wUOKRgjXlFa1 ZuSuv/bY148uPezYZoLy5IH6dDMgcV9DI6zW/gljFhFPmbX/DATWlMDmKxUWU7poqz ExFhHxqpLrkhUSyOOp57x4JmdwEK1fnRB+S/K4AwJ8VV+3YgPSgeOj5RMwf3me3svk BxLILEGIHQ7dA== Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C09726331C for ; Tue, 26 Jul 2022 14:46:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="EqyVT1rc"; dkim-atps=neutral Received: by mail-wm1-x331.google.com with SMTP id b21-20020a05600c4e1500b003a32bc8612fso8093507wmq.3 for ; Tue, 26 Jul 2022 05:46:04 -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=hAGPSSJvx902LtVAushGNNjOrVHyzSw5YGgJ1D+1AZw=; b=EqyVT1rcXxLyu9+4ZmCrtStqBYynVEtSvlD+WYaLfbRPi3cd/wmNeK369cc4+vKSor WQorr92OljXTEJneMKxfw4WZhyCgEv30ClA2se7HruIKDRPcQM0fSw3BJ5eALt6KmqGl 7Aqy4LfHg0sRZFXSLcX2APtdoH0/6n8isF60z9x2dYQ/RRznHQpMhNl37a0huGgOTd6O s4ipfFthKPqNl5XBRAvJO9VzWxl8IOPDK9ipGD1Dth8ZTh+9dqSF5nh2sSqAyNL2dkta gNKpYoi2Nw1HTt6Cy225txi/+796qkq9YlBF0RMxKmbhXgI/TVLOMM3KidArYkr8riCY DUjA== 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=hAGPSSJvx902LtVAushGNNjOrVHyzSw5YGgJ1D+1AZw=; b=UW7fwa8CGsEFTLZ0xdIBPPmmJpI4OZuLHlRDd/9YeXVKzV3SVI4xJXDlRAymjaZMdN fPgcCDaU7bDhHh2COCPFcf4b1S+yOyEIHkAgDiByni8z+KNpB/mtWs+hU8rFVyqYPbDg Cg+mKdtGB8l9sQoNhbpCkkPiUDFHTBHJMZkN+K+kel6BFaU4yL3w5xBaKs4LNvGgmOCy 5xp0DutKJNJi6VKJk1fcz1yp23MHFW4UYHFgsvoKcpDLA7r3IvVW+/h9GBpovx/QCxmz Whxmqn6c6wpGPXPNVOGUyRqPX+4wga5jY/L2VYNvyYNu6ip1Wf+qt3ngFlq9P5ZyyrXB A0Sw== X-Gm-Message-State: AJIora94v9H95X2ZL9L274TsIYxHaQwy3FDd5uRL4t4gKgEERYEAZQFy Zx2z1zZNB6P3VDe9g7uejaiKSPPX/5EBKA== X-Google-Smtp-Source: AGRyM1upYnl7vfbH/riMtf7XRRd4Q4M8Hj7/YR+eWnLdx2E9fn27eiA/UaoFqhNxRq/85jPQsW5xCQ== X-Received: by 2002:a05:600c:3ac7:b0:3a3:64c3:6ddf with SMTP id d7-20020a05600c3ac700b003a364c36ddfmr5970643wms.105.1658839563425; Tue, 26 Jul 2022 05:46:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 05:46:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 13:45:40 +0100 Message-Id: <20220726124549.1646-9-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 08/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/[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/black_level_status.h | 6 +- src/ipa/raspberrypi/controller/rpi/agc.cpp | 2 +- .../controller/rpi/black_level.cpp | 34 ++--- .../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 +- 10 files changed, 160 insertions(+), 162 deletions(-) diff --git a/src/ipa/raspberrypi/controller/black_level_status.h b/src/ipa/raspberrypi/controller/black_level_status.h index d085f64b27fe..df3661401d99 100644 --- a/src/ipa/raspberrypi/controller/black_level_status.h +++ b/src/ipa/raspberrypi/controller/black_level_status.h @@ -13,9 +13,9 @@ extern "C" { #endif struct BlackLevelStatus { - uint16_t black_level_r; // out of 16 bits - uint16_t black_level_g; - uint16_t black_level_b; + uint16_t blackLevelR; // out of 16 bits + uint16_t blackLevelG; + uint16_t blackLevelB; }; #ifdef __cplusplus diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index c19769f4e27b..408ff9cf296d 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -250,7 +250,7 @@ void Agc::setFixedShutter(Duration fixedShutter) void Agc::setFixedAnalogueGain(double fixedAnalogueGain) { - fixedAnalogueGain_ = fixedAnalogueGain_; + fixedAnalogueGain_ = fixedAnalogueGain; // Set this in case someone calls Pause() straight after. status_.analogueGain = fixedAnalogueGain; } diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.cpp b/src/ipa/raspberrypi/controller/rpi/black_level.cpp index 6b3497f13c19..101b5ea92cf5 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("blackLevelR", blackLevel); + blackLevelG_ = params.get("blackLevelG", blackLevel); + blackLevelB_ = params.get("blackLevelB", 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 + // Possibly we should think about doing this in a switchMode 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.blackLevelR = blackLevelR_; + status.blackLevelG = blackLevelG_; + status.blackLevelB = 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_;