From patchwork Fri Mar 31 07:23:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18498 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 58619C329D for ; Fri, 31 Mar 2023 07:40:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE47962759; Fri, 31 Mar 2023 09:40:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680248451; bh=eJv12V6KwFXPTSxr4TloZ2Rl1o7jM2rYSgPYX4ktmR0=; 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=TcLbVGnIh5OmzjXkNeDT+FSL6vWM3dY3XeeppGVhuFcnUx1QDQwRZyLLy6t7QCC/+ s5b7xiRcBznYo16jgFMy4yV29nqm+emEF6UJbKvqolWrhDd0saG+OKdZBfP7tIct3K AuoE8+v0+Ot1/FhWmNpScs8YLN7LcVN0ZrBb+oESzuh9q9YDHp3HtFFbQLkuAf6t4+ E4hfPpgQM/Ur/jmnkq0hW8FyIlvoO63U+sJGEnJiCJ2VRGpUTZAkOEzAM2Rj0Lmsde ENbJwRmkDTLygHKXzwKKS3V5HrTH5DtzPVhZDeBJVrYpsWHvr9FFeJ9KePfxIFY2io 5Z+IQZ3LO3ffg== Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C62AA62754 for ; Fri, 31 Mar 2023 09:40:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="nfsDN1tq"; dkim-atps=neutral Received: by mail-io1-xd2c.google.com with SMTP id h187so7668253iof.7 for ; Fri, 31 Mar 2023 00:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1680248448; 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=WfsHCbIkbpjQForzTwd4q36w5B1LLe0FLiY7FZyGvyo=; b=nfsDN1tqHVHyVmLTZVaTJjQtwoWtURIIRg6L6iQVoRQ3VsIBXrB2OtfuFlxrPm3rdw Be81alWGQVfKRSKaFVDZGEPnYAZxAnBPutSS3vVUG5BWxAcqSLUfL13rhzqSo8nP/g11 Izj48Yh3jhJn/GMBO9OyzjzlomRQ9nTw9/HDI8c2fKy9w+6D9Cm/Qg0F4MYSqEpaca37 vAN92BZm9j0a2U+vTTKohcmIDNIkRIPVyt/K9QxH/h3DlszRPGI+YHDX8I7PA5zwUEZs im3d7ysCDt8jrvvt++G3ePYRpjSpDQ3DT5o512SD/fYhnVBz9eVsmTctqUOdmoHyc04l 2RXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680248448; 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=WfsHCbIkbpjQForzTwd4q36w5B1LLe0FLiY7FZyGvyo=; b=VObWhrYjaIRJSCOahIimFSWw4d8iOIxlc2xjqclCtfCpIAW0HBpl1HD5TyaaHXBM8L PBvegV3ARKSxWcrxWJqMVrJ1absxecjLNPc7d6I1v9ZW2JFG4VG8ydC8hDj8ftxrmPfY +lNFMFNE40cKduXY+7GvOrnWkB9mg/km88k+maG62Kx9jWtQekHzFhElASSt//Fus5PF iV/wms23zTL1ifxctxpSvCx4rCqVkWKUsfzfB6qDquFuelikJv9eXNC4elaovC/GbPj/ Hb7CWc8gSlwdNLdqks/EQyroK+WFW/aQMcsfZj0Jr17r+jUoBslhdZMkbFIMuSNn0++M REgw== X-Gm-Message-State: AO0yUKXNx8BRvQ4G5ohwylBuk2D5K6btl48Yfj3TdqiunmXJek4oKOBX o1ejT08twWvZC2kZafL2Z89S661S0FIeF0bRho98rw== X-Google-Smtp-Source: AK7set99C4JBGL/5dwIPE4XNdh+R7u5RGbmWx1p5KJbAq62b/aBjNamxB1Rgr4gBRJdM+uv8sO/qZQ== X-Received: by 2002:a5e:d612:0:b0:753:121f:72a7 with SMTP id w18-20020a5ed612000000b00753121f72a7mr20020518iom.8.1680248448340; Fri, 31 Mar 2023 00:40:48 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id i17-20020a6bf411000000b0074555814e73sm421943iog.32.2023.03.31.00.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 00:40:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 08:23:33 +0100 Message-Id: <20230331072341.24851-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230331072341.24851-1-naush@raspberrypi.com> References: <20230331072341.24851-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 92c65a2c2f6c..e24529920a4b 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -1394,20 +1394,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, @@ -1415,11 +1414,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, @@ -1427,7 +1422,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],