{"id":8675,"url":"https://patchwork.libcamera.org/api/patches/8675/?format=json","web_url":"https://patchwork.libcamera.org/patch/8675/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20200708134417.67747-7-paul.elder@ideasonboard.com>","date":"2020-07-08T13:44:02","name":"[libcamera-devel,v4,06/21] libcamera: PixelFormatInfo: Add functions stride and frameSize","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c5ebd00d96042e75eda74408a204ec402d579344","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8675/mbox/","series":[{"id":1090,"url":"https://patchwork.libcamera.org/api/series/1090/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1090","date":"2020-07-08T13:43:56","name":"Clean up formats in v4l2-compat and pipeline handlers","version":4,"mbox":"https://patchwork.libcamera.org/series/1090/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8675/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8675/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 E52E9BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jul 2020 13:44:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B3EBF61124;\n\tWed,  8 Jul 2020 15:44:43 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DC9FE610B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jul 2020 15:44:42 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 70D4D51B;\n\tWed,  8 Jul 2020 15:44:41 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"izfWgpg4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594215882;\n\tbh=AyDMzbKkI5i3eRGnjzMm2HtvG29+dqw181TtVpwUvIA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=izfWgpg4tYjOZKFJcpyfSrznTaSXh+V9OJY8tbmP9h44dkgbPlQHMQHY0YFcuxIAY\n\tck5Fi7awq6GSuIsCLXsu43VHBFPfJlNptO5+Wd41GB8nmdgtKeMsQHSwdPLqkgO3FY\n\tIBucZLnVnIphuAu3Ue9hmQpyGIV7VCdyzTG8Y7mE=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  8 Jul 2020 22:44:02 +0900","Message-Id":"<20200708134417.67747-7-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200708134417.67747-1-paul.elder@ideasonboard.com>","References":"<20200708134417.67747-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v4 06/21] libcamera: PixelFormatInfo: Add\n\tfunctions stride and frameSize","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add member functions to PixelFormatInfo for calculating stride and frame\nsize. This will simplify existing code that calculates these things.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v4:\n- add overloaded frameSize() that takes array of strides\n- add optional parameter to stride() for byte alignment\n\nChanges in v3:\n- rename functions to stride and frameSize, from bytesPerLine and\n  imageSize, respectively\n\nChanges in v2:\n- make these functions const\n- add documentation\n- inline DIV_ROUND_UP\n---\n include/libcamera/internal/formats.h |  6 +++\n src/libcamera/formats.cpp            | 73 ++++++++++++++++++++++++++++\n 2 files changed, 79 insertions(+)","diff":"diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\nindex 054be37..e347a46 100644\n--- a/include/libcamera/internal/formats.h\n+++ b/include/libcamera/internal/formats.h\n@@ -52,6 +52,12 @@ public:\n \tstatic const PixelFormatInfo &info(const PixelFormat &format);\n \tstatic const PixelFormatInfo &info(const V4L2PixelFormat &format);\n \n+\tunsigned int stride(unsigned int width, unsigned int plane,\n+\t\t\t    unsigned int align = 0) const;\n+\tunsigned int frameSize(const Size &size) const;\n+\tunsigned int frameSize(const Size &size,\n+\t\t\t       const std::array<unsigned int, 3> &strides) const;\n+\n \t/* \\todo Add support for non-contiguous memory planes */\n \tconst char *name;\n \tPixelFormat format;\ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 6d96055..c355e57 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -732,4 +732,77 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)\n \treturn info->second;\n }\n \n+/**\n+ * \\brief Compute the stride\n+ * \\param[in] width The width of the line, in pixels\n+ * \\param[in] plane The index of the plane whose stride is to be computed\n+ * \\param[in] align The number of bytes to align to (0 for default alignment)\n+ * \\return The number of bytes necessary to store a line, or 0 if the\n+ * PixelFormatInfo instance or the \\a plane is not valid\n+ */\n+unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane,\n+\t\t\t\t     unsigned int align) const\n+{\n+\tif (!isValid())\n+\t\treturn 0;\n+\n+\tif (plane > planes.size() || !planes[plane].bytesPerGroup)\n+\t\treturn 0;\n+\n+\t/* ceil(width / pixelsPerGroup) * bytesPerGroup */\n+\tunsigned int stride = (width + pixelsPerGroup - 1) / pixelsPerGroup\n+\t\t\t      * planes[plane].bytesPerGroup;\n+\n+\tif (!align)\n+\t\treturn stride;\n+\n+\t/* ceil(stride / align) * align */\n+\treturn (stride + align - 1) / align * align;\n+}\n+\n+/**\n+ * \\brief Compute the bytes necessary to store the frame\n+ * \\param[in] size The size of the frame, in pixels\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) const\n+{\n+\t/* stride * ceil(height / verticalSubSampling) */\n+\tunsigned int sum = 0;\n+\tfor (unsigned int i = 0; i < 3; i++) {\n+\t\tunsigned int vertSubSample = planes[i].verticalSubSampling;\n+\t\tif (!vertSubSample)\n+\t\t\tcontinue;\n+\t\tsum += stride(size.width, i)\n+\t\t     * ((size.height + vertSubSample - 1) / vertSubSample);\n+\t}\n+\n+\treturn sum;\n+}\n+\n+/**\n+ * \\brief Compute the bytes necessary to store the frame\n+ * \\param[in] size The size of the frame, in pixels\n+ * \\param[in] strides The strides to use for each 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\n+PixelFormatInfo::frameSize(const Size &size,\n+\t\t\t   const std::array<unsigned int, 3> &strides) const\n+{\n+\t/* stride * ceil(height / verticalSubSampling) */\n+\tunsigned int sum = 0;\n+\tfor (unsigned int i = 0; i < 3; i++) {\n+\t\tunsigned int vertSubSample = planes[i].verticalSubSampling;\n+\t\tif (!vertSubSample)\n+\t\t\tcontinue;\n+\t\tsum += strides[i]\n+\t\t     * ((size.height + vertSubSample - 1) / vertSubSample);\n+\t}\n+\n+\treturn sum;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v4","06/21"]}