From patchwork Tue Mar 15 17:53:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15453 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 6B228BDE17 for ; Tue, 15 Mar 2022 17:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C5FB632E9; Tue, 15 Mar 2022 18:53:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647366835; bh=7AS/3W+JcRjGwq7NqYyLfTa+SB8XRCp4BPvzwC6i2uc=; 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=dMb06Hz/6ibompYHvXyzIl+lOC9hMEvD/GKBj2QrHEqL1rVQ6pdcb3lsG8IwfwFfB fTvoj3GNcwc/hCju91/e1pXH907/MS3fq48VH7UajKyrydTn6BcQv8zjDnwpOp8qab Ga7gQUMD+71AOHSDI99+GSQGX/uGVmORkiv+HB1CdYpEWmeiBveyRMStFbO/jr4PTS JEevJPMAmlr1C56V0H3BPna8VUH8yTTq6H8Rt1l7EX2pV0SWoqU/IcIZ+IahDcCjBT eCiwdchM8XMAKSlSC13DFtnG1WQoEmmXJQQPGu162FePndUu/BEK8gHvpI/xsGMd7r CJLFbibY1jbIw== 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 C79FC604DC for ; Tue, 15 Mar 2022 18:53:53 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="F7LIvDOq"; 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 6569F1C34; Tue, 15 Mar 2022 18:53:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647366833; bh=7AS/3W+JcRjGwq7NqYyLfTa+SB8XRCp4BPvzwC6i2uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7LIvDOqnjbz5mqjKvV5WUZIutx2IGjzP08Ajkz2nusHGf2QKKG2CXmMeGtxRI1Z8 qrjeGQEg7RSZcNpSuWpxFD0skUo5tIQx+WNntuF0hMTWk8ZTnpVH9xKOm8M+7g7v8I Bx1+mPGD/HXxKmmPmEhmy4CqQPNVx1Ij0SuVFZUc= To: libcamera devel Date: Tue, 15 Mar 2022 17:53:43 +0000 Message-Id: <20220315175345.479951-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> References: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] 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. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- 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..3cedf8cbd687 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 dimensions. */ +static constexpr uint8_t kAfMinGridWidth = 16; +/** The minimum vertical grid dimensions. */ +static constexpr uint8_t kAfMinGridHeight = 16; +/** The maximum horizontal grid dimensions. */ +static constexpr uint8_t kAfMaxGridWidth = 32; +/** The maximum vertical grid dimensions. */ +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 Tue Mar 15 17:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15454 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 00D96C3262 for ; Tue, 15 Mar 2022 17:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E63FB604DA; Tue, 15 Mar 2022 18:53:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647366836; bh=rHcFZzLLbiRXEO5UNZlK2Upbi+S11EVe2qeCnKUc9AY=; 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=D4RWjG/QACA9Rz42vaU3Cr2LfFMfhIMcli6yb13Op9+5rEJcpXxTCrNy/CqMALya8 6zsCSWoBZMIf0ByaYpdN2pOqfzTUoeZvi6PW0Ql4eBuF2FenkzoH0hyvpziE+S/g+U VOh4CnUh037xdeK7JbrST//M3cTgse8k350HpTZlRXq6oN5/EqqobtZ+GjLo6jfRls bd7d58v7H1CUfXazGHIQrLQUaDILKAcDVFhPOMYMVv3fo7a47Gtk3T2LIMwHlb7FOY OGBm1uIV2Wcs/Sjf9PFs0CcKfplJav/fBbOnd425BjphE1KuK5HwMZPeJ5LasjLuJm /Jh9xLpedvCDA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0BA3C604DA for ; Tue, 15 Mar 2022 18:53:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NBQuLVtP"; 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 A7C8F1C57; Tue, 15 Mar 2022 18:53:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647366833; bh=rHcFZzLLbiRXEO5UNZlK2Upbi+S11EVe2qeCnKUc9AY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBQuLVtPabSW+MBuxdNxo+rjrmkoiyK8WPJeNlEN0s4RSUesfdwP1Vfz0VehNOf66 yJB7mrQXAzxvSrdyW/YIUpsLiDTaSVvNeIJjflmzLLSsixRCGpfsXe/P0sx/L+b1nl a7Kx0nhhzAK6R0bBilaVAC64Hor1GnFiSDNsVtPo= To: libcamera devel Date: Tue, 15 Mar 2022 17:53:44 +0000 Message-Id: <20220315175345.479951-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> References: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] 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. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- 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 3cedf8cbd687..469762a29937 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -141,16 +141,24 @@ 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 + * - Provide an alignedTo on a point, or Rectangle x,y position + */ + 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 = (start.x / 2) * 2; + grid.y_start = (start.y / 2) * 2; + grid.y_start |= IPU3_UAPI_GRID_Y_START_EN; /* Initial max focus step */ maxStep_ = kMaxFocusSteps; From patchwork Tue Mar 15 17:53:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15455 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 514CFC3263 for ; Tue, 15 Mar 2022 17:53:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC5A161FBC; Tue, 15 Mar 2022 18:53:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1647366836; bh=CGzjh9tM+VIsTg401TThvU12GfgXHHpsOkPLGx57dn0=; 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=a8CORCX9hRIz6k7tQNxnypMspIgIuUo9uhGgdvWvKK/5vEjWUJQV4Rn7FmAPnUXPy PokMnPlr9boNMuj9mOkFLmpWMlqbCfk5q82U3gpbWlE2rEGJT10NoPjLz96X8j1z1i 27qitxtTjj08RLhOk8+2QK80gOipCQLN5+xmOzdHtUEfi0fdvMnehFfnY7Z3H/CKiz CPZ/OqIkO2VKJzTgHbA0VixSZqMX79s4YFImKtGwl+kQKuNwLksNsY1oeOyuRx0y9O 4jf4dF6nWxwXfy2eWQg8rAfTQgdRaI60kDogBYpItFU/oIqkrF8yWDt3QQBdbF3krv 6B6xiRGQGRtqA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BD776118A for ; Tue, 15 Mar 2022 18:53:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YcQVPciG"; 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 EBD0C1C6D; Tue, 15 Mar 2022 18:53:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1647366834; bh=CGzjh9tM+VIsTg401TThvU12GfgXHHpsOkPLGx57dn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YcQVPciGw4hj/YYmb60/fpygEyL1tgrUoMyYiLwRDCn6m1HEHXUjbw4bmVnp/psTC ck9kN2xMUq45bPH97rPb/9ejGH9QY6BICoXVfDePTgNttx2ZWBxE4WC24ODagRFsSF +5tDnAllUj/3K1u21OqlxdbnPo/4om8RwsXYkLr0= To: libcamera devel Date: Tue, 15 Mar 2022 17:53:45 +0000 Message-Id: <20220315175345.479951-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> References: <20220315175345.479951-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] 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(). Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- 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 469762a29937..e10cff968895 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 / sizeof(y_table_item_t) < 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);