Show a patch.

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

{
    "id": 19471,
    "url": "https://patchwork.libcamera.org/api/patches/19471/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19471/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240130181311.43745-3-hdegoede@redhat.com>",
    "date": "2024-01-30T18:13:11",
    "name": "[RFC,2/2] libcamera: debayer_cpu: Stop requiring 2 lines of padding at the top/bottom",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "0169d427f1f8d841016f35a70155f7c084de8d81",
    "submitter": {
        "id": 102,
        "url": "https://patchwork.libcamera.org/api/people/102/?format=api",
        "name": "Hans de Goede",
        "email": "hdegoede@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19471/mbox/",
    "series": [
        {
            "id": 4162,
            "url": "https://patchwork.libcamera.org/api/series/4162/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4162",
            "date": "2024-01-30T18:13:09",
            "name": "libcamera: debayer_cpu: Stop requiring 2 lines of padding at the top/bottom",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4162/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19471/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19471/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 3AFA1C32C2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Jan 2024 18:13:25 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B23A462143;\n\tTue, 30 Jan 2024 19:13:24 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B31A62139\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Jan 2024 19:13:20 +0100 (CET)",
            "from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-664-4QwRf-TgPpWl47Ssynajgw-1;\n\tTue, 30 Jan 2024 13:13:16 -0500",
            "from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id 810EB3C2A1C2;\n\tTue, 30 Jan 2024 18:13:15 +0000 (UTC)",
            "from shalem.redhat.com (unknown [10.39.192.94])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 876FA40C106C;\n\tTue, 30 Jan 2024 18:13:14 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"LooDNX5J\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1706638399;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=sASw2vwQy2sWQkoeAM+sNL96F0p+dRyP247spWsQM/M=;\n\tb=LooDNX5JIzkzDKq36vAIa6P28TQWEyAJW/cCg7BPvG1P6x+8SfkROdIZAsTv4pD/ggrQ5A\n\tS9eFyLjq8EadpHVZ1mIF1J7yqETCeISAm56QOYcFVGsIHtryyqUMZv51hRQaqsDjuKUd9y\n\tjvmADdl7QvFqwS58Hff8DoPRU/B3yWU=",
        "X-MC-Unique": "4QwRf-TgPpWl47Ssynajgw-1",
        "From": "Hans de Goede <hdegoede@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[RFC 2/2] libcamera: debayer_cpu: Stop requiring 2 lines of padding\n\tat the top/bottom",
        "Date": "Tue, 30 Jan 2024 19:13:11 +0100",
        "Message-ID": "<20240130181311.43745-3-hdegoede@redhat.com>",
        "In-Reply-To": "<20240130181311.43745-1-hdegoede@redhat.com>",
        "References": "<20240130181311.43745-1-hdegoede@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.2",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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>",
        "Cc": "Maxime Ripard <mripard@redhat.com>, Pavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Since the standard bayer pattern debayer functions now take an array\nof 3 src pointers (previous-, current- and next-line) we can easily\navoid the need to have 2 lines (2 to keep the pattern unchanged)\npadding at the top / bottom.\n\nInstead when debayering the first line, pass the next-line pointer also\nas previous-line pointer and pass the prev-line pointer as next-line\npointer when debayering the last line.\n\nThis allows the output to be 4 lines higher, which is esp. useful\nwith the current hi556 kernel driver which has a max-height for\nthe bauer data of 722 lines. So before this change it was not\npossible to generate a standard 1280x720 output.\n\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n .../internal/software_isp/debayer_cpu.h       |  3 +-\n src/libcamera/software_isp/debayer_cpu.cpp    | 76 +++++++++++++++----\n 2 files changed, 64 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/software_isp/debayer_cpu.h b/include/libcamera/internal/software_isp/debayer_cpu.h\nindex bcb634d5..061e22f0 100644\n--- a/include/libcamera/internal/software_isp/debayer_cpu.h\n+++ b/include/libcamera/internal/software_isp/debayer_cpu.h\n@@ -79,8 +79,9 @@ public:\n \tunsigned int frameSize() { return outputConfig_.frameSize; }\n \n private:\n-\tvoid initLinePointers(const uint8_t *linePointers[], const uint8_t *src);\n+\tvoid setupInputMemcpy(const uint8_t *linePointers[]);\n \tvoid shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src);\n+\tvoid memcpyNextLine(const uint8_t *linePointers[]);\n \tvoid process2(const uint8_t *src, uint8_t *dst);\n \tvoid process4(const uint8_t *src, uint8_t *dst);\n \t/* 8-bit raw bayer format */\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 14fc383e..d9a7e34f 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -754,14 +754,10 @@ DebayerCpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size\n \treturn std::make_tuple(stride, stride * size.height);\n }\n \n-void DebayerCpu::initLinePointers(const uint8_t *linePointers[], const uint8_t *src)\n+void DebayerCpu::setupInputMemcpy(const uint8_t *linePointers[])\n {\n \tconst int patternHeight = inputConfig_.patternSize.height;\n \n-\tfor (int i = 0; i < patternHeight; i++)\n-\t\tlinePointers[i + 1] = src +\n-\t\t\t\t      (-patternHeight / 2 + i) * (int)inputConfig_.stride;\n-\n \tif (!enableInputMemcpy_)\n \t\treturn;\n \n@@ -788,10 +784,14 @@ void DebayerCpu::shiftLinePointers(const uint8_t *linePointers[], const uint8_t\n \n \tlinePointers[patternHeight] = src +\n \t\t\t\t      (patternHeight / 2) * (int)inputConfig_.stride;\n+}\n \n+void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n+{\n \tif (!enableInputMemcpy_)\n \t\treturn;\n \n+\tconst int patternHeight = inputConfig_.patternSize.height;\n \tsize_t lineLength = (window_.width + 2 * inputConfig_.patternSize.width) *\n \t\t\t    inputConfig_.bpp / 8;\n \tint padding = inputConfig_.patternSize.width * inputConfig_.bpp / 8;\n@@ -803,22 +803,53 @@ void DebayerCpu::shiftLinePointers(const uint8_t *linePointers[], const uint8_t\n \n void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n {\n-\tconst unsigned int y_end = window_.y + window_.height;\n+\tunsigned int y_end = window_.y + window_.height;\n+\t/* Holds [0] previous- [1] current- [2] next-line */\n \tconst uint8_t *linePointers[3];\n \n \t/* Adjust src to top left corner of the window */\n \tsrc += window_.y * inputConfig_.stride + window_.x * inputConfig_.bpp / 8;\n \n-\tinitLinePointers(linePointers, src);\n+\t/* [x] becomes [x - 1] after initial shiftLinePointers() call */\n+\tif (window_.y) {\n+\t\tlinePointers[1] = src - inputConfig_.stride; /* previous-line */\n+\t\tlinePointers[2] = src;\n+\t} else {\n+\t\t/* window_.y == 0, use the next line as prev line */\n+\t\tlinePointers[1] = src + inputConfig_.stride;\n+\t\tlinePointers[2] = src;\n+\t\t/* Last 2 lines also need special handling */\n+\t\ty_end -= 2;\n+\t}\n+\n+\tsetupInputMemcpy(linePointers);\n \n \tfor (unsigned int y = window_.y; y < y_end; y += 2) {\n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n \t\tstats_->processLine0(y, linePointers);\n \t\t(this->*debayer0_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n \n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n+\t\t(this->*debayer1_)(dst, linePointers);\n+\t\tsrc += inputConfig_.stride;\n+\t\tdst += outputConfig_.stride;\n+\t}\n+\n+\tif (window_.y == 0) {\n+\t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n+\t\tstats_->processLine0(y_end, linePointers);\n+\t\t(this->*debayer0_)(dst, linePointers);\n+\t\tsrc += inputConfig_.stride;\n+\t\tdst += outputConfig_.stride;\n+\n+\t\tshiftLinePointers(linePointers, src);\n+\t\t/* next line may point outside of src, use prev. */\n+\t\tlinePointers[2] = linePointers[0];\n \t\t(this->*debayer1_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -828,32 +859,46 @@ void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n {\n \tconst unsigned int y_end = window_.y + window_.height;\n+\t/*\n+\t * This holds pointers to [0] 2-lines up [1] 1-line up [2] current-line\n+\t * [3] 1-line down [4] 2-lines down.\n+\t */\n \tconst uint8_t *linePointers[5];\n \n \t/* Adjust src to top left corner of the window */\n \tsrc += window_.y * inputConfig_.stride + window_.x * inputConfig_.bpp / 8;\n \n-\tinitLinePointers(linePointers, src);\n+\t/* [x] becomes [x - 1] after initial shiftLinePointers() call */\n+\tlinePointers[1] = src - 2 * inputConfig_.stride;\n+\tlinePointers[2] = src - inputConfig_.stride;\n+\tlinePointers[3] = src;\n+\tlinePointers[4] = src + inputConfig_.stride;\n+\n+\tsetupInputMemcpy(linePointers);\n \n \tfor (unsigned int y = window_.y; y < y_end; y += 4) {\n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n \t\tstats_->processLine0(y, linePointers);\n \t\t(this->*debayer0_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n \n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n \t\t(this->*debayer1_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n \n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n \t\tstats_->processLine2(y, linePointers);\n \t\t(this->*debayer2_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n \n \t\tshiftLinePointers(linePointers, src);\n+\t\tmemcpyNextLine(linePointers);\n \t\t(this->*debayer3_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -948,18 +993,21 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n SizeRange DebayerCpu::sizes(PixelFormat inputFormat, const Size &inputSize)\n {\n \tSize pattern_size = patternSize(inputFormat);\n+\tunsigned int border_height = pattern_size.height;\n \n \tif (pattern_size.isNull())\n \t\treturn {};\n \n+\t/* No need for top/bottom border with a pattern height of 2 */\n+\tif (pattern_size.height == 2)\n+\t\tborder_height = 0;\n+\n \t/*\n-\t * For debayer interpolation a border of pattern-height x pattern-width\n-\t * is kept around the entire image. Combined with a minimum-size of\n-\t * pattern-height x pattern-width this means the input-size needs to be\n-\t * at least (3 * pattern-height) x (3 * pattern-width).\n+\t * For debayer interpolation a border is kept around the entire image\n+\t * and the minimum output size is pattern-height x pattern-width.\n \t */\n \tif (inputSize.width < (3 * pattern_size.width) ||\n-\t    inputSize.height < (3 * pattern_size.height)) {\n+\t    inputSize.height < (2 * border_height + pattern_size.height)) {\n \t\tLOG(Debayer, Warning)\n \t\t\t<< \"Input format size too small: \" << inputSize.toString();\n \t\treturn {};\n@@ -967,7 +1015,7 @@ SizeRange DebayerCpu::sizes(PixelFormat inputFormat, const Size &inputSize)\n \n \treturn SizeRange(Size(pattern_size.width, pattern_size.height),\n \t\t\t Size((inputSize.width - 2 * pattern_size.width) & ~(pattern_size.width - 1),\n-\t\t\t      (inputSize.height - 2 * pattern_size.height) & ~(pattern_size.height - 1)),\n+\t\t\t      (inputSize.height - 2 * border_height) & ~(pattern_size.height - 1)),\n \t\t\t pattern_size.width, pattern_size.height);\n }\n \n",
    "prefixes": [
        "RFC",
        "2/2"
    ]
}