From patchwork Mon Mar 27 12:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18471 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 598D2BD160 for ; Mon, 27 Mar 2023 12:20:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 156B662744; Mon, 27 Mar 2023 14:20:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679919646; bh=p8bjwYcPHre60o2C+WXibtxyErkFZE3S7agTpN+m80M=; 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=1J16qOH79mlFamkgG4cpg/m8nNvWo6/HTZfHK/mOAbYTBrYb0NkajKFPdPGwajZaG l98GvRG+AsiEpixn51SdO4FtoWTktT2Q00IFBRVHo2bRU+8aNNyr92z6e7jb7f8Cjs yvCOXUD018anwfsSppMcdBpR04xaX9prmtiRegQtiH7icrZOKYIhKtnHJqlMJV4nXh ZoTqhILwavN6NhuCow4kSiOUdL+6df80+5WS59kgFrbQcUSFxzFQTKH/pUyH0+uDaU CBwiVheTKa1Mws51SXd/aHthR/DjlDrGjhysqDLaP6wtOnCZIR8JWiKrzKXc2LNFKZ I8fCTx+Z1OROg== Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C000862740 for ; Mon, 27 Mar 2023 14:20:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KxeYuUtz"; dkim-atps=neutral Received: by mail-io1-xd2b.google.com with SMTP id k17so3803090iob.1 for ; Mon, 27 Mar 2023 05:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679919642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=budr3U+RGAt0DckKXPoFcDC9ZFRMq47CvRp3MWMf5AA=; b=KxeYuUtzVgyF6J1Lo9lIyxmxSfYKUCGQh05EG7Qf16CjEkKTt5iVNlxcFl52S/w/Qy 8QL51NdGQD/Ra6U6PSU/3tkACYH3RO86rmgpWYtvaT/OkNJPC80UN2NpKpNBwN0OlQp6 mbOVqGTx5I4Q9pO7/p9kOPy+RKHlQg8A3G7PMw/gafLDoNznoYfB3SR9lj+P2bNvjxMl D7Y5cXNHNe4b4EXYjWJqtK9PiqyhwGm7GTRxdmgzkjSkj77M7j7lWznsmCEQx25tQQM/ rx7JZlU1PLMg7Dl7eI4472MLfn2adk5zN6HXuBt6Jc4ar6DJb2fcgLh9SeH833Cz4n0G 3Zbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679919642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=budr3U+RGAt0DckKXPoFcDC9ZFRMq47CvRp3MWMf5AA=; b=r5iWsgPERR2fSGKg3I9C+M9vV14g+5Qxvwcftd5oW3EM59d11XKev2G3vuXhL8KTjw 5ZO0Twey/XSvUz+IDvoAlSuvqfsrXY9P+X+7q5d9bWVj4c7XpG+OIa8FElqVgMq1UTaC ZusWXDHrRM74g/7EVzUH7Cm/siKQVD0REWNQafGa5P6aYWT+8AN0TdqiwntEEqT+qNku LvSnjOzvRtqtHRdThUNp4QxaeXpOeRi0CPosDqwInAIVIymMOQKse7cEAgscpdfThjiB 3pZWAYjYk9zRnu1yaVxX4aC8MX5j05SEwDYLQ0FZZeFO9QeRdIJAQHwjKSySbm2dqwhO 3wog== X-Gm-Message-State: AO0yUKVrM96pLcb3dqPkFAmlAyRxKI9cWnMNtp9CvLWce90vcIhbpViX hS5knarksy1aCxKHbMbgRE62/ypZSSJtth3hP3Fpsw== X-Google-Smtp-Source: AK7set8O3NSZzJMD7ctnUOuif0Ol+ZZxLCGhZxijB5a9GZkwVFLc7qSJTamFgHw+fdHAm8rYhHARtQ== X-Received: by 2002:a6b:e50f:0:b0:758:10a7:6813 with SMTP id y15-20020a6be50f000000b0075810a76813mr8803664ioc.16.1679919642083; Mon, 27 Mar 2023 05:20:42 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r7-20020a5edb47000000b00758ff97aaedsm3239026iop.16.2023.03.27.05.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 05:20:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Mar 2023 13:20:22 +0100 Message-Id: <20230327122030.11756-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327122030.11756-1-naush@raspberrypi.com> References: <20230327122030.11756-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/10] ipa: raspberrypi: Add hardware configuration to the controller 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" Add a new Controller::HardwareConfig structure that captures the hardware statistics grid/histogram sizes and pipeline widths. This ensures there is a single centralised places for these parameters. Add a getHardwareConfig() helper function to retrieve these values for a given hardware target. Update the statistics populating routine in the IPA to use the values from this structure instead of the hardcoded numbers. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/algorithm.h | 4 +++ src/ipa/raspberrypi/controller/controller.cpp | 31 +++++++++++++++++++ src/ipa/raspberrypi/controller/controller.h | 11 +++++++ src/ipa/raspberrypi/raspberrypi.cpp | 21 +++++-------- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/algorithm.h b/src/ipa/raspberrypi/controller/algorithm.h index 7c22fbe4945c..4aa814ebbebd 100644 --- a/src/ipa/raspberrypi/controller/algorithm.h +++ b/src/ipa/raspberrypi/controller/algorithm.h @@ -45,6 +45,10 @@ public: { return controller_->getTarget(); } + const Controller::HardwareConfig &getHardwareConfig() const + { + return controller_->getHardwareConfig(); + } private: Controller *controller_; diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index a6250ee140b0..fa1721130783 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -20,6 +20,25 @@ using namespace libcamera; LOG_DEFINE_CATEGORY(RPiController) +static const std::map HardwareConfigMap = { + { + "bcm2835", + { + /* + * There are only ever 15 AGC regions computed by the firmware + * due to zoning, but the HW defines AGC_REGIONS == 16! + */ + .agcRegions = { 15 , 1 }, + .agcZoneWeights = { 15 , 1 }, + .awbRegions = { 16, 12 }, + .focusRegions = { 4, 3 }, + .numHistogramBins = 128, + .numGammaPoints = 33, + .pipelineWidth = 13 + } + }, +}; + Controller::Controller() : switchModeCalled_(false) { @@ -148,3 +167,15 @@ const std::string &Controller::getTarget() const { return target_; } + +const Controller::HardwareConfig &Controller::getHardwareConfig() const +{ + auto cfg = HardwareConfigMap.find(getTarget()); + + /* + * This really should not happen, the IPA ought to validate the target + * on initialisation. + */ + ASSERT(cfg != HardwareConfigMap.end()); + return cfg->second; +} diff --git a/src/ipa/raspberrypi/controller/controller.h b/src/ipa/raspberrypi/controller/controller.h index 24e02903d438..c6af5cd6c7d4 100644 --- a/src/ipa/raspberrypi/controller/controller.h +++ b/src/ipa/raspberrypi/controller/controller.h @@ -37,6 +37,16 @@ typedef std::unique_ptr AlgorithmPtr; class Controller { public: + struct HardwareConfig { + libcamera::Size agcRegions; + libcamera::Size agcZoneWeights; + libcamera::Size awbRegions; + libcamera::Size focusRegions; + unsigned int numHistogramBins; + unsigned int numGammaPoints; + unsigned int pipelineWidth; + }; + Controller(); ~Controller(); int read(char const *filename); @@ -47,6 +57,7 @@ public: Metadata &getGlobalMetadata(); Algorithm *getAlgorithm(std::string const &name) const; const std::string &getTarget() const; + const HardwareConfig &getHardwareConfig() const; protected: int createAlgorithm(const std::string &name, const libcamera::YamlObject ¶ms); diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 86359538cf67..b64cb96e2dde 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1392,20 +1392,19 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co { using namespace RPiController; + const Controller::HardwareConfig &hw = controller_.getHardwareConfig(); unsigned int i; StatisticsPtr statistics = std::make_unique(Statistics::AgcStatsPos::PreWb, Statistics::ColourStatsPos::PostLsc); /* RGB histograms are not used, so do not populate them. */ - statistics->yHist = RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS); + statistics->yHist = RPiController::Histogram(stats->hist[0].g_hist, + hw.numHistogramBins); - /* - * All region sums are based on a 13-bit pipeline bit-depth. Normalise - * this to 16-bits for the AGC/AWB/ALSC algorithms. - */ - constexpr unsigned int scale = Statistics::NormalisationFactorPow2 - 13; + /* All region sums are based on a 16-bit normalised pipeline bit-depth. */ + unsigned int scale = Statistics::NormalisationFactorPow2 - hw.pipelineWidth; - statistics->awbRegions.init({ DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y }); + statistics->awbRegions.init(hw.awbRegions); for (i = 0; i < statistics->awbRegions.numRegions(); i++) statistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum << scale, stats->awb_stats[i].g_sum << scale, @@ -1413,11 +1412,7 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co stats->awb_stats[i].counted, stats->awb_stats[i].notcounted }); - /* - * There are only ever 15 regions computed by the firmware due to zoning, - * but the HW defines AGC_REGIONS == 16! - */ - statistics->agcRegions.init(15); + statistics->agcRegions.init(hw.agcRegions); for (i = 0; i < statistics->agcRegions.numRegions(); i++) statistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum << scale, stats->agc_stats[i].g_sum << scale, @@ -1425,7 +1420,7 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co stats->agc_stats[i].counted, stats->awb_stats[i].notcounted }); - statistics->focusRegions.init({ 4, 3 }); + statistics->focusRegions.init(hw.focusRegions); for (i = 0; i < statistics->focusRegions.numRegions(); i++) statistics->focusRegions.set(i, { stats->focus_stats[i].contrast_val[1][1] / 1000, stats->focus_stats[i].contrast_val_num[1][1],