Show a patch.

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

{
    "id": 13989,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13989/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13989/",
    "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": "<20210930093715.73293-7-jeanmichel.hautbois@ideasonboard.com>",
    "date": "2021-09-30T09:37:09",
    "name": "[libcamera-devel,v2,06/12] ipa: ipu3: Change limits and split loops in calculateBdsGrid()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "8260f50adb35e8b4a04efe7121d837ac2ea9d5de",
    "submitter": {
        "id": 75,
        "url": "https://patchwork.libcamera.org/api/1.1/people/75/?format=api",
        "name": "Jean-Michel Hautbois",
        "email": "jeanmichel.hautbois@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13989/mbox/",
    "series": [
        {
            "id": 2587,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2587/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2587",
            "date": "2021-09-30T09:37:03",
            "name": "Improve ImgU statistics usage",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2587/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13989/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13989/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 E0FE5BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Sep 2021 09:37:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 68146691CE;\n\tThu, 30 Sep 2021 11:37:31 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E8436691B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Sep 2021 11:37:20 +0200 (CEST)",
            "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:bab4:22c5:662d:e478])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 94E0C2A8;\n\tThu, 30 Sep 2021 11:37:20 +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=\"eEzPCG/6\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632994640;\n\tbh=y0J9HLzYTe1+uA6GRWu6M/vctdJ+OqQCQ/fUe0fFy2Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=eEzPCG/6jD7/ij/fuWnnFNsMl2nZ5vl+exhpB/IXPknIKuFoWaX9+VsbM5/FG7Xp9\n\t/nutRTjHe4odA3Vc+APlfa+PwG0on/97w8cTj2YJw9CxwLGJ+n5J9I9ZVXcc5w9ASw\n\t/scI22ybFMO5lRMEC5wiWh1Vbbulhd92VuvvD2FM=",
        "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 30 Sep 2021 11:37:09 +0200",
        "Message-Id": "<20210930093715.73293-7-jeanmichel.hautbois@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20210930093715.73293-1-jeanmichel.hautbois@ideasonboard.com>",
        "References": "<20210930093715.73293-1-jeanmichel.hautbois@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 06/12] ipa: ipu3: Change limits and\n\tsplit loops in calculateBdsGrid()",
        "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": "The loops over the width and height of the image when calculating the\nBDS grid parameters are nested, but they're actually independent. Split\nthem to reduce the complexity.\n\nWhile at it, split out the constants to documented const expressions\nfor the grid sizes.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/ipu3/ipu3.cpp | 70 ++++++++++++++++++++++++++++---------------\n 1 file changed, 46 insertions(+), 24 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex b3ac96ed..757a5d50 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -19,6 +19,7 @@\n #include <linux/v4l2-controls.h>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include <libcamera/control_ids.h>\n #include <libcamera/framebuffer.h>\n@@ -136,8 +137,18 @@\n  * <linux/intel-ipu3.h> struct ipu3_uapi_gamma_corr_lut for further details.\n  */\n \n-static constexpr uint32_t kMaxCellWidthPerSet = 80;\n-static constexpr uint32_t kMaxCellHeightPerSet = 60;\n+/* Minimum grid width, expressed as a number of cells */\n+static constexpr uint32_t kMinGridWidth = 16;\n+/* Maximum grid width, expressed as a number of cells */\n+static constexpr uint32_t kMaxGridWidth = 80;\n+/* Minimum grid height, expressed as a number of cells */\n+static constexpr uint32_t kMinGridHeight = 16;\n+/* Maximum grid height, expressed as a number of cells */\n+static constexpr uint32_t kMaxGridHeight = 60;\n+/* log2 of the minimum grid cell width and height, in pixels */\n+static constexpr uint32_t kMinCellSizeLog2 = 3;\n+/* log2 of the maximum grid cell width and height, in pixels */\n+static constexpr uint32_t kMaxCellSizeLog2 = 6;\n \n namespace libcamera {\n \n@@ -281,45 +292,56 @@ int IPAIPU3::start()\n }\n \n /**\n+ * \\brief Calculate a grid for the AWB statistics\n+ *\n  * This function calculates a grid for the AWB algorithm in the IPU3 firmware.\n  * Its input is the BDS output size calculated in the ImgU.\n  * It is limited for now to the simplest method: find the lesser error\n  * with the width/height and respective log2 width/height of the cells.\n  *\n- * \\todo The frame is divided into cells which can be 8x8 => 128x128.\n+ * \\todo The frame is divided into cells which can be 8x8 => 64x64.\n  * As a smaller cell improves the algorithm precision, adapting the\n  * x_start and y_start parameters of the grid would provoke a loss of\n  * some pixels but would also result in more accurate algorithms.\n  */\n void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n {\n-\tuint32_t minError = std::numeric_limits<uint32_t>::max();\n \tSize best;\n \tSize bestLog2;\n \n \t/* Set the BDS output size in the IPAConfiguration structure */\n \tcontext_.configuration.grid.bdsOutputSize = bdsOutputSize;\n \n-\tfor (uint32_t widthShift = 3; widthShift <= 6; ++widthShift) {\n-\t\tuint32_t width = std::min(kMaxCellWidthPerSet,\n-\t\t\t\t\t  bdsOutputSize.width >> widthShift);\n-\t\twidth = width << widthShift;\n-\t\tfor (uint32_t heightShift = 3; heightShift <= 6; ++heightShift) {\n-\t\t\tint32_t height = std::min(kMaxCellHeightPerSet,\n-\t\t\t\t\t\t  bdsOutputSize.height >> heightShift);\n-\t\t\theight = height << heightShift;\n-\t\t\tuint32_t error  = std::abs(static_cast<int>(width - bdsOutputSize.width))\n-\t\t\t\t\t\t\t+ std::abs(static_cast<int>(height - bdsOutputSize.height));\n-\n-\t\t\tif (error > minError)\n-\t\t\t\tcontinue;\n-\n-\t\t\tminError = error;\n-\t\t\tbest.width = width;\n-\t\t\tbest.height = height;\n-\t\t\tbestLog2.width = widthShift;\n-\t\t\tbestLog2.height = heightShift;\n-\t\t}\n+\tuint32_t minError = std::numeric_limits<uint32_t>::max();\n+\tfor (uint32_t shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) {\n+\t\tuint32_t width = std::clamp(bdsOutputSize.width >> shift,\n+\t\t\t\t\t    kMinGridWidth,\n+\t\t\t\t\t    kMaxGridWidth);\n+\n+\t\twidth = width << shift;\n+\t\tuint32_t error = std::abs(static_cast<int>(width - bdsOutputSize.width));\n+\t\tif (error >= minError)\n+\t\t\tcontinue;\n+\n+\t\tminError = error;\n+\t\tbest.width = width;\n+\t\tbestLog2.width = shift;\n+\t}\n+\n+\tminError = std::numeric_limits<uint32_t>::max();\n+\tfor (uint32_t shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) {\n+\t\tuint32_t height = std::clamp(bdsOutputSize.height >> shift,\n+\t\t\t\t\t     kMinGridHeight,\n+\t\t\t\t\t     kMaxGridHeight);\n+\n+\t\theight = height << shift;\n+\t\tuint32_t error = std::abs(static_cast<int>(height - bdsOutputSize.height));\n+\t\tif (error >= minError)\n+\t\t\tcontinue;\n+\n+\t\tminError = error;\n+\t\tbest.height = height;\n+\t\tbestLog2.height = shift;\n \t}\n \n \tstruct ipu3_uapi_grid_config &bdsGrid = context_.configuration.grid.bdsGrid;\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "06/12"
    ]
}