From patchwork Mon Jan 24 10:31:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15293 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 260C4BF415 for ; Mon, 24 Jan 2022 10:31:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E9CB60987; Mon, 24 Jan 2022 11:31:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BYPFnPwK"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A477E60215 for ; Mon, 24 Jan 2022 11:31:10 +0100 (CET) Received: by mail-wm1-x334.google.com with SMTP id o30-20020a05600c511e00b0034f4c3186f4so2758072wms.3 for ; Mon, 24 Jan 2022 02:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lUd6MuJ460zqOHLslCR49u36QMbLyzBHDCNTLUdvVHI=; b=BYPFnPwKVb6HGczlyYU9Jawy3UFyKFAg6XnVONMyG3S5PuxILSbRAkkHQpJGYF+79f KO1Wss4iM0I+AUtTRZ98tD84BIyuACQEIkKtlvQ5zh93zmSHRlGVfs6xVNlS9RVG59eb lciRs+B1cMmkBoT01OInAfkMgfg08bAYdIpCbTaduglioTgDvYI28R4/lzvku91cIEbu N8o1ZjBP/0GOKL6b7mjd6FaF18bH7C92e0+9LX06tQ7iPFefzndtyeL0ybF0pxKGL/7D OcNJ/BLf5Rb8x8gCygChn/L3ejDPr0gjt9DFNO8tqxc3gFFwo81M5F291FhmRZlk+X9R 2HXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lUd6MuJ460zqOHLslCR49u36QMbLyzBHDCNTLUdvVHI=; b=IcU7vOOYjlESaZanY/sZWm07IBfkvLXfqgdoQJ6CcaIa94YZP0xvmuFW2pYpEYq13y 2MOkCt7M1p8xUIlNnxFI89oiOvyXx0rfIiFLrXKZJ5mqbOsotj02MZutIwW/gyW95uxh wtYKLAWq8VFGPrVEvPsi+faLwMfiLhAopT8pBkUs2IkK0DycGDbUaY5qAgGNCB2Sh9Q6 FGB3gCcdoIw1kPuhj8EcUjBZ9tui6u1eeRb2oOiwLJrcypsj//It6oP+09g9s0HXQgre EPd4Uj6IrCOzA08Ep8ekzqxKFEOCR8IuAW5LOWNboEGZYtwX40xQJ+vExLzWfVSIrU+y ncDA== X-Gm-Message-State: AOAM531VYrSNYkiWdD8vs15WHnRe9hkD0mE1pPVsdd4vBsMUYPZvq6v5 DaSQJTx2pIoauQ3fYqYG8yXjzwZkUHRX+A== X-Google-Smtp-Source: ABdhPJyCTl3EVdeqyQru6Ea2BSbBAlnmgzEsQqvEqMbyQcJmBFkTwlvmJJFiFWSy2JmunIsvURc25w== X-Received: by 2002:a05:600c:3391:: with SMTP id o17mr1206309wmp.156.1643020270048; Mon, 24 Jan 2022 02:31:10 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:d877:8ca4:c9e0:6bb7]) by smtp.gmail.com with ESMTPSA id x6sm16285480wrn.18.2022.01.24.02.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 02:31:09 -0800 (PST) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Jan 2022 10:31:06 +0000 Message-Id: <20220124103107.1799464-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/2] ipa: raspberrypi: Limit the maximum sensor gain used 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" Limit the gain code to the maximum value reported by the sensor controls when sending to DelayedControls. The AGC algorithm will handle a lower gain used by the sensor, provided provided it knows the actual gain used. This change ensures that DelayedControls will never report an unclipped gain used. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/raspberrypi.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 0ed41385018a..a72d516f84ee 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -173,6 +173,9 @@ private: /* Frame duration (1/fps) limits. */ Duration minFrameDuration_; Duration maxFrameDuration_; + + /* Maximum gain code for the sensor. */ + uint32_t maxSensorGainCode_; }; int IPARPi::init(const IPASettings &settings, ipa::RPi::SensorConfig *sensorConfig) @@ -357,6 +360,8 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, return -1; } + maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get(); + /* Setup a metadata ControlList to output metadata. */ libcameraMetadata_ = ControlList(controls::controls); @@ -1113,6 +1118,13 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) { int32_t gainCode = helper_->GainCode(agcStatus->analogue_gain); + /* + * Ensure anything larger than the max gain code will not be passed to + * DelayedControls. The AGC will correctly handle a lower gain returned + * by the sensor, provided it knows the actual gain used. + */ + gainCode = std::min(gainCode, maxSensorGainCode_); + /* GetVBlanking might clip exposure time to the fps limits. */ Duration exposure = agcStatus->shutter_time; int32_t vblanking = helper_->GetVBlanking(exposure, minFrameDuration_, maxFrameDuration_);