Show a patch.

GET /api/1.1/patches/13672/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13672,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13672/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13672/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210906225636.14683-6-laurent.pinchart@ideasonboard.com>",
    "date": "2021-09-06T22:56:12",
    "name": "[libcamera-devel,v3,06/30] libcamera: formats: Add planeSize() helpers to PixelFormatInfo",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "36801ccd648dea8bd3965dc08be3845d7733fd7f",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13672/mbox/",
    "series": [
        {
            "id": 2482,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2482/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2482",
            "date": "2021-09-06T22:54:20",
            "name": "libcamera: Handle fallout of FrameBuffer offset support",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2482/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13672/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13672/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 423A1BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 22:57:09 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EF02669180;\n\tTue,  7 Sep 2021 00:57:06 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F13EC6916A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 00:57:00 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A860891;\n\tTue,  7 Sep 2021 00:57:00 +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=\"ttWRg0kd\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969020;\n\tbh=gPr5UjzG2uC9IWNT501744MbdukW6WqdEIsA0DPdpWY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ttWRg0kdQwN7Be3HJ9v2pu0cphby7HE/SNqmml99Pe+92ISISeG67vjT+yaQNdQlz\n\tDbdM1kw4wE40qkzgmyhANzwxxoRw+EGsWI6VEz+g1r9oYqKEmtshJ7is0fOeP5R8q7\n\tyw9qIH9DdPJG76lbocxDv0+AutlRCbTO/QtxdUIk=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  7 Sep 2021 01:56:12 +0300",
        "Message-Id": "<20210906225636.14683-6-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 06/30] libcamera: formats: Add\n\tplaneSize() helpers to PixelFormatInfo",
        "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": "Add two helpers functions to the PixelFormatInfo class to compute the\nbyte size of a given plane, taking the frame size, the stride, the\nalignment constraints and the vertical subsampling into account.\n\nUse the new functions through the code base to replace manual\nimplementations.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\n---\nChanges since v1:\n\n- Factor out duplicated code\n---\n include/libcamera/internal/formats.h     |  4 ++\n src/android/mm/generic_camera_buffer.cpp | 11 +---\n src/android/yuv/post_processor_yuv.cpp   | 10 ++-\n src/libcamera/formats.cpp                | 77 +++++++++++++++++++-----\n src/libcamera/v4l2_videodevice.cpp       |  6 +-\n 5 files changed, 74 insertions(+), 34 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h\nindex a07de6bc6020..b2869c93e960 100644\n--- a/include/libcamera/internal/formats.h\n+++ b/include/libcamera/internal/formats.h\n@@ -41,6 +41,10 @@ public:\n \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+\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,\n \t\t\t       const std::array<unsigned int, 3> &strides) const;\ndiff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp\nindex 22efc4d4b13a..93aa5821e470 100644\n--- a/src/android/mm/generic_camera_buffer.cpp\n+++ b/src/android/mm/generic_camera_buffer.cpp\n@@ -108,16 +108,9 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,\n \n \tunsigned int offset = 0;\n \tfor (unsigned int i = 0; i < numPlanes; ++i) {\n-\t\t/*\n-\t\t * \\todo Remove if this plane size computation function is\n-\t\t * added to PixelFormatInfo.\n-\t\t */\n-\t\tconst unsigned int vertSubSample = info.planes[i].verticalSubSampling;\n-\t\tconst unsigned int stride = info.stride(size.width, i, 1u);\n-\t\tconst unsigned int planeSize =\n-\t\t\tstride * ((size.height + vertSubSample - 1) / vertSubSample);\n+\t\tconst unsigned int planeSize = info.planeSize(size, i);\n \n-\t\tplaneInfo_[i].stride = stride;\n+\t\tplaneInfo_[i].stride = info.stride(size.width, i, 1u);\n \t\tplaneInfo_[i].offset = offset;\n \t\tplaneInfo_[i].size = planeSize;\n \ndiff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\nindex 6952fc38b0ef..7b3b49609cb1 100644\n--- a/src/android/yuv/post_processor_yuv.cpp\n+++ b/src/android/yuv/post_processor_yuv.cpp\n@@ -134,11 +134,9 @@ void PostProcessorYuv::calculateLengths(const StreamConfiguration &inCfg,\n \t\tsourceStride_[i] = inCfg.stride;\n \t\tdestinationStride_[i] = nv12Info.stride(destinationSize_.width, i, 1);\n \n-\t\tconst unsigned int vertSubSample =\n-\t\t\tnv12Info.planes[i].verticalSubSampling;\n-\t\tsourceLength_[i] = sourceStride_[i] *\n-\t\t\t((sourceSize_.height + vertSubSample - 1) / vertSubSample);\n-\t\tdestinationLength_[i] = destinationStride_[i] *\n-\t\t\t((destinationSize_.height + vertSubSample - 1) / vertSubSample);\n+\t\tsourceLength_[i] = nv12Info.planeSize(sourceSize_.height, i,\n+\t\t\t\t\t\t      sourceStride_[i]);\n+\t\tdestinationLength_[i] = nv12Info.planeSize(destinationSize_.height, i,\n+\t\t\t\t\t\t\t   destinationStride_[i]);\n \t}\n }\ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex c993960eb982..ce0081a8a3d1 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -11,6 +11,7 @@\n #include <errno.h>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include <libcamera/formats.h>\n \n@@ -801,32 +802,80 @@ unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane,\n }\n \n /**\n- * \\brief Compute the number of bytes necessary to store a frame\n+ * \\brief Compute the number of bytes necessary to store a plane of a frame\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  *\n- * The frame is computed by adding the product of the line stride and the frame\n- * height for all planes, taking subsampling and other format characteristics\n- * into account. Additional stride alignment constraints may be specified\n- * through the \\a align parameter, and will apply to all planes. For more\n- * complex stride constraints, use the frameSize() overloaded version that takes\n- * an array of stride values.\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+ * Stride alignment constraints may be specified through the \\a align parameter.\n  *\n  * \\sa stride()\n  *\n+ * \\return The number of bytes necessary to store the plane, or 0 if the\n+ * PixelFormatInfo instance is not valid or the plane number isn't valid for the\n+ * format\n+ */\n+unsigned int PixelFormatInfo::planeSize(const Size &size, unsigned int plane,\n+\t\t\t\t\tunsigned int align) 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+}\n+\n+/**\n+ * \\brief Compute the number of bytes necessary to store a plane of a frame\n+ * \\param[in] height The height of the frame, in pixels\n+ * \\param[in] plane The plane index\n+ * \\param[in] stride The plane stride, in bytes\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+ * Stride alignment constraints may be specified through the \\a align parameter.\n+ *\n+ * \\return The number of bytes necessary to store the plane, or 0 if the\n+ * PixelFormatInfo instance is not valid or the plane number isn't valid for the\n+ * format\n+ */\n+unsigned int PixelFormatInfo::planeSize(unsigned int height, unsigned int plane,\n+\t\t\t\t\tunsigned int stride) const\n+{\n+\tunsigned int vertSubSample = planes[plane].verticalSubSampling;\n+\tif (!vertSubSample)\n+\t\treturn 0;\n+\n+\t/* stride * ceil(height / verticalSubSampling) */\n+\treturn stride * ((height + vertSubSample - 1) / vertSubSample);\n+}\n+\n+/**\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+ *\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+ * more complex stride constraints, use the frameSize() overloaded version that\n+ * takes an array of stride values.\n+ *\n+ * \\sa planeSize()\n+ *\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 {\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, align)\n-\t\t     * ((size.height + vertSubSample - 1) / vertSubSample);\n+\n+\tfor (const auto &[i, plane] : utils::enumerate(planes)) {\n+\t\tif (plane.bytesPerGroup == 0)\n+\t\t\tbreak;\n+\n+\t\tsum += planeSize(size, i, align);\n \t}\n \n \treturn sum;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 84ccb97495f5..1c4e6fbf7fe7 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1337,11 +1337,7 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n \t\t\tplanes[i].offset = offset;\n \n \t\t\t/* \\todo Take the V4L2 stride into account */\n-\t\t\tconst unsigned int vertSubSample =\n-\t\t\t\tinfo.planes[i].verticalSubSampling;\n-\t\t\tplanes[i].length =\n-\t\t\t\tinfo.stride(format_.size.width, i, 1u) *\n-\t\t\t\t((format_.size.height + vertSubSample - 1) / vertSubSample);\n+\t\t\tplanes[i].length = info.planeSize(format_.size, i);\n \t\t\toffset += planes[i].length;\n \t\t}\n \t}\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "06/30"
    ]
}