{"id":21555,"url":"https://patchwork.libcamera.org/api/1.1/patches/21555/?format=json","web_url":"https://patchwork.libcamera.org/patch/21555/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241009074642.2965791-4-chenghaoyang@chromium.org>","date":"2024-10-09T07:41:21","name":"[3/5] libcamera: format: Extend plane size calculation to accept scanline alignment","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"639337217cedb79821816ab1bcd0702595ce9fb6","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/1.1/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21555/mbox/","series":[{"id":4670,"url":"https://patchwork.libcamera.org/api/1.1/series/4670/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4670","date":"2024-10-09T07:41:18","name":"Add InfoFrame","version":1,"mbox":"https://patchwork.libcamera.org/series/4670/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21555/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21555/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 885A4C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Oct 2024 07:46:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B73A65376;\n\tWed,  9 Oct 2024 09:46:57 +0200 (CEST)","from mail-pg1-x535.google.com (mail-pg1-x535.google.com\n\t[IPv6:2607:f8b0:4864:20::535])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CF26263527\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 09:46:53 +0200 (CEST)","by mail-pg1-x535.google.com with SMTP id\n\t41be03b00d2f7-7ea16c7759cso1696474a12.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 09 Oct 2024 00:46:53 -0700 (PDT)","from chenghaoyang-low.c.googlers.com.com\n\t(199.211.81.34.bc.googleusercontent.com. [34.81.211.199])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-2e2a57077c2sm944414a91.17.2024.10.09.00.46.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 09 Oct 2024 00:46:51 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"R46HTvBU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1728460012; x=1729064812;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=LARBt1OC+m6EqoRtLJGDk6jJj2R9CzZ07H1YfA0LEvs=;\n\tb=R46HTvBUl0wCud2I1sRj+WIU9iwtjprdwWPCdAgvtQsyGBbOR2bFxhnI9AXYcEgneG\n\tfN5RXYaw3bpZhzhHn+e8jE0bHr747+GyQXqoT3jJdP/Spx7SGODNyT2pv0HRs6qJcOnF\n\tHfUXToVkZVjF3qXWZ7Z1x63HvKsf+Xq8ZyWAQ=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1728460012; x=1729064812;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=LARBt1OC+m6EqoRtLJGDk6jJj2R9CzZ07H1YfA0LEvs=;\n\tb=OAEk3IeuihIy3Mt3X3ug5u/C9tBrBU+Lrb1bIR3OadskkZHyZEHRYiKhqL77EzwOu1\n\tuLOLEj5hID51r1642PG+R5LsW9p1tu8xX0/qeXUATMiaQ6VKJotuvrLDGhzDuc8m1uWn\n\tepWSQQWMO1l8I+Jx7O6x8ndMMfUuKrEdCoTWZxW/kDVAM5Mj8q+sGVhsErjrONx09gK5\n\tnwfP038sYNS9yIg16LiGXFURQBuqVmBSx6Zrf8I6eXrq+E0aT5Lam3CmJVjfRstTwgsd\n\t9Rp7HQWpAV3eZeFc3jfMkxZIxUBtwpyihjZlGzVuFvsxx56nhH1IZNH66NGCa6VV4U4/\n\tWflA==","X-Gm-Message-State":"AOJu0Yxk7/rQ8LWO3lhm2CjmMhwVW+bctgCPKLKvJmbIEqEjLYLWf/2m\n\tG81221Tv+UG0hnooko8SBi51c5nf4pJlTp0u1Dufv3WMu4dW9UzGGMIwzZXeLauce+YaNk2nH88\n\t71g==","X-Google-Smtp-Source":"AGHT+IFlQW9SdLiLmSVXsMQl5d7eA+0gtc1T3oyPHEBuDJqJY0vRxjNjYuhlgfRwVJjZVaaRLTgMSQ==","X-Received":"by 2002:a05:6a21:3944:b0:1d3:42f3:ff6d with SMTP id\n\tadf61e73a8af0-1d8a3c3a455mr2357609637.31.1728460012051; \n\tWed, 09 Oct 2024 00:46:52 -0700 (PDT)","From":"Harvey Yang <chenghaoyang@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","Subject":"[PATCH 3/5] libcamera: format: Extend plane size calculation to\n\taccept 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","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Han-Lin Chen <hanlinchen@chromium.org>\n\nAs some platforms need alignment on scanline, this patch extends the\nformat::planeSize() method to accept scanline alignment.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nCo-developed-by: Harvey Yang <chenghaoyang@chromium.org>\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/internal/formats.h |  5 +++--\n src/libcamera/formats.cpp            | 17 +++++++++++++----\n 2 files changed, 16 insertions(+), 6 deletions(-)","diff":"diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\nindex 6a3e9c16a..143ab1dce 100644\n--- a/include/libcamera/internal/formats.h\n+++ b/include/libcamera/internal/formats.h\n@@ -40,10 +40,11 @@ public:\n \tunsigned int stride(unsigned int width, unsigned int plane,\n \t\t\t    unsigned int align = 1) const;\n \tunsigned int planeSize(const Size &size, unsigned int plane,\n-\t\t\t       unsigned int align = 1) const;\n+\t\t\t       unsigned int align = 1, unsigned scanAlign = 1) const;\n \tunsigned int planeSize(unsigned int height, unsigned int plane,\n \t\t\t       unsigned int stride) const;\n-\tunsigned int frameSize(const Size &size, unsigned int align = 1) const;\n+\tunsigned int frameSize(const Size &size, unsigned int align = 1,\n+\t\t\t       unsigned scanAlign = 1) const;\n \tunsigned int frameSize(const Size &size,\n \t\t\t       const std::array<unsigned int, 3> &strides) const;\n \ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex dbefb0947..7643a5a23 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -1093,6 +1093,7 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane,\n  * \\param[in] size The size of the frame, in pixels\n  * \\param[in] plane The plane index\n  * \\param[in] align The stride alignment, in bytes (1 for default alignment)\n+ * \\param[in] scanAlign The scanline alignment, in bytes (1 for default alignment)\n  *\n  * The plane size is computed by multiplying the line stride and the frame\n  * height, taking subsampling and other format characteristics into account.\n@@ -1105,13 +1106,19 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane,\n  * format\n  */\n unsigned int PixelFormatInfo::planeSize(const Size &size, unsigned int plane,\n-\t\t\t\t\tunsigned int align) const\n+\t\t\t\t\tunsigned int align, unsigned scanAlign) const\n {\n \tunsigned int stride = PixelFormatInfo::stride(size.width, plane, align);\n \tif (!stride)\n \t\treturn 0;\n \n-\treturn planeSize(size.height, plane, stride);\n+\tunsigned int vertSubSample = planes[plane].verticalSubSampling;\n+\tif (!vertSubSample)\n+\t\treturn 0;\n+\n+\tunsigned int planeHeight = (size.height + vertSubSample - 1) / vertSubSample;\n+\n+\treturn stride * ((planeHeight + scanAlign - 1) / scanAlign * scanAlign);\n }\n \n /**\n@@ -1143,6 +1150,7 @@ unsigned int PixelFormatInfo::planeSize(unsigned int height, unsigned int plane,\n  * \\brief Compute the number of bytes necessary to store a frame\n  * \\param[in] size The size of the frame, in pixels\n  * \\param[in] align The stride alignment, in bytes (1 for default alignment)\n+ * \\param[in] scanAlign The scanline alignment, in bytes (1 for default alignment)\n  *\n  * The frame size is computed by adding the size of all planes, as computed by\n  * planeSize(), using the specified alignment constraints for all planes. For\n@@ -1154,7 +1162,8 @@ unsigned int PixelFormatInfo::planeSize(unsigned int height, unsigned int plane,\n  * \\return The number of bytes necessary to store the frame, or 0 if the\n  * PixelFormatInfo instance is not valid\n  */\n-unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align) const\n+unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align,\n+\t\t\t\t\tunsigned scanAlign) const\n {\n \tunsigned int sum = 0;\n \n@@ -1162,7 +1171,7 @@ unsigned int PixelFormatInfo::frameSize(const Size &size, unsigned int align) co\n \t\tif (plane.bytesPerGroup == 0)\n \t\t\tbreak;\n \n-\t\tsum += planeSize(size, i, align);\n+\t\tsum += planeSize(size, i, align, scanAlign);\n \t}\n \n \treturn sum;\n","prefixes":["3/5"]}