From patchwork Sat Dec 20 17:27:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 25617 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 6BC94C3257 for ; Sat, 20 Dec 2025 17:27:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B0F761F8B; Sat, 20 Dec 2025 18:27:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="pZ3neCsV"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="K3gwAQI8"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B518F6142F for ; Sat, 20 Dec 2025 18:27:08 +0100 (CET) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BKBP17T3813079 for ; Sat, 20 Dec 2025 17:27:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=vDOcA/K0sWgLAjNFkPnv56dWZf7YgCNx8cO GDj2FkG0=; b=pZ3neCsVR3UJwyotl3zTBlnZb+UmzHPHMMqIqeWy3vawX0D8oXC P6CVSyI4IdzRp5UPam4UUD+iJOxsU2SPRRLaAKCy/cWLlkbg+8TVzJUuisHQCIDa 4IYxfwYiiO5YG/YE5MWTIVTgBmMzfLd1NdL+ESkiJ/guPC7jiaYyXSCLDhXtP7v5 8z7WZVi23i9pCeVv0aPKYISUL9IVzZR2pRuKhAXOflRVx1KkHYBwbQsKNumnTiCO nFVCXrpYqVm7+prI502p7fgXlM/GOlo44l+e+7uumcyK9HZGQmN5fTnyYh8JPNuB YpqPHQqkhpeQMRUbDgIMiPo3i7emBkrxxTw== Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4b5mru11se-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 20 Dec 2025 17:27:06 +0000 (GMT) Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4ed74ab4172so60688941cf.1 for ; Sat, 20 Dec 2025 09:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1766251625; x=1766856425; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vDOcA/K0sWgLAjNFkPnv56dWZf7YgCNx8cOGDj2FkG0=; b=K3gwAQI8NSKg4UE1hFVYHa+OXc7i1CAlFkZVWN4tkfTbTija61QO+JDt542ady/TSA Rz7NO4Xq6oIZjja0CCbRK+NMS4FPjZ7XRbkr3qPIoWIM4sMzMDxtYeDBjuR/A8AVatBA 4tSF39RwJbmGo5s/uCyVqXbq7mPhahL9D4oyzhUtWj+qZ6Rv3F1CnVdHLV8ivcM4oqEr dncS9TDC7hFXyvh/1MKWdcNyocRw4rhmTNdDw3XdN6Jsx0Hy5BfeKug6NSS5OdRLinSz mCDkRrr7KlFBalWk6tNgYGaZuI6seUkEmMrOe3UmuvTjvM+xBI6rHXcDA4X63igTXLwL lyUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766251625; x=1766856425; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vDOcA/K0sWgLAjNFkPnv56dWZf7YgCNx8cOGDj2FkG0=; b=AFkC7sl2GIzhpp9N1t1EdtgiTK3owmnijECn0ordnu5YL4eP0Jur1gVHKq1CG3AvGf Il3htdlMM+iFdT70GrCe8XOmBJEOqs7RJ+BD9FndZCLLmbWXadWFP9X8mYGi5Z1oyk4v 8o5wkoT3AmTtu6bQSOg9bZ97zb5FtoICRIKJF/EzOnR0nIeHS7nSV46uSuvGGIRujV2R ziatzyD6cPI/zHtTpFTokZ4w19UJaDRaGYqkgqNwmnInhBCQc5WAeNzLAbYEnf1zyM82 fMELW7AJ+fHGFUAT2Eyf38wUkoUpfWKS58jXOGMANDzhoGnoTbEdml3AtwQw02QTMOn9 n83g== X-Gm-Message-State: AOJu0Yz5458SLPQ7IuvBeLnhzbc6JIqg6QCvHRJO34IJE/V6i7ybSTHq Sh0HfFJuXWriiIsYjvT0qDEoKxptHwrjZbTOoWT7LkSUIhL/fSEiyKlNuojONXsns1JZlEWHPYf KX+InrWJ0BUl3BtsoDXX3LYcOS7BtklfdkVZ1diNjLTkI+zYlvEnMapkOS05z2eVsoOy2Osgt3u 9WSl8txFPQ X-Gm-Gg: AY/fxX7ptpknEK9xVJqrWN9P0xbKp9pxsZs/4ISzbFDNjAbJDTaift4p/96rnYsVW6o SD/Smg45cuP/rJuCQdDbcgebPUYWUc4+jrJSYuVzu/2kXZj7iQ8ZoQJSF4aPgrBqG4W60F1CErG f2QAwLelSbOYUx3nH4+h0spRsNpXMhyquAvtj94xkLsEfO1bf2ZtMKtYLlPwDZ7Hfk8jgeyXeMX dYlGpqd2ksIRpjiqf1Y3sN08xGRi3m0CXd72XVOIZCr0q6B0QIV5RxkizAM7bG6+694p97rs2fZ Z9svY3CVpRhH0hyLK8DezYUrgF8ykAVFc6lD1shZzDbgJg96TodepxItp7cCTJGptThCrDFxy1N GNbQSZaZalaV9GNUtX9lDOPv89CcmTApjFCKO7mFDnR59GLrleHAYUzggHX2LTv21pLs6EcpV00 33jGCj/XZojY72wArbMv/GVUUE X-Received: by 2002:a05:622a:4a84:b0:4ee:2459:3d6c with SMTP id d75a77b69052e-4f4abdb5dadmr89222471cf.58.1766251625351; Sat, 20 Dec 2025 09:27:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDq995twtec++D7pubtWy6qs5d/Jo3JOir1IKQzvA+ha/mnYI1hLZQEoWJaZZ6faT/ndHQAA== X-Received: by 2002:a05:622a:4a84:b0:4ee:2459:3d6c with SMTP id d75a77b69052e-4f4abdb5dadmr89222241cf.58.1766251624884; Sat, 20 Dec 2025 09:27:04 -0800 (PST) Received: from shalem (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b91599844sm5183679a12.25.2025.12.20.09.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Dec 2025 09:27:03 -0800 (PST) From: Hans de Goede To: libcamera-devel@lists.libcamera.org, Milan Zamazal Cc: Hans de Goede Subject: [PATCH] ipa: simple: agc: Make sure activeState.agc expo/again are always initialized Date: Sat, 20 Dec 2025 18:27:03 +0100 Message-ID: <20251220172703.321681-1-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjIwMDE1MyBTYWx0ZWRfXyLaDhD17gLCH EJXPIGyRmratlBrTSnSH1dsVRdZwocTx75itj823fnyk6pqmTHh+5M8rXsgk3wY16pHCK5LYt14 Ol9hsvoGGYInh9ujet01poVo5l0hH4G9i616Y3+VrDJki2cXqObnW3vMRq4hH225j2qMJ6H3VYy c1k2PR5Jabkv6YsR9OKx/eQtLtnw0RhH6JIqlbd/m9wu3icAq8id/5lMRaV3hNaDeq72SE8C3wE 6iSc+43eYWGDH0fj5A3GhsPeS2WKv77fr6Nqgf1XTY1qAvAfpi+kxP0pmKGHSS3bmWzduJBnJY3 LwtOsDvBq5UBHXezAO/nhbumzt2Ezygy1DGFP2VK9IlSb3QD3ewI2hOY/TiGns0Pqm/KG+bCmWy BwuGrUvA4tnWPdsmt0YoaZlW2/PI+P5aR9Ma/pd8ORRg33ye9aUI8aLPugE1lMqJXWs0yznQ1O7 +mSga35Z5f5nBa5SwFA== X-Authority-Analysis: v=2.4 cv=VMnQXtPX c=1 sm=1 tr=0 ts=6946dc6a cx=c_pps a=JbAStetqSzwMeJznSMzCyw==:117 a=xqWC_Br6kY4A:10 a=wP3pNCr1ah4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=16YhMSmgSZaTCJXQ5R4A:9 a=uxP6HrT_eTzRwkO_Te1X:22 X-Proofpoint-ORIG-GUID: 2joDU7hZ61b8i0x9CBB4VtszS-jFd1EB X-Proofpoint-GUID: 2joDU7hZ61b8i0x9CBB4VtszS-jFd1EB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1121, Hydra:6.1.9, FMLib:17.12.100.49 definitions=2025-12-20_04,2025-12-19_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2512200153 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" If the first frame of a stream is bad, the IPA will not get called with frame == 0, leaving activeState.agc expo/again uninitialized. This causes the agc algorithm to set a very low gain and exposure on the next run (where it will hit the if (!stats->valid) {} path) resulting in starting with a black image. Fix this by using a valid flag instead of checking for frame == 0. The entire activeState gets cleared to 0 on configure() resetting the new valid flag. Signed-off-by: Hans de Goede --- src/ipa/simple/algorithms/agc.cpp | 5 +++-- src/ipa/simple/ipa_context.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp index 189de770..2f7e040c 100644 --- a/src/ipa/simple/algorithms/agc.cpp +++ b/src/ipa/simple/algorithms/agc.cpp @@ -100,7 +100,7 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou } void Agc::process(IPAContext &context, - const uint32_t frame, + [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, const SwIspStats *stats, ControlList &metadata) @@ -110,13 +110,14 @@ void Agc::process(IPAContext &context, metadata.set(controls::ExposureTime, exposureTime.get()); metadata.set(controls::AnalogueGain, frameContext.sensor.gain); - if (frame == 0) { + if (!context.activeState.agc.valid) { /* * Init active-state from sensor values in case updateExposure() * does not run for the first frame. */ context.activeState.agc.exposure = frameContext.sensor.exposure; context.activeState.agc.again = frameContext.sensor.gain; + context.activeState.agc.valid = true; } if (!stats->valid) { diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index c3081e30..26b60fb6 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -40,6 +40,7 @@ struct IPAActiveState { struct { int32_t exposure; double again; + bool valid; } agc; struct {