{"id":21575,"url":"https://patchwork.libcamera.org/api/patches/21575/?format=json","web_url":"https://patchwork.libcamera.org/patch/21575/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20241009200110.275544-5-hdegoede@redhat.com>","date":"2024-10-09T20:01:10","name":"[RFC,4/4] libcamera: swstats_cpu: Add processFrame() method","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c8c170d1dc9757b5121aa723903268c6ca0d38c5","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21575/mbox/","series":[{"id":4678,"url":"https://patchwork.libcamera.org/api/series/4678/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4678","date":"2024-10-09T20:01:06","name":"libcamera: swstats_cpu: Add processFrame() method","version":1,"mbox":"https://patchwork.libcamera.org/series/4678/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21575/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21575/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 5DF5AC32E7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Oct 2024 20:01:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E597565371;\n\tWed,  9 Oct 2024 22:01:26 +0200 (CEST)","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 7455B65371\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 22:01:23 +0200 (CEST)","from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-306-8ws9KG8ZN2Sjhp-hz2nD4w-1;\n\tWed, 09 Oct 2024 16:01:21 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.17])\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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid 4CFEE1956096 for <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 20:01:20 +0000 (UTC)","from shalem.redhat.com (unknown [10.39.192.36])\n\tby mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id E5E991956052; Wed,  9 Oct 2024 20:01:18 +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=\"WX+TmK01\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1728504082;\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=BzGMLtbHgThgWiWQw3PO/tTyIxnrqi/KRjbj0UyKIwA=;\n\tb=WX+TmK01EDIMYSTPGVLSfGcLq1UbEJmiuEkCYa0OVTB2g+O15F9L3kMAtjFAiF0/W1EA2i\n\tinD6O3jEBcMIyFKqB7DbrhV/ZP9CIf7s4N2OAghL2VEmmc0wj7LM6yr6uf8fNtYZo/leb4\n\tEdZAa9tVv6k8JscmrDtLK3reg2PDiqs=","X-MC-Unique":"8ws9KG8ZN2Sjhp-hz2nD4w-1","From":"Hans de Goede <hdegoede@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>, Maxime Ripard <mripard@redhat.com>, \n\tHans de Goede <hdegoede@redhat.com>","Subject":"[RFC 4/4] libcamera: swstats_cpu: Add processFrame() method","Date":"Wed,  9 Oct 2024 22:01:10 +0200","Message-ID":"<20241009200110.275544-5-hdegoede@redhat.com>","In-Reply-To":"<20241009200110.275544-1-hdegoede@redhat.com>","References":"<20241009200110.275544-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","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":"Add a method to the SwstatsCpu class to process a whole Framebuffer in\none go, rather then line by line. This is useful for gathering stats\nwhen debayering is not necessary or is not done on the CPU.\n\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n src/libcamera/software_isp/swstats_cpu.cpp | 72 ++++++++++++++++++++++\n src/libcamera/software_isp/swstats_cpu.h   | 10 +++\n 2 files changed, 82 insertions(+)","diff":"diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 5e4246a9..117147c2 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -16,6 +16,7 @@\n #include <libcamera/stream.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/mapped_framebuffer.h\"\n \n namespace libcamera {\n \n@@ -363,8 +364,11 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n \tBayerFormat bayerFormat =\n \t\tBayerFormat::fromPixelFormat(inputCfg.pixelFormat);\n \n+\tstride_ = inputCfg.stride;\n+\n \tif (bayerFormat.packing == BayerFormat::Packing::None &&\n \t    setupStandardBayerOrder(bayerFormat.order) == 0) {\n+\t\tbpp_ = (bayerFormat.bitDepth + 7) & ~7;\n \t\tswitch (bayerFormat.bitDepth) {\n \t\tcase 8:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n@@ -385,6 +389,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n \t\tySkipMask_ = 0x02;\n \t\txShift_ = 0;\n+\t\tbpp_ = 10;\n \n \t\tswitch (bayerFormat.order) {\n \t\tcase BayerFormat::BGGR:\n@@ -425,4 +430,71 @@ void SwStatsCpu::setWindow(const Rectangle &window)\n \twindow_.height &= ~(patternSize_.height - 1);\n }\n \n+void SwStatsCpu::processFrame2(const uint8_t *src)\n+{\n+\tunsigned int yEnd = window_.y + window_.height;\n+\tconst uint8_t *linePointers[3];\n+\n+\t/* Adjust src to top left corner of the window */\n+\tsrc += window_.y * stride_ + window_.x * bpp_ / 8;\n+\n+\tfor (unsigned int y = window_.y; y < yEnd; y += 2) {\n+\t\tif (y & ySkipMask_) {\n+\t\t\tsrc += stride_ * 2;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* linePointers[0] is not used by any stats0_ functions */\n+\t\tlinePointers[1] = src;\n+\t\tlinePointers[2] = src + stride_;\n+\t\t(this->*stats0_)(linePointers);\n+\t\tsrc += stride_ * 2;\n+\t}\n+}\n+\n+void SwStatsCpu::processFrame4(const uint8_t *src)\n+{\n+\tconst unsigned int yEnd = window_.y + window_.height;\n+\tconst uint8_t *linePointers[4];\n+\n+\t/* Adjust src to top left corner of the window */\n+\tsrc += window_.y * stride_ + window_.x * bpp_ / 8;\n+\n+\tfor (unsigned int y = window_.y; y < yEnd; y += 4) {\n+\t\tif (y & ySkipMask_) {\n+\t\t\tsrc += stride_ * 4;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* linePointers[0] and [1] are not used by 4 line pattern stats0_ functions */\n+\t\tlinePointers[2] = src;\n+\t\tlinePointers[3] = src + stride_;\n+\t\t(this->*stats0_)(linePointers);\n+\t\tsrc += stride_ * 2;\n+\n+\t\tlinePointers[2] = src;\n+\t\tlinePointers[3] = src + stride_;\n+\t\t(this->*stats2_)(linePointers);\n+\t\tsrc += stride_ * 2;\n+\t}\n+}\n+\n+void SwStatsCpu::processFrame(FrameBuffer *input)\n+{\n+\tbench_.startFrame();\n+\n+\tMappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read);\n+\tif (!in.isValid()) {\n+\t\tLOG(SwStatsCpu, Error) << \"mmap-ing buffer(s) failed\";\n+\t\treturn;\n+\t}\n+\n+\tif (patternSize_.height == 2)\n+\t\tprocessFrame2(in.planes()[0].data());\n+\telse\n+\t\tprocessFrame4(in.planes()[0].data());\n+\n+\tbench_.finishFrame();\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\nindex 26a2f462..bb178a04 100644\n--- a/src/libcamera/software_isp/swstats_cpu.h\n+++ b/src/libcamera/software_isp/swstats_cpu.h\n@@ -18,9 +18,12 @@\n #include <libcamera/geometry.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/framebuffer.h\"\n #include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/swisp_stats.h\"\n \n+#include \"benchmark.h\"\n+\n namespace libcamera {\n \n class PixelFormat;\n@@ -42,6 +45,7 @@ public:\n \tvoid setWindow(const Rectangle &window);\n \tvoid startFrame();\n \tvoid finishFrame(uint32_t frame, uint32_t bufferId);\n+\tvoid processFrame(FrameBuffer *input);\n \n \tvoid processLine0(unsigned int y, const uint8_t *src[])\n \t{\n@@ -77,6 +81,9 @@ private:\n \tvoid statsBGGR10PLine0(const uint8_t *src[]);\n \tvoid statsGBRG10PLine0(const uint8_t *src[]);\n \n+\tvoid processFrame2(const uint8_t *src);\n+\tvoid processFrame4(const uint8_t *src);\n+\n \t/* Variables set by configure(), used every line */\n \tstatsProcessFn stats0_;\n \tstatsProcessFn stats2_;\n@@ -89,9 +96,12 @@ private:\n \tSize patternSize_;\n \n \tunsigned int xShift_;\n+\tunsigned int bpp_; /* Memory used per pixel, not precision */\n+\tunsigned int stride_;\n \n \tSharedMemObject<SwIspStats> sharedStats_;\n \tSwIspStats stats_;\n+\tBenchmark bench_;\n };\n \n } /* namespace libcamera */\n","prefixes":["RFC","4/4"]}