From patchwork Wed Mar 22 13:06:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18432 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 361E3C329F for ; Wed, 22 Mar 2023 13:06:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1D4662716; Wed, 22 Mar 2023 14:06:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679490387; bh=GzdIKbckX0bRqpgpUVf0MR/k60yQLQR4p9/YtYtkHlU=; 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=gVcAPgT6Hx4EC+zS/Wd2/W7N/u9dxhkrKDaq72vIHH3twX38TGSQbHuOqtL20T2y1 o9gXV0/48sfMwfGrXkggBbnk6ep11TLYDV2u1U2JxA+Sn/230o077+R40mjHVBMZuy PK496yvYqsvm1dBOLvMsnN4xjA3n/SXZyK7KRHCOlAa18DSasdDfGbt/h6yPsVJRMz +SzpqGW/rSUCaQ7A4uyqEyP0MLWiGfDMGqljpqlp77O0t303YG2r4ORxOp3wo9BxUh u4JxYddmIrAWOGx1pWWvhVXbYuLZfQhmoK/VzP6UGo70y9M/P7TdpYz2qSwaz2eyUd muhNjAuWjFRmQ== 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 7D283626DB for ; Wed, 22 Mar 2023 14:06:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="g883W8OV"; dkim-atps=neutral Received: by mail-io1-xd2e.google.com with SMTP id m22so8407009ioy.4 for ; Wed, 22 Mar 2023 06:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679490383; 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=eKdjahHZlI08PdsXsAVyS9pD8aARi8WXwJYPUcC+57Y=; b=g883W8OVh5Uh0SgWdoS33FtJgYBeXlZcAYc0ghroYnhrp3BgJyO5rjJS1S3P/hd8AB +fSAyKyz+JjBhTLJet59YbnsAWtus5bFZ/792OD42C6eH/kYoq2/EzrWZHCJ5KOZf2Hl AOJ2jlEUa0MOuNEfRhSb5u/s2oRBWppI42j/t3/VnCvthT7pJp6f7vTb4qeTB2ry1+XJ +XgW7/rhnaVUOHljKPFySCD1atu6NBhpv9EhGlExFuw8+iAibWroRae8HK8JamgnKLVW 5rN/TdaZKJEH18VwZi7y+G0pfkvLSWEceewWoqBdd5W4ECYZQsY2QLaHOebJTz7aqu8q 837Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679490383; 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=eKdjahHZlI08PdsXsAVyS9pD8aARi8WXwJYPUcC+57Y=; b=rBXvA1rvZgDwT+M0orN6nANwNwKE94VVsw/7D4ejmSJ96mnPFBRBjPQtPiVP7VvFAz 0EXzs/h0TJ2n8deBDY8zEr/6JPu95RjBP+gTUYN8EFJCveVWurcHB4FDmrt20Vom9Nt9 jyOaZr79mnfUZQr2hS87fjqXq5PJIBVh4YXllyVGWMcfEAaJ+zjZm8IymioJi0jFtKxb 6iX1JqdSriE+m8l9eB3t3ededwuvD8DLR1zPGV4OtOm6GJ+noLsmPF7HTc1hMUf6FKZa 3PQIodi/7eGWG0UOOoe6T5Y/fuIh1isbIvIFY7pZtHMFnDcVQOtT3vKHMRfzLpYqjBD5 6Ttw== X-Gm-Message-State: AO0yUKWMC7BRZ+TLD1xdl4Vcvya59EWOPEdw/N2HrGOOZUP9nA6W0QaZ IuehfvIZ9gWy+9Ry+rFM1xu5o8NJ4XyPxBMwfpjA6w== X-Google-Smtp-Source: AK7set8WvT6o8fUxeO1cxO3mUZqgX7LK0o9ySCl/98BoHKkpQc99O96ajEww5K6jYtXtXjeNm1GXEg== X-Received: by 2002:a5e:de46:0:b0:752:ee32:322d with SMTP id e6-20020a5ede46000000b00752ee32322dmr4002575ioq.18.1679490382932; Wed, 22 Mar 2023 06:06:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 06:06:22 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Mar 2023 13:06:07 +0000 Message-Id: <20230322130612.5208-6-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 05/10] ipa: raspberrypi: alsc: Use a better type name for sparse arrays 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" From: David Plowman The algorithm uses the data type std::vector> to represent the large sparse matrices that are XY (X, Y being the ALSC grid size) high but with only 4 non-zero elements on each row. Replace this slightly long type name by SparseArray. No functional changes. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 24 ++++++++++----------- src/ipa/raspberrypi/controller/rpi/alsc.h | 10 ++++++++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 524c48093590..3a2e8fe00ca6 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -607,7 +607,7 @@ static double computeWeight(double Ci, double Cj, double sigma) /* Compute all weights. */ static void computeW(const Array2D &C, double sigma, - std::vector> &W) + SparseArray &W) { size_t XY = C.size(); size_t X = C.dimensions().width; @@ -623,8 +623,8 @@ static void computeW(const Array2D &C, double sigma, /* Compute M, the large but sparse matrix such that M * lambdas = 0. */ static void constructM(const Array2D &C, - const std::vector> &W, - std::vector> &M) + const SparseArray &W, + SparseArray &M) { size_t XY = C.size(); size_t X = C.dimensions().width; @@ -651,37 +651,37 @@ static void constructM(const Array2D &C, * left/right neighbours are zero down the left/right edges, so we don't need * need to test the i value to exclude them. */ -static double computeLambdaBottom(int i, const std::vector> &M, +static double computeLambdaBottom(int i, const SparseArray &M, Array2D &lambda) { return M[i][1] * lambda[i + 1] + M[i][2] * lambda[i + lambda.dimensions().width] + M[i][3] * lambda[i - 1]; } -static double computeLambdaBottomStart(int i, const std::vector> &M, +static double computeLambdaBottomStart(int i, const SparseArray &M, Array2D &lambda) { return M[i][1] * lambda[i + 1] + M[i][2] * lambda[i + lambda.dimensions().width]; } -static double computeLambdaInterior(int i, const std::vector> &M, +static double computeLambdaInterior(int i, const SparseArray &M, Array2D &lambda) { return M[i][0] * lambda[i - lambda.dimensions().width] + M[i][1] * lambda[i + 1] + M[i][2] * lambda[i + lambda.dimensions().width] + M[i][3] * lambda[i - 1]; } -static double computeLambdaTop(int i, const std::vector> &M, +static double computeLambdaTop(int i, const SparseArray &M, Array2D &lambda) { return M[i][0] * lambda[i - lambda.dimensions().width] + M[i][1] * lambda[i + 1] + M[i][3] * lambda[i - 1]; } -static double computeLambdaTopEnd(int i, const std::vector> &M, +static double computeLambdaTopEnd(int i, const SparseArray &M, Array2D &lambda) { return M[i][0] * lambda[i - lambda.dimensions().width] + M[i][3] * lambda[i - 1]; } /* Gauss-Seidel iteration with over-relaxation. */ -static double gaussSeidel2Sor(const std::vector> &M, double omega, +static double gaussSeidel2Sor(const SparseArray &M, double omega, Array2D &lambda, double lambdaBound) { int XY = lambda.size(); @@ -753,8 +753,8 @@ static void reaverage(Array2D &data) static void runMatrixIterations(const Array2D &C, Array2D &lambda, - const std::vector> &W, - std::vector> &M, double omega, + const SparseArray &W, + SparseArray &M, double omega, unsigned int nIter, double threshold, double lambdaBound) { constructM(C, W, M); @@ -813,7 +813,7 @@ void Alsc::doAlsc() { Array2D &cr = tmpC_[0], &cb = tmpC_[1], &calTableR = tmpC_[2], &calTableB = tmpC_[3], &calTableTmp = tmpC_[4]; - std::vector> &wr = tmpM_[0], &wb = tmpM_[1], &M = tmpM_[2]; + SparseArray &wr = tmpM_[0], &wb = tmpM_[1], &M = tmpM_[2]; /* * Calculate our R/B ("Cr"/"Cb") colour statistics, and assess which are diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h index 1ab61299c4cd..0b6d9478073c 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.h +++ b/src/ipa/raspberrypi/controller/rpi/alsc.h @@ -68,6 +68,14 @@ private: std::vector data_; }; +/* + * We'll use the term SparseArray for the large sparse matrices that are + * XY tall but have only 4 non-zero elements on each row. + */ + +template +using SparseArray = std::vector>; + struct AlscCalibration { double ct; Array2D table; @@ -160,7 +168,7 @@ private: /* Temporaries for the computations */ std::array, 5> tmpC_; - std::array>, 3> tmpM_; + std::array, 3> tmpM_; }; } /* namespace RPiController */