From patchwork Mon May 3 09:27:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12164 X-Patchwork-Delegate: jacopo@jmondi.org 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 92A25BDE78 for ; Mon, 3 May 2021 09:26:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE86B6892B; Mon, 3 May 2021 11:26:26 +0200 (CEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB0EF602C0 for ; Mon, 3 May 2021 11:26:25 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 77ECCE0009 for ; Mon, 3 May 2021 09:26:25 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 3 May 2021 11:27:01 +0200 Message-Id: <20210503092705.15562-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503092705.15562-1-jacopo@jmondi.org> References: <20210503092705.15562-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/7] libcamera: ipu3: imgu: Fix BDS height calculation 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IF rectangle height is iteratively computed by first subtracting the scaling factor to the estimated height, then in a successive loop by adding the same scaling factor until the maximum IF size is not reached. As the computed IF height is not cached in any variable, the second loop over-writes the result of the first one, even if the BDS alignment condition is not satisfied. Fix this by caching the result of the two iterations, and use the one that produced any result, with a preference for the one produced by the second loop, as implemented in the reference python script. Tested-by: Jean-Michel Hautbois Reviewed-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund Reviewed-by: Hirokazu Honda --- src/libcamera/pipeline/ipu3/imgu.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 36fee31c1962..ea654e57b0e7 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -129,10 +129,10 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc float bdsHeight; if (!isSameRatio(pipe->input, gdc)) { + unsigned int foundIfHeights[2] = { 0, 0 }; float estIFHeight = (iif.width * gdc.height) / static_cast(gdc.width); estIFHeight = std::clamp(estIFHeight, minIFHeight, iif.height); - bool found = false; ifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H); while (ifHeight >= minIFHeight && ifHeight / bdsSF >= minBDSHeight) { @@ -142,7 +142,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc unsigned int bdsIntHeight = static_cast(bdsHeight); if (!(bdsIntHeight % BDS_ALIGN_H)) { - found = true; + foundIfHeights[0] = ifHeight; break; } } @@ -158,7 +158,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc unsigned int bdsIntHeight = static_cast(bdsHeight); if (!(bdsIntHeight % BDS_ALIGN_H)) { - found = true; + foundIfHeights[1] = ifHeight; break; } } @@ -166,7 +166,12 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc ifHeight += IF_ALIGN_H; } - if (found) { + if (foundIfHeights[0]) + ifHeight = foundIfHeights[0]; + if (foundIfHeights[1]) + ifHeight = foundIfHeights[1]; + + if (foundIfHeights[0] || foundIfHeights[1]) { unsigned int bdsIntHeight = static_cast(bdsHeight); pipeConfigs.push_back({ bdsSF, { iif.width, ifHeight },