Patch Detail
Show a patch.
GET /api/1.1/patches/19319/?format=api
{ "id": 19319, "url": "https://patchwork.libcamera.org/api/1.1/patches/19319/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19319/", "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": "<20231214121350.206015-5-hdegoede@redhat.com>", "date": "2023-12-14T12:13:42", "name": "[libcamera-devel,04/11] libcamera: software_isp: Add SwStatsCpu class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "484129f5b4f7749cc32117e57b53b61000c25e92", "submitter": { "id": 102, "url": "https://patchwork.libcamera.org/api/1.1/people/102/?format=api", "name": "Hans de Goede", "email": "hdegoede@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19319/mbox/", "series": [ { "id": 4117, "url": "https://patchwork.libcamera.org/api/1.1/series/4117/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4117", "date": "2023-12-14T12:13:38", "name": "libcamera: introduce Software ISP and Software IPA", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4117/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19319/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19319/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 F1249BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Dec 2023 12:14:06 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 936DA62B58;\n\tThu, 14 Dec 2023 13:14:06 +0100 (CET)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 20E1C62B52\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Dec 2023 13:14:04 +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-561-ubUzBS2MNyar7QWjPNJQIg-1; Thu, 14 Dec 2023 07:13:58 -0500", "from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3])\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 5DD4E848C07;\n\tThu, 14 Dec 2023 12:13:58 +0000 (UTC)", "from shalem.redhat.com (unknown [10.39.194.72])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id ECD581121306;\n\tThu, 14 Dec 2023 12:13:56 +0000 (UTC)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1702556046;\n\tbh=wzZtq87pwIp4bkDwv99FE+gohvDyk6GlJxITW4iDdh8=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=HbZvufE3ug2Dtga1XoTJJJyl1ISAE6DAKMRRHPuGIyDmo4nA1MLOOHC0i6damns1d\n\tDTpUdjHMA28v6+cF0lHobPvysPJ7FO9E97dZFiQjXR/4AQ1RK3VwRAHWmga2T9WVGz\n\twuhhOT2nsg2Z74RyIVEDrq0NtCjZwDCXxZLOyNVhyJG2Es3aqtRHET19cMsDf9EQXp\n\tkjkDHe29zkhvsBWmpVwwasKHy9TLiecXTIDJTVMyrVfHIBD8sxARFedlRAHwXXKCCl\n\tpJaGzsyU6B9Qz5v6xsJFYRgRU/PUyctRsKmwOcQA7jERvjFOp2TUREVq0K0j5U0WuR\n\tYawlV1mQVK2qQ==", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1702556043;\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=dWnOKmi+sc5buSYcLiTXGs4X2NRo61ufepPWcmP87vM=;\n\tb=T/k+kqD9sfmgJ6Jfv9Yd2XAVUIHpJmnuNmJRlrf6c3mlXlxceqSTQ1mkEefGWaPzxbl9RD\n\twjp87iTU5iftQTi9UGHUUeOCavIFKPC+nvnJSuqnXqX5rQbrRQht+XgvPxZkt5nYk5SKBc\n\tqcX79EsSeVEiOsFl24KLKKomIJLDpEs=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"T/k+kqD9\"; \n\tdkim-atps=neutral", "X-MC-Unique": "ubUzBS2MNyar7QWjPNJQIg-1", "To": "libcamera-devel@lists.libcamera.org,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>", "Date": "Thu, 14 Dec 2023 13:13:42 +0100", "Message-ID": "<20231214121350.206015-5-hdegoede@redhat.com>", "In-Reply-To": "<20231214121350.206015-1-hdegoede@redhat.com>", "References": "<20231214121350.206015-1-hdegoede@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.3", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true", "Subject": "[libcamera-devel] [PATCH 04/11] libcamera: software_isp: Add\n\tSwStatsCpu class", "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>", "From": "Hans de Goede via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Hans de Goede <hdegoede@redhat.com>", "Cc": "Maxime Ripard <mripard@redhat.com>, g.martti@gmail.com,\n\tt.langendam@gmail.com, srinivas.kandagatla@linaro.org,\n\tPavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>, admin@dennisbonke.com", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add a CPU based SwStats implementation for SoftwareISP / SoftIPA use.\n\nCo-authored-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nSuggested-by: Pavel Machek <pavel@ucw.cz>\nSigned-off-by: Pavel Machek <pavel@ucw.cz>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n .../internal/software_isp/meson.build | 1 +\n .../internal/software_isp/swstats_cpu.h | 46 +++++\n src/libcamera/software_isp/meson.build | 1 +\n src/libcamera/software_isp/swstats_cpu.cpp | 169 ++++++++++++++++++\n 4 files changed, 217 insertions(+)\n create mode 100644 include/libcamera/internal/software_isp/swstats_cpu.h\n create mode 100644 src/libcamera/software_isp/swstats_cpu.cpp", "diff": "diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build\nindex 1c43acc4..1d9e4018 100644\n--- a/include/libcamera/internal/software_isp/meson.build\n+++ b/include/libcamera/internal/software_isp/meson.build\n@@ -3,4 +3,5 @@\n libcamera_internal_headers += files([\n 'swisp_stats.h',\n 'swstats.h',\n+ 'swstats_cpu.h',\n ])\ndiff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nnew file mode 100644\nindex 00000000..0ceb995f\n--- /dev/null\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -0,0 +1,46 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Linaro Ltd\n+ * Copyright (C) 2023, Red Hat Inc.\n+ *\n+ * Authors:\n+ * Hans de Goede <hdegoede@redhat.com> \n+ *\n+ * swstats_cpu.h - CPU based software statistics implementation\n+ */\n+\n+#pragma once\n+\n+#include \"libcamera/internal/shared_mem_object.h\"\n+#include \"libcamera/internal/software_isp/swisp_stats.h\"\n+#include \"libcamera/internal/software_isp/swstats.h\"\n+\n+namespace libcamera {\n+\n+class SwStatsCpu : public SwStats\n+{\n+public:\n+\tSwStatsCpu();\n+\t~SwStatsCpu() { }\n+\n+\tbool isValid() const { return sharedStats_.fd().isValid(); }\n+\tconst SharedFD &getStatsFD() { return sharedStats_.fd(); }\n+\tint configure(const StreamConfiguration &inputCfg);\n+\t/* FIXME this should be dropped once AWB has moved to the IPA */\n+\tSwIspStats getStats() { return *sharedStats_; }\n+private:\n+\tvoid statsBGGR10PLine0(const uint8_t *src, unsigned int stride);\n+\tvoid statsGBRG10PLine0(const uint8_t *src, unsigned int stride);\n+\tvoid statsGRBG10PLine0(const uint8_t *src, unsigned int stride);\n+\tvoid statsRGGB10PLine0(const uint8_t *src, unsigned int stride);\n+\tvoid resetStats(void);\n+\tvoid finishStats(void);\n+\n+\tSharedMemObject<SwIspStats> sharedStats_;\n+\tSwIspStats stats_;\n+\n+\tunsigned int bright_sum_;\n+\tunsigned int too_bright_sum_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build\nindex 9359075d..d31c6217 100644\n--- a/src/libcamera/software_isp/meson.build\n+++ b/src/libcamera/software_isp/meson.build\n@@ -2,4 +2,5 @@\n \n libcamera_sources += files([\n \t'swstats.cpp',\n+\t'swstats_cpu.cpp',\n ])\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nnew file mode 100644\nindex 00000000..15f23953\n--- /dev/null\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -0,0 +1,169 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Linaro Ltd\n+ * Copyright (C) 2023, Red Hat Inc.\n+ *\n+ * Authors:\n+ * Hans de Goede <hdegoede@redhat.com> \n+ *\n+ * swstats_cpu.cpp - CPU based software statistics implementation\n+ */\n+\n+#include \"libcamera/internal/software_isp/swstats_cpu.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/stream.h>\n+\n+#include \"libcamera/internal/bayer_format.h\"\n+\n+namespace libcamera {\n+\n+SwStatsCpu::SwStatsCpu()\n+\t: SwStats()\n+{\n+\tsharedStats_ = SharedMemObject<SwIspStats>(\"softIsp_stats\");\n+\tif (!sharedStats_.fd().isValid())\n+\t\tLOG(SwStats, Error)\n+\t\t\t<< \"Failed to create shared memory for statistics\";\n+}\n+\n+/* for brightness values in the 0 to 255 range: */\n+static const unsigned int BRIGHT_LVL = 170U << 8;\n+static const unsigned int TOO_BRIGHT_LVL = 210U << 8;\n+\n+static const unsigned int RED_Y_MUL = 77;\t\t/* 0.30 * 256 */\n+static const unsigned int GREEN_Y_MUL = 150;\t\t/* 0.59 * 256 */\n+static const unsigned int BLUE_Y_MUL = 29;\t\t/* 0.11 * 256 */\n+\n+static inline __attribute__((always_inline)) void\n+statsBayer10P(const int width, const uint8_t *src0, const uint8_t *src1, bool bggr, unsigned int &bright_sum_, unsigned int &too_bright_sum_, SwIspStats &stats_)\n+{\n+\tconst int width_in_bytes = width * 5 / 4;\n+\tuint8_t r, g, b, g2;\n+\tunsigned int y_val;\n+\tunsigned int sumR = 0;\n+\tunsigned int sumG = 0;\n+\tunsigned int sumB = 0;\n+\n+\tunsigned int bright_sum = 0;\n+\tunsigned int too_bright_sum = 0;\n+\n+\tfor (int x = 0; x < width_in_bytes; x += 5) {\n+\t\tif (bggr) {\n+\t\t\t/* BGGR */\n+\t\t\tb = src0[x];\n+\t\t\tg = src0[x + 1];\n+\t\t\tg2 = src1[x];\n+\t\t\tr = src1[x + 1];\n+\t\t} else {\n+\t\t\t/* GBRG */\n+\t\t\tg = src0[x];\n+\t\t\tb = src0[x + 1];\n+\t\t\tr = src1[x];\n+\t\t\tg2 = src1[x + 1];\n+\t\t}\n+\t\tg = g + g2 / 2;\n+\n+\t\tsumR += r;\n+\t\tsumG += g;\n+\t\tsumB += b;\n+\n+\t\ty_val = r * RED_Y_MUL;\n+\t\ty_val += g * GREEN_Y_MUL;\n+\t\ty_val += b * BLUE_Y_MUL;\n+\t\tif (y_val > BRIGHT_LVL) ++bright_sum;\n+\t\tif (y_val > TOO_BRIGHT_LVL) ++too_bright_sum;\n+\t}\n+\n+\tstats_.sumR_ += sumR;\n+\tstats_.sumG_ += sumG;\n+\tstats_.sumB_ += sumB;\n+\n+\tbright_sum_ += bright_sum;\n+\ttoo_bright_sum_ += too_bright_sum;\n+}\n+\n+void SwStatsCpu::statsBGGR10PLine0(const uint8_t *src, unsigned int stride)\n+{\n+\tstatsBayer10P(window_.width, src, src + stride, true, bright_sum_, too_bright_sum_, stats_);\n+}\n+\n+void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src, unsigned int stride)\n+{\n+\tstatsBayer10P(window_.width, src, src + stride, false, bright_sum_, too_bright_sum_, stats_);\n+}\n+\n+void SwStatsCpu::statsGRBG10PLine0(const uint8_t *src, unsigned int stride)\n+{\n+\t/* GRBG is BGGR with the lines swapped */\n+\tstatsBayer10P(window_.width, src + stride, src, true, bright_sum_, too_bright_sum_, stats_);\n+}\n+\n+void SwStatsCpu::statsRGGB10PLine0(const uint8_t *src, unsigned int stride)\n+{\n+\t/* RGGB is GBRG with the lines swapped */\n+\tstatsBayer10P(window_.width, src + stride, src, false, bright_sum_, too_bright_sum_, stats_);\n+}\n+\n+void SwStatsCpu::resetStats(void)\n+{\n+\tstats_.sumR_ = 0;\n+\tstats_.sumB_ = 0;\n+\tstats_.sumG_ = 0;\n+\n+\tbright_sum_ = 0;\n+\ttoo_bright_sum_ = 0;\n+}\n+\n+void SwStatsCpu::finishStats(void)\n+{\n+\t/* calculate the fractions of \"bright\" and \"too bright\" pixels */\n+\tstats_.bright_ratio = (float)bright_sum_ / (window_.height * window_.width / 16);\n+\tstats_.too_bright_ratio = (float)too_bright_sum_ / (window_.height * window_.width / 16);\n+\n+\t*sharedStats_ = stats_;\n+\tstatsReady.emit(0);\n+}\n+\n+int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n+{\n+\tBayerFormat bayerFormat =\n+\t\tBayerFormat::fromPixelFormat(inputCfg.pixelFormat);\n+\n+\tstartFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::resetStats;\n+\tfinishFrame_ = (SwStats::statsVoidFn)&SwStatsCpu::finishStats;\n+\n+\tif (bayerFormat.bitDepth == 10 &&\n+\t bayerFormat.packing == BayerFormat::Packing::CSI2) {\n+\t\tbpp_ = 10;\n+\t\tpatternSize_.height = 2;\n+\t\tpatternSize_.width = 4; /* 5 bytes per *4* pixels */\n+\t\ty_skip_mask_ = 0x0c; /* Skip every 3th and 4th line */\n+\t\tx_shift_ = 0;\n+\n+\t\tswitch (bayerFormat.order) {\n+\t\tcase BayerFormat::BGGR:\n+\t\t\tstats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsBGGR10PLine0;\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::GBRG:\n+\t\t\tstats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsGBRG10PLine0;\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::GRBG:\n+\t\t\tstats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsGRBG10PLine0;\n+\t\t\treturn 0;\n+\t\tcase BayerFormat::RGGB:\n+\t\t\tstats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsRGGB10PLine0;\n+\t\t\treturn 0;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t/* } else if (future supported fmts) { ... */\n+\t}\n+\n+\tLOG(SwStats, Info)\n+\t\t<< \"Unsupported input format \" << inputCfg.pixelFormat.toString();\n+\treturn -EINVAL;\n+}\n+\n+} /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "04/11" ] }