From patchwork Fri Mar 31 07:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18501 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 A5256C329E for ; Fri, 31 Mar 2023 07:40:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 57ACC6278A; Fri, 31 Mar 2023 09:40:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1680248455; bh=klPCji71t9ff50/NTw25Wr7qoGXqjM2oZwi1ptHCVKI=; 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=TK3iyqJnQ6e9qTJDUAnf1KQSJEU7mN2uiLVayevDURw/SbBZzqTpO+6CLF4QX8lwx 9awhTfkUXcuTAsKT5sANK7JEpENtzIYNbwGCDy/0OFUgNrd7SLIGx+Zq2MRIGf2xR6 zpm8G605Uieyi9IArpsuZ5fbkhTF6YN8+4Eq5cVxwlf1dPReigdrMtOPzKB2tbvGap 6vdkOSj8pjc8YBRERexF/LxvcGOaVvLjmZvIAAWI8IMdI227qVf2okc2c/TcI0pKUt 76eYfCz18glD9y60/0EKseYa5jWjxtVgdWS6K2Sddt+nW780iEPQN0r6qcEp3/1Cqx qGdSjq5NEzIhg== Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 109C762754 for ; Fri, 31 Mar 2023 09:40:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="M7OOqDGK"; dkim-atps=neutral Received: by mail-io1-xd2c.google.com with SMTP id h187so7668305iof.7 for ; Fri, 31 Mar 2023 00:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1680248452; 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=548zcSLJYSR6puTSQTcbbtm0W6Y5GofHbCgq+Ac6wj0=; b=M7OOqDGKYqMQFtZEiafYztQE9d0F+GX8c3YlHV4+G3ApUf3uFJHx42DXE/+ze2LgcK XqngZ/rjWu3QypjMP3CuE38pvY3rOA4nkT2c1ENvKospTcMSFeMtEfbB444gILoZLt9I 3lQITFKmb7exElJYXIqFIos5oosds75gX86r5nLSSp1rB1hJqalzPuk82Djf5FGqJQrY 6B6USeBGMPmqn2Qdp4ENzJwDRdtyd4VGvpayuVyj0zTZ7jyQxQhCOnTIQg7hEBxqha9z ci6vJbnmwaj6FjNlfCQYKOcHhxBz4EeCuermjPuz4qUUzWKUTmfMU85jQtexN/aw2woK 5BIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680248452; 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=548zcSLJYSR6puTSQTcbbtm0W6Y5GofHbCgq+Ac6wj0=; b=EZpPu5gfc9IafHo/t/F+9OlJGxNsxLqIeM4Il1IdiY4uhH8tu4Etkr5hr0XdjOmXMv 27nLNWjupRhWWZT69275SsDQy4wz59ep4FfaZ1YZVnpX++WaZ3FityKkrU2oqRm46sZI xzmCxNBIApAwJc/J2KEfGvp5Ax5Jy1tuikGKXnE2oN3fwGSftXNK61H6VAGrTuP9jOZc yvuq4BeOYMNnf7g7N/HSIZXFpFU7G/d0ymeXViPCnN4Azf/T1Y61jV7o8aw3S0hSQpxM mQaHuOjfg9cuM7pYgs0wqPFLwylm4Ydg8xSEr4lJl1M3Wh/0f5wqgN6ZXIaGvbWVzQFC GBgw== X-Gm-Message-State: AO0yUKX+0sBQDH/XzupXfemhEzWCHaJMlfMgRwzbC924EV9GU+R0SlYm JH+It5Nd3H8z+ncLF9QkoVAb6bHqRgABQ0+7kLDg8Q== X-Google-Smtp-Source: AK7set+r1qYivsl9wCo7KlfMqxO+4NEO/Egi3ao/192LhMH3d2DUZNo5aSneg9N6bpAb2AufIzhffw== X-Received: by 2002:a5e:c001:0:b0:752:8aee:6d91 with SMTP id u1-20020a5ec001000000b007528aee6d91mr18664332iol.12.1680248452407; Fri, 31 Mar 2023 00:40:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 00:40:52 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 31 Mar 2023 08:23:36 +0100 Message-Id: <20230331072341.24851-6-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 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 Cc: Jacopo Mondi 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 */