From patchwork Wed Mar 19 09:55:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22974 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 BA87CC3301 for ; Wed, 19 Mar 2025 09:55:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8526D68945; Wed, 19 Mar 2025 10:55:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="iBYr5VXU"; 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 A183968942 for ; Wed, 19 Mar 2025 10:55:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742378141; 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; bh=jLXJ9oh6OmoEOoNxTJbS7txMUPKgACaPLLp7jjPpkkk=; b=iBYr5VXUJvUNIZnwPqZewQtiknp118nwn0rgBluwMpe5Hu+TewHQiCjkoVtRe4DNMU0Scq Q+1Tx8nTDKOyfQceb4hTvmNNCEn5nr27ECFe4Hz8BCTx1UfPwzoE0soPecNIu2gvA1960C 1dLTQb+F+mEFHfStPVXUUzAkEyOZeok= 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-644-Xi2mKXd7PJeqzA24lFwenA-1; Wed, 19 Mar 2025 05:55:39 -0400 X-MC-Unique: Xi2mKXd7PJeqzA24lFwenA-1 X-Mimecast-MFC-AGG-ID: Xi2mKXd7PJeqzA24lFwenA_1742378138 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 96919180035E; Wed, 19 Mar 2025 09:55:38 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.226.102]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4454C1956094; Wed, 19 Mar 2025 09:55:36 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Robert Mader , Kieran Bingham Subject: [PATCH v2] libcamera: software_isp: Reset stored exposure in black level Date: Wed, 19 Mar 2025 10:55:33 +0100 Message-ID: <20250319095533.24550-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DAW3Byhe4YRjUmwP-d6n0UFo4na7aWdzooX_pcjoDBs_1742378138 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" Automatic black level setting in software ISP updates the determined black level value when exposure or gain change. It stores the last exposure and gain values to detect the change. BlackLevel::configure() resets the stored black level value but not the exposure and gain values. This can prevent updating the black value and cause bad image output, e.g. after suspending and resuming a camera, if exposure and gain remain unchanged. Let's store exposure and gain in IPAActiveState. Although the values are not supposed to be used outside BlackLevel class, storing them in the context has the advantage of their automatic reset together with the other context contents and having them in `blc' struct indicates their relationship to the black value computation. Bug: https://bugs.libcamera.org/show_bug.cgi?id=259 Signed-off-by: Milan Zamazal --- src/ipa/simple/algorithms/blc.cpp | 10 +++++----- src/ipa/simple/algorithms/blc.h | 2 -- src/ipa/simple/ipa_context.h | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp index 1d7d370b..089e492a 100644 --- a/src/ipa/simple/algorithms/blc.cpp +++ b/src/ipa/simple/algorithms/blc.cpp @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* - * Copyright (C) 2024, Red Hat Inc. + * Copyright (C) 2024-2025, Red Hat Inc. * * Black level handling */ @@ -54,8 +54,8 @@ void BlackLevel::process(IPAContext &context, if (context.configuration.black.level.has_value()) return; - if (frameContext.sensor.exposure == exposure_ && - frameContext.sensor.gain == gain_) { + if (frameContext.sensor.exposure == context.activeState.blc.lastExposure && + frameContext.sensor.gain == context.activeState.blc.lastGain) { return; } @@ -79,8 +79,8 @@ void BlackLevel::process(IPAContext &context, seen += histogram[i]; if (seen >= pixelThreshold) { context.activeState.blc.level = i * histogramRatio; - exposure_ = frameContext.sensor.exposure; - gain_ = frameContext.sensor.gain; + context.activeState.blc.lastExposure = frameContext.sensor.exposure; + context.activeState.blc.lastGain = frameContext.sensor.gain; LOG(IPASoftBL, Debug) << "Auto-set black level: " << i << "/" << SwIspStats::kYHistogramSize diff --git a/src/ipa/simple/algorithms/blc.h b/src/ipa/simple/algorithms/blc.h index 52d59cab..db9e6d63 100644 --- a/src/ipa/simple/algorithms/blc.h +++ b/src/ipa/simple/algorithms/blc.h @@ -30,8 +30,6 @@ public: ControlList &metadata) override; private: - int32_t exposure_; - double gain_; std::optional definedLevel_; }; diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 4af51306..b1198af5 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -33,6 +33,8 @@ struct IPASessionConfiguration { struct IPAActiveState { struct { uint8_t level; + int32_t lastExposure; + double lastGain; } blc; struct {