From patchwork Mon Mar 27 12:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18477 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 3028AC329C for ; Mon, 27 Mar 2023 12:20:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D67F66276E; Mon, 27 Mar 2023 14:20:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679919653; bh=ikDcOL4X/wpeiEwyev6qGchPa+D+ecIaiLLxK93NTDI=; 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=sGTK48dfDLaLXEEjQglwNhSo+ivZ63VIVhFSZ5t2Sh/zV3ZEwYq18ZMXgKZ41DJ0+ etDPZhylMiV17O5jf0f/wS8uJxLAz5Zpo4jPn1gwVTnzRwoN/+rIZb2JRnmYFdrGQA Zqd8sTSyCOH9V0oR9DjVsv6+LdBYNEvoQJ4cJQkGt49/xFux9ZcTW/iVoJnRn70UI1 9itESjgjR2Wiw8Ai05ZEi9nHgdaRm4UthvtqJVjfMb0aD5dlCXR4wdvuiXoIBXldcg mB/ir6wK3+v0IjZ2HVXVeiSj/b9YlKhkSoTQS7ub5DV1sYFdAXzDfcx/lfynD2wZD7 kBiQ1kB4A0Rlg== 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 F2B9A62758 for ; Mon, 27 Mar 2023 14:20:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZS6sZh7T"; dkim-atps=neutral Received: by mail-il1-x12a.google.com with SMTP id h11so4512798ild.11 for ; Mon, 27 Mar 2023 05:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679919649; 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=jFO9Xj1fKv8w1hxje+taVYe/vtFu0agkjxfPZsxmJQQ=; b=ZS6sZh7Trtz78CXj32JqqZy1CHyYojL6fNy1IoyWNykhnKjtx4RGYxebk+uTqF/5s0 AZO4C1C1RNNRcuxqwUf1nezN24gX16Nx5SSAzx/cQKiz1v12/Gz5V2ZafRgbM9/AKZRy SEiSpvGy8Eh/f55/No0JKJeNxepoOV9+3hxMgsB9SxT06K1fRtvQ74k/Jy73ml+uWgJ8 xmLOaVTF74yrTcb6pnyi36+/XKD3cC8B/jMOjEcHLQoihhsEaqxE2XeqSZQmn+3HOEcc PUsTfVdodESPKu7plLFio7PEy6QLS+7zv+q1xnSa3zVOLPOF/mvnOylF9UZ3foA/d5FQ 6l0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679919649; 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=jFO9Xj1fKv8w1hxje+taVYe/vtFu0agkjxfPZsxmJQQ=; b=UWBaj9bOF0Dtv/G2nu5YSjBOpK6iCnSohNEHZXzhN3bcEcq/sDKROxkxtiWpx3eSKb JxENYWnfTj6cJAWqFJfWLzly3GLBWO5FRgY0EIMaqWoFEFJgn5KLWimS61Cks/x+znDn wLLFR2fDHv8DDqvEMuQmy69REA4RdpdDwaqxUrpYqtMSY5VnmbkJueII6dO+pUVe+gXv tmvN4oXdX3CnlUNktJmi0GVP5QVt3cohHBCaSYj/d8CaWr3C+y7Yn/6B1cpb3BVxaeBw LaViJHZgXCbbaCeYJgJOyccezoiPDLpNleqSxDK8AcqccRa4f6laiR72qSu1yZoPUJD8 uJVw== X-Gm-Message-State: AAQBX9cpNqnei3Gti8qtX18UPs9e55MTbKMbwSq9wVH6NY4L7Kp5VMyK ZvGM5cj2V0lBQ7aJXx0F6PZ2uTTTXXDOvFflx8SaCQ== X-Google-Smtp-Source: AKy350bpm90pMeoJsaLV9ynHorlNTwk7/PJxoajuKhuWZksJf7Mu9O7ve/wSByUCm3LuQs22NYfvvw== X-Received: by 2002:a05:6e02:811:b0:315:365d:5358 with SMTP id u17-20020a056e02081100b00315365d5358mr9665395ilm.10.1679919649425; Mon, 27 Mar 2023 05:20:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 05:20:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Mar 2023 13:20:28 +0100 Message-Id: <20230327122030.11756-9-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 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 4ea0dd41e66c..fb96bb556e84 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,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 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); };