From patchwork Wed Oct 9 07:41:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21555 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 885A4C32DE for ; Wed, 9 Oct 2024 07:46:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B73A65376; Wed, 9 Oct 2024 09:46:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="R46HTvBU"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CF26263527 for ; Wed, 9 Oct 2024 09:46:53 +0200 (CEST) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-7ea16c7759cso1696474a12.1 for ; Wed, 09 Oct 2024 00:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728460012; x=1729064812; darn=lists.libcamera.org; 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=LARBt1OC+m6EqoRtLJGDk6jJj2R9CzZ07H1YfA0LEvs=; b=R46HTvBUl0wCud2I1sRj+WIU9iwtjprdwWPCdAgvtQsyGBbOR2bFxhnI9AXYcEgneG fN5RXYaw3bpZhzhHn+e8jE0bHr747+GyQXqoT3jJdP/Spx7SGODNyT2pv0HRs6qJcOnF HfUXToVkZVjF3qXWZ7Z1x63HvKsf+Xq8ZyWAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728460012; x=1729064812; 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=LARBt1OC+m6EqoRtLJGDk6jJj2R9CzZ07H1YfA0LEvs=; b=OAEk3IeuihIy3Mt3X3ug5u/C9tBrBU+Lrb1bIR3OadskkZHyZEHRYiKhqL77EzwOu1 uLOLEj5hID51r1642PG+R5LsW9p1tu8xX0/qeXUATMiaQ6VKJotuvrLDGhzDuc8m1uWn epWSQQWMO1l8I+Jx7O6x8ndMMfUuKrEdCoTWZxW/kDVAM5Mj8q+sGVhsErjrONx09gK5 nwfP038sYNS9yIg16LiGXFURQBuqVmBSx6Zrf8I6eXrq+E0aT5Lam3CmJVjfRstTwgsd 9Rp7HQWpAV3eZeFc3jfMkxZIxUBtwpyihjZlGzVuFvsxx56nhH1IZNH66NGCa6VV4U4/ WflA== X-Gm-Message-State: AOJu0Yxk7/rQ8LWO3lhm2CjmMhwVW+bctgCPKLKvJmbIEqEjLYLWf/2m G81221Tv+UG0hnooko8SBi51c5nf4pJlTp0u1Dufv3WMu4dW9UzGGMIwzZXeLauce+YaNk2nH88 71g== X-Google-Smtp-Source: AGHT+IFlQW9SdLiLmSVXsMQl5d7eA+0gtc1T3oyPHEBuDJqJY0vRxjNjYuhlgfRwVJjZVaaRLTgMSQ== X-Received: by 2002:a05:6a21:3944:b0:1d3:42f3:ff6d with SMTP id adf61e73a8af0-1d8a3c3a455mr2357609637.31.1728460012051; Wed, 09 Oct 2024 00:46:52 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e2a57077c2sm944414a91.17.2024.10.09.00.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 00:46:51 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Han-Lin Chen , Harvey Yang Subject: [PATCH 3/5] libcamera: format: Extend plane size calculation to accept scanline alignment Date: Wed, 9 Oct 2024 07:41:21 +0000 Message-ID: <20241009074642.2965791-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog In-Reply-To: <20241009074642.2965791-1-chenghaoyang@chromium.org> References: <20241009074642.2965791-1-chenghaoyang@chromium.org> MIME-Version: 1.0 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" From: Han-Lin Chen As some platforms need alignment on scanline, this patch extends the format::planeSize() method to accept scanline alignment. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- include/libcamera/internal/formats.h | 5 +++-- src/libcamera/formats.cpp | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 6a3e9c16a..143ab1dce 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -40,10 +40,11 @@ public: unsigned int stride(unsigned int width, unsigned int plane, unsigned int align = 1) const; unsigned int planeSize(const Size &size, unsigned int plane, - unsigned int align = 1) const; + unsigned int align = 1, unsigned scanAlign = 1) const; unsigned int planeSize(unsigned int height, unsigned int plane, unsigned int stride) const; - unsigned int frameSize(const Size &size, unsigned int align = 1) const; + unsigned int frameSize(const Size &size, unsigned int align = 1, + unsigned scanAlign = 1) const; unsigned int frameSize(const Size &size, const std::array &strides) const; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index dbefb0947..7643a5a23 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -1093,6 +1093,7 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane, * \param[in] size The size of the frame, in pixels * \param[in] plane The plane index * \param[in] align The stride alignment, in bytes (1 for default alignment) + * \param[in] scanAlign The scanline alignment, in bytes (1 for default alignment) * * The plane size is computed by multiplying the line stride and the frame * height, taking subsampling and other format characteristics into account. @@ -1105,13 +1106,19 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane, * format */ unsigned int PixelFormatInfo::planeSize(const Size &size, unsigned int plane, - unsigned int align) const + unsigned int align, unsigned scanAlign) const { unsigned int stride = PixelFormatInfo::stride(size.width, plane, align); if (!stride) return 0; - return planeSize(size.height, plane, stride); + unsigned int vertSubSample = planes[plane].verticalSubSampling; + if (!vertSubSample) + return 0; + + unsigned int planeHeight = (size.height + vertSubSample - 1) / vertSubSample; + + return stride * ((planeHeight + scanAlign - 1) / scanAlign * scanAlign); } /** @@ -1143,6 +1150,7 @@ unsigned int PixelFormatInfo::planeSize(unsigned int height, unsigned int plane, * \brief Compute the number of bytes necessary to store a frame * \param[in] size The size of the frame, in pixels * \param[in] align The stride alignment, in bytes (1 for default alignment) + * \param[in] scanAlign The scanline alignment, in bytes (1 for default alignment) * * The frame size is computed by adding the size of all planes, as computed by * planeSize(), using the specified alignment constraints for all planes. For @@ -1154,7 +1162,8 @@ unsigned int PixelFormatInfo::planeSize(unsigned int height, unsigned int plane, * \return The number of bytes necessary to store the frame, or 0 if the * PixelFormatInfo instance is not valid */ -unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align) const +unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align, + unsigned scanAlign) const { unsigned int sum = 0; @@ -1162,7 +1171,7 @@ unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align) co if (plane.bytesPerGroup == 0) break; - sum += planeSize(size, i, align); + sum += planeSize(size, i, align, scanAlign); } return sum;