Patch Detail
Show a patch.
GET /api/patches/26816/?format=api
{ "id": 26816, "url": "https://patchwork.libcamera.org/api/patches/26816/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26816/", "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": "<20260602-swisp_12p-v2-1-2e6d25db7081@ideasonboard.com>", "date": "2026-06-02T11:55:30", "name": "[v2] libcamera: software_isp: Support 12-bit CSI2 packed raw bayer formats", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "e448b6941e1c72f0ee381f039e457329c1525391", "submitter": { "id": 223, "url": "https://patchwork.libcamera.org/api/people/223/?format=api", "name": "Jai Luthra", "email": "jai.luthra@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26816/mbox/", "series": [ { "id": 5972, "url": "https://patchwork.libcamera.org/api/series/5972/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5972", "date": "2026-06-02T11:55:30", "name": "[v2] libcamera: software_isp: Support 12-bit CSI2 packed raw bayer formats", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5972/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26816/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26816/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 68337BDCBC\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 2 Jun 2026 11:55:52 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 772606303C;\n\tTue, 2 Jun 2026 13:55:51 +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 BB77861754\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 2 Jun 2026 13:55:50 +0200 (CEST)", "from mail.ideasonboard.com (unknown\n\t[IPv6:2401:4900:1c66:476d:c684:fe78:389f:7375])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EE3A997F;\n\tTue, 2 Jun 2026 13:55:26 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"nGAq80kX\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1780401327;\n\tbh=bdaFtEyren7j3fafwqirYFkk/BVWAj+iH6JaSZsxoSY=;\n\th=From:Date:Subject:To:Cc:From;\n\tb=nGAq80kXCeYyNhoyw1RrimN6UDTDpsEDHh/Fpotdn+PilxfNQ1XrA/CU1cJzk73Hs\n\tHblhHlk6gBS7+EFu1RG4+5Q4MtWuY67wGQ+diPVcjhf5hyR6Hu44XvbvBioa1nq9v+\n\tNiSBjX5Rb4uToLOse4xHn8DdWHVsE/9qL3aalK4k=", "From": "Jai Luthra <jai.luthra@ideasonboard.com>", "Date": "Tue, 02 Jun 2026 17:25:30 +0530", "Subject": "[PATCH v2] libcamera: software_isp: Support 12-bit CSI2 packed raw\n\tbayer formats", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20260602-swisp_12p-v2-1-2e6d25db7081@ideasonboard.com>", "X-B4-Tracking": "v=1; b=H4sIAAAAAAAC/23MQQ6CMBCF4auQWVvTDhaIK+5hiCntKLOQNh2DG\n\tsLdraxd/i8v3wpCmUngXK2QaWHhOJfAQwV+cvOdFIfSgBobbRGVvFjS1WBSjQuIdAq6GzWUf8p\n\t04/duXYbSE8sz5s9OL+a3/lMWo4wiY6yvbd21Y9tzICdxHqPL4ejjA4Zt275H1mb+qQAAAA==", "X-Change-ID": "20260522-swisp_12p-6ad22e4d08b0", "To": "Hans de Goede <johannes.goede@oss.qualcomm.com>, \n\tMilan Zamazal <mzamazal@redhat.com>, \n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>", "Cc": "libcamera-devel@lists.libcamera.org, \n\tJai Luthra <jai.luthra@ideasonboard.com>", "X-Mailer": "b4 0.14.3", "X-Developer-Signature": "v=1; a=openpgp-sha256; l=13495;\n\ti=jai.luthra@ideasonboard.com; h=from:subject:message-id;\n\tbh=bdaFtEyren7j3fafwqirYFkk/BVWAj+iH6JaSZsxoSY=;\n\tb=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBqHsS2PXbMLoG5PPgiClkQnTtOfNv02yJBGsO4/\n\tC9wdeXKggKJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCah7EtgAKCRBD3pH5JJpx\n\tRTFDD/sHSuyAYN3Asqm6p0HUVu6drpM0N+u4qnUokHXJVA9Lkm6c6uvmdqh/LGU4yX8tlhf73pn\n\t4KbbYUgR2eXlLPgbDq7Otx3NT9XiE8HohAzDwXyjuxxwWqvvYQWpiqroo8aunMBhygI7kpIW/q2\n\t5i1ND/JFFb7UnBmnbLmCdRW7XmVWQCLV3DCnITv+dNPvjnchkv+SOLM1jL6y3bUnejpNCO4lra7\n\t+mIDgbUvr9bg8J+N58brweXtHM9ABCUApB+CnKJgHxgWuWflzWGjA4FmXQIgwcWvQXJK1OA8wSz\n\tyH8QZO+p9S52LMR7v04tKgr5hgkupqF12oDNmCVjfdop5l3026rwxEMZIl7Rlz7UG1lksseckyB\n\tE8JIynS4ndND5ibUyERj64TjLm7fEYs3kvu9qDC66abT6mMNZIFuCILkXlOqUreoj929Nkh3TCs\n\tAhmj6fDh3tIN8UE7qnXAvr0THtlWzGLVLGFiB60qndWIaM99NBa4l7q3EmdaJ/JVhQRa/VsFwyC\n\tpG9ZInehZSa+sTJ5QayJc0t9+AkucL5nap/Nasp1hDUD2AqruBHe+ra8RdvXBuv5H92jVGPdteC\n\t0yKjsVSRZnCMO2XRSlKXbFElfwrbMJMJPgoXchEVF5tE7dbrTCs8QiWQQwCEDobvjd/4MgiKc6j\n\tnVUlylgb/HybEyQ==", "X-Developer-Key": "i=jai.luthra@ideasonboard.com; a=openpgp;\n\tfpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145", "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 support for debayering 12-bit CSI2 packed raw bayer formats.\n\nAlso add support for the same in SwStats, skipping one 2x2 block\nhorizontally and skipping every 3rd and 4th line vertically, like done\nfor other raw bayer formats.\n\nGPUISP support was always present in the packed shaders (which already\nhandle skipping the pixel with LSBs), so enable it too.\n\nSigned-off-by: Jai Luthra <jai.luthra@ideasonboard.com>\n---\nThis is tested for RGGB12P using IMX678 on Arduino Uno Q. The sensor\ndoesn't change bayer layout on flips, so I couldn't verify other layouts\n---\nChanges in v2:\n- Handle 12bit/10bit packed stats together\n- Reuse output format definition across all input formats for each\n (CPU/GPU) pipeline\n- Fix wrong odd pixel bayer order comments in debayer12P_xxx functions\n- Link to v1: https://lore.kernel.org/r/20260522-swisp_12p-v1-1-e115c35387b7@ideasonboard.com\n---\n .../libcamera/internal/software_isp/swstats_cpu.h | 3 +\n src/libcamera/software_isp/debayer_cpu.cpp | 122 +++++++++++++++++++--\n src/libcamera/software_isp/debayer_cpu.h | 9 ++\n src/libcamera/software_isp/debayer_egl.cpp | 25 +++--\n src/libcamera/software_isp/swstats_cpu.cpp | 67 ++++++++++-\n 5 files changed, 202 insertions(+), 24 deletions(-)\n\n\n---\nbase-commit: ad5506544b798539e1d094ec2eac0b2a1ecbdc4d\nchange-id: 20260522-swisp_12p-6ad22e4d08b0\n\nBest regards,", "diff": "diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nindex b5348c6fe..13fa75826 100644\n--- a/include/libcamera/internal/software_isp/swstats_cpu.h\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -98,6 +98,9 @@ private:\n \t/* Bayer 10 bpp packed */\n \tvoid statsBGGR10PLine0(const uint8_t *src[], SwIspStats &stats);\n \tvoid statsGBRG10PLine0(const uint8_t *src[], SwIspStats &stats);\n+\t/* Bayer 12 bpp packed */\n+\tvoid statsBGGR12PLine0(const uint8_t *src[], SwIspStats &stats);\n+\tvoid statsGBRG12PLine0(const uint8_t *src[], SwIspStats &stats);\n \n \tvoid processBayerFrame2(MappedFrameBuffer &in);\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 1f9b24da0..d2596d32b 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -351,6 +351,78 @@ void DebayerCpu::debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[])\n \t}\n }\n \n+template<bool addAlphaByte, bool ccmEnabled>\n+void DebayerCpu::debayer12P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[])\n+{\n+\tconst int widthInBytes = window_.width * 3 / 2;\n+\tconst uint8_t *prev = src[0];\n+\tconst uint8_t *curr = src[1];\n+\tconst uint8_t *next = src[2];\n+\n+\tfor (int x = 0; x < widthInBytes;) {\n+\t\t/* Even pixel */\n+\t\tBGGR_BGR888(2, 1, 1)\n+\t\t/* Odd pixel BGGR -> GBRG */\n+\t\tGBRG_BGR888(1, 2, 1)\n+\t\t/* Skip 3rd src byte with 2 x 4 least-significant-bits */\n+\t\tx++;\n+\t}\n+}\n+\n+template<bool addAlphaByte, bool ccmEnabled>\n+void DebayerCpu::debayer12P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[])\n+{\n+\tconst int widthInBytes = window_.width * 3 / 2;\n+\tconst uint8_t *prev = src[0];\n+\tconst uint8_t *curr = src[1];\n+\tconst uint8_t *next = src[2];\n+\n+\tfor (int x = 0; x < widthInBytes;) {\n+\t\t/* Even pixel */\n+\t\tGRBG_BGR888(2, 1, 1)\n+\t\t/* Odd pixel GRBG -> RGGB */\n+\t\tRGGB_BGR888(1, 2, 1)\n+\t\t/* Skip 3rd src byte with 2 x 4 least-significant-bits */\n+\t\tx++;\n+\t}\n+}\n+\n+template<bool addAlphaByte, bool ccmEnabled>\n+void DebayerCpu::debayer12P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[])\n+{\n+\tconst int widthInBytes = window_.width * 3 / 2;\n+\tconst uint8_t *prev = src[0];\n+\tconst uint8_t *curr = src[1];\n+\tconst uint8_t *next = src[2];\n+\n+\tfor (int x = 0; x < widthInBytes;) {\n+\t\t/* Even pixel */\n+\t\tGBRG_BGR888(2, 1, 1)\n+\t\t/* Odd pixel GBRG -> BGGR */\n+\t\tBGGR_BGR888(1, 2, 1)\n+\t\t/* Skip 3rd src byte with 2 x 4 least-significant-bits */\n+\t\tx++;\n+\t}\n+}\n+\n+template<bool addAlphaByte, bool ccmEnabled>\n+void DebayerCpu::debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[])\n+{\n+\tconst int widthInBytes = window_.width * 3 / 2;\n+\tconst uint8_t *prev = src[0];\n+\tconst uint8_t *curr = src[1];\n+\tconst uint8_t *next = src[2];\n+\n+\tfor (int x = 0; x < widthInBytes;) {\n+\t\t/* Even pixel */\n+\t\tRGGB_BGR888(2, 1, 1)\n+\t\t/* Odd pixel RGGB -> GRBG */\n+\t\tGRBG_BGR888(1, 2, 1)\n+\t\t/* Skip 3rd src byte with 2 x 4 least-significant-bits */\n+\t\tx++;\n+\t}\n+}\n+\n /*\n * Setup the Debayer object according to the passed in parameters.\n * Return 0 on success, a negative errno value on failure\n@@ -360,6 +432,12 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n {\n \tBayerFormat bayerFormat =\n \t\tBayerFormat::fromPixelFormat(inputFormat);\n+\tstd::vector<PixelFormat> outputFormats = { formats::RGB888,\n+\t\t\t\t\t\t formats::XRGB8888,\n+\t\t\t\t\t\t formats::ARGB8888,\n+\t\t\t\t\t\t formats::BGR888,\n+\t\t\t\t\t\t formats::XBGR8888,\n+\t\t\t\t\t\t formats::ABGR8888 };\n \n \tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10 || bayerFormat.bitDepth == 12) &&\n \t bayerFormat.packing == BayerFormat::Packing::None &&\n@@ -367,12 +445,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n \t\tconfig.bpp = (bayerFormat.bitDepth + 7) & ~7;\n \t\tconfig.patternSize.width = 2;\n \t\tconfig.patternSize.height = 2;\n-\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888,\n-\t\t\t\t\t\t\t\t formats::XRGB8888,\n-\t\t\t\t\t\t\t\t formats::ARGB8888,\n-\t\t\t\t\t\t\t\t formats::BGR888,\n-\t\t\t\t\t\t\t\t formats::XBGR8888,\n-\t\t\t\t\t\t\t\t formats::ABGR8888 });\n+\t\tconfig.outputFormats = outputFormats;\n \t\treturn 0;\n \t}\n \n@@ -382,12 +455,17 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n \t\tconfig.bpp = 10;\n \t\tconfig.patternSize.width = 4; /* 5 bytes per *4* pixels */\n \t\tconfig.patternSize.height = 2;\n-\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::RGB888,\n-\t\t\t\t\t\t\t\t formats::XRGB8888,\n-\t\t\t\t\t\t\t\t formats::ARGB8888,\n-\t\t\t\t\t\t\t\t formats::BGR888,\n-\t\t\t\t\t\t\t\t formats::XBGR8888,\n-\t\t\t\t\t\t\t\t formats::ABGR8888 });\n+\t\tconfig.outputFormats = outputFormats;\n+\t\treturn 0;\n+\t}\n+\n+\tif (bayerFormat.bitDepth == 12 &&\n+\t bayerFormat.packing == BayerFormat::Packing::CSI2 &&\n+\t isStandardBayerOrder(bayerFormat.order)) {\n+\t\tconfig.bpp = 12;\n+\t\tconfig.patternSize.width = 2; /* 3 bytes per *2* pixels */\n+\t\tconfig.patternSize.height = 2;\n+\t\tconfig.outputFormats = outputFormats;\n \t\treturn 0;\n \t}\n \n@@ -538,6 +616,26 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat,\n \t\t}\n \t}\n \n+\tif (bayerFormat.bitDepth == 12 &&\n+\t bayerFormat.packing == BayerFormat::Packing::CSI2) {\n+\t\tswitch (bayerFormat.order) {\n+\t\tcase BayerFormat::BGGR:\n+\t\t\tSET_DEBAYER_METHODS(debayer12P_BGBG_BGR888, debayer12P_GRGR_BGR888)\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::GBRG:\n+\t\t\tSET_DEBAYER_METHODS(debayer12P_GBGB_BGR888, debayer12P_RGRG_BGR888)\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::GRBG:\n+\t\t\tSET_DEBAYER_METHODS(debayer12P_GRGR_BGR888, debayer12P_BGBG_BGR888)\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::RGGB:\n+\t\t\tSET_DEBAYER_METHODS(debayer12P_RGRG_BGR888, debayer12P_GBGB_BGR888)\n+\t\t\treturn 0;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n \treturn invalidFmt();\n }\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 68da95083..5281c65cb 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -110,6 +110,15 @@ private:\n \tvoid debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]);\n \ttemplate<bool addAlphaByte, bool ccmEnabled>\n \tvoid debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]);\n+\t/* CSI-2 packed 12-bit raw bayer format (all the 4 orders) */\n+\ttemplate<bool addAlphaByte, bool ccmEnabled>\n+\tvoid debayer12P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);\n+\ttemplate<bool addAlphaByte, bool ccmEnabled>\n+\tvoid debayer12P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);\n+\ttemplate<bool addAlphaByte, bool ccmEnabled>\n+\tvoid debayer12P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]);\n+\ttemplate<bool addAlphaByte, bool ccmEnabled>\n+\tvoid debayer12P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]);\n \n \tstatic int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);\n \tstatic int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);\ndiff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 7b9e02d90..9ea892f11 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -52,16 +52,18 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n \tBayerFormat bayerFormat =\n \t\tBayerFormat::fromPixelFormat(inputFormat);\n \n+\tstd::vector<PixelFormat> outputFormats = { formats::XRGB8888,\n+\t\t\t\t\t\t formats::ARGB8888,\n+\t\t\t\t\t\t formats::XBGR8888,\n+\t\t\t\t\t\t formats::ABGR8888 };\n+\n \tif ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) &&\n \t bayerFormat.packing == BayerFormat::Packing::None &&\n \t isStandardBayerOrder(bayerFormat.order)) {\n \t\tconfig.bpp = (bayerFormat.bitDepth + 7) & ~7;\n \t\tconfig.patternSize.width = 2;\n \t\tconfig.patternSize.height = 2;\n-\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::XRGB8888,\n-\t\t\t\t\t\t\t\t formats::ARGB8888,\n-\t\t\t\t\t\t\t\t formats::XBGR8888,\n-\t\t\t\t\t\t\t\t formats::ABGR8888 });\n+\t\tconfig.outputFormats = outputFormats;\n \t\treturn 0;\n \t}\n \n@@ -71,10 +73,17 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf\n \t\tconfig.bpp = 10;\n \t\tconfig.patternSize.width = 4; /* 5 bytes per *4* pixels */\n \t\tconfig.patternSize.height = 2;\n-\t\tconfig.outputFormats = std::vector<PixelFormat>({ formats::XRGB8888,\n-\t\t\t\t\t\t\t\t formats::ARGB8888,\n-\t\t\t\t\t\t\t\t formats::XBGR8888,\n-\t\t\t\t\t\t\t\t formats::ABGR8888 });\n+\t\tconfig.outputFormats = outputFormats;\n+\t\treturn 0;\n+\t}\n+\n+\tif (bayerFormat.bitDepth == 12 &&\n+\t bayerFormat.packing == BayerFormat::Packing::CSI2 &&\n+\t isStandardBayerOrder(bayerFormat.order)) {\n+\t\tconfig.bpp = 12;\n+\t\tconfig.patternSize.width = 2; /* 3 bytes per *2* pixels */\n+\t\tconfig.patternSize.height = 2;\n+\t\tconfig.outputFormats = outputFormats;\n \t\treturn 0;\n \t}\n \ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 0815ec9a3..2f57a5f33 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -323,6 +323,58 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[], SwIspStats &stats)\n \tSWSTATS_FINISH_LINE_STATS()\n }\n \n+void SwStatsCpu::statsBGGR12PLine0(const uint8_t *src[], SwIspStats &stats)\n+{\n+\tconst uint8_t *src0 = src[1] + window_.x * 3 / 2;\n+\tconst uint8_t *src1 = src[2] + window_.x * 3 / 2;\n+\tconst unsigned int widthInBytes = window_.width * 3 / 2;\n+\n+\tSWSTATS_START_LINE_STATS(uint8_t)\n+\n+\tif (swapLines_)\n+\t\tstd::swap(src0, src1);\n+\n+\t/* x += 6 sample every other 2x2 block */\n+\tfor (unsigned int x = 0; x < widthInBytes; x += 6) {\n+\t\tb = src0[x];\n+\t\tg = src0[x + 1];\n+\t\tg2 = src1[x];\n+\t\tr = src1[x + 1];\n+\n+\t\tg = (g + g2) / 2;\n+\n+\t\tSWSTATS_ACCUMULATE_LINE_STATS(1)\n+\t}\n+\n+\tSWSTATS_FINISH_LINE_STATS()\n+}\n+\n+void SwStatsCpu::statsGBRG12PLine0(const uint8_t *src[], SwIspStats &stats)\n+{\n+\tconst uint8_t *src0 = src[1] + window_.x * 3 / 2;\n+\tconst uint8_t *src1 = src[2] + window_.x * 3 / 2;\n+\tconst unsigned int widthInBytes = window_.width * 3 / 2;\n+\n+\tSWSTATS_START_LINE_STATS(uint8_t)\n+\n+\tif (swapLines_)\n+\t\tstd::swap(src0, src1);\n+\n+\t/* x += 6 sample every other 2x2 block */\n+\tfor (unsigned int x = 0; x < widthInBytes; x += 6) {\n+\t\tg = src0[x];\n+\t\tb = src0[x + 1];\n+\t\tr = src1[x];\n+\t\tg2 = src1[x + 1];\n+\n+\t\tg = (g + g2) / 2;\n+\n+\t\tSWSTATS_ACCUMULATE_LINE_STATS(1)\n+\t}\n+\n+\tSWSTATS_FINISH_LINE_STATS()\n+}\n+\n /**\n * \\brief Reset state to start statistics gathering for a new frame\n * \\param[in] frame The frame number\n@@ -440,10 +492,17 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg, unsigned int stat\n \t\t}\n \t}\n \n-\tif (bayerFormat.bitDepth == 10 &&\n+\tuint8_t bitDepth = bayerFormat.bitDepth;\n+\n+\tif ((bitDepth == 10 || bitDepth == 12) &&\n \t bayerFormat.packing == BayerFormat::Packing::CSI2) {\n+\t\tif (bitDepth == 10)\n+\t\t\tpatternSize_.width = 4; /* 5 bytes per *4* pixels */\n+\t\telse\n+\t\t\tpatternSize_.width = 2; /* 3 bytes for *2* pixels */\n+\n \t\tpatternSize_.height = 2;\n-\t\tpatternSize_.width = 4; /* 5 bytes per *4* pixels */\n+\n \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n \t\tySkipMask_ = 0x02;\n \t\txShift_ = 0;\n@@ -453,12 +512,12 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg, unsigned int stat\n \t\tswitch (bayerFormat.order) {\n \t\tcase BayerFormat::BGGR:\n \t\tcase BayerFormat::GRBG:\n-\t\t\tstats0_ = &SwStatsCpu::statsBGGR10PLine0;\n+\t\t\tstats0_ = (bitDepth == 10) ? &SwStatsCpu::statsBGGR10PLine0 : &SwStatsCpu::statsBGGR12PLine0;\n \t\t\tswapLines_ = bayerFormat.order == BayerFormat::GRBG;\n \t\t\treturn 0;\n \t\tcase BayerFormat::GBRG:\n \t\tcase BayerFormat::RGGB:\n-\t\t\tstats0_ = &SwStatsCpu::statsGBRG10PLine0;\n+\t\t\tstats0_ = (bitDepth == 10) ? &SwStatsCpu::statsGBRG10PLine0 : &SwStatsCpu::statsGBRG12PLine0;\n \t\t\tswapLines_ = bayerFormat.order == BayerFormat::RGGB;\n \t\t\treturn 0;\n \t\tdefault:\n", "prefixes": [ "v2" ] }