{"id":23511,"url":"https://patchwork.libcamera.org/api/patches/23511/?format=json","web_url":"https://patchwork.libcamera.org/patch/23511/","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":"<20250611013245.133785-6-bryan.odonoghue@linaro.org>","date":"2025-06-11T01:32:15","name":"[05/35] libcamera: swstats_cpu: Add processFrame() method","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2d17decffe9749a830f95c0f75ce6aaed8ab3e81","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/?format=json","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23511/mbox/","series":[{"id":5212,"url":"https://patchwork.libcamera.org/api/series/5212/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5212","date":"2025-06-11T01:32:10","name":"Add GLES 2.0 GPUISP to libcamera","version":1,"mbox":"https://patchwork.libcamera.org/series/5212/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23511/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23511/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 45CE9BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Jun 2025 01:33:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 861DD68DC9;\n\tWed, 11 Jun 2025 03:33:18 +0200 (CEST)","from mail-wm1-x329.google.com (mail-wm1-x329.google.com\n\t[IPv6:2a00:1450:4864:20::329])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 98CA368DC3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Jun 2025 03:33:16 +0200 (CEST)","by mail-wm1-x329.google.com with SMTP id\n\t5b1f17b1804b1-45300c82c1cso12448265e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Jun 2025 18:33:16 -0700 (PDT)","from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4532514138asm5680625e9.3.2025.06.10.18.33.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 10 Jun 2025 18:33:15 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"Y5j/eX2E\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1749605596; x=1750210396;\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=m1BLltBsmdQhPvHqn+5sDHtKgqD170z2rc524w52XgE=;\n\tb=Y5j/eX2EeDA8igfTsXOYnFAvXsrRVH4fxjWZdwgBcrD5+vr6CL5C2l+KlWhgUqcUax\n\tGE4bEs27OuCgttqiu9BrePb+Jj+IG9wkwDiev5ddooF0krMVggbdDxyo1AYt0LAg2vFg\n\tW1uuNty+wlYjhYe7YZD2Q5HUDxxofRv6Hpi+6jJaNkJsXlDaZb6kNHywmNIMZPB7kVfp\n\td1S9nzYztPbIzw33a/2g+0QMyDkTBMaljJHUrtss9wsQt66C2vUbdwJzwO7QjlpeS1bG\n\t6X0Wa4Bq0uEMNiElKR+ZOTwUD4PCYDUTvI5nXS3nHGYX/E+cgHw3qMOTLiWMI/QvepoO\n\tyH4A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1749605596; x=1750210396;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=m1BLltBsmdQhPvHqn+5sDHtKgqD170z2rc524w52XgE=;\n\tb=NDQY3rcEfB2eBbpkNnK8d/aiyZeccdQedz8iQXFeb1zcEIMsMUn/1FLbLtxfWxAlUu\n\tiby4+SvKEwZLVRqoQ4IDA98lFijoR9+SmmaNgZhMo+oCjs8JBL3qNyXj0lwmthaCDbe+\n\tRNGZqfyC0IT3rwuQEez9skoFEPsw6i5FXZ4mexcJL30CAJfEX00xzOojOv9ck5YjwZOt\n\tIzDkxRUmLIpj9St97IfAEc4gAnNejLLX4wI7frykrnf8wo5raLFdYy7478q7xS4wnq0b\n\tx0F7XDgUNPQb8lcnO5HD3ZehfODmU35ntW4DYYj2pKEmpSSvTPX+Ijag9lkmVF7nAVOh\n\td2oA==","X-Gm-Message-State":"AOJu0YxNOKhB376PN5Tb5AELnvwBoZO5lRhburXKPlkqbp+s7Rv5YJwq\n\tVFq6oSW0Dm4K/T8pWAxszu3HBI6f8vxw/63g8dNpj6oX6kgHBkuMrJpOHHIMH+7Qrvtso4ZQFQq\n\tQtpQSfEk=","X-Gm-Gg":"ASbGnct4aHhWXntiEUKBP4ARKo78/TXnfd0M/p/o0NjLaBrVloOEbW5a8OKK7r1Rapj\n\t0uXuDC+7LJNEvkE1MKWpdTskP/tpYM3t5tauhKxNooMlVnmNRlX4zn8vLNi+1W9yL8ogc30Jg/A\n\tks+/lAJfU9KnkpSZ1Cr0erVDXlFjRixMYYlv4PgomcewQ3aGJs2KoUl7JCQVlMqNcQ2zvS1nqrf\n\t2h2rQPOOqrISp0fTqi6PSIzn7T7f2Fs2/H70LlKkgrxEal7X+gpmh5GYz6PTgqdoy7Jlyqy6hhA\n\tYz9z0dnuZVp3H7Z7rR4xb7J8t9vd0yMJZekRHwUFLKbt7ZwRohth9Gyo7gY5XhtMQBWF6eidBIb\n\tTx3KrH8UcJl/9FFUWaRqwRfy5FG2mGq58Qt3yPOwNLxASBWf1sPFB","X-Google-Smtp-Source":"AGHT+IHBNIkT76W547r/SoPZrG8WOAN7YjiFswyXT4vhEJ6KqEO+2ALh+5EfbuWiaQOtE0ThdRffSA==","X-Received":"by 2002:a05:600c:3e85:b0:43c:f629:66f4 with SMTP id\n\t5b1f17b1804b1-45324cfb301mr7135975e9.0.1749605595892; \n\tTue, 10 Jun 2025 18:33:15 -0700 (PDT)","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"Hans de Goede <hdegoede@redhat.com>, Milan Zamazal <mzamazal@redhat.com>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>","Subject":"[PATCH 05/35] libcamera: swstats_cpu: Add processFrame() method","Date":"Wed, 11 Jun 2025 02:32:15 +0100","Message-ID":"<20250611013245.133785-6-bryan.odonoghue@linaro.org>","X-Mailer":"git-send-email 2.49.0","In-Reply-To":"<20250611013245.133785-1-bryan.odonoghue@linaro.org>","References":"<20250611013245.133785-1-bryan.odonoghue@linaro.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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 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\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n .../internal/software_isp/swstats_cpu.h       | 12 +++++\n src/libcamera/software_isp/swstats_cpu.cpp    | 51 +++++++++++++++++++\n 2 files changed, 63 insertions(+)","diff":"diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nindex 26a2f462..fa47cec9 100644\n--- a/include/libcamera/internal/software_isp/swstats_cpu.h\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -18,12 +18,16 @@\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+class MappedFrameBuffer;\n struct StreamConfiguration;\n \n class SwStatsCpu\n@@ -42,6 +46,7 @@ public:\n \tvoid setWindow(const Rectangle &window);\n \tvoid startFrame();\n \tvoid finishFrame(uint32_t frame, uint32_t bufferId);\n+\tvoid processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input);\n \n \tvoid processLine0(unsigned int y, const uint8_t *src[])\n \t{\n@@ -65,6 +70,7 @@ public:\n \n private:\n \tusing statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);\n+\tusing processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in);\n \n \tint setupStandardBayerOrder(BayerFormat::Order order);\n \t/* Bayer 8 bpp unpacked */\n@@ -77,6 +83,10 @@ private:\n \tvoid statsBGGR10PLine0(const uint8_t *src[]);\n \tvoid statsGBRG10PLine0(const uint8_t *src[]);\n \n+\tvoid processBayerFrame2(MappedFrameBuffer &in);\n+\n+\tprocessFrameFn processFrame_;\n+\n \t/* Variables set by configure(), used every line */\n \tstatsProcessFn stats0_;\n \tstatsProcessFn stats2_;\n@@ -89,9 +99,11 @@ private:\n \tSize patternSize_;\n \n \tunsigned int xShift_;\n+\tunsigned int stride_;\n \n \tSharedMemObject<SwIspStats> sharedStats_;\n \tSwIspStats stats_;\n+\tBenchmark bench_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex aa5654dc..1ff15f5b 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@@ -360,11 +361,14 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order)\n  */\n int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n {\n+\tstride_ = inputCfg.stride;\n+\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\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\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\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n \n \t\tswitch (bayerFormat.order) {\n \t\tcase BayerFormat::BGGR:\n@@ -425,4 +430,50 @@ void SwStatsCpu::setWindow(const Rectangle &window)\n \twindow_.height &= ~(patternSize_.height - 1);\n }\n \n+void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in)\n+{\n+\tconst uint8_t *src = in.planes()[0].data();\n+\tconst uint8_t *linePointers[3];\n+\n+\t/* Adjust src for starting at window_.y */\n+\tsrc += window_.y * stride_;\n+\n+\tfor (unsigned int y = 0; y < window_.height; 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+/**\n+ * \\brief Calculate statistics for a frame in one go\n+ * \\param[in] frame The frame number\n+ * \\param[in] bufferId ID of the statistics buffer\n+ * \\param[in] input The frame to process\n+ *\n+ * This may only be called after a successful setWindow() call.\n+ */\n+void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input)\n+{\n+\tbench_.startFrame();\n+\tstartFrame();\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+\t(this->*processFrame_)(in);\n+\tfinishFrame(frame, bufferId);\n+\tbench_.finishFrame();\n+}\n+\n } /* namespace libcamera */\n","prefixes":["05/35"]}