From patchwork Wed Jun 11 01:32:15 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: 23511 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 45CE9BDE6B for ; Wed, 11 Jun 2025 01:33:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 861DD68DC9; Wed, 11 Jun 2025 03:33:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Y5j/eX2E"; 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 98CA368DC3 for ; Wed, 11 Jun 2025 03:33:16 +0200 (CEST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-45300c82c1cso12448265e9.3 for ; Tue, 10 Jun 2025 18:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749605596; x=1750210396; 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=m1BLltBsmdQhPvHqn+5sDHtKgqD170z2rc524w52XgE=; b=Y5j/eX2EeDA8igfTsXOYnFAvXsrRVH4fxjWZdwgBcrD5+vr6CL5C2l+KlWhgUqcUax GE4bEs27OuCgttqiu9BrePb+Jj+IG9wkwDiev5ddooF0krMVggbdDxyo1AYt0LAg2vFg W1uuNty+wlYjhYe7YZD2Q5HUDxxofRv6Hpi+6jJaNkJsXlDaZb6kNHywmNIMZPB7kVfp d1S9nzYztPbIzw33a/2g+0QMyDkTBMaljJHUrtss9wsQt66C2vUbdwJzwO7QjlpeS1bG 6X0Wa4Bq0uEMNiElKR+ZOTwUD4PCYDUTvI5nXS3nHGYX/E+cgHw3qMOTLiWMI/QvepoO yH4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749605596; x=1750210396; 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=m1BLltBsmdQhPvHqn+5sDHtKgqD170z2rc524w52XgE=; b=NDQY3rcEfB2eBbpkNnK8d/aiyZeccdQedz8iQXFeb1zcEIMsMUn/1FLbLtxfWxAlUu iby4+SvKEwZLVRqoQ4IDA98lFijoR9+SmmaNgZhMo+oCjs8JBL3qNyXj0lwmthaCDbe+ RNGZqfyC0IT3rwuQEez9skoFEPsw6i5FXZ4mexcJL30CAJfEX00xzOojOv9ck5YjwZOt IzDkxRUmLIpj9St97IfAEc4gAnNejLLX4wI7frykrnf8wo5raLFdYy7478q7xS4wnq0b x0F7XDgUNPQb8lcnO5HD3ZehfODmU35ntW4DYYj2pKEmpSSvTPX+Ijag9lkmVF7nAVOh d2oA== X-Gm-Message-State: AOJu0YxNOKhB376PN5Tb5AELnvwBoZO5lRhburXKPlkqbp+s7Rv5YJwq VFq6oSW0Dm4K/T8pWAxszu3HBI6f8vxw/63g8dNpj6oX6kgHBkuMrJpOHHIMH+7Qrvtso4ZQFQq QtpQSfEk= X-Gm-Gg: ASbGnct4aHhWXntiEUKBP4ARKo78/TXnfd0M/p/o0NjLaBrVloOEbW5a8OKK7r1Rapj 0uXuDC+7LJNEvkE1MKWpdTskP/tpYM3t5tauhKxNooMlVnmNRlX4zn8vLNi+1W9yL8ogc30Jg/A ks+/lAJfU9KnkpSZ1Cr0erVDXlFjRixMYYlv4PgomcewQ3aGJs2KoUl7JCQVlMqNcQ2zvS1nqrf 2h2rQPOOqrISp0fTqi6PSIzn7T7f2Fs2/H70LlKkgrxEal7X+gpmh5GYz6PTgqdoy7Jlyqy6hhA Yz9z0dnuZVp3H7Z7rR4xb7J8t9vd0yMJZekRHwUFLKbt7ZwRohth9Gyo7gY5XhtMQBWF6eidBIb Tx3KrH8UcJl/9FFUWaRqwRfy5FG2mGq58Qt3yPOwNLxASBWf1sPFB X-Google-Smtp-Source: AGHT+IHBNIkT76W547r/SoPZrG8WOAN7YjiFswyXT4vhEJ6KqEO+2ALh+5EfbuWiaQOtE0ThdRffSA== X-Received: by 2002:a05:600c:3e85:b0:43c:f629:66f4 with SMTP id 5b1f17b1804b1-45324cfb301mr7135975e9.0.1749605595892; Tue, 10 Jun 2025 18:33:15 -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-4532514138asm5680625e9.3.2025.06.10.18.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 18:33:15 -0700 (PDT) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: Hans de Goede , Milan Zamazal , Bryan O'Donoghue 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 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 --- .../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 26a2f462..fa47cec9 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 aa5654dc..1ff15f5b 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 */