From patchwork Wed Mar 22 13:06:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18429 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 594F6C329C for ; Wed, 22 Mar 2023 13:06:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A0B9E626E6; Wed, 22 Mar 2023 14:06:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679490383; bh=J1uasa5/tJAHTXqgL1/mM0u5Q3ArfZnJ87UFIogFh88=; 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=eB6wyYSwASaqkoh5yo+6u5o7Xy9uDevIoi+dvET34BGZre92BbZgrM2G9t3OTvPX9 3QKhDKX7E2vPLKzuLoWuB7alIVT9l2Fh8Et0jLmf2qQMwOn/gKQXZE7SVn0vXevGtc OyJIGU5uSKC5Oq72EF1F0Ieb6kkzaFAvJPyLngCM5w5syxWQ79NT0oI7Efa6BQRBF/ EhNTlP36RcQvRiG4igksdmcJsMfRSZXYwlWneKZcjq7APkdGaPB4d4/9LjgQMhMQEX Vru2AAo+1KzXdz/vDaz4lTBlDWtBN8l/jFyZXUCvrO0PCPyYAOZXj4W8KJH0L130Xj VSlFCL31vwHAw== Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 991FE61ECE for ; Wed, 22 Mar 2023 14:06:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Gg35Co84"; dkim-atps=neutral Received: by mail-io1-xd2e.google.com with SMTP id m22so8406911ioy.4 for ; Wed, 22 Mar 2023 06:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679490379; 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=xf8pOLOBSpsB8lB4jAOqwlWtCYuXLJMzQzDn0iSf5F4=; b=Gg35Co84B+VcmfBaHoNjKgzVITDHGRKcaHlvsNqQjIt6XSTov1FZmbDO2749Lj72ze j4mRbL8ikyHrlIxbHhaUkt83l46SaVOJVJWGQMx6VpiGbJxh6ANnIS0HQxW35d5ZAG/h Lqk/Lo8cvH3IkAQeHfpgj0VJq8gQGaz/2RMYmbN1Nl1sy8mfsAFAo2xe9fb0Z74BAXhj fWA6jdki/1imqLQL4RE+uQDcH/hKjy4fD6cn7JKvsEBit/BOGvGU/f85v2/BNzfSdD3U raTnOcBrNTD3WbGoT0SEtGgBH/HyqGq+UMuIcOnfEnd++CvLwLGkU+dm1mfv0TcQw8hs dRrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679490379; 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=xf8pOLOBSpsB8lB4jAOqwlWtCYuXLJMzQzDn0iSf5F4=; b=tabPjjIN9MXcwyljU8QUJ+j7kV09OvXtlSohrH+3DZpshIOBg7ux1FpBU5+ThhMj6q kjynq+mIf2coyLcRJk04FpZTZ0133ILxazUU3WHbd0RVTq4ixvcavZINTl324dBm1VX1 U8PAVs0R0N9wsG8Kc7xe1kaL34vlFRu+jckRVVRSOciLLW5Pg9xOtbYjWxJlz0aiN9DR 0JSkwG0AzkDsEeOXLcCP5o0gturTiXUgEMIcDov3LxLhdXtUBxNYsVJFGtI62Q78M99l Xr9LC487PJ/LQnhIW9j4dEbhaIFW+3y8t5h2Y6m3/2JCedBjFVNdfcCPY7qrKdxq/d0a FMEA== X-Gm-Message-State: AO0yUKXkpUfTuxhxKsV48iWIFo6dJTpW55h0pI8vCvPsFgvf23zdf9LM 71Lf4l9nJZjSCNeEB+g5HCIkSQWodrZk8S/tAWhs/Q== X-Google-Smtp-Source: AK7set/BYwWUWicJqbLAYhwHGgTtVwF9Ow62denmkmsP9LljcShdzMNlWsvUYTquF/jUdYeSj2ShJQ== X-Received: by 2002:a05:6602:1616:b0:752:6f1b:63a2 with SMTP id x22-20020a056602161600b007526f1b63a2mr2043043iow.3.1679490378288; Wed, 22 Mar 2023 06:06:18 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id l6-20020a026646000000b003c488204c6fsm4927960jaf.76.2023.03.22.06.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 06:06:18 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Mar 2023 13:06:04 +0000 Message-Id: <20230322130612.5208-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322130612.5208-1-naush@raspberrypi.com> References: <20230322130612.5208-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 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 --- src/ipa/raspberrypi/controller/algorithm.h | 4 ++ src/ipa/raspberrypi/controller/controller.cpp | 39 +++++++++++++++++++ src/ipa/raspberrypi/controller/controller.h | 11 ++++++ src/ipa/raspberrypi/raspberrypi.cpp | 21 ++++------ 4 files changed, 62 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..2c7517aec6b4 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -20,6 +20,31 @@ 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 + } + }, + /* For error handling. */ + { + "error", + { + } + } +}; + Controller::Controller() : switchModeCalled_(false) { @@ -148,3 +173,17 @@ 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. + */ + if (cfg == HardwareConfigMap.end()) + return HardwareConfigMap.at("error"); + + 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],