Show a patch.

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

{
    "id": 26228,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/26228/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26228/",
    "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": "<20260223160930.27913-3-johannes.goede@oss.qualcomm.com>",
    "date": "2026-02-23T16:09:28",
    "name": "[v2,2/4] software_isp: debayer_cpu: Add DebayerCpuThread class",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "05d002c47f843614f794cd72edfde4db85de9df3",
    "submitter": {
        "id": 242,
        "url": "https://patchwork.libcamera.org/api/1.1/people/242/?format=api",
        "name": "Hans de Goede",
        "email": "johannes.goede@oss.qualcomm.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/26228/mbox/",
    "series": [
        {
            "id": 5809,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5809/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5809",
            "date": "2026-02-23T16:09:27",
            "name": "software_isp: debayer_cpu: Add multi-threading support",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5809/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26228/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26228/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 D776DBE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Feb 2026 16:09:42 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD1C36229F;\n\tMon, 23 Feb 2026 17:09:41 +0100 (CET)",
            "from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com\n\t[205.220.168.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EB746228C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Feb 2026 17:09:38 +0100 (CET)",
            "from pps.filterd (m0279865.ppops.net [127.0.0.1])\n\tby mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n\t61NDsIHr185231 for <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Feb 2026 16:09:37 GMT",
            "from mail-qk1-f198.google.com (mail-qk1-f198.google.com\n\t[209.85.222.198])\n\tby mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cgr69gefx-1\n\t(version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Feb 2026 16:09:36 +0000 (GMT)",
            "by mail-qk1-f198.google.com with SMTP id\n\taf79cd13be357-8cb3ff05c73so4360646885a.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Feb 2026 08:09:36 -0800 (PST)",
            "from t14s.vakwerkhuis.com ([78.108.130.194])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-b9084c60b91sm338284066b.14.2026.02.23.08.09.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Feb 2026 08:09:34 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=qualcomm.com header.i=@qualcomm.com\n\theader.b=\"CnPWj1lq\"; dkim=pass (2048-bit key;\n\tunprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n\theader.b=\"eeaQvlgC\"; dkim-atps=neutral",
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n\tcc:content-transfer-encoding:date:from:in-reply-to:message-id\n\t:mime-version:references:subject:to; s=qcppdkim1; bh=Hk4PSd+0CFh\n\t8zus8u0oNViuor7lWwSz24+it6uh27zQ=; b=CnPWj1lq8et0BO4Q5BYRRskvJUO\n\tmpyi7QF0liBYzQNsqlWxfiHJOmoynhQseQ98OOfGrnP07FRKdOrsWj0S/nAUhgL8\n\tb/Zcg8KeEpBvnd6IZWqhpfET6JsHSAekgvK+6OmEAOvLM9Sw+KuKvOiqNr2pe7nC\n\tIodJJQ/4WK+vpsrua/WxnkHocOuHvLwy8OWKhRRbPQKFq5uBcvZj30AcNsbDzTrG\n\tK1+r4CIAAWzjPZ/aoayMKCFLGvH6qkvG2tKxl/pQQIOX5a6CsToKwObG1ZgSxFTO\n\tO+OPji+bgE+TPiTvwUrsYZrEpHpdYmcAnRqZ0wWhtwXM5UGf8i6kN7Q1gFw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=oss.qualcomm.com; s=google; t=1771862976; x=1772467776;\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=Hk4PSd+0CFh8zus8u0oNViuor7lWwSz24+it6uh27zQ=;\n\tb=eeaQvlgCpQedAC1s2YZKkkdGP1asVyB+i/Ov/J644/mvm6HK2APVqri5NRKSd7EKYn\n\tBLQz/BR9rqzDqq7LLoqwByfjlNlaog7UqYl4g3YQyFsR4q0ECRoveegfc6IcZbzjp3sS\n\tNdnaEj25b/IEssWSuuX/JYFpkl/dnUnUxFqVERrWbdaxCHU67ddMWL/ZBw1iBKvbz9f6\n\tTyum1HkxuNv/FHzWkxeonTzAitZkiXrpxCs3L4CMl71iRDUq7ZfFl1AmXaz13yGkH8jQ\n\tjW8a4pRC/jKehKQTBKhGVA1caNJzWU+M2QaG8fZwssVssBDREDesfiAE3PHEcRZO51nB\n\t57xA=="
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1771862976; x=1772467776;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=Hk4PSd+0CFh8zus8u0oNViuor7lWwSz24+it6uh27zQ=;\n\tb=FG7+2ZV8Q5rTcFA6FdpndZrW8E5Ab5ucXQQkoaHIgM3bHOjrO+fMrSol4Gr0AOyOGF\n\tp8K9W3nk2FP/JIZ2gAQ07Ng4l00rmaWJ9MFFR/Z+wmWveqTKnVDCsaCmBFN1tKyU1aHB\n\tzTxAU4loOBy+gcW4uszZIOWwjx66UoQRL9fYJ2iUdQsFsym42FbaMnMrZeEOiwH+Chwp\n\tuFzZRwppnQ3C9t2ukvYE5blX3D3A3DkYQb61FvuXOUlur22TBQRD51H6XZ/T1/b6Vg+v\n\t81bng38nY095drgPUWH24cfEyh1kfhoxgUxjeFMYesyU9wjUhLfp3ciYRTZKhmMb16Ma\n\tTnXw==",
        "X-Gm-Message-State": "AOJu0Yzf31OC/tJmHLMyIRWNVhhbd2NBxJ8UnOkUTaXwOMhhxskjDKF9\n\trYltCQCMsbPozjKdsRSmUfP9wWLIAyYnkkn9+yWxjPjaPMJ4BNLWalCvewvTKDDnAe8TDpdu1UM\n\tHooIibp0uecokhbncv+Qu/ewWN8zkaSJr4DPsMqOZNnp6ANvTk+PwQ3Y4L6LQgSxz532/ZH1WKa\n\tTYnqVHKbrJ",
        "X-Gm-Gg": "AZuq6aKGEKd3M5aCRLjt5yBEH7GhUUZ/w/cn9j7Cco+X8dfpUSQIgjFQ+kCxLBFMKUE\n\t2gvIrWxRvrzoVuNiJcqIjy68ToLi2T8Szz/pbROpiBjRZHVPhOKzmpcPBDvzPllR5W2DnCEyQQv\n\tolA7bgy0jGx55UG8gykVbdV9pcqeLdbLPtTFIYuiDPorFrX4fNZiD/esxw2FPpDJggTVUiuGHeD\n\tTSwbcY5nUE0ag6DsgMK35URtDtIZymIPfc6B/Aa/1khJqxc7w6gjZ709jI83qLRpJy0OhJtwuBa\n\tgv2yN4jTOLMkoywJCisSKEkoje5eUT4Bl7yh9mQUuAoowWIs+LSVXVwy99oF7m2F8JyuehIZfBK\n\t3xsupE5htjX7It260nqWsd1PY5n6wMPJ3QXfsqcd6eKhtEQ5j5g==",
        "X-Received": [
            "by 2002:a05:620a:294f:b0:8c6:acca:4a29 with SMTP id\n\taf79cd13be357-8cb8c9d295cmr1190118685a.13.1771862975354; \n\tMon, 23 Feb 2026 08:09:35 -0800 (PST)",
            "by 2002:a05:620a:294f:b0:8c6:acca:4a29 with SMTP id\n\taf79cd13be357-8cb8c9d295cmr1190112085a.13.1771862974706; \n\tMon, 23 Feb 2026 08:09:34 -0800 (PST)"
        ],
        "From": "Hans de Goede <johannes.goede@oss.qualcomm.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Milan Zamazal <mzamazal@redhat.com>,\n\tHans de Goede <johannes.goede@oss.qualcomm.com>",
        "Subject": "[PATCH v2 2/4] software_isp: debayer_cpu: Add DebayerCpuThread class",
        "Date": "Mon, 23 Feb 2026 17:09:28 +0100",
        "Message-ID": "<20260223160930.27913-3-johannes.goede@oss.qualcomm.com>",
        "X-Mailer": "git-send-email 2.52.0",
        "In-Reply-To": "<20260223160930.27913-1-johannes.goede@oss.qualcomm.com>",
        "References": "<20260223160930.27913-1-johannes.goede@oss.qualcomm.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Authority-Analysis": "v=2.4 cv=O6A0fR9W c=1 sm=1 tr=0 ts=699c7bc0 cx=c_pps\n\ta=qKBjSQ1v91RyAK45QCPf5w==:117 a=rrvG0T/C2D967D07Ol03YQ==:17\n\ta=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n\ta=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8\n\ta=SjPJea1MOwGqAC1umdEA:9 a=NFOGd7dJGGMPyQGDc5-O:22",
        "X-Proofpoint-ORIG-GUID": "mQBfYl70XMxUUsEkVBoIv4NSHL1cXpKl",
        "X-Proofpoint-GUID": "mQBfYl70XMxUUsEkVBoIv4NSHL1cXpKl",
        "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjIzMDEzOSBTYWx0ZWRfX22WHIFcxRukX\n\t9d0yyxW7yji/H+aJuCZL+cmG096th4SQ2QHZjVDREw/yem4EGaR8y7UUoIVbcV/wNkfap64Ox9q\n\tvr7lxYHS9gAfSKK+VtGoaZ2oRoLSbqCfL5pM2Mzh07/R0i7M5d7TM/pZn//6vrSnTmVpgGPB3/v\n\tgPJrT5wM3ahDnG2IAeMEj/L/Xg+Qe5yTrZkaPOlf3YSOZjJtY1hSEa4+5m2uv0DOgneQSxYMNqD\n\t5DVf4QcUYfsOZX8nfz2vNUl89obIC5TpB6eCusPkz2bnddzM/3O6cj1bZLfb1dXcYiClNtbaCmX\n\tH7BscVegbtev7w+uUVR0JA+C118C/N4kxONktu/xws5tpVed00uVF/ZkhwtLihdCtPe3tc6hqa0\n\ty6g3VEW9Ixt6EtIyCFNZn2lH679e6Xq3jFOyXcLmbDdYrHK+eEjFJj/fLqAJhBeVnVE2wDpSiyx\n\tfh1ILUncNIPcceUOLWg==",
        "X-Proofpoint-Virus-Version": "vendor=baseguard\n\tengine=ICAP:2.0.293, Aquarius:18.0.1121, Hydra:6.1.51,\n\tFMLib:17.12.100.49\n\tdefinitions=2026-02-23_03,2026-02-23_03,2025-10-01_01",
        "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 clxscore=1015 lowpriorityscore=0 adultscore=0\n\tpriorityscore=1501\n\timpostorscore=0 phishscore=0 malwarescore=0 bulkscore=0\n\tsuspectscore=0\n\tclassifier=typeunknown authscore=0 authtc= authcc= route=outbound\n\tadjust=0\n\treason=mlx scancount=1 engine=8.22.0-2602130000\n\tdefinitions=main-2602230139",
        "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 a DebayerCpuThreadclass and use this in the inner render loop.\nThis contains data which needs to be separate per thread.\n\nThis is a preparation patch for making DebayerCpu support multi-threading.\n\nBenchmarking on the Arduino Uno-Q with a weak CPU which is good for\nperformance testing, shows 146-147ms per 3272x2464 frame both before and\nafter this change, with things maybe being 0.5 ms slower after this change.\n\nSigned-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>\n---\nChanges in v2:\n- Replace the DebayerCpuThreadData struct from v1 with a DebayerCpuThread\n  class, derived from Object to allow calling invokeMethod for thread re-use\n  in followup patches\n- As part of this also move a bunch of methods which primarily deal with\n  per thread data: setupInputMemcpy(), shiftLinePointers(), memcpyNextLine(),\n  process*() to the new DebayerCpuThread class\n---\n src/libcamera/software_isp/debayer_cpu.cpp | 215 ++++++++++++++-------\n src/libcamera/software_isp/debayer_cpu.h   |  20 +-\n 2 files changed, 159 insertions(+), 76 deletions(-)",
    "diff": "diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex e7b012105..122bfbb05 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -27,6 +27,38 @@\n \n namespace libcamera {\n \n+class DebayerCpuThread : public Object\n+{\n+public:\n+\tDebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex,\n+\t\t\t bool enableInputMemcpy);\n+\n+\tvoid configure(unsigned int yStart, unsigned int yEnd);\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 process(uint32_t frame, const uint8_t *src, uint8_t *dst);\n+\tvoid process2(uint32_t frame, const uint8_t *src, uint8_t *dst);\n+\tvoid process4(uint32_t frame, const uint8_t *src, uint8_t *dst);\n+\n+\tDebayerCpu *debayer_;\n+\tunsigned int threadIndex_;\n+\tunsigned int yStart_;\n+\tunsigned int yEnd_;\n+\tunsigned int lineBufferLength_;\n+\tunsigned int lineBufferPadding_;\n+\tunsigned int lineBufferIndex_;\n+\tstd::vector<uint8_t> lineBuffers_[DebayerCpu::kMaxLineBuffers];\n+\tbool enableInputMemcpy_;\n+};\n+\n+DebayerCpuThread::DebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex,\n+\t\t\t\t   bool enableInputMemcpy)\n+\t: debayer_(debayer), threadIndex_(threadIndex),\n+\t  enableInputMemcpy_(enableInputMemcpy)\n+{\n+}\n+\n /**\n  * \\class DebayerCpu\n  * \\brief Class for debayering on the CPU\n@@ -53,8 +85,14 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfigurat\n \t * \\todo Make memcpy automatic based on runtime detection of platform\n \t * capabilities.\n \t */\n-\tenableInputMemcpy_ =\n+\tbool enableInputMemcpy =\n \t\tconfiguration.option<bool>({ \"software_isp\", \"copy_input_buffer\" }).value_or(true);\n+\n+\t/* Just one thread object for now, which will be called inline rather than async */\n+\tthreads_.resize(1);\n+\n+\tfor (unsigned int i = 0; i < threads_.size(); i++)\n+\t\tthreads_[i] = new DebayerCpuThread(this, i, enableInputMemcpy);\n }\n \n DebayerCpu::~DebayerCpu() = default;\n@@ -484,7 +522,7 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \tif (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0)\n \t\treturn -EINVAL;\n \n-\tif (stats_->configure(inputCfg) != 0)\n+\tif (stats_->configure(inputCfg, threads_.size()) != 0)\n \t\treturn -EINVAL;\n \n \tconst Size &statsPatternSize = stats_->patternSize();\n@@ -548,17 +586,36 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \t */\n \tstats_->setWindow(Rectangle(window_.size()));\n \n+\tunsigned int yStart = 0;\n+\tunsigned int linesPerThread = (window_.height / threads_.size()) &\n+\t\t\t\t      ~(inputConfig_.patternSize.height - 1);\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < (threads_.size() - 1); i++) {\n+\t\tthreads_[i]->configure(yStart, yStart + linesPerThread);\n+\t\tyStart += linesPerThread;\n+\t}\n+\tthreads_[i]->configure(yStart, window_.height);\n+\n+\treturn 0;\n+}\n+\n+void DebayerCpuThread::configure(unsigned int yStart, unsigned int yEnd)\n+{\n+\tDebayer::DebayerInputConfig &inputConfig = debayer_->inputConfig_;\n+\n+\tyStart_ = yStart;\n+\tyEnd_ = yEnd;\n+\n \t/* pad with patternSize.Width on both left and right side */\n-\tlineBufferPadding_ = inputConfig_.patternSize.width * inputConfig_.bpp / 8;\n-\tlineBufferLength_ = window_.width * inputConfig_.bpp / 8 +\n+\tlineBufferPadding_ = inputConfig.patternSize.width * inputConfig.bpp / 8;\n+\tlineBufferLength_ = debayer_->window_.width * inputConfig.bpp / 8 +\n \t\t\t    2 * lineBufferPadding_;\n \n \tif (enableInputMemcpy_) {\n-\t\tfor (unsigned int i = 0; i <= inputConfig_.patternSize.height; i++)\n+\t\tfor (unsigned int i = 0; i <= inputConfig.patternSize.height; i++)\n \t\t\tlineBuffers_[i].resize(lineBufferLength_);\n \t}\n-\n-\treturn 0;\n }\n \n /*\n@@ -599,9 +656,9 @@ DebayerCpu::strideAndFrameSize(const PixelFormat &outputFormat, const Size &size\n \treturn std::make_tuple(stride, stride * size.height);\n }\n \n-void DebayerCpu::setupInputMemcpy(const uint8_t *linePointers[])\n+void DebayerCpuThread::setupInputMemcpy(const uint8_t *linePointers[])\n {\n-\tconst unsigned int patternHeight = inputConfig_.patternSize.height;\n+\tconst unsigned int patternHeight = debayer_->inputConfig_.patternSize.height;\n \n \tif (!enableInputMemcpy_)\n \t\treturn;\n@@ -617,20 +674,20 @@ void DebayerCpu::setupInputMemcpy(const uint8_t *linePointers[])\n \tlineBufferIndex_ = patternHeight;\n }\n \n-void DebayerCpu::shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src)\n+void DebayerCpuThread::shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src)\n {\n-\tconst unsigned int patternHeight = inputConfig_.patternSize.height;\n+\tconst unsigned int patternHeight = debayer_->inputConfig_.patternSize.height;\n \n \tfor (unsigned int i = 0; i < patternHeight; i++)\n \t\tlinePointers[i] = linePointers[i + 1];\n \n-\tlinePointers[patternHeight] = src +\n-\t\t\t\t      (patternHeight / 2) * (int)inputConfig_.stride;\n+\tlinePointers[patternHeight] =\n+\t\tsrc + (patternHeight / 2) * (int)debayer_->inputConfig_.stride;\n }\n \n-void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n+void DebayerCpuThread::memcpyNextLine(const uint8_t *linePointers[])\n {\n-\tconst unsigned int patternHeight = inputConfig_.patternSize.height;\n+\tconst unsigned int patternHeight = debayer_->inputConfig_.patternSize.height;\n \n \tif (!enableInputMemcpy_)\n \t\treturn;\n@@ -643,23 +700,42 @@ void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n \tlineBufferIndex_ = (lineBufferIndex_ + 1) % (patternHeight + 1);\n }\n \n-void DebayerCpu::process2(uint32_t frame, const uint8_t *src, uint8_t *dst)\n+void DebayerCpuThread::process(uint32_t frame, const uint8_t *src, uint8_t *dst)\n {\n-\tunsigned int yEnd = window_.height;\n+\tRectangle &window = debayer_->window_;\n+\n+\t/* Adjust src to top left corner of the window */\n+\tsrc += (window.y + yStart_) * debayer_->inputConfig_.stride +\n+\t       window.x * debayer_->inputConfig_.bpp / 8;\n+\t/* Adjust dst for yStart_ */\n+\tdst += yStart_ * debayer_->outputConfig_.stride;\n+\n+\tif (debayer_->inputConfig_.patternSize.height == 2)\n+\t\tprocess2(frame, src, dst);\n+\telse\n+\t\tprocess4(frame, src, dst);\n+}\n+\n+void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst)\n+{\n+\tunsigned int outputStride = debayer_->outputConfig_.stride;\n+\tunsigned int inputStride = debayer_->inputConfig_.stride;\n+\tRectangle &window = debayer_->window_;\n+\tunsigned int yEnd = yEnd_;\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 \t/* [x] becomes [x - 1] after initial shiftLinePointers() call */\n-\tif (window_.y) {\n-\t\tlinePointers[1] = src - inputConfig_.stride; /* previous-line */\n+\tif (window.y + yStart_) {\n+\t\tlinePointers[1] = src - inputStride; /* 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\t/* Top line, use the next line as prev line */\n+\t\tlinePointers[1] = src + inputStride;\n \t\tlinePointers[2] = src;\n+\t}\n+\n+\tif (window.y == 0 && yEnd_ == window.height) {\n \t\t/*\n \t\t * Last 2 lines also need special handling.\n \t\t * (And configure() ensures that yEnd >= 2.)\n@@ -669,83 +745,93 @@ void DebayerCpu::process2(uint32_t frame, const uint8_t *src, uint8_t *dst)\n \n \tsetupInputMemcpy(linePointers);\n \n-\tfor (unsigned int y = 0; y < yEnd; y += 2) {\n+\t/*\n+\t * Note y is the line-number *inside* the window, since stats_' window\n+\t * is the stats window inside/relative to the debayer window. IOW for\n+\t * single thread rendering y goes from 0 to window.height.\n+\t */\n+\tfor (unsigned int y = yStart_; y < yEnd; y += 2) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(frame, y, linePointers);\n-\t\t(this->*debayer0_)(dst, linePointers);\n-\t\tsrc += inputConfig_.stride;\n-\t\tdst += outputConfig_.stride;\n+\t\tdebayer_->stats_->processLine0(frame, y, linePointers, threadIndex_);\n+\t\tdebayer_->debayer0(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\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\tdebayer_->debayer1(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\n \t}\n \n-\tif (window_.y == 0) {\n+\tif (window.y == 0 && yEnd_ == window.height) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(frame, yEnd, linePointers);\n-\t\t(this->*debayer0_)(dst, linePointers);\n-\t\tsrc += inputConfig_.stride;\n-\t\tdst += outputConfig_.stride;\n+\t\tdebayer_->stats_->processLine0(frame, yEnd, linePointers, threadIndex_);\n+\t\tdebayer_->debayer0(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\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+\t\tdebayer_->debayer1(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\n \t}\n }\n \n-void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n+void DebayerCpuThread::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n {\n+\tunsigned int outputStride = debayer_->outputConfig_.stride;\n+\tunsigned int inputStride = debayer_->inputConfig_.stride;\n+\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 \t/* [x] becomes [x - 1] after initial shiftLinePointers() call */\n-\tlinePointers[1] = src - 2 * inputConfig_.stride;\n-\tlinePointers[2] = src - inputConfig_.stride;\n+\tlinePointers[1] = src - 2 * inputStride;\n+\tlinePointers[2] = src - inputStride;\n \tlinePointers[3] = src;\n-\tlinePointers[4] = src + inputConfig_.stride;\n+\tlinePointers[4] = src + inputStride;\n \n \tsetupInputMemcpy(linePointers);\n \n-\tfor (unsigned int y = 0; y < window_.height; y += 4) {\n+\t/*\n+\t * Note y is the line-number *inside* the window, since stats_' window\n+\t * is the stats window inside/relative to the debayer window. IOW for\n+\t * single thread rendering y goes from 0 to window.height.\n+\t */\n+\tfor (unsigned int y = yStart_; y < yEnd_; y += 4) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(frame, y, linePointers);\n-\t\t(this->*debayer0_)(dst, linePointers);\n-\t\tsrc += inputConfig_.stride;\n-\t\tdst += outputConfig_.stride;\n+\t\tdebayer_->stats_->processLine0(frame, y, linePointers, threadIndex_);\n+\t\tdebayer_->debayer0(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\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\tdebayer_->debayer1(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\n \n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine2(frame, y, linePointers);\n-\t\t(this->*debayer2_)(dst, linePointers);\n-\t\tsrc += inputConfig_.stride;\n-\t\tdst += outputConfig_.stride;\n+\t\tdebayer_->stats_->processLine2(frame, y, linePointers, threadIndex_);\n+\t\tdebayer_->debayer2(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\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+\t\tdebayer_->debayer3(dst, linePointers);\n+\t\tsrc += inputStride;\n+\t\tdst += outputStride;\n \t}\n }\n \n@@ -867,10 +953,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \n \tstats_->startFrame(frame);\n \n-\tif (inputConfig_.patternSize.height == 2)\n-\t\tprocess2(frame, in.planes()[0].data(), out.planes()[0].data());\n-\telse\n-\t\tprocess4(frame, in.planes()[0].data(), out.planes()[0].data());\n+\tthreads_[0]->process(frame, in.planes()[0].data(), out.planes()[0].data());\n \n \tmetadata.planes()[0].bytesused = out.planes()[0].size();\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 7a6517462..7196dcdd0 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -26,6 +26,7 @@\n \n namespace libcamera {\n \n+class DebayerCpuThread;\n class DebayerCpu : public Debayer\n {\n public:\n@@ -44,6 +45,8 @@ public:\n \tconst SharedFD &getStatsFD() { return stats_->getStatsFD(); }\n \n private:\n+\tfriend class DebayerCpuThread;\n+\n \t/**\n \t * \\brief Called to debayer 1 line of Bayer input data to output format\n \t * \\param[out] dst Pointer to the start of the output line to write\n@@ -74,6 +77,11 @@ private:\n \t */\n \tusing debayerFn = void (DebayerCpu::*)(uint8_t *dst, const uint8_t *src[]);\n \n+\tvoid debayer0(uint8_t *dst, const uint8_t *src[]) { (this->*debayer0_)(dst, src); }\n+\tvoid debayer1(uint8_t *dst, const uint8_t *src[]) { (this->*debayer1_)(dst, src); }\n+\tvoid debayer2(uint8_t *dst, const uint8_t *src[]) { (this->*debayer2_)(dst, src); }\n+\tvoid debayer3(uint8_t *dst, const uint8_t *src[]) { (this->*debayer3_)(dst, src); }\n+\n \t/* 8-bit raw bayer format */\n \ttemplate<bool addAlphaByte, bool ccmEnabled>\n \tvoid debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);\n@@ -105,11 +113,6 @@ private:\n \tint setDebayerFunctions(PixelFormat inputFormat,\n \t\t\t\tPixelFormat outputFormat,\n \t\t\t\tbool ccmEnabled);\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(uint32_t frame, const uint8_t *src, uint8_t *dst);\n-\tvoid process4(uint32_t frame, const uint8_t *src, uint8_t *dst);\n \tvoid updateGammaTable(const DebayerParams &params);\n \tvoid updateLookupTables(const DebayerParams &params);\n \n@@ -142,12 +145,9 @@ private:\n \tdebayerFn debayer3_;\n \tRectangle window_;\n \tstd::unique_ptr<SwStatsCpu> stats_;\n-\tstd::vector<uint8_t> lineBuffers_[kMaxLineBuffers];\n-\tunsigned int lineBufferLength_;\n-\tunsigned int lineBufferPadding_;\n-\tunsigned int lineBufferIndex_;\n \tunsigned int xShift_; /* Offset of 0/1 applied to window_.x */\n-\tbool enableInputMemcpy_;\n+\n+\tstd::vector<DebayerCpuThread *>threads_;\n };\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "v2",
        "2/4"
    ]
}