From patchwork Sun Aug 24 00:48:17 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: 24188 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 4404EC32BB for ; Sun, 24 Aug 2025 00:48:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B6A069309; Sun, 24 Aug 2025 02:48:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="PJbSxArD"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45E58692F3 for ; Sun, 24 Aug 2025 02:48:41 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-45a1abf5466so20830845e9.0 for ; Sat, 23 Aug 2025 17:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755996521; x=1756601321; darn=lists.libcamera.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NGF5nV7Z4LkgV9ObL3ETdEhX8lK4F6LQvhvfeDnOBfA=; b=PJbSxArD/SsTkpXr+eqv5iYxg4D6Bl8YUkCBIqfKsYoUKx4GsvN2H/8XKrFaRrcV2q /SaU8k//1u+5feEI0FW7mVyTU75t0BHQa1bfJTeIWjfRW+4NaPcNmOloKrkZFlepOvsc aTjM7C5I9ETumIhOT1VHrewiEm9LX5M8JS3VBJ5U2pfxzqT/5XAhQbSM0BeWXS9lLrEn Ku2yEazw47kM7snk68p1fHeq1csyI3xDNfBPXarE+cGR7vu1nCndyOjyM1IC/C/Z5DDj OA7TBQa+43rrXpAgA7lunHafkHdp5gesACKwGjZ7nkKjUu1+Itce2CNSaLazlQ6cKzjE G8uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755996521; x=1756601321; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NGF5nV7Z4LkgV9ObL3ETdEhX8lK4F6LQvhvfeDnOBfA=; b=BSSVT6dqWtElUNwoJ1zv+m6p37bzLf7bT3qaS/sT2lXttRgvWoVYrWVRDm98fwhmn3 3pqOu1cQf6oaOrgp9+bGj7XQK6Ry5Q/B1HfF7X7sxlKgP2z2a2hyOsAuiIBONameIPlg il/UFvlVjzr2GefKI8+u70dD0fx8TqNIwxhHPjwkXmBxX4lXvCOr6WVobjQ1ipkHXKUD nordR6MVENTBZep4U4KgviyQ68oG/GHbSdJnrn38lbwtlJ8Rwm0V60NQaNlR+s2j8vVR y1QEWBoDJKWv0TUYGSX5kubS7Dlnle0G/mTTRw72RDTV0uzx/oy6eabw/220lCm6aP3N Iiqw== X-Gm-Message-State: AOJu0YwEKDx4aMddP8XVh8CxIXaCAd3fZcbZHfttKbEz+btEF4qf9WDl IVMJ6sAPSmvelZCGFJbwC3DyyswQqKMveLYV4Y57W8v8wBimlpoDrR5kzb4gqCqlcvo= X-Gm-Gg: ASbGnctrqYFvqCCLXYB2K97Ns9uLvh9XOILPn2mNybqPORDgkF2fogCR8XIlsZUC/ET kGPVDzqAX3xQfm+qbJdpUgCtcUTfEANuC7IfrKnckg8/aIrw7xIXwHR20iufwCcF+4mXVvuyhPV lck3LeDa+Chu1gNLocf7rZZ20e4RZoz9h2sWQDLijcFE8NFTUohDgu8cr3QFETPrI6exT5FYjyx zdMyL2K+m90cHIYqKPicjHfO6iUSx49lriyBtSUXVLG5MtBJMTzlpTF18bGnYSWAo/Ze6+U8In6 E+D/Pffi2JVwkFhDBs07qty8lzI9KIXIbUsC7UpUgI4mFwdafi3HEYehhhrsnIYVYj7qG1+or3u GEdhl9wLLbyUzAB5QJK8mIvfWWDxVYdYv09WVY8tpcGOS57vJpkykdnkuHPpXx/TKwLQvNm2IWF +tYr6uzc7gp1K39ywHqv1u X-Google-Smtp-Source: AGHT+IHTdKzlMZ1KCyfSfv2B7hl+zgpJ22W49Sj/JfBJaM9/aWUBEg6d6VQiHgX+WLbSXoE+404ViQ== X-Received: by 2002:a05:600c:4f49:b0:439:4b23:9e8e with SMTP id 5b1f17b1804b1-45b5416dc42mr54925125e9.3.1755996520728; Sat, 23 Aug 2025 17:48:40 -0700 (PDT) Received: from [192.168.0.13] (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b4e1d530esm69347225e9.0.2025.08.23.17.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Aug 2025 17:48:40 -0700 (PDT) From: Bryan O'Donoghue Date: Sun, 24 Aug 2025 01:48:17 +0100 Subject: [PATCH v2 05/37] libcamera: swstats_cpu: Add processFrame() method MIME-Version: 1.0 Message-Id: <20250824-b4-v0-5-2-gpuisp-v2-a-v2-5-96f4576c814e@linaro.org> References: <20250824-b4-v0-5-2-gpuisp-v2-a-v2-0-96f4576c814e@linaro.org> In-Reply-To: <20250824-b4-v0-5-2-gpuisp-v2-a-v2-0-96f4576c814e@linaro.org> To: libcamera-devel@lists.libcamera.org Cc: Bryan O'Donoghue , Hans de Goede , Milan Zamazal X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5199; i=bryan.odonoghue@linaro.org; h=from:subject:message-id; bh=b8XaxNg/2llfAP9VuIKy9JajGNNOdI7TmUN8CE9bpcg=; b=owEBbQKS/ZANAwAKASJxO7Ohjcg6AcsmYgBoqmFdjy28eG4IZmQ/67ozOeNtrQeQh4BmR1eMP MPvnRSm2eOJAjMEAAEKAB0WIQTmk/sqq6Nt4Rerb7QicTuzoY3IOgUCaKphXQAKCRAicTuzoY3I Otk2EACpX6lb3Y4doEhNEyZh6f3uLD2IvSaC/WUgj/ZC4CAp7tXtGUR+4wEsOy6QDDNotb86jB/ Rb28uKMmsHEhMuTBFCFP2zaw/uHScaXvV70zJSmfhH53oIbT9uB3ZfdxvLBqqUpROyY6sVOC0qz WeW/Z22rcJIUJq2AFm8mUtEAo2aF7dOH6Cc0T85p1KZ1GPeYmCiqa99NrzIdDCsD07Hbk4DNSaR n5AQLPqEFm5eNqlLKaGgA9/V9pbhZLWrY05pskXQL8FQyZUf+1OFjsDNpmambAyecQMmjxa2KF6 Rz+afwrbyLI1UgGcblJ30/N3gEiQmo0djCv0NcL+d/XuKLB9B6XTxVIGXtKtvBuSRa420vil43C VTV8eEdCHwPOWr5KhVjfbOOZiSXHpcwybTVNVw4AyxV1mliCWF8nTa0w+y6y2iNoumA8mVQ9bCh ZKmt08q9t74neOfbtTy8KGV0ntDFwmMPAa1oe6faUDyjOFGu5Q6rhev3GDth3A20SEjLT+wJXYi HDA79HKZSWMY0QdGWBGQ5JxNi9Sg8fPxoyNZb/ta8SNWYykcVqJKMxzDSVjnKQwfnGvY0ay211v pUqDylIY2vNpUpy/41Bu5cJI5tw2acHXE+OkoQpiNM72pmrBWIC+JtUXHbteOmRfJp79aO40MqB sMpCtRIPhu2tpLA== X-Developer-Key: i=bryan.odonoghue@linaro.org; a=openpgp; fpr=E693FB2AABA36DE117AB6FB422713BB3A18DC83A 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 Signed-off-by: Bryan O'Donoghue --- .../libcamera/internal/software_isp/swstats_cpu.h | 12 +++++ src/libcamera/software_isp/swstats_cpu.cpp | 51 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h index 26a2f462eb1eea359abbb9366e3eba5704ee293f..fa47cec91c1ffce28f9a212bc7a29499daed8be5 100644 --- a/include/libcamera/internal/software_isp/swstats_cpu.h +++ b/include/libcamera/internal/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 */ diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 347fc32db13d81cef3d6d1bb7d64241e06d4ad0e..9d45d228e343621605cf5085711c3af9a6915ea4 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 */