From patchwork Fri Mar 31 07:23:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18504 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 3F1EBC329F for ; Fri, 31 Mar 2023 07:41:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D425E6277E; Fri, 31 Mar 2023 09:41:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680248460; bh=zxN8L9BcQbJI34o+Lrtm03FoFSjDEr3NlDyqe82KZiA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=d+dapaJMfZh7k5P9/Fhj+jY/DfwM7Vghid6eUlrnk167fl7PbGDiFDeHCOf+tu1+c cWMhgPfDNOVE/qxrda1MQwE+QJbVoi/z8QpU2O66mUit9iiv1ScW0m34s0DAUJojTk prub6DaeiyQQPihaiH7NaC6LowKjULzT/7UHkROO6lvhz/IrVT81Wml9Et7eDgx8AG bB20eVQf+otBjnry+ATCuCr7KDFLbUrF1cpMRRaCqXWBCO4Y0JFU32ekqVllnhlRMz ZNQjq7i23wARCWRMPQoR4NSM1ORP7Dn2NgVPApu0yapbSvifauIr6guZWjUq/n18aQ CGiTvATS8K9SQ== Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E0C66279C for ; Fri, 31 Mar 2023 09:40:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="RbeHncS/"; dkim-atps=neutral Received: by mail-io1-xd30.google.com with SMTP id x3so1879023iov.3 for ; Fri, 31 Mar 2023 00:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1680248456; 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=rrS46SBM06NUoF4wxPBdfbbZvRNbGZyJPXft+5T02xE=; b=RbeHncS/3pL4Xg6CPucUhgn/ZCNxWhXsFdcBTvDxsMkd6u9Nvzr+BthAKX7uEEsKe6 ObeP3AvM/+6fKoedkWu3R5N6R0ZH8oxKGr+6uZfW+bRgNF7HlWrjGqeDzT6w6zRg0BFO y+l9Gjp5dshk9cZgv/Y2A7f0Tp64AbluPzqmIOWq8n77gacCdgANZ+eTAtWnUUjxKXs+ 60IhIhZx0t0jc32vpTNVVCawmOpfenZ0Iwf9HLuJArjcDK7pDeVjBnTf9FQc8BoDm6Qn UxDZQjOj3DDYw0guIBEZMBfiz5HM+FSJxxIUkjNEVc7dNFHsgzwJtnXfRDMCWwYc9znu 8PVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680248456; 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=rrS46SBM06NUoF4wxPBdfbbZvRNbGZyJPXft+5T02xE=; b=kbNX5OYxL4C7kkdEzrsWGKxZRMuwXrMl7yPTLCyfcW4wUI8wR3N6FTL9CevSgAdWEc v+tDvznlHHXPid4sNQmBPCj6hHXJM6t2En5J2p5fHw2aBPzlhrGg8r1D8DukpGuTZP4o L439wEdQ2jLwrYOcecYhXNQVMcZpkJRKxFXP8rRZRdMfHrEtHfUbbBcZ3QI7SlLuiDMl jDXhRY/J0qOmpg1KDwnw9W08Z4f1T0H4B+uOMQL/52CNYhC4qUEcVIq+KYU+W07vNnOl OnmI6qBVzeGhGT7UjD25ajbhlzXJEDj0VR1f6zI8p56JEXTszHw2v9yRwmm8ljFNTiZn gDMQ== X-Gm-Message-State: AO0yUKW1sHv+hwkb06e+9eq4LeJZkk1h5QKNXwoYKxiCCHZJ2gv/hq1x ru3kxAWUKmU8PaaeI3dricVwcVEB0kdIEtDdC6sleg== X-Google-Smtp-Source: AK7set//g8Bwy9l51n1GAGQDDEjq4zIeOAFKiiy5pomWgHFjNONN/Ddtzt1Fj/CjxJ1V04Mtz3A+YQ== X-Received: by 2002:a5e:8412:0:b0:758:a647:d21e with SMTP id h18-20020a5e8412000000b00758a647d21emr17587818ioj.21.1680248456097; Fri, 31 Mar 2023 00:40:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 00:40:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 08:23:39 +0100 Message-Id: <20230331072341.24851-9-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 08/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 Cc: Jacopo Mondi 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: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 20 +++++++++++++------- src/ipa/raspberrypi/controller/rpi/agc.h | 9 +-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index f438cab8840a..e6fb7b8dbeb3 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; @@ -248,6 +243,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 @@ -585,9 +588,12 @@ 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 4fa9b8de5fb2..4e5f272fac78 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); };