From patchwork Thu Nov 11 08:10:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kate Hsuan X-Patchwork-Id: 14544 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 96D2BBF415 for ; Thu, 11 Nov 2021 08:11:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E2D476032C; Thu, 11 Nov 2021 09:11:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="fKcrwKEa"; 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 102246032C for ; Thu, 11 Nov 2021 09:11:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636618276; 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=zBcqDE5XOd6HhoUknkgwmMNbgDnWvMFa930ki34KSzU=; b=fKcrwKEaalgALGvMmPCy78kMCWYVKwIVFTroGjj+mQpuqxTBVjinhpx8vOWUlhIPvgPw7y p5WKXfbFFyu9ekdp3K1mETB+AATtFtqWlMUAqCVgwQ0MfbeSac+BIXdOs5ajCDFuZ/X8IY 345J7KQWunzJUKLJQsISraIvTDWMRvA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-LGFEccYUPyurqtHiWNF9VA-1; Thu, 11 Nov 2021 03:11:15 -0500 X-MC-Unique: LGFEccYUPyurqtHiWNF9VA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBD928042F0 for ; Thu, 11 Nov 2021 08:11:14 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.193.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id CECE160854; Thu, 11 Nov 2021 08:11:11 +0000 (UTC) From: Kate Hsuan To: libcamera devel Date: Thu, 11 Nov 2021 16:10:55 +0800 Message-Id: <20211111081055.61127-1-hpa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hpa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH] ipa: ipu3: agc: Fix -nan exception 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 user may equip a cam cover to make sure security.If they want to disable the cam, the cam cover could be physically closed to ensure the image will not be delivered. In this situation, the image will be all black and it triggers the -nan exception for some values. Eventually, the exposure will be locked. As a result, we only can get a black image. evGain is calculated by kEvGainTarget * knumHistogramBins / iqMean_. For a black image, a -nan of iqMean_ will lead evGain miss calculated. Consequently, the exposure value can not be correctly estimated and be locked at -nan as well. In this situation, evGain is set to 1.0 and try to estimate again through the next frame. Also, an additional check makes sure the exposure value is between minTotalExposure and maxTotalExposure. Signed-off-by: Kate Hsuan --- src/ipa/ipu3/algorithms/agc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index b5d736c1..d965febe 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -191,6 +191,8 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain) /* Estimate the gain needed to have the proportion wanted */ double evGain = kEvGainTarget * knumHistogramBins / iqMean_; + if(std::isnan(evGain)) + evGain = 1.0; /* extracted from Rpi::Agc::computeTargetExposure */ /* Calculate the shutter time in seconds */ @@ -210,7 +212,9 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain) /* Clamp the exposure value to the min and max authorized */ utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_; - currentExposure_ = std::min(currentExposure_, maxTotalExposure); + utils::Duration minTotalExposure = minShutterSpeed * minAnalogueGain_; + + currentExposure_ = std::clamp(currentExposure_, minTotalExposure, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ << ", maximum is " << maxTotalExposure; @@ -232,7 +236,6 @@ void Agc::computeExposure(uint32_t &exposure, double &analogueGain) LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " << shutterTime << " and " << stepGain; - exposure = shutterTime / lineDuration_; analogueGain = stepGain;