From patchwork Thu Nov 19 20:46:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 29052 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 BDA6CC3355 for ; Thu, 19 Nov 2026 20:46:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B2A206A93E; Thu, 19 Nov 2026 21:46:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KTEPDTPS"; 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 9742C6A92B for ; Thu, 19 Nov 2026 21:46:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795121195; 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=CnZ9nLs7HSTUQOQbH6OpA94OG3IJfJcqNyBU+6o8wwc=; b=KTEPDTPS/RfmyoSTcaIArpCgHNbvkPVmuzaOVez+BTqk36oalihnugwfk/6Aw81rQRf/an 9NFV7XQC3Za+2ZazvO+4yxqGyZtq/jNSVzNuygGeAtrxo+WjRpc5HTQKX45EK6S9SsPr0e S9rWtlW4xW2uxEDKtnkJxStTEqPrToo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-142-qyBO7QvzPc2hv-FLgYcU_A-1; Thu, 19 Nov 2026 20:46:31 +0000 X-MC-Unique: qyBO7QvzPc2hv-FLgYcU_A-1 X-Mimecast-MFC-AGG-ID: qyBO7QvzPc2hv-FLgYcU_A_1795121190 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9A7741800630; Thu, 19 Nov 2026 20:46:30 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E215B195604E; Thu, 19 Nov 2026 20:46:28 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , =?utf-8?b?QmFybmFiw6FzIFDFkWN6?= =?utf-8?q?e?= , Kieran Bingham , Robert Mader , Jayden Milne Subject: [PATCH v3 4/8] libcamera: software_isp: Add variance to stats Date: Thu, 19 Nov 2026 21:46:07 +0100 Message-ID: <20261119204611.278218-5-mzamazal@redhat.com> In-Reply-To: <20261119204611.278218-1-mzamazal@redhat.com> References: <20261119204611.278218-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: epWDGBy0rpvlXhVxJ-F8LHwQVlE6jLA_ePIEuGuiLi8_1795121190 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" The libipa Af algorithm requests variance value as its input. Let's add the corresponding member to SwIspStats and initialise it. This commit is preparatory and doesn't implement computation of the variance nor introduces other changes to the stats like when to update them for autofocus. Signed-off-by: Milan Zamazal --- include/libcamera/internal/software_isp/swisp_stats.h | 8 +++++++- src/libcamera/software_isp/swstats_cpu.cpp | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/software_isp/swisp_stats.h b/include/libcamera/internal/software_isp/swisp_stats.h index 65d826f6c..a0f6f4a79 100644 --- a/include/libcamera/internal/software_isp/swisp_stats.h +++ b/include/libcamera/internal/software_isp/swisp_stats.h @@ -17,7 +17,7 @@ namespace libcamera { /** * \brief Statistics for the Software ISP * - * The software ISP computes two types of statistics: + * The software ISP computes the following types of statistics: * * - The accumulator counts the number of non-saturated pixels and sums their * R, G and B channels individually. Pixels that have any saturated channel @@ -27,6 +27,8 @@ namespace libcamera { * - The histogram groups pixels in bins based on their luminance and counts * the number of pixels in each bin. Saturated pixels are included. * + * - The variance value for autofocus. + * * The value types are large enough to not overflow. Should they still overflow * for some reason, no check is performed and they wrap around. */ @@ -56,6 +58,10 @@ struct SwIspStats { * \brief A histogram of luminance values of all the sampled pixels */ Histogram yHistogram; + /** + * \brief A variance value for the autofocus algorithm + */ + double variance; }; } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 0aa5597a9..ed1aa83e4 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -407,6 +407,7 @@ void SwStatsCpu::startFrame(uint32_t frame) for (auto &s : stats_) { s.sum_ = RGB({ 0, 0, 0 }); s.numPixels_ = 0; + s.variance = 0.0; s.yHistogram.fill(0); } } @@ -425,10 +426,12 @@ void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId) if (valid) { sharedStats_->sum_ = RGB({ 0, 0, 0 }); sharedStats_->numPixels_ = 0; + sharedStats_->variance = 0.0; sharedStats_->yHistogram.fill(0); for (const auto &s : stats_) { sharedStats_->sum_ += s.sum_; sharedStats_->numPixels_ += s.numPixels_; + sharedStats_->variance += s.variance; for (unsigned int j = 0; j < SwIspStats::kYHistogramSize; j++) sharedStats_->yHistogram[j] += s.yHistogram[j]; }