From patchwork Sat Oct 31 18:40:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 28729 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 492ECC3261 for ; Sat, 31 Oct 2026 18:41:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7ADA69140; Sat, 31 Oct 2026 19:41:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="f9T4/cyB"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E183C6914A for ; Sat, 31 Oct 2026 19:41:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793472063; 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=xDkCCH66h+ojerlkvVlVvfTl1Ph606P+Tjou2ihK1j8=; b=f9T4/cyBA6WXCQul++r/VE+Dg4dX6zmedWru+kOMFQGQnWjooE31JfgzKr0HmYMzzto6Ld VPoIL1EMKFONolTnn/xmLoxlfAjB0HmvA7T8WaRUDhj6Sl2QJb/Z2lv2lBxESBOWKFnKXm HRYs65xlbY1mx+vaV7UL3L5+2ick74c= Received: from mx-prod-mc-06.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-327-jThSOE_CPoyLds4RqQZJdw-1; Sat, 31 Oct 2026 14:41:00 -0400 X-MC-Unique: jThSOE_CPoyLds4RqQZJdw-1 X-Mimecast-MFC-AGG-ID: jThSOE_CPoyLds4RqQZJdw_1793472059 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD5CD1802154; Sat, 31 Oct 2026 18:40:58 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F9661800480; Sat, 31 Oct 2026 18:40:57 +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 Subject: [PATCH v2 4/8] libcamera: software_isp: Add variance to stats Date: Sat, 31 Oct 2026 19:40:36 +0100 Message-ID: <20261031184040.20139-5-mzamazal@redhat.com> In-Reply-To: <20261031184040.20139-1-mzamazal@redhat.com> References: <20261031184040.20139-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uM1jNgzqFNuYG_E3CcZNGKQNVmnQHaatHZTo1u0SFdA_1793472059 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]; }