From patchwork Wed Sep 15 02:30:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13855 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 2542EBDC71 for ; Wed, 15 Sep 2021 02:31:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7857469189; Wed, 15 Sep 2021 04:31:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fYldfD8U"; dkim-atps=neutral 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 ED23260247 for ; Wed, 15 Sep 2021 04:31:15 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52C5424F; Wed, 15 Sep 2021 04:31:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1631673075; bh=v64vdeejrNdyrZAr2XUS3eWjUhvRQpYUznSbVC9xldA=; h=From:To:Cc:Subject:Date:From; b=fYldfD8U68HpFQAO/ltdJY9ym3LVPVo1MhgDwtntQS4kIKqiH+521yq3X5LVMYQOz QEkWVXqbSMK3uL59ZD9ZakwUjJYl5m1D5XCFkyt11WM91xnZKUOh4otJ6im27k/nqy PgAYUQ6rIcJcgZTknFEl/LFdvexuB8mNQ30EZqY0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Sep 2021 05:30:43 +0300 Message-Id: <20210915023043.7703-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: ipu3: Split width and height loops in calculateBdsGrid() 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 loops over the width and height of the image when calculating the BDS grid parameters are imbricated, but they're actually independent. Split them to reduce the complexity. Signed-off-by: Laurent Pinchart --- src/ipa/ipu3/ipu3.cpp | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 30d2a53903ec..36fe4a6c9154 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -293,33 +293,42 @@ int IPAIPU3::start() */ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize) { - uint32_t minError = std::numeric_limits::max(); Size best; Size bestLog2; /* Set the BDS output size in the IPAConfiguration structure */ context_.configuration.grid.bdsOutputSize = bdsOutputSize; - for (uint32_t widthShift = 3; widthShift <= 7; ++widthShift) { + uint32_t minError = std::numeric_limits::max(); + + for (uint32_t shift = 3; shift <= 7; ++shift) { uint32_t width = std::min(kMaxCellWidthPerSet, - bdsOutputSize.width >> widthShift); - width = width << widthShift; - for (uint32_t heightShift = 3; heightShift <= 7; ++heightShift) { - int32_t height = std::min(kMaxCellHeightPerSet, - bdsOutputSize.height >> heightShift); - height = height << heightShift; - uint32_t error = std::abs(static_cast(width - bdsOutputSize.width)) - + std::abs(static_cast(height - bdsOutputSize.height)); + bdsOutputSize.width >> shift); + width = width << shift; + uint32_t error = std::abs(static_cast(width - bdsOutputSize.width)); - if (error > minError) - continue; + if (error > minError) + continue; - minError = error; - best.width = width; - best.height = height; - bestLog2.width = widthShift; - bestLog2.height = heightShift; - } + minError = error; + best.width = width; + bestLog2.width = shift; + } + + minError = std::numeric_limits::max(); + + for (uint32_t shift = 3; shift <= 7; ++shift) { + uint32_t height = std::min(kMaxCellHeightPerSet, + bdsOutputSize.height >> shift); + height = height << shift; + uint32_t error = std::abs(static_cast(height - bdsOutputSize.height)); + + if (error > minError) + continue; + + minError = error; + best.height = height; + bestLog2.height = shift; } struct ipu3_uapi_grid_config &bdsGrid = context_.configuration.grid.bdsGrid;