From patchwork Tue Apr 22 21:59:00 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: 23220 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 2C1D4C331F for ; Tue, 22 Apr 2025 21:59:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C748A68B2E; Tue, 22 Apr 2025 23:59:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="mmrfnrki"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CFA868ADC for ; Tue, 22 Apr 2025 23:59:30 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso47638665e9.3 for ; Tue, 22 Apr 2025 14:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745359169; x=1745963969; 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=0Ek6jmyDtRYKIUfKdQ2Duk5zmK3pCbgsZ+bQyRX+gec=; b=mmrfnrkixhkvZdaunLhDPWfdHBP9+BRKQHNFa8TLQi8KPKxJf6/B0pDxuenryla+dd HgRCvqR4JZT4n465qYzxOiw8dLysT7st0KtjDbJar9JbSlCSTJjKl7SbeokcARh7ewZQ KACGAvo/YuNJSCT2M0TC8ry/H8zTpvvIPh0pRGWNHdQMUUpR3etYcMOY/LMuOkA4pbFc Awa+FlIl7InhcLppOC99QOaRCuZLGdiV5FNc36dJsw6SD7mYDPg6HHPBunM4ZTX6pNuL oyfX4fvv/t5rqa0xbhHVhAavGjA+IhQkqVVaqW+IIoHtNgaZ0RYxTE64eiCM0IHFkVS+ 0ghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745359169; x=1745963969; 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=0Ek6jmyDtRYKIUfKdQ2Duk5zmK3pCbgsZ+bQyRX+gec=; b=pMvoK1bDborg0Zoj58LqWyICbfWskhiqnMoymN+jFREUxwFXbKOF9g+QarhBgux5Tt if3GaUWDa6Rlg5IGo8LFREDAqI1As22vJJ1GIGLoD+JE/+aBlVduOqxz49B6RREtfkEO JKbr8ILsM6cc/APrpL/LsuHghqUaczM7G7LVP/5dkLrJ46FKAbZn9nudt+cNKVJbx+jU 0FeEKHEruzcvkJILhEKS748PxMOqeeUYLsc+Sf6YhtYGeNm/wiEJr1Vv4U7HJj3zMHRv HFOR42t2LDM4/HragtniVg5pNvnGMzRavA00SfmycQXwqWa9HwoAA8X4AZby/Bpfdahw MObA== X-Gm-Message-State: AOJu0YzoUj7QVzWIDfS4s828LABaYI1ZySwruC3Dohm12mxabdxN+AG+ +A9R2vgEeMU2dpKEVuMj1U6xXDM0aaQZU8o9pRxMO3tULYPSK2wyeq7G7QqggmACZgL1DKxuKJV Me+Y= X-Gm-Gg: ASbGnctZmYIbvMFXP7aLfWQPfnACRFWUyP/Y+A9NIVrcDnthCXKavNPcHUFvEveLskd glfAq4LjLDFr3Og/Nug5a6Lp6XOkRaVLga8LdI1K+ZKZsVE4LveaWzsgiQeVq1H1IAUGaJ7eHT7 xHsrAR+KUeur/IIgWy6HUwQodm+CT53+sD/FTie41t1HL4hL+DtPK889JEiD/Us5xlGtV5I+JA4 CFHVi1Wg9r2zrdIs59SRv3NZUZf5ciEoim3HOVx2A52V5YvMdxLG4gTF132PMSRHGrjfXcrdL5C 36wg852SaJIxhPhOVMRm8pHcIhBDvHVobmhSyp7LxLUFRz9+Rrj9jOsu5xRZ8bNAClacxEMsGeT X7kqT2fEtdJGiLsYvlh68 X-Google-Smtp-Source: AGHT+IHmZmFyH8dP26NLUxZpRzrfIDqhpoAvHdN+xIYOB6zlvzv1v5Hk7cI1KkWr0p5qV6qNUB76iQ== X-Received: by 2002:a05:600c:5491:b0:43c:eeee:b706 with SMTP id 5b1f17b1804b1-4406abf93c8mr136303875e9.24.1745359169461; Tue, 22 Apr 2025 14:59:29 -0700 (PDT) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-44092d2eccesm2726615e9.20.2025.04.22.14.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 14:59:28 -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 07/27] libcamera: swstats_cpu: Add processFrame() method Date: Tue, 22 Apr 2025 22:59:00 +0100 Message-ID: <20250422215920.4297-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250422215920.4297-1-bryan.odonoghue@linaro.org> References: <20250422215920.4297-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 --- Changes since the RFC: - Make processFrame() call startFrame() and finishFrame() rather then making the caller do this - Add doxygen documentation for processFrame() Signed-off-by: Bryan O'Donoghue --- src/libcamera/software_isp/swstats_cpu.cpp | 51 ++++++++++++++++++++++ src/libcamera/software_isp/swstats_cpu.h | 12 +++++ 2 files changed, 63 insertions(+) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 5e4246a9..af407b4d 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 { @@ -360,11 +361,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; @@ -385,6 +389,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: @@ -425,4 +430,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(); + + 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 */ diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h index 26a2f462..fa47cec9 100644 --- a/src/libcamera/software_isp/swstats_cpu.h +++ b/src/libcamera/software_isp/swstats_cpu.h @@ -18,12 +18,16 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/framebuffer.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 @@ -42,6 +46,7 @@ public: void setWindow(const Rectangle &window); void startFrame(); void finishFrame(uint32_t frame, uint32_t bufferId); + void processFrame(uint32_t frame, uint32_t bufferId, FrameBuffer *input); void processLine0(unsigned int y, const uint8_t *src[]) { @@ -65,6 +70,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 */ @@ -77,6 +83,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_; @@ -89,9 +99,11 @@ private: Size patternSize_; unsigned int xShift_; + unsigned int stride_; SharedMemObject sharedStats_; SwIspStats stats_; + Benchmark bench_; }; } /* namespace libcamera */