From patchwork Mon Mar 27 12:20:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18474 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 EE1FDC326C for ; Mon, 27 Mar 2023 12:20:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A116562767; Mon, 27 Mar 2023 14:20:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679919651; 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=mtCRhjttbE6t4Hriduc8rqn+NZLzL9l4LIVPnQqqCJY2MpkyfIoh7DVmB0kqKd2Oz UA0pJK4O9wI8d8/lfVvSGXmxN8ccqQAin4eygsxkzhzzvvCULrApnNIcrQLm+niX/b QAcPPXzQ3I73C9qMorWFnJZntc86gSF5Eu+BWFNl67h1aRZd/dr43jl7gqbtbUk4Ex kO5H2ZUc/r5bJP1qnWXnZ8ovqypVs1QTV393dxUcGL+4xZMSst7iUQMIgttLaDgrAa mDfmV4IrIbUZHci+S0Ttk7NPpiYEc//LUHH4t5uPR2k9C1RsKZP+puVgjeefoys1j0 qIWmEnGKzACAA== 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 3E81962747 for ; Mon, 27 Mar 2023 14:20:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="cuCWr7qb"; dkim-atps=neutral Received: by mail-il1-x12a.google.com with SMTP id h11so4512717ild.11 for ; Mon, 27 Mar 2023 05:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1679919646; 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=cuCWr7qbrh2dk9ysm9/4Yi+HViFsEDnCNDAuJvvnohN6QwdQaOeSnHUq7yVs6oK83m 3CMCYufg5ipouPZIpEMn2JjLRBjOimaI9ckytp1muPK9Obm+d8umozH2SgJNSFLYx++q pJn/815uxj016I7wDjLxqNh574tz0wcXnjqvjp8I5OL4QKTaMQhozuUmQuV2jpSmRLo6 WUjTkDuMk7sjvYPUKQGZ3MkajOECj0EY/eLhIn+twgE7Do0NA0lfhKRG3MiL+d+2nEdB YyJf59reUh70lIstYluOdgfrTINa0UoVLaR4zPlX/2DzOfz8mfBPi8mlIULaBKvCaty8 RJ+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679919646; 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=2qN0OV5vJe+IiNOrSlmZj9t2kHI34hjA6p8iyDyrAzIB6r98dcPBMJ1Q+44udLY3Gu kLWf/uBXcfKol7LZlOiDxbngXv9f0BTHRCZjkHeHN28f8l9hWefnpbf8rRuCr2xVxcxD Gk9uuWBgk5K4hXQ7JHWon9zi4hm5+AxnQ/uU9twCpSEur9wciLa24PsEKSJepg4EtEML vLSDd+XXg1o5yLJc7PF0+mIbckQD9Qjn7lcpo+0gUOXwgMhfIcxhHkyiRPocvqCBgpDF ng6khmDg8/GnR3XGxp5kkFS7h3WpxmkCg1pXo5ui50EZj1t8+Ai589kHhBR6W0TKkXT5 pwZQ== X-Gm-Message-State: AAQBX9d+GtSjUBQrt+Ks9E/pdqWgAzzDHoJPOkCkcX+dJ/evBA3j8tZa tsohcdFZLAPw60OkyZE+KKZyp4RYoc6+JORJRDmQ0Q== X-Google-Smtp-Source: AKy350YkYUUcK7HiNDPSGBkShSBbq4CzNDLwmgCdHU3wK+UFUQTeGh5hxYCObXxE7HVXI8lapTqB8g== X-Received: by 2002:a92:512:0:b0:316:b0bb:3d99 with SMTP id q18-20020a920512000000b00316b0bb3d99mr7950014ile.22.1679919645815; Mon, 27 Mar 2023 05:20:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 05:20:45 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Mar 2023 13:20:25 +0100 Message-Id: <20230327122030.11756-6-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 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 */