From patchwork Tue Jul 26 12:45:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16789 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 CA211C3275 for ; Tue, 26 Jul 2022 12:46:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 83FF46333F; Tue, 26 Jul 2022 14:46:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658839579; bh=e6FvbeLkjaAUZP2qRm/ba8QTF9Z/rJow1YHM5XrAWBo=; 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=q/pfxZALlIz6c6yhRK09WOEtYnNyMptv9mxxTPxAtDWTubrnlXP68QjcYlf+1sYDs C/ODcykToU/AP58ZLVo0vD6wQhHiPJJ6OaqW5/G9bQuQU2fH5OIYXIp4apwxzGrmQM 1OSDV7eBvEMqB6qTQiXyi7LanBPudW5kgKf2gJXw49IieMzr9JUaz4c1V9qrz0K1kH GpT6uEbiheuvAb4i0Ka7G5owZHyb1FCgEkWrUrWxv8plAGmOX6j8fe9hiSiAhn/uUO 3qytmilwywN8lok4tucqNUMPC+qC4gJWc0d+Qt8IVo1SxpoHbL8EY5mzAj9yNs1gBE ErCeB2we47zqw== Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EFC863337 for ; Tue, 26 Jul 2022 14:46:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="cPgDCsfh"; dkim-atps=neutral Received: by mail-wr1-x42c.google.com with SMTP id b26so20017780wrc.2 for ; Tue, 26 Jul 2022 05:46:13 -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=q9EarpEVg/g9/qwGp4A/c3Lb52RzZkR19iEqdrCfwI8=; b=cPgDCsfhm7l7wvGvRePEkOjgmuidNaGDpmJ7ujechj1f07n1xVChFeX0yBDjgX2x82 zCQKwCr6fHErLn5DDjqtK9U6OFOCFMmgcjhV2TAJqiZRW1bi1FC2bdUTgJS8i45MoZfA 94FYy5nZ7O7c+/v2uU7kbLvvidJi6tFEuIclNQiepwu9IXXyMaDdMkJSKPv2Mmv5EwPp S3WAN5aJaoFvWMbWe4LsFhNQHOBbk/xbO4IRY2P7TedLo3jYLUu/KHXjn6T8SILM4el9 ZwqeK3BKvchCI+v9hmbhkdneg7GiSvqr2+m7qtUulVtOwEBY4ebGraMnvOUrN2h+/ivz X+SA== 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=q9EarpEVg/g9/qwGp4A/c3Lb52RzZkR19iEqdrCfwI8=; b=FBLj0QjTNN7VBVqSl0B4ZbDZDj3dupSEr3cwz8ypnygGxW+H6OGbqiN6oa1nrMZ6TW CBeZg3vTe56lZRbRLCiHOLeMz8JK40yygZTGje7nYOY9sP8xmHa58l6fIkqLdQK4Zws1 F7XdSL3BZpoSeIUHQ5ko8wMwqxymf+zpT8t1LKYNO2ayRZHHJw/itpgYLZac+e3FvJx8 tfo8/lcMwnJQIL8o34Fr/5fy/RqoXoYy8ETHvQX92h2YSLulZUYbTBqiwEcoKh2pBOUF eXs1u5R9r77l8xJlQ/ojG9lmINpjRdtRQnJeJ3LudQGhlgWEsLeHt+vRXeVmmRxRjNEn PJLA== X-Gm-Message-State: AJIora/RO7wBoW+lvhsWHDExINhoVfvXmJ374/mGdZgFIk1ucz6WBgNu wDFIEb77h5pTSf4R8BvmEbSeEIclH5+uyQ== X-Google-Smtp-Source: AGRyM1sbd064ImZhYIcm9TJvMXI6dRXPAdrSXBlNQJAa89lilw/bF4Ju1qo0Otma1V83nKcYzYBoNA== X-Received: by 2002:a05:6000:18c1:b0:21e:4712:b284 with SMTP id w1-20020a05600018c100b0021e4712b284mr10234057wrq.545.1658839573061; Tue, 26 Jul 2022 05:46:13 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 05:46:11 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 13:45:48 +0100 Message-Id: <20220726124549.1646-17-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 16/17] ipa: raspberrypi: Remove #define constants 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" Replace all #define constant values with equivalent constexpr definitions. As a drive-by, remove the CAMERA_MODE_NAME_LEN constant as it is unused. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/alsc_status.h | 10 ++++----- src/ipa/raspberrypi/controller/camera_mode.h | 2 -- .../raspberrypi/controller/contrast_status.h | 4 ++-- src/ipa/raspberrypi/controller/rpi/agc.cpp | 22 +++++++++---------- src/ipa/raspberrypi/controller/rpi/agc.h | 4 ++-- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 4 ++-- src/ipa/raspberrypi/controller/rpi/alsc.h | 22 +++++++++---------- src/ipa/raspberrypi/controller/rpi/awb.cpp | 8 +++---- .../raspberrypi/controller/rpi/contrast.cpp | 6 ++--- src/ipa/raspberrypi/raspberrypi.cpp | 2 +- 10 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/ipa/raspberrypi/controller/alsc_status.h b/src/ipa/raspberrypi/controller/alsc_status.h index 498880daf2d1..e5aa7e37c330 100644 --- a/src/ipa/raspberrypi/controller/alsc_status.h +++ b/src/ipa/raspberrypi/controller/alsc_status.h @@ -11,11 +11,11 @@ * "alsc.status" metadata. */ -#define ALSC_CELLS_X 16 -#define ALSC_CELLS_Y 12 +constexpr unsigned int AlscCellsX = 16; +constexpr unsigned int AlscCellsY = 12; struct AlscStatus { - double r[ALSC_CELLS_Y][ALSC_CELLS_X]; - double g[ALSC_CELLS_Y][ALSC_CELLS_X]; - double b[ALSC_CELLS_Y][ALSC_CELLS_X]; + double r[AlscCellsY][AlscCellsX]; + double g[AlscCellsY][AlscCellsX]; + double b[AlscCellsY][AlscCellsX]; }; diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h index 0ac6c07fb7bf..a6ccf8c1c600 100644 --- a/src/ipa/raspberrypi/controller/camera_mode.h +++ b/src/ipa/raspberrypi/controller/camera_mode.h @@ -16,8 +16,6 @@ * including binning, scaling, cropping etc. */ -#define CAMERA_MODE_NAME_LEN 32 - struct CameraMode { /* bit depth of the raw camera output */ uint32_t bitdepth; diff --git a/src/ipa/raspberrypi/controller/contrast_status.h b/src/ipa/raspberrypi/controller/contrast_status.h index 11d55295963b..ef2a7c680fc2 100644 --- a/src/ipa/raspberrypi/controller/contrast_status.h +++ b/src/ipa/raspberrypi/controller/contrast_status.h @@ -11,7 +11,7 @@ * of contrast stretching based on the AGC histogram. */ -#define CONTRAST_NUM_POINTS 33 +constexpr unsigned int ContrastNumPoints = 33; struct ContrastPoint { uint16_t x; @@ -19,7 +19,7 @@ struct ContrastPoint { }; struct ContrastStatus { - struct ContrastPoint points[CONTRAST_NUM_POINTS]; + struct ContrastPoint points[ContrastNumPoints]; double brightness; double contrast; }; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index e9a945e3a630..e0c174b6580d 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -28,17 +28,17 @@ LOG_DEFINE_CATEGORY(RPiAgc) #define NAME "rpi.agc" -#define PIPELINE_BITS 13 /* seems to be a 13-bit pipeline */ +static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */ void AgcMeteringMode::read(boost::property_tree::ptree const ¶ms) { int num = 0; for (auto &p : params.get_child("weights")) { - if (num == AGC_STATS_SIZE) + if (num == AgcStatsSize) LOG(RPiAgc, Fatal) << "AgcConfig: too many weights"; weights[num++] = p.second.get_value(); } - if (num != AGC_STATS_SIZE) + if (num != AgcStatsSize) LOG(RPiAgc, Fatal) << "AgcConfig: insufficient weights"; } @@ -525,11 +525,11 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb, * "average" metering (i.e. all pixels equally important). */ double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0; - for (int i = 0; i < AGC_STATS_SIZE; i++) { + for (unsigned int i = 0; i < AgcStatsSize; i++) { double counted = regions[i].counted; - double rAcc = std::min(regions[i].r_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted); - double gAcc = std::min(regions[i].g_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted); - double bAcc = std::min(regions[i].b_sum * gain, ((1 << PIPELINE_BITS) - 1) * counted); + double rAcc = std::min(regions[i].r_sum * gain, ((1 << PipelineBits) - 1) * counted); + double gAcc = std::min(regions[i].g_sum * gain, ((1 << PipelineBits) - 1) * counted); + double bAcc = std::min(regions[i].b_sum * gain, ((1 << PipelineBits) - 1) * counted); rSum += rAcc * weights[i]; gSum += gAcc * weights[i]; bSum += bAcc * weights[i]; @@ -542,7 +542,7 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb, double ySum = rSum * awb.gainR * .299 + gSum * awb.gainG * .587 + bSum * awb.gainB * .114; - return ySum / pixelSum / (1 << PIPELINE_BITS); + return ySum / pixelSum / (1 << PipelineBits); } /* @@ -553,13 +553,13 @@ static double computeInitialY(bcm2835_isp_stats *stats, AwbStatus const &awb, * (contrived) cases. */ -#define EV_GAIN_Y_TARGET_LIMIT 0.9 +static constexpr double EvGainYTargetLimit = 0.9; static double constraintComputeGain(AgcConstraint &c, Histogram &h, double lux, double evGain, double &targetY) { targetY = c.yTarget.eval(c.yTarget.domain().clip(lux)); - targetY = std::min(EV_GAIN_Y_TARGET_LIMIT, targetY * evGain); + targetY = std::min(EvGainYTargetLimit, targetY * evGain); double iqm = h.interQuantileMean(c.qLo, c.qHi); return (targetY * NUM_HISTOGRAM_BINS) / iqm; } @@ -578,7 +578,7 @@ void Agc::computeGain(bcm2835_isp_stats *statistics, Metadata *imageMetadata, * that we consider the histogram constraints. */ targetY = config_.yTarget.eval(config_.yTarget.domain().clip(lux.lux)); - targetY = std::min(EV_GAIN_Y_TARGET_LIMIT, targetY * evGain); + targetY = std::min(EvGainYTargetLimit, targetY * evGain); /* * Do this calculation a few times as brightness increase can be diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h index 48b33a10c73a..f57afa6dc80c 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.h +++ b/src/ipa/raspberrypi/controller/rpi/agc.h @@ -22,12 +22,12 @@ * number (which is 16). */ -#define AGC_STATS_SIZE 15 +constexpr unsigned int AgcStatsSize = 15; namespace RPiController { struct AgcMeteringMode { - double weights[AGC_STATS_SIZE]; + double weights[AgcStatsSize]; void read(boost::property_tree::ptree const ¶ms); }; diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 7df89445711a..03ae33501dc0 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -23,8 +23,8 @@ LOG_DEFINE_CATEGORY(RPiAlsc) #define NAME "rpi.alsc" -static const int X = ALSC_CELLS_X; -static const int Y = ALSC_CELLS_Y; +static const int X = AlscCellsX; +static const int Y = AlscCellsY; static const int XY = X * Y; static const double InsufficientData = -1.0; diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h index e17f2fe93379..4e9a715ae0ab 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.h +++ b/src/ipa/raspberrypi/controller/rpi/alsc.h @@ -19,7 +19,7 @@ namespace RPiController { struct AlscCalibration { double ct; - double table[ALSC_CELLS_X * ALSC_CELLS_Y]; + double table[AlscCellsX * AlscCellsY]; }; struct AlscConfig { @@ -35,7 +35,7 @@ struct AlscConfig { uint16_t minG; double omega; uint32_t nIter; - double luminanceLut[ALSC_CELLS_X * ALSC_CELLS_Y]; + double luminanceLut[AlscCellsX * AlscCellsY]; double luminanceStrength; std::vector calibrationsCr; std::vector calibrationsCb; @@ -61,7 +61,7 @@ private: AlscConfig config_; bool firstTime_; CameraMode cameraMode_; - double luminanceTable_[ALSC_CELLS_X * ALSC_CELLS_Y]; + double luminanceTable_[AlscCellsX * AlscCellsY]; std::thread asyncThread_; void asyncFunc(); /* asynchronous thread function */ std::mutex mutex_; @@ -87,8 +87,8 @@ private: int frameCount_; /* counts up to startupFrames for Process function */ int frameCount2_; - double syncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; - double prevSyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; + double syncResults_[3][AlscCellsY][AlscCellsX]; + double prevSyncResults_[3][AlscCellsY][AlscCellsX]; void waitForAysncThread(); /* * The following are for the asynchronous thread to use, though the main @@ -98,13 +98,13 @@ private: /* copy out the results from the async thread so that it can be restarted */ void fetchAsyncResults(); double ct_; - bcm2835_isp_stats_region statistics_[ALSC_CELLS_Y * ALSC_CELLS_X]; - double asyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; - double asyncLambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; - double asyncLambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; + bcm2835_isp_stats_region statistics_[AlscCellsY * AlscCellsX]; + double asyncResults_[3][AlscCellsY][AlscCellsX]; + double asyncLambdaR_[AlscCellsX * AlscCellsY]; + double asyncLambdaB_[AlscCellsX * AlscCellsY]; void doAlsc(); - double lambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; - double lambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; + double lambdaR_[AlscCellsX * AlscCellsY]; + double lambdaB_[AlscCellsX * AlscCellsY]; }; } /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index c379e6b92649..ad75d55f0976 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -18,8 +18,8 @@ LOG_DEFINE_CATEGORY(RPiAwb) #define NAME "rpi.awb" -#define AWB_STATS_SIZE_X DEFAULT_AWB_REGIONS_X -#define AWB_STATS_SIZE_Y DEFAULT_AWB_REGIONS_Y +static constexpr unsigned int AwbStatsSizeX = DEFAULT_AWB_REGIONS_X; +static constexpr unsigned int AwbStatsSizeY = DEFAULT_AWB_REGIONS_Y; /* * todo - the locking in this algorithm needs some tidying up as has been done @@ -357,7 +357,7 @@ static void generateStats(std::vector &zones, bcm2835_isp_stats_region *stats, double minPixels, double minG) { - for (int i = 0; i < AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y; i++) { + for (unsigned int i = 0; i < AwbStatsSizeX * AwbStatsSizeY; i++) { Awb::RGB zone; double counted = stats[i].counted; if (counted >= minPixels) { @@ -599,7 +599,7 @@ void Awb::awbBayes() * valid... not entirely sure about this. */ Pwl prior = interpolatePrior(); - prior *= zones_.size() / (double)(AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y); + prior *= zones_.size() / (double)(AwbStatsSizeX * AwbStatsSizeY); prior.map([](double x, double y) { LOG(RPiAwb, Debug) << "(" << x << "," << y << ")"; }); diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index 04aeb91e4d61..9e60dc5d47e7 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -70,15 +70,15 @@ static void fillInStatus(ContrastStatus &status, double brightness, { status.brightness = brightness; status.contrast = contrast; - for (int i = 0; i < CONTRAST_NUM_POINTS - 1; i++) { + for (unsigned int i = 0; i < ContrastNumPoints - 1; i++) { int x = i < 16 ? i * 1024 : (i < 24 ? (i - 16) * 2048 + 16384 : (i - 24) * 4096 + 32768); status.points[i].x = 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; + status.points[ContrastNumPoints - 1].x = 65535; + status.points[ContrastNumPoints - 1].y = 65535; } void Contrast::initialise() diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 951d8c65abfd..9d550354d78e 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1235,7 +1235,7 @@ void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList struct bcm2835_isp_gamma gamma; gamma.enabled = 1; - for (int i = 0; i < CONTRAST_NUM_POINTS; i++) { + for (unsigned int i = 0; i < ContrastNumPoints; i++) { gamma.x[i] = contrastStatus->points[i].x; gamma.y[i] = contrastStatus->points[i].y; }