Patch Detail
Show a patch.
GET /api/patches/18441/?format=api
{ "id": 18441, "url": "https://patchwork.libcamera.org/api/patches/18441/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18441/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230322161317.18055-4-naush@raspberrypi.com>", "date": "2023-03-22T16:13:17", "name": "[libcamera-devel,v1,3/3] ipa: raspberrypi: Ensure shutter speed and gain are clipped in the AGC", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "1b901d1aa5de94c704fb1f94ade1ca988f4259d3", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18441/mbox/", "series": [ { "id": 3811, "url": "https://patchwork.libcamera.org/api/series/3811/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3811", "date": "2023-03-22T16:13:14", "name": "Raspberry Pi: Sensor limits", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3811/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18441/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18441/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1D290C329D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Mar 2023 16:13:19 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43A1A62715;\n\tWed, 22 Mar 2023 17:13:18 +0100 (CET)", "from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com\n\t[IPv6:2607:f8b0:4864:20::d2a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B3C45626DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 17:13:14 +0100 (CET)", "by mail-io1-xd2a.google.com with SMTP id s4so8682117ioj.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Mar 2023 09:13:14 -0700 (PDT)", "from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tn24-20020a02a918000000b004050d92f6d4sm5100119jam.50.2023.03.22.09.13.13\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Mar 2023 09:13:13 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679501598;\n\tbh=T5UmdV72nfTRwNUVi7eQo2sbBcMiLO+uLhjRMQVEiy4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=oZqjzVbthTSITcs7FW4NkMCfpieY5oc/XOqLue0ZSRi6SEI+YF5ydIKlY+/nNPlLB\n\tRFSMdn5RTHP+QfLyWafwR+6rYvceOSBPZ5tTfUY4AIvzq83kSf+ouWsI34/nZ+a7Yk\n\tov0w9vCZC0dLuNRtlEfBbVrwQHbcO8rLQc5pGXUKCpMe6WS0fAN2CQhYJLmfnqwreV\n\tFpI3od6RktHRITiIjB6vsdZWIrAf26XErK3HN0YKaYyWkbIjf2UJWvwWMJDK1ezyY+\n\tUTa1YjxPEEijoIPOsMHcxMbZNMow6vGDpfhF6zy4MZFPG7mvyWfHx/Q9SDROH+qPNt\n\tmuxSJtGv0XXMg==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679501594;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=0clupoib3wTLjICcDff6DmuNnVx8wOrUSKdGYrk+q6I=;\n\tb=NIAoES7W8XFY2Ivk7m/YXYLKGKBKtwcjg1Dz/HSMkZY6Zz0GJLNF+qq06IcEVqn3B3\n\tRmqwkjZlZepvRGqQDRdOysoS29+d9U0cYkhOtpaAlC8zFWGpezVtGkMwqRmPf0U3encd\n\tKNhDhYIS7KB6o10y99X2WmdTHEl26haKNsvFTpABFGYZWzgOHwEZKVz3vY++s+seBM8L\n\t3aS+78nDTvUHRMjZCH8llp6dz5XVqoMPdLrn0SxThzw7oVElP47QIqo8twpkbDUol5Lj\n\tR+MA0CQsMedtP+aH8xdqkdAGxLgk9klA+1rSrxhaA1z28P+jBCJNw2vczd8e4zPwUci7\n\tyE8Q==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"NIAoES7W\"; dkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679501594;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=0clupoib3wTLjICcDff6DmuNnVx8wOrUSKdGYrk+q6I=;\n\tb=eA8RjeIAdBsLBiLbZZbDZb3DFujgJXL9uDa2fKxSxmWykqUwtpIlyS3A9pP6vx7gTH\n\taPFrYDMk42fDjfByp5Bxz8Sp5+IZkwxjm4m7e7GtDj/NqkD7yZevDyWvXeb5nAfmdGQm\n\t1lJijGhhtcowNeJ6WR7r/D8/nWDyJ7fkmUm25xz61ySMXFHu9r12To8iSPNTTUUuDLLu\n\tficpq+uzEslZdz65e4KCjg3opbzQP3FfLeKsBOnSiIhbLH18JMA++5mxkg1UHrs7niTr\n\tLHVybCruBHMKjJyfk6BaDhhAXr8Ub+wU0lHMNJn/a3kBrltJoGA9VkIDAz/B6bRpLOVJ\n\tt21Q==", "X-Gm-Message-State": "AO0yUKXruoSV2VMVSRhpbCIMGjcGqxH4LjoJZjtWEZ+dw5i/nXkjM28G\n\t/dU6j/Wx8JWalqTOFLzWMpE8RFHcKh2sbwE0rVkUQQ==", "X-Google-Smtp-Source": "AK7set8pXynw/dxNeSXaupCxLJrXzURHhpjr35ABPZOgD2lDJZbjMmimzNgknwlCYBJ6bUJ3tv6cmw==", "X-Received": "by 2002:a5e:c605:0:b0:74c:8cec:548e with SMTP id\n\tf5-20020a5ec605000000b0074c8cec548emr4997612iok.4.1679501594087; \n\tWed, 22 Mar 2023 09:13:14 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 22 Mar 2023 16:13:17 +0000", "Message-Id": "<20230322161317.18055-4-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20230322161317.18055-1-naush@raspberrypi.com>", "References": "<20230322161317.18055-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v1 3/3] ipa: raspberrypi: Ensure shutter\n\tspeed and gain are clipped in the AGC", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Naushir Patuck <naush@raspberrypi.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Limit the AGC gain calculations to the minimum value given by\nSensorLimits. The maximum value remains unclipped as any gain over the\nSensorLimits maximum will be made up by digital gain.\n\nRename clipShutter to limitShutter for consistency, and have the latter\nlimit the shutter speed to both upper and lower bounds.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 47 +++++++++++++++++-----\n src/ipa/raspberrypi/controller/rpi/agc.h | 3 +-\n 2 files changed, 39 insertions(+), 11 deletions(-)", "diff": "diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex eaabc5fa9cd0..ee81537c653c 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -309,14 +309,14 @@ void Agc::setFixedShutter(Duration fixedShutter)\n {\n \tfixedShutter_ = fixedShutter;\n \t/* Set this in case someone calls disableAuto() straight after. */\n-\tstatus_.shutterTime = clipShutter(fixedShutter_);\n+\tstatus_.shutterTime = limitShutter(fixedShutter_);\n }\n \n void Agc::setFixedAnalogueGain(double fixedAnalogueGain)\n {\n \tfixedAnalogueGain_ = fixedAnalogueGain;\n \t/* Set this in case someone calls disableAuto() straight after. */\n-\tstatus_.analogueGain = fixedAnalogueGain;\n+\tstatus_.analogueGain = limitGain(fixedAnalogueGain);\n }\n \n void Agc::setMeteringMode(std::string const &meteringModeName)\n@@ -342,7 +342,7 @@ void Agc::switchMode(CameraMode const &cameraMode,\n \n \thousekeepConfig();\n \n-\tDuration fixedShutter = clipShutter(fixedShutter_);\n+\tDuration fixedShutter = limitShutter(fixedShutter_);\n \tif (fixedShutter && fixedAnalogueGain_) {\n \t\t/* We're going to reset the algorithm here with these fixed values. */\n \n@@ -516,7 +516,7 @@ void Agc::housekeepConfig()\n {\n \t/* First fetch all the up-to-date settings, so no one else has to do it. */\n \tstatus_.ev = ev_;\n-\tstatus_.fixedShutter = clipShutter(fixedShutter_);\n+\tstatus_.fixedShutter = limitShutter(fixedShutter_);\n \tstatus_.fixedAnalogueGain = fixedAnalogueGain_;\n \tstatus_.flickerPeriod = flickerPeriod_;\n \tLOG(RPiAgc, Debug) << \"ev \" << status_.ev << \" fixedShutter \"\n@@ -703,7 +703,7 @@ void Agc::computeTargetExposure(double gain)\n \t\tDuration maxShutter = status_.fixedShutter\n \t\t\t\t\t ? status_.fixedShutter\n \t\t\t\t\t : exposureMode_->shutter.back();\n-\t\tmaxShutter = clipShutter(maxShutter);\n+\t\tmaxShutter = limitShutter(maxShutter);\n \t\tDuration maxTotalExposure =\n \t\t\tmaxShutter *\n \t\t\t(status_.fixedAnalogueGain != 0.0\n@@ -803,15 +803,16 @@ void Agc::divideUpExposure()\n \tdouble analogueGain;\n \tshutterTime = status_.fixedShutter ? status_.fixedShutter\n \t\t\t\t\t : exposureMode_->shutter[0];\n-\tshutterTime = clipShutter(shutterTime);\n+\tshutterTime = limitShutter(shutterTime);\n \tanalogueGain = status_.fixedAnalogueGain != 0.0 ? status_.fixedAnalogueGain\n \t\t\t\t\t\t\t: exposureMode_->gain[0];\n+\tanalogueGain = limitGain(analogueGain);\n \tif (shutterTime * analogueGain < exposureValue) {\n \t\tfor (unsigned int stage = 1;\n \t\t stage < exposureMode_->gain.size(); stage++) {\n \t\t\tif (!status_.fixedShutter) {\n \t\t\t\tDuration stageShutter =\n-\t\t\t\t\tclipShutter(exposureMode_->shutter[stage]);\n+\t\t\t\t\tlimitShutter(exposureMode_->shutter[stage]);\n \t\t\t\tif (stageShutter * analogueGain >= exposureValue) {\n \t\t\t\t\tshutterTime = exposureValue / analogueGain;\n \t\t\t\t\tbreak;\n@@ -824,6 +825,7 @@ void Agc::divideUpExposure()\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t\tanalogueGain = exposureMode_->gain[stage];\n+\t\t\t\tanalogueGain = limitGain(analogueGain);\n \t\t\t}\n \t\t}\n \t}\n@@ -846,6 +848,7 @@ void Agc::divideUpExposure()\n \t\t\t * gain as a side-effect.\n \t\t\t */\n \t\t\tanalogueGain = std::min(analogueGain, exposureMode_->gain.back());\n+\t\t\tanalogueGain = limitGain(analogueGain);\n \t\t\tshutterTime = newShutterTime;\n \t\t}\n \t\tLOG(RPiAgc, Debug) << \"After flicker avoidance, shutter \"\n@@ -872,13 +875,37 @@ void Agc::writeAndFinish(Metadata *imageMetadata, bool desaturate)\n \t\t\t << \" analogue gain \" << filtered_.analogueGain;\n }\n \n-Duration Agc::clipShutter(Duration shutter)\n+Duration Agc::limitShutter(Duration shutter)\n {\n-\tif (sensorLimits_.maxShutter)\n-\t\tshutter = std::min(shutter, sensorLimits_.maxShutter);\n+\t/*\n+\t * shutter == 0 is a special case for fixed shutter values, and must pass\n+\t * through unchanged\n+\t */\n+\tif (!shutter)\n+\t\treturn shutter;\n+\n+\tshutter = std::clamp(shutter, sensorLimits_.minShutter,\n+\t\t\t sensorLimits_.maxShutter);\n \treturn shutter;\n }\n \n+double Agc::limitGain(double gain) const\n+{\n+\t/*\n+\t * Only limit the lower bounds of the gain value to what the sensor limits.\n+\t * The upper bound on analogue gain will be made up with additional digital\n+\t * gain applied by the ISP.\n+\t *\n+\t * gain == 0.0 is a special case for fixed shutter values, and must pass\n+\t * through unchanged\n+\t */\n+\tif (!gain)\n+\t\treturn gain;\n+\n+\tgain = std::max(gain, sensorLimits_.minAnalogueGain);\n+\treturn gain;\n+}\n+\n /* Register algorithm with the system. */\n static Algorithm *create(Controller *controller)\n {\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h\nindex 150a5f6e4428..c48acbba61f0 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.h\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.h\n@@ -103,7 +103,8 @@ private:\n \tvoid filterExposure(bool desaturate);\n \tvoid divideUpExposure();\n \tvoid writeAndFinish(Metadata *imageMetadata, bool desaturate);\n-\tlibcamera::utils::Duration clipShutter(libcamera::utils::Duration shutter);\n+\tlibcamera::utils::Duration limitShutter(libcamera::utils::Duration shutter);\n+\tdouble limitGain(double gain) const;\n \tAgcMeteringMode *meteringMode_;\n \tAgcExposureMode *exposureMode_;\n \tAgcConstraintMode *constraintMode_;\n", "prefixes": [ "libcamera-devel", "v1", "3/3" ] }