From patchwork Wed Oct 9 20:01:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 21575 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 5DF5AC32E7 for ; Wed, 9 Oct 2024 20:01:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E597565371; Wed, 9 Oct 2024 22:01:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="WX+TmK01"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7455B65371 for ; Wed, 9 Oct 2024 22:01:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728504082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BzGMLtbHgThgWiWQw3PO/tTyIxnrqi/KRjbj0UyKIwA=; b=WX+TmK01EDIMYSTPGVLSfGcLq1UbEJmiuEkCYa0OVTB2g+O15F9L3kMAtjFAiF0/W1EA2i inD6O3jEBcMIyFKqB7DbrhV/ZP9CIf7s4N2OAghL2VEmmc0wj7LM6yr6uf8fNtYZo/leb4 EdZAa9tVv6k8JscmrDtLK3reg2PDiqs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-8ws9KG8ZN2Sjhp-hz2nD4w-1; Wed, 09 Oct 2024 16:01:21 -0400 X-MC-Unique: 8ws9KG8ZN2Sjhp-hz2nD4w-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CFEE1956096 for ; Wed, 9 Oct 2024 20:01:20 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.36]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5E991956052; Wed, 9 Oct 2024 20:01:18 +0000 (UTC) From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Maxime Ripard , Hans de Goede Subject: [RFC 4/4] libcamera: swstats_cpu: Add processFrame() method Date: Wed, 9 Oct 2024 22:01:10 +0200 Message-ID: <20241009200110.275544-5-hdegoede@redhat.com> In-Reply-To: <20241009200110.275544-1-hdegoede@redhat.com> References: <20241009200110.275544-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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" 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. Signed-off-by: Hans de Goede Reviewed-by: Milan Zamazal --- src/libcamera/software_isp/swstats_cpu.cpp | 72 ++++++++++++++++++++++ src/libcamera/software_isp/swstats_cpu.h | 10 +++ 2 files changed, 82 insertions(+) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 5e4246a9..117147c2 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 { @@ -363,8 +364,11 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg) BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputCfg.pixelFormat); + stride_ = inputCfg.stride; + if (bayerFormat.packing == BayerFormat::Packing::None && setupStandardBayerOrder(bayerFormat.order) == 0) { + bpp_ = (bayerFormat.bitDepth + 7) & ~7; 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; + bpp_ = 10; switch (bayerFormat.order) { case BayerFormat::BGGR: @@ -425,4 +430,71 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.height &= ~(patternSize_.height - 1); } +void SwStatsCpu::processFrame2(const uint8_t *src) +{ + unsigned int yEnd = window_.y + window_.height; + const uint8_t *linePointers[3]; + + /* Adjust src to top left corner of the window */ + src += window_.y * stride_ + window_.x * bpp_ / 8; + + for (unsigned int y = window_.y; y < yEnd; 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; + } +} + +void SwStatsCpu::processFrame4(const uint8_t *src) +{ + const unsigned int yEnd = window_.y + window_.height; + const uint8_t *linePointers[4]; + + /* Adjust src to top left corner of the window */ + src += window_.y * stride_ + window_.x * bpp_ / 8; + + for (unsigned int y = window_.y; y < yEnd; y += 4) { + if (y & ySkipMask_) { + src += stride_ * 4; + continue; + } + + /* linePointers[0] and [1] are not used by 4 line pattern stats0_ functions */ + linePointers[2] = src; + linePointers[3] = src + stride_; + (this->*stats0_)(linePointers); + src += stride_ * 2; + + linePointers[2] = src; + linePointers[3] = src + stride_; + (this->*stats2_)(linePointers); + src += stride_ * 2; + } +} + +void SwStatsCpu::processFrame(FrameBuffer *input) +{ + bench_.startFrame(); + + MappedFrameBuffer in(input, MappedFrameBuffer::MapFlag::Read); + if (!in.isValid()) { + LOG(SwStatsCpu, Error) << "mmap-ing buffer(s) failed"; + return; + } + + if (patternSize_.height == 2) + processFrame2(in.planes()[0].data()); + else + processFrame4(in.planes()[0].data()); + + bench_.finishFrame(); +} + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h index 26a2f462..bb178a04 100644 --- a/src/libcamera/software_isp/swstats_cpu.h +++ b/src/libcamera/software_isp/swstats_cpu.h @@ -18,9 +18,12 @@ #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; @@ -42,6 +45,7 @@ public: void setWindow(const Rectangle &window); void startFrame(); void finishFrame(uint32_t frame, uint32_t bufferId); + void processFrame(FrameBuffer *input); void processLine0(unsigned int y, const uint8_t *src[]) { @@ -77,6 +81,9 @@ private: void statsBGGR10PLine0(const uint8_t *src[]); void statsGBRG10PLine0(const uint8_t *src[]); + void processFrame2(const uint8_t *src); + void processFrame4(const uint8_t *src); + /* Variables set by configure(), used every line */ statsProcessFn stats0_; statsProcessFn stats2_; @@ -89,9 +96,12 @@ private: Size patternSize_; unsigned int xShift_; + unsigned int bpp_; /* Memory used per pixel, not precision */ + unsigned int stride_; SharedMemObject sharedStats_; SwIspStats stats_; + Benchmark bench_; }; } /* namespace libcamera */