From patchwork Wed Mar 22 13:06:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18436 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 3D9C1C32A2 for ; Wed, 22 Mar 2023 13:06:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9BCA56270D; Wed, 22 Mar 2023 14:06:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679490393; bh=icouwjstIJlplcREzPnVduaDDhW/ubniFTTqrI/y6FU=; 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=xLV22dgMXQNFzxvoSsch1uRDjhg4Sg5YfCATW3JIi4S9UqlsXFfKz5x4LbvCGfPnh g3tGQygmnD8lWlb/JPBi5I7Vuo7Wq9ZqHxRNJtnQwqAIlP4lSDnfLnB0edWBcQmQDL OcfpUTr1RrEHe21Vn+kp+8l8H7MLJM0g8Ws3Jr0dvJVExjlNPTzjgeNj2pBMh/c874 FqLcwMT2X1Q7fu6VoA98c2CG5Q3jGeKP2/Z8XQG7sCpxlPOFrNQR/TXj8fP3oV8PlD GTSIK4BlcQBajK3uJoLvOIXD1+5ozDeNEnTrzxcwySXlLy/9YK5UAMFEvh77nh9C1e bj9J91VgeS2Xw== Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B28A762742 for ; Wed, 22 Mar 2023 14:06:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LRRacJ87"; dkim-atps=neutral Received: by mail-il1-x12a.google.com with SMTP id s1so3865698ild.6 for ; Wed, 22 Mar 2023 06:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679490387; 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=GM7wpbXpS06YcWhjewbppISe52faOHMFSk9/O0DNzEQ=; b=LRRacJ87oZGnJkjkesd+Ht/3B3SNA27IZgTMEbB+of/ASQoNt7YOki2JRslxNrDSyT LD6cYpqXp0dvz1wVptEJboQQc3NBT7OApqCel4OUivYZ5c4R9ACwJ0Va4i89ww2/q4cG nx0C9j2+F/dnRLL9JmqrVDea23p+J7RNCgFdN6yKYfUj3CAjLLIv4KNdlHwv5pTQP56K 4fE2cN8O3nokyTFfCOjpxUHC3MqPZzPQLOTo3ZDfUy4yQxSSS8btl1ZV/W4kFt70x1w0 BpuknBzR9geu6ExjhQFf4Z8o8sW3+Rskm00NKs+valOHMEbq/SPaPh7mZgcnKWV2mlR7 VL/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679490387; 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=GM7wpbXpS06YcWhjewbppISe52faOHMFSk9/O0DNzEQ=; b=b3+KLZUnw+cunhU7obXWL/Swmjxbk+yM5Fprnf6J4/5SPGq0B9UUc+pJWgY3RubceC CnVPNoLyyH5aUZ8uDIq/8KJIw7EE236sqYIvH52SVTk3L9E+pATz5oH8YnaJxNtIbdOx vMAPnPBrYv0zoXVApUXf6R4PDkrxZYyvfrl/DfsqdIlN7xc2IXZ+uAOlq8U+GCL/KASa TyaQD0iKPrLsn3HY63RQ2RvpVHbx9W9tI9I3FLkHHYzoavlsciAqGMWT99P+nhRPSWlf cGLEMj5q+237hh9YCpLFr+cNotSTk168PCZsxM5Jkqxc9rY0J3YGDgAHhToLJoo/8hTR K6tw== X-Gm-Message-State: AO0yUKVvMELPjiO0OZtwV/OYXaP7Qw8KrpVLMu03YPURSQ0ak2wP31xA yV2KyssA+tf8kWvrD3ssk4U9QhlVzp5vKAlp9q9fwg== X-Google-Smtp-Source: AK7set8PLqXmH0UGWOwh5b25oKKhBUnJz48E4VC3aauokboJ7eB6nS2E70NvbIckivVwVoDCTVt6Dw== X-Received: by 2002:a92:c80c:0:b0:313:fea2:be5c with SMTP id v12-20020a92c80c000000b00313fea2be5cmr4201055iln.11.1679490387186; Wed, 22 Mar 2023 06:06:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 06:06:26 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Mar 2023 13:06:11 +0000 Message-Id: <20230322130612.5208-10-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 09/10] ipa: raspberrypi: Generalise the agc algorithm 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" Remove any hard-coded assumptions about the target hardware platform from the AGC algorithm. Instead, use the "target" string provided by the camera tuning config and generalised statistics structures to determing parameters such as grid and region sizes. This change replaces all hard-coded arrays with equivalent std::vector types. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 19 ++++++++++++------- src/ipa/raspberrypi/controller/rpi/agc.h | 9 +-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 4ea0dd41e66c..3e4a8149b9ae 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -31,17 +31,12 @@ LOG_DEFINE_CATEGORY(RPiAgc) int AgcMeteringMode::read(const libcamera::YamlObject ¶ms) { const YamlObject &yamlWeights = params["weights"]; - if (yamlWeights.size() != AgcStatsSize) { - LOG(RPiAgc, Error) << "AgcMeteringMode: Incorrect number of weights"; - return -EINVAL; - } - unsigned int num = 0; for (const auto &p : yamlWeights.asList()) { auto value = p.get(); if (!value) return -EINVAL; - weights[num++] = *value; + weights.push_back(*value); } return 0; @@ -249,6 +244,14 @@ int Agc::read(const libcamera::YamlObject ¶ms) if (ret) return ret; + const Size &size = getHardwareConfig().agcZoneWeights; + for (auto const &modes : config_.meteringModes) { + if (modes.second.weights.size() != size.width * size.height) { + LOG(RPiAgc, Error) << "AgcMeteringMode: Incorrect number of weights"; + return -EINVAL; + } + } + /* * Set the config's defaults (which are the first ones it read) as our * current modes, until someone changes them. (they're all known to @@ -582,9 +585,11 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata) } static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, - double weights[], double gain) + std::vector &weights, double gain) { constexpr uint64_t maxVal = 1 << Statistics::NormalisationFactorPow2; + + ASSERT(weights.size() == stats->agcRegions.numRegions()); /* * Note how the calculation below means that equal weights give you * "average" metering (i.e. all pixels equally important). diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h index f04896ca25ad..d11a49c9cd85 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.h +++ b/src/ipa/raspberrypi/controller/rpi/agc.h @@ -17,17 +17,10 @@ /* This is our implementation of AGC. */ -/* - * This is the number actually set up by the firmware, not the maximum possible - * number (which is 16). - */ - -constexpr unsigned int AgcStatsSize = 15; - namespace RPiController { struct AgcMeteringMode { - double weights[AgcStatsSize]; + std::vector weights; int read(const libcamera::YamlObject ¶ms); };