From patchwork Wed Oct 15 01:22:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 24653 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B6B4DC3331 for ; Wed, 15 Oct 2025 01:23:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E9F66062B; Wed, 15 Oct 2025 03:23:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="nCJz3kWw"; dkim-atps=neutral Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 644DF60612 for ; Wed, 15 Oct 2025 03:23:03 +0200 (CEST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-afcb7ae6ed0so1019340966b.3 for ; Tue, 14 Oct 2025 18:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1760491383; x=1761096183; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K3FoQV7xQAgIgQqS1yVdt6nWFXu6g4HjccATVbBtrDE=; b=nCJz3kWwMt90XTKCh0VTvIRxwNAoT7zbHlJw3tZtbvm3RnMHdF9xD3Whje/HupUkKv yDCNGQd+5z0zk0Qmriij4ndVp+HXZexNwvOiU6CzYwHYlXu6BgFTrCetbRzzu+1GclKN bTEcCwR1tB1VGm+UTqCH1WyUPy3YiTMK0SWdma0CLnrG2mT9gow6lKNTviGOow3zI2WF qSYUR7Vw8+0xFg0KXDX9EyavmMWCsWxgIARxf1lhtvRMg8hTfDgWI1aGBjF+gQCnOWps yplpQLZXVqWI9e4iSWzguPbXLFKdwsi/o8tVFwVfpFSR0YCythToNSPvQVPUci8guSCq trjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760491383; x=1761096183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K3FoQV7xQAgIgQqS1yVdt6nWFXu6g4HjccATVbBtrDE=; b=c359c78raLj48SA62F7KBdkEpkUxBFLWm0Chusy9G2sP2k0Ql9bFN7jw+RhzM6TP0f +P/ZsQ7O0RNxxo4er/33S4z9z8YnsGBH5MdSK/nUams7pwsATWn9HVzbva7+89jHNLYy BK0BiO8dUZGTLEBfeWZiTH0CfObz3qncDr9ytsXN0TDqb83JXolHn4Urlwq0XWS8buC3 Q8PkRh04lcxeB1bZlcbk2RSEbvf0PQJzm/CgJehByFzucY7TCaVexEph9CPurb7XzeYW Dn9qXAvAc6xovyH0vH74pBGwKghYVuYeaMyAnA5ZG28zkmn44GZ6lgJMFb5a2KAdQSoE hIMw== X-Gm-Message-State: AOJu0YwRPOn8QziUMs4y1rTGdIVLAByYgsv/410JrJxWZv1der0n/1F7 RB2TkjCh3J5APrjnK9njvyzmTfRLZiKDVmQPl8yGBe/059I/S0eCrMHrj26qfVos3HNdwe+m2ch V3J0z X-Gm-Gg: ASbGnctl1dgbNmULZSJj89kPxA78vlBhKWerruWFfyptEUH2kCfzXYFkGE7zEd1tk+x 2lNVaTb47eOALcJz2tJ+WzRQ3jELCUdVLyrphffk0exAsfOWDdNLJSRTK5l8i2BJdKW6GfAk16O EoYJZkXwG2TjduFymoOVJ78ggMBRxqezXHav1aWeDOgbyNMFipTz6Y86fU+Gef+dZ2H47X+pnHn FwYmqEnl2y3e+87/nEV12gdtBCM2kIwXbYG8KdSkZ+I4+4M6ub6Umh8/jHBl2/whER2sBq4OSCa gTA6mZ7o7uQjJVcE4koRrgrewGi8ww48T8HPCwwrNuJXBHayyh5wjSYdP5uSEdPdapP9otnWJHh udnXMH16scU/XWTRf3jts6nHsaxg9fjSfOpxsQ8wZZB158lEfMDxcUkZoVs41/dn0rQnPQw1lkx lXBMmaQuKSSVCH+jNpAEwvBOM+YyXO1BwwPMN/tJE+ X-Google-Smtp-Source: AGHT+IFu7TXzYDOw5vPrHJev2fFl+vpINNy7wwph4Z68XiLd0VEdVFPLowVBtVpLhfdcK9U+KCTQxg== X-Received: by 2002:a17:907:c06:b0:b3d:cc4a:a2fa with SMTP id a640c23a62f3a-b50ac1cc3afmr2492271066b.36.1760491382516; Tue, 14 Oct 2025 18:23:02 -0700 (PDT) Received: from inspiron14p-linux.nxsw.local (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b5ccd7b202dsm98348466b.82.2025.10.14.18.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Oct 2025 18:23:02 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org, bod.linux@nxsw.ie Subject: [PATCH v3 08/39] libcamera: swstats_cpu: Add processFrame() method Date: Wed, 15 Oct 2025 02:22:20 +0100 Message-ID: <20251015012251.17508-9-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251015012251.17508-1-bryan.odonoghue@linaro.org> References: <20251015012251.17508-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Hans de Goede Add a method to the SwstatsCpu class to process a whole Framebuffer in one go, rather then line by line. This is useful for gathering stats when debayering is not necessary or is not done on the CPU. Reviewed-by: Milan Zamazal Signed-off-by: Hans de Goede [bod: various rebase spalts fixed] Signed-off-by: Bryan O'Donoghue Reviewed-by: Kieran Bingham --- .../internal/software_isp/swstats_cpu.h | 15 ++++- src/libcamera/software_isp/software_isp.cpp | 5 +- src/libcamera/software_isp/swstats_cpu.cpp | 55 ++++++++++++++++++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index fae575f8..64b3e23f 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/software_isp/swstats_cpu.h @@ -18,18 +18,23 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.h" +#include "libcamera/internal/global_configuration.h" #include "libcamera/internal/shared_mem_object.h" #include "libcamera/internal/software_isp/swisp_stats.h" +#include "benchmark.h" + namespace libcamera { class PixelFormat; +class MappedFrameBuffer; struct StreamConfiguration; class SwStatsCpu { public: - SwStatsCpu(); + SwStatsCpu(const GlobalConfiguration &configuration); ~SwStatsCpu() = default; /* @@ -50,6 +55,7 @@ public: void setWindow(const Rectangle &window); void startFrame(uint32_t frame); void finishFrame(uint32_t frame, uint32_t bufferId); + void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input); void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[]) { @@ -79,6 +85,7 @@ public: private: using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]); + using processFrameFn = void (SwStatsCpu::*)(MappedFrameBuffer &in); int setupStandardBayerOrder(BayerFormat::Order order); /* Bayer 8 bpp unpacked */ @@ -91,6 +98,10 @@ private: void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); + void processBayerFrame2(MappedFrameBuffer &in); + + processFrameFn processFrame_; + /* Variables set by configure(), used every line */ statsProcessFn stats0_; statsProcessFn stats2_; @@ -103,9 +114,11 @@ private: Size patternSize_; unsigned int xShift_; + unsigned int stride_; SharedMemObject sharedStats_; SwIspStats stats_; + Benchmark bench_; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index b7651b7d..6f1f88fe 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -107,14 +107,15 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor, return; } - auto stats = std::make_unique(); + const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration(); + + auto stats = std::make_unique(configuration); if (!stats->isValid()) { LOG(SoftwareIsp, Error) << "Failed to create SwStatsCpu object"; return; } stats->statsReady.connect(this, &SoftwareIsp::statsReady); - const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration(); debayer_ = std::make_unique(std::move(stats), configuration); debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady); debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady); diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 55e764b0..48d12c51 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -16,6 +16,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/mapped_framebuffer.h" namespace libcamera { @@ -144,8 +145,8 @@ namespace libcamera { LOG_DEFINE_CATEGORY(SwStatsCpu) -SwStatsCpu::SwStatsCpu() - : sharedStats_("softIsp_stats") +SwStatsCpu::SwStatsCpu(const GlobalConfiguration &configuration) + : sharedStats_("softIsp_stats"), bench_(configuration) { if (!sharedStats_) LOG(SwStatsCpu, Error) @@ -386,11 +387,14 @@ int SwStatsCpu::setupStandardBayerOrder(BayerFormat::Order order) */ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) { + stride_ = inputCfg.stride; + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputCfg.pixelFormat); if (bayerFormat.packing == BayerFormat::Packing::None && setupStandardBayerOrder(bayerFormat.order) == 0) { + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.bitDepth) { case 8: stats0_ = &SwStatsCpu::statsBGGR8Line0; @@ -411,6 +415,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) /* Skip every 3th and 4th line, sample every other 2x2 block */ ySkipMask_ = 0x02; xShift_ = 0; + processFrame_ = &SwStatsCpu::processBayerFrame2; switch (bayerFormat.order) { case BayerFormat::BGGR: @@ -475,4 +480,50 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.height &= ~(patternSize_.height - 1); } +void SwStatsCpu::processBayerFrame2(MappedFrameBuffer &in) +{ + const uint8_t *src = in.planes()[0].data(); + const uint8_t *linePointers[3]; + + /* Adjust src for starting at window_.y */ + src += window_.y * stride_; + + for (unsigned int y = 0; y < window_.height; y += 2) { + if (y & ySkipMask_) { + src += stride_ * 2; + continue; + } + + /* linePointers[0] is not used by any stats0_ functions */ + linePointers[1] = src; + linePointers[2] = src + stride_; + (this->*stats0_)(linePointers); + src += stride_ * 2; + } +} + +/** + * \brief Calculate statistics for a frame in one go + * \param[in] frame The frame number + * \param[in] bufferId ID of the statistics buffer + * \param[in] input The frame to process + * + * This may only be called after a successful setWindow() call. + */ +void SwStatsCpu::processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input) +{ + bench_.startFrame(); + startFrame(frame); + + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + if (!in.isValid()) { + LOG(SwStatsCpu, Error) << "mmap-ing buffer(s) failed"; + return; + } + + (this->*processFrame_)(in); + finishFrame(frame, bufferId); + bench_.finishFrame(); +} + } /* namespace libcamera */