{"id":19770,"url":"https://patchwork.libcamera.org/api/1.1/patches/19770/?format=json","web_url":"https://patchwork.libcamera.org/patch/19770/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240319123622.675599-14-mzamazal@redhat.com>","date":"2024-03-19T12:36:00","name":"[v6,13/18] libcamera: swstats_cpu: Add support for 8, 10 and 12 bpp unpacked bayer input","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a009f8e18df4b9704f585e6c64b7c44c303a0dfb","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/1.1/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19770/mbox/","series":[{"id":4231,"url":"https://patchwork.libcamera.org/api/1.1/series/4231/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4231","date":"2024-03-19T12:35:47","name":"libcamera: introduce Software ISP and Software IPA","version":6,"mbox":"https://patchwork.libcamera.org/series/4231/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19770/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19770/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 75D36C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Mar 2024 12:37:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 188BA62D37;\n\tTue, 19 Mar 2024 13:37:35 +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 EB6FB62D2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Mar 2024 13:37:32 +0100 (CET)","from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n\t[66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-170-GVXZJ16cPDmcYtEr7igRnA-1; Tue, 19 Mar 2024 08:37:28 -0400","from smtp.corp.redhat.com\n\t(int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7])\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 90E0480026B;\n\tTue, 19 Mar 2024 12:37:27 +0000 (UTC)","from nuthatch.redhat.com (unknown [10.45.226.119])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id DB4351C060A6;\n\tTue, 19 Mar 2024 12:37:25 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"bagBq9Hl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1710851851;\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=xpxRtnwE9qEZI2OeeWgRCKDmS6DLlgupCI1EjvDqThk=;\n\tb=bagBq9HlgfqrHnEQVKnhZywgGywsRKUJ8FzOE6O8JQgjw/5FXh84Ev+2kO0uaU5WLeGkhm\n\tmsVfk30VD1GLGktGJfbTC/Z2oaFTfn4A0yKsygpj6srGAogXU+yOQzIx2X3M1fEk0jegC6\n\tHB7e+OhuB2txX3n5MprOt4byPz8rqTc=","X-MC-Unique":"GVXZJ16cPDmcYtEr7igRnA-1","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Hans de Goede <hdegoede@redhat.com>,\n\tAndrey Konovalov <andrey.konovalov.ynk@gmail.com>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tMaxime Ripard <mripard@redhat.com>, Milan Zamazal <mzamazal@redhat.com>, \n\tPavel Machek <pavel@ucw.cz>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v6 13/18] libcamera: swstats_cpu: Add support for 8,\n\t10 and 12 bpp unpacked bayer input","Date":"Tue, 19 Mar 2024 13:36:00 +0100","Message-ID":"<20240319123622.675599-14-mzamazal@redhat.com>","In-Reply-To":"<20240319123622.675599-1-mzamazal@redhat.com>","References":"<20240319123622.675599-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.11.54.7","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Hans de Goede <hdegoede@redhat.com>\n\nAdd support for 8, 10 and 12 bpp unpacked bayer input for all 4 standard\nbayer orders.\n\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\nReviewed-by: Pavel Machek <pavel@ucw.cz>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n src/libcamera/software_isp/swstats_cpu.cpp | 128 +++++++++++++++++++++\n src/libcamera/software_isp/swstats_cpu.h   |   9 ++\n 2 files changed, 137 insertions(+)","diff":"diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 448d0e4c..be310f56 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -71,6 +71,83 @@ static const unsigned int kBlueYMul = 29; /* 0.114 * 256 */\n \tstats_.sumG_ += sumG;       \\\n \tstats_.sumB_ += sumB;\n \n+void SwStatsCpu::statsBGGR8Line0(const uint8_t *src[])\n+{\n+\tconst uint8_t *src0 = src[1] + window_.x;\n+\tconst uint8_t *src1 = src[2] + window_.x;\n+\n+\tSWSTATS_START_LINE_STATS(uint8_t)\n+\n+\tif (swapLines_)\n+\t\tstd::swap(src0, src1);\n+\n+\t/* x += 4 sample every other 2x2 block */\n+\tfor (int x = 0; x < (int)window_.width; x += 4) {\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::statsBGGR10Line0(const uint8_t *src[])\n+{\n+\tconst uint16_t *src0 = (const uint16_t *)src[1] + window_.x;\n+\tconst uint16_t *src1 = (const uint16_t *)src[2] + window_.x;\n+\n+\tSWSTATS_START_LINE_STATS(uint16_t)\n+\n+\tif (swapLines_)\n+\t\tstd::swap(src0, src1);\n+\n+\t/* x += 4 sample every other 2x2 block */\n+\tfor (int x = 0; x < (int)window_.width; x += 4) {\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\t/* divide Y by 4 for 10 -> 8 bpp value */\n+\t\tSWSTATS_ACCUMULATE_LINE_STATS(4)\n+\t}\n+\n+\tSWSTATS_FINISH_LINE_STATS()\n+}\n+\n+void SwStatsCpu::statsBGGR12Line0(const uint8_t *src[])\n+{\n+\tconst uint16_t *src0 = (const uint16_t *)src[1] + window_.x;\n+\tconst uint16_t *src1 = (const uint16_t *)src[2] + window_.x;\n+\n+\tSWSTATS_START_LINE_STATS(uint16_t)\n+\n+\tif (swapLines_)\n+\t\tstd::swap(src0, src1);\n+\n+\t/* x += 4 sample every other 2x2 block */\n+\tfor (int x = 0; x < (int)window_.width; x += 4) {\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\t/* divide Y by 16 for 12 -> 8 bpp value */\n+\t\tSWSTATS_ACCUMULATE_LINE_STATS(16)\n+\t}\n+\n+\tSWSTATS_FINISH_LINE_STATS()\n+}\n+\n void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src[])\n {\n \tconst uint8_t *src0 = src[1] + window_.x * 5 / 4;\n@@ -147,6 +224,42 @@ void SwStatsCpu::finishFrame(void)\n \tstatsReady.emit(0);\n }\n \n+/**\n+ * \\brief Setup SwStatsCpu object for standard Bayer orders\n+ * \\param[in] order The Bayer order\n+ *\n+ * Check if order is a standard Bayer order and setup xShift_ and swapLines_\n+ * so that a single BGGR stats function can be used for all 4 standard orders.\n+ */\n+int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order)\n+{\n+\tswitch (order) {\n+\tcase BayerFormat::BGGR:\n+\t\txShift_ = 0;\n+\t\tswapLines_ = false;\n+\t\tbreak;\n+\tcase BayerFormat::GBRG:\n+\t\txShift_ = 1; /* BGGR -> GBRG */\n+\t\tswapLines_ = false;\n+\t\tbreak;\n+\tcase BayerFormat::GRBG:\n+\t\txShift_ = 0;\n+\t\tswapLines_ = true; /* BGGR -> GRBG */\n+\t\tbreak;\n+\tcase BayerFormat::RGGB:\n+\t\txShift_ = 1; /* BGGR -> GBRG */\n+\t\tswapLines_ = true; /* GBRG -> RGGB */\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tpatternSize_.height = 2;\n+\tpatternSize_.width = 2;\n+\tySkipMask_ = 0x02; /* Skip every 3th and 4th line */\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Configure the statistics object for the passed in input format.\n  * \\param[in] inputCfg The input format\n@@ -158,6 +271,21 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n \tBayerFormat bayerFormat =\n \t\tBayerFormat::fromPixelFormat(inputCfg.pixelFormat);\n \n+\tif (bayerFormat.packing == BayerFormat::Packing::None &&\n+\t    setupStandardBayerOrder(bayerFormat.order) == 0) {\n+\t\tswitch (bayerFormat.bitDepth) {\n+\t\tcase 8:\n+\t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n+\t\t\treturn 0;\n+\t\tcase 10:\n+\t\t\tstats0_ = &SwStatsCpu::statsBGGR10Line0;\n+\t\t\treturn 0;\n+\t\tcase 12:\n+\t\t\tstats0_ = &SwStatsCpu::statsBGGR12Line0;\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n \tif (bayerFormat.bitDepth == 10 &&\n \t    bayerFormat.packing == BayerFormat::Packing::CSI2) {\n \t\tpatternSize_.height = 2;\ndiff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\nindex 0ac9ae71..bbbcf69b 100644\n--- a/src/libcamera/software_isp/swstats_cpu.h\n+++ b/src/libcamera/software_isp/swstats_cpu.h\n@@ -17,6 +17,7 @@\n \n #include <libcamera/geometry.h>\n \n+#include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/swisp_stats.h\"\n \n@@ -120,6 +121,14 @@ private:\n \t */\n \tusing statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);\n \n+\tint setupStandardBayerOrder(BayerFormat::Order order);\n+\t/* Bayer 8 bpp unpacked */\n+\tvoid statsBGGR8Line0(const uint8_t *src[]);\n+\t/* Bayer 10 bpp unpacked */\n+\tvoid statsBGGR10Line0(const uint8_t *src[]);\n+\t/* Bayer 12 bpp unpacked */\n+\tvoid statsBGGR12Line0(const uint8_t *src[]);\n+\t/* Bayer 10 bpp packed */\n \tvoid statsBGGR10PLine0(const uint8_t *src[]);\n \tvoid statsGBRG10PLine0(const uint8_t *src[]);\n \n","prefixes":["v6","13/18"]}