From patchwork Wed Mar 23 13:56:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15519 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 95014C0F1B for ; Wed, 23 Mar 2022 13:56:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D1A9B604E6; Wed, 23 Mar 2022 14:56:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648043782; bh=UP8RwrbAGIDvpzVfZBXzAkr+JuifgC6JtwxjI7CpIl8=; 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=Z8a+bZ0NfB5xVjoJOkTNloBmiNUoolQXvh1vOYZjnN5TkTUsOjOy9yZvWoLZNzNvU YUovBu/87UkwFKtdyEslqg4+yNm4EM9NoRbw8Gmhi5JN/2z2La/3jAZ3pHLKTigIO6 lsxMscDixnxJx7OcNpfi1rk5YGieM95ozOYHHGT6AYSBnfkhZkXj7PUNfXBX4PgxA6 +B5y+adfduwifLCtuZ6+TBinVqZaRXrGCz2E2WSU/6EOzzkfGZdFvCOaqOwaOTqMhl I2XGlsJgvgzZd4igcp79kpcEzGpWDg4bMViDdfGQ0Ax5aP8ASuTjEEoACBPp7T31T1 ZTcG+mV2mdlZg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D1C9D604C6 for ; Wed, 23 Mar 2022 14:56:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Hiudojm5"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 63838FFD; Wed, 23 Mar 2022 14:56:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648043780; bh=UP8RwrbAGIDvpzVfZBXzAkr+JuifgC6JtwxjI7CpIl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hiudojm5VY6aUqOVcM7aD3d73pLmG0sWouPkx4xfn+IzNDSMM4ZWPL8C6Wr2IyyRR PZaJWxCHR2bFvAp1KOdIfZpGOf7xDxogBOFhQ3KdqXiqE75e3tIgI4tSXMW6u+1YZW 5yT+BCWu4VEBsbK5AYHe7VV5/r7ZJ+8IDsADjtUo= To: libcamera devel Date: Wed, 23 Mar 2022 13:56:10 +0000 Message-Id: <20220323135614.865252-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> References: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/5] ipa: ipu3: af: Move constants to implementation 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A selection of constants are imported from ChromiumOS. Move these out of the header, and simplify their documentation. Further more, add a direct reference to the location they were obtained from. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- v2: - s/dimensions/dimension/ on single items. src/ipa/ipu3/algorithms/af.cpp | 73 ++++++++++------------------------ src/ipa/ipu3/algorithms/af.h | 11 ----- 2 files changed, 22 insertions(+), 62 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 0170a3728892..634d0f2e3176 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -29,59 +29,30 @@ * \file af.h */ -/** - * \var kAfMinGridWidth - * \brief the minimum width of AF grid. - * The minimum grid horizontal dimensions. - */ - -/** - * \var kAfMinGridHeight - * \brief the minimum height of AF grid. - * The minimum grid vertical dimensions. - */ - -/** - * \var kAfMaxGridWidth - * \brief the maximum width of AF grid. - * The maximum grid horizontal dimensions. - */ - -/** - * \var kAfMaxGridHeight - * \brief The maximum height of AF grid. - * The maximum grid vertical dimensions. - */ - -/** - * \var kAfMinGridBlockWidth - * \brief The minimum block size of the width. - * The minimum value of Log2 of the width of the grid cell. - */ - -/** - * \var kAfMinGridBlockHeight - * \brief The minimum block size of the height. - * The minimum value of Log2 of the height of the grid cell. - */ - -/** - * \def kAfMaxGridBlockWidth - * \brief The maximum block size of the width. - * The maximum value of Log2 of the width of the grid cell. - */ - -/** - * \var kAfMaxGridBlockHeight - * \brief The maximum block size of the height. - * The maximum value of Log2 of the height of the grid cell. +/* + * Static variables from ChromiumOS Intel Camera HAL and ia_imaging library: + * - https://chromium.googlesource.com/chromiumos/platform/arc-camera/+/master/hal/intel/psl/ipu3/statsConverter/ipu3-stats.h + * - https://chromium.googlesource.com/chromiumos/platform/camera/+/refs/heads/main/hal/intel/ipu3/include/ia_imaging/af_public.h */ -/** - * \var kAfDefaultHeightPerSlice - * \brief The default number of blocks in vertical axis per slice. - * The number of blocks in vertical axis per slice. - */ +/** The minimum horizontal grid dimension. */ +static constexpr uint8_t kAfMinGridWidth = 16; +/** The minimum vertical grid dimension. */ +static constexpr uint8_t kAfMinGridHeight = 16; +/** The maximum horizontal grid dimension. */ +static constexpr uint8_t kAfMaxGridWidth = 32; +/** The maximum vertical grid dimension. */ +static constexpr uint8_t kAfMaxGridHeight = 24; +/** The minimum value of Log2 of the width of the grid cell. */ +static constexpr uint16_t kAfMinGridBlockWidth = 4; +/** The minimum value of Log2 of the height of the grid cell. */ +static constexpr uint16_t kAfMinGridBlockHeight = 3; +/** The maximum value of Log2 of the width of the grid cell. */ +static constexpr uint16_t kAfMaxGridBlockWidth = 6; +/** The maximum value of Log2 of the height of the grid cell. */ +static constexpr uint16_t kAfMaxGridBlockHeight = 6; +/** The number of blocks in vertical axis per slice. */ +static constexpr uint16_t kAfDefaultHeightPerSlice = 2; namespace libcamera { diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index 13c7e0e877fd..906f2843dd49 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -15,17 +15,6 @@ #include "algorithm.h" -/* Static variables from repo of chromium */ -static constexpr uint8_t kAfMinGridWidth = 16; -static constexpr uint8_t kAfMinGridHeight = 16; -static constexpr uint8_t kAfMaxGridWidth = 32; -static constexpr uint8_t kAfMaxGridHeight = 24; -static constexpr uint16_t kAfMinGridBlockWidth = 4; -static constexpr uint16_t kAfMinGridBlockHeight = 3; -static constexpr uint16_t kAfMaxGridBlockWidth = 6; -static constexpr uint16_t kAfMaxGridBlockHeight = 6; -static constexpr uint16_t kAfDefaultHeightPerSlice = 2; - namespace libcamera { namespace ipa::ipu3::algorithms { From patchwork Wed Mar 23 13:56:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15520 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 41A8DC3264 for ; Wed, 23 Mar 2022 13:56:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 546AC604DC; Wed, 23 Mar 2022 14:56:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648043783; bh=rq/501rDmA76E3DPYoKB5MxCRbLMz8+YX2gCqye4RxM=; 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=CA2yoesZhMcFmzWwTJUdD/J4ctRn2B1f5L2wkyttNuDEtgng92g7flHLi4bGjLz1k AQTTmJBHhE6PWQ9sW0zWsrybRW77wWNsCiCRi9HEMZQWvNpUsBz3QpBqqEaZYHziGy iodU1txEaPv//TauF/Wou1ti0QzA6vScnV71L7XIWN70nJuXbiwfgjMxi6h+xcVRMc OtJziPcsdEcdU0+3pIuG6pqRwt8VfHWGhNAMEEQn98VxbhuzxVP2tfWWp6riFlYgVj f1lvzaYyON/kKP98rPOrY5kP7oRLNP5j2wlHoVIrYfOvOpV1ECBH9F1wuT4fXz+rX3 rMFb0AaJdmsew== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 08307604C4 for ; Wed, 23 Mar 2022 14:56:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VDWxlG0E"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E42E130D; Wed, 23 Mar 2022 14:56:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648043780; bh=rq/501rDmA76E3DPYoKB5MxCRbLMz8+YX2gCqye4RxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VDWxlG0E/pGKS0OT3bYlXETY4x/r1HPOO1W2qcwfB+BTe8tIunNiYZ6VrTyeMmHNh jw1xenNr537G3JJ243llPnG41PkSi6D/1Rbz5TP0FHznZYrb0g8MzRecWIySECHrIh sYDu0BRWqHsE1iMM7O9BusUe392RuPrk9cbpBOFw= To: libcamera devel Date: Wed, 23 Mar 2022 13:56:11 +0000 Message-Id: <20220323135614.865252-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> References: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/5] ipa: ipu3: af: Use geometry classes to perform grid centering 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use our geometry classes for Rectangle, Size and Point to identify the region of interest for the autofocus, and center it on the BDS output. This will facilitate custom ROI being passed in through controls at a later time. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/ipa/ipu3/algorithms/af.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 634d0f2e3176..f5a489412a9e 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -141,16 +141,23 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo) grid.block_height_log2 = kAfMinGridBlockHeight; grid.height_per_slice = kAfDefaultHeightPerSlice; - /* x_start and y start are default to BDS center */ - grid.x_start = (configInfo.bdsOutputSize.width / 2) - - (((grid.width << grid.block_width_log2) / 2)); - grid.y_start = (configInfo.bdsOutputSize.height / 2) - - (((grid.height << grid.block_height_log2) / 2)); + /* Position the AF grid in the center of the BDS output. */ + Rectangle bds(configInfo.bdsOutputSize); + Size gridSize(grid.width << grid.block_width_log2, + grid.height << grid.block_height_log2); + + /* + * \todo - Support request metadata + * - Set the ROI based on any input controls in the request + * - Return the AF ROI as metadata in the Request + */ + Rectangle roi = gridSize.centeredTo(bds.center()); + Point start = roi.topLeft(); /* x_start and y_start should be even */ - grid.x_start = (grid.x_start / 2) * 2; - grid.y_start = (grid.y_start / 2) * 2; - grid.y_start = grid.y_start | IPU3_UAPI_GRID_Y_START_EN; + grid.x_start = utils::alignDown(start.x, 2); + grid.y_start = utils::alignDown(start.y, 2); + grid.y_start |= IPU3_UAPI_GRID_Y_START_EN; /* Initial max focus step */ maxStep_ = kMaxFocusSteps; From patchwork Wed Mar 23 13:56:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15521 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 046BAC3265 for ; Wed, 23 Mar 2022 13:56:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ACE1A632E5; Wed, 23 Mar 2022 14:56:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648043785; bh=A1g4kuQaYiTSdeq7im294Vu8hMz13VzXpGOkDfCbC/4=; 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=Ho1AYEp+lf3NFms67ZDwiD04PYTaWTZ1KAcf6cVwoFFeeVD7R8g0B93oH75W0YGM5 W0+W0ZzbIONWhzHrkowfurHPjpDY2MivgcVtRlXXf+X8oJ5HJePFoUCJ/1x4oDBA7R 5cSJqCeatwuBrdPQdvRBZlYOVtFjAxAs/LVvUYF4dBwK3N2nyuoDOoz19j5bL8r7pj bepvlMGANajbTSp5DEPmip0eD+x1tFe49sR/TTEQfl/WJHZDDM/HxrOToBtOrElGrR db3CqyVENyAJcZEtdZc66zWE4URUYUmYwVIeDCjq9XS/C+T8k7wayavKkVz25qHI3U Iirrmi7YOAi8g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 347F9604C6 for ; Wed, 23 Mar 2022 14:56:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="deuwMcak"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D8C1F9DE; Wed, 23 Mar 2022 14:56:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648043781; bh=A1g4kuQaYiTSdeq7im294Vu8hMz13VzXpGOkDfCbC/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=deuwMcakgvVcudhenUGDSt0mhe1rM40nWIgxmH0BI4zfM7RsCxX3cLtKMsIJhver7 dZVBf3C2nSA1CdwGoUC3NU5ExyXNqd2Cyu0AtbwSrMYhHAEZyrjRVyMAEXfGvwsRY7 ZXo3WmAdb8bQuFiXlbzo1JXkrfGCOLDpyQlQnmtM= To: libcamera devel Date: Wed, 23 Mar 2022 13:56:12 +0000 Message-Id: <20220323135614.865252-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> References: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] ipa: ipu3: af: Remove redundant memcpy 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The af statistics can be accessed directly from the mapped buffer. Remove the redundant memcpy, and simplify the call to afEstimateVariance(). Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- v2: - Fix ASSERT src/ipa/ipu3/algorithms/af.cpp | 12 ++++-------- src/ipa/ipu3/algorithms/af.h | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index f5a489412a9e..68e100fdc504 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -336,7 +336,7 @@ void Af::afIgnoreFrameReset() * * \return The variance of the values in the data set \a y_item selected by \a isY1 */ -double Af::afEstimateVariance(y_table_item_t *y_item, uint32_t len, +double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len, bool isY1) { uint32_t z = 0; @@ -406,25 +406,21 @@ bool Af::afIsOutOfFocus(IPAContext context) */ void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { - y_table_item_t y_item[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE / sizeof(y_table_item_t)]; + const y_table_item_t *y_item = reinterpret_cast(&stats->af_raw_buffer.y_table); uint32_t afRawBufferLen; /* Evaluate the AF buffer length */ afRawBufferLen = context.configuration.af.afGrid.width * context.configuration.af.afGrid.height; - memcpy(y_item, stats->af_raw_buffer.y_table, - afRawBufferLen * sizeof(y_table_item_t)); + ASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE); /* * Calculate the mean and the variance of AF statistics for a given grid. * For coarse: y1 are used. * For fine: y2 results are used. */ - if (coarseCompleted_) - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, false); - else - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, true); + currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_); if (!context.frameContext.af.stable) { afCoarseScan(context); diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index 906f2843dd49..3b5758e868ea 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -41,7 +41,7 @@ private: void afReset(IPAContext &context); bool afNeedIgnoreFrame(); void afIgnoreFrameReset(); - double afEstimateVariance(y_table_item_t *y_item, uint32_t len, + double afEstimateVariance(const y_table_item_t *y_item, uint32_t len, bool isY1); bool afIsOutOfFocus(IPAContext context); From patchwork Wed Mar 23 13:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15522 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 821AEC0F1B for ; Wed, 23 Mar 2022 13:56:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21B4E61FBC; Wed, 23 Mar 2022 14:56:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648043786; bh=X62HXjRtuLhRG+xiOJG8feXQQi7KB3lw9f4CtrUGNP4=; 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=QmshO7cQDbn/WnypgWXhbH5RHv7nngQw8rgQ6scYp8Ebqmiva3Bc+5CnZtSjIb7pr 8U0eGF55VSAzyJygMMvbQuoSwZLyBORB5kKFuUjTicDMCLt9LtlABL4/ST23XSrG+D wNdMQVT+rPTyVuj/0qcmgaR6iZGXEtYlrMrflHepWcSVZ6RFacGmlCvWg0Qv/vIQY9 EoMHcwvmAuE1Q/ddbFDE29cHjreRjz/xnXnIj42xCrbDTUE/EefAexqJ9B2eGp8szB NpLKgL+Slfv+C586IuZoDbMmH+PT3lhaAgHU95Yx0m6UcoQ2lSVGP91qDAGITOOqQj VcTCgsDil0mfg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 697C1604D5 for ; Wed, 23 Mar 2022 14:56:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="arwI1GAS"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2094FFFD; Wed, 23 Mar 2022 14:56:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648043781; bh=X62HXjRtuLhRG+xiOJG8feXQQi7KB3lw9f4CtrUGNP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=arwI1GASzOWpF13S32ko989qBq9LV+2nEOvAW4l7vc+oq3h2uOPGEHrC54Tfy7BHB KK+JFNNreBHNBS7JJ4kjin773dpd/NiLoiTVITawVJIK8N/bWwOI4CRUXxW7Bg8Ner TOg3p7sIpn/RpS1k2keeo/uQwE6g4wQOecJi3TYY= To: libcamera devel Date: Wed, 23 Mar 2022 13:56:13 +0000 Message-Id: <20220323135614.865252-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> References: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/5] ipa: ipu3: af: Use Span for y_table_item_t 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Convert the y_table_item_t to a Span and use that for iteration when estimating variance of the table. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/af.cpp | 34 +++++++++++++++++----------------- src/ipa/ipu3/algorithms/af.h | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 68e100fdc504..ff5e9fb5b3c5 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -336,29 +336,29 @@ void Af::afIgnoreFrameReset() * * \return The variance of the values in the data set \a y_item selected by \a isY1 */ -double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len, - bool isY1) +double Af::afEstimateVariance(Span y_items, bool isY1) { - uint32_t z = 0; uint32_t total = 0; double mean; double var_sum = 0; - for (z = 0; z < len; z++) { + for (auto y : y_items) { if (isY1) - total += y_item[z].y1_avg; + total += y.y1_avg; else - total += y_item[z].y2_avg; + total += y.y2_avg; } - mean = total / len; - for (z = 0; z < len; z++) { + + mean = total / y_items.size(); + + for (auto y : y_items) { if (isY1) - var_sum += pow((y_item[z].y1_avg - mean), 2); + var_sum += pow((y.y1_avg - mean), 2); else - var_sum += pow((y_item[z].y2_avg - mean), 2); + var_sum += pow((y.y2_avg - mean), 2); } - return var_sum / static_cast(len); + return var_sum / static_cast(y_items.size()); } /** @@ -406,21 +406,21 @@ bool Af::afIsOutOfFocus(IPAContext context) */ void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { - const y_table_item_t *y_item = reinterpret_cast(&stats->af_raw_buffer.y_table); - uint32_t afRawBufferLen; - /* Evaluate the AF buffer length */ - afRawBufferLen = context.configuration.af.afGrid.width * - context.configuration.af.afGrid.height; + uint32_t afRawBufferLen = context.configuration.af.afGrid.width * + context.configuration.af.afGrid.height; ASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE); + Span y_items(reinterpret_cast(&stats->af_raw_buffer.y_table), + afRawBufferLen); + /* * Calculate the mean and the variance of AF statistics for a given grid. * For coarse: y1 are used. * For fine: y2 results are used. */ - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_); + currentVariance_ = afEstimateVariance(y_items, !coarseCompleted_); if (!context.frameContext.af.stable) { afCoarseScan(context); diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index 3b5758e868ea..b85cf94163ff 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -41,8 +41,8 @@ private: void afReset(IPAContext &context); bool afNeedIgnoreFrame(); void afIgnoreFrameReset(); - double afEstimateVariance(const y_table_item_t *y_item, uint32_t len, - bool isY1); + double afEstimateVariance(Span y_items, bool isY1); + bool afIsOutOfFocus(IPAContext context); /* VCM step configuration. It is the current setting of the VCM step. */ From patchwork Wed Mar 23 13:56:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15523 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 8B1EEC3264 for ; Wed, 23 Mar 2022 13:56:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 12285604E9; Wed, 23 Mar 2022 14:56:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648043787; bh=ksqITB42MM48DgLEZ5ynX4or9LnP0P5pmn4QxUXRY/g=; 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=R61D1QuPed4r5b5u6ZXthGaGjqqPtedt/QvzwqkDqlDvQXIiZV5ASGBt3bf15oiTG W7Xcsyj3+HjGd8xGf9Rhirs7LwckGXsA0sYlCRSnlFrfdSBnB1LGhaRuYlz9c9pq+Y zQii1BKgj2z4+MBSmVM3ImtwPiwYiAiZzqARuYH4D8DbTX+jJ7w8o5WgwrftjJPr2d ttPM5+I2O5INmZHaCsY0oqjzoy0fA62MN2U+vermL2gKGGgZSGoJuTrlkWD4KhVnYy jTa0bCtgLaNFdi3ImNJa6pdX0vbxin0hLsdxd93uNxNL67CyQ80/R/mdLfvLfrVepU Fjw5oVIyUdwzQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A92A8604E8 for ; Wed, 23 Mar 2022 14:56:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ntzbQ2zv"; dkim-atps=neutral Received: from Monstersaurus.ksquared.org.uk.beta.tailscale.net (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 57A349DE; Wed, 23 Mar 2022 14:56:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648043781; bh=ksqITB42MM48DgLEZ5ynX4or9LnP0P5pmn4QxUXRY/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntzbQ2zvHPpuePQjXPcw6LpfW93rQ90IhRH8s2F2rgknbBwA64ue27E2wEIYU6jsU U7PM+rXc1xrf7yzqjacKtjGlEXnSrqnM44LeB7IX2yT5C8rs2jDTdXiiUCVoPMNob7 7aTC/1H28HT+cBX3E2P8LTO83RTkTF6XcIAr/Sgg= To: libcamera devel Date: Wed, 23 Mar 2022 13:56:14 +0000 Message-Id: <20220323135614.865252-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> References: <20220323135614.865252-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/5] ipa: ipu3: af: Simplify accumulations of y_items 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: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Simplify the accumulation of the total and variance with a ternary operator. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- This is optional really, it's only really a stylistic preference. src/ipa/ipu3/algorithms/af.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index ff5e9fb5b3c5..940ed68ea14a 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -342,20 +342,14 @@ double Af::afEstimateVariance(Span y_items, bool isY1) double mean; double var_sum = 0; - for (auto y : y_items) { - if (isY1) - total += y.y1_avg; - else - total += y.y2_avg; - } + for (auto y : y_items) + total += isY1 ? y.y1_avg : y.y2_avg; mean = total / y_items.size(); for (auto y : y_items) { - if (isY1) - var_sum += pow((y.y1_avg - mean), 2); - else - var_sum += pow((y.y2_avg - mean), 2); + double avg = isY1 ? y.y1_avg : y.y2_avg; + var_sum += pow((avg - mean), 2); } return var_sum / static_cast(y_items.size());