{"id":15253,"url":"https://patchwork.libcamera.org/api/patches/15253/?format=json","web_url":"https://patchwork.libcamera.org/patch/15253/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220105155539.5550-4-david.plowman@raspberrypi.com>","date":"2022-01-05T15:55:39","name":"[libcamera-devel,v3,3/3] libcamera: pipeline: raspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d3f16ed9ef48b152ca5497661767617c47b87a94","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15253/mbox/","series":[{"id":2879,"url":"https://patchwork.libcamera.org/api/series/2879/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2879","date":"2022-01-05T15:55:36","name":"Make use of V4L2_CID_NOTIFY_GAINS","version":3,"mbox":"https://patchwork.libcamera.org/series/2879/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15253/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15253/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 13EFBBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Jan 2022 15:55:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51A7F60929;\n\tWed,  5 Jan 2022 16:55:56 +0100 (CET)","from mail-wr1-x434.google.com (mail-wr1-x434.google.com\n\t[IPv6:2a00:1450:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8AC406091E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Jan 2022 16:55:53 +0100 (CET)","by mail-wr1-x434.google.com with SMTP id o3so25767175wrh.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 05 Jan 2022 07:55:53 -0800 (PST)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tg18sm3387491wmq.5.2022.01.05.07.55.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 05 Jan 2022 07:55:52 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"Fl0C7v90\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=6I2BI1zfIjVzPL34bFfXVjP3zHJicz/y3mpIIBe39+c=;\n\tb=Fl0C7v90JdXsZTpGcsTIhkhOzG5eTLhnE4B91Ucf51jfTAp4YweQ8rjH09DL4cqatT\n\tiCG5BrHq27F6qEJ9/Kx+fQyNTMuZhvjY8laZ+Yu5fFGEZ5N9z44NK+PR8jLeZ4hmEZzE\n\t390BobRL0mKZdzaShcntM1Hx6ZM4rR7keGxkap4eoGuzFoZIug/zVADFbkMOGLhDoTrN\n\t8JFIxiHD1gAjTv1fC0wIHgJNFv7NOeHuts4FZcWeBxiqYrmkxLMIWLmPyqnpA6ZyPLAI\n\t9bsQhzeZsdiO+9FHTxWV6mCf76TpPL8rkxemxGqs4ePdeyjwxoGZ4FkVEvssEBpNBHas\n\t9wmw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=6I2BI1zfIjVzPL34bFfXVjP3zHJicz/y3mpIIBe39+c=;\n\tb=7iqaBb+hMMTG2hK/u4DKF5Y+WTZFrl3K0vGLUeopWVa8VsQM95y1bw7be3ej6PlOSl\n\tpx2f1MyQ3ihSZUENQnTTSOqFZ7Skpf5asu7WLjaRcSVzlxbcc5jdodlFCH5Elp8OYw2Z\n\tdWwGeH+7bKFUqeD9xP5+TpOFt7o+2FS6AcxxxiGrLxD98Vqvu7OMdMvS9WsmOsCimnbd\n\tDK2pBg38FWVSazCTtwtK6lZ/w0/CmmTGWmdW6bZiv0F0QHGXInmjrSFAz2J/BaUKBX/b\n\t3LVBMCeQn+btb/fe9vQHUOb+x1kGgUH4IzdPMxCkpSwIuLwecOIlqSzSrcDjJW7oc1Vb\n\t6/tQ==","X-Gm-Message-State":"AOAM530IYqoWCt4+P8WY7Bdi2SGEUGA2Ub9gXlVMG8sUoQ56uZ/vAXdA\n\to4L09eYZIsUlXmQirFiktoIvgYIShDcxLIiT","X-Google-Smtp-Source":"ABdhPJzcT5uSMb5QVyk5odGAYP4fWLsKR90EYml403+DkT2SxA9zweIXIFrtSUTXaqOBDvPE2ylmlw==","X-Received":"by 2002:a05:6000:15cd:: with SMTP id\n\ty13mr47750066wry.28.1641398153146; \n\tWed, 05 Jan 2022 07:55:53 -0800 (PST)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  5 Jan 2022 15:55:39 +0000","Message-Id":"<20220105155539.5550-4-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20220105155539.5550-1-david.plowman@raspberrypi.com>","References":"<20220105155539.5550-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/3] libcamera: pipeline: raspberrypi:\n\tUpdate sensor's V4L2_CID_NOTIFY_GAINS control","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it\nmeans the sensor wants to be told the latest colour gains.\n\nWe store whether the control exists and if so its default value, to\nsave us checking for it on every frame.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 31 +++++++++++++++++++\n 1 file changed, 31 insertions(+)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex b5c687da..4adef952 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -264,6 +264,12 @@ public:\n \n \tunsigned int dropFrameCount_;\n \n+\t/*\n+\t * If set, this stores the value that represets a gain of one for\n+\t * the V4L2_CID_NOTIFY_GAINS control.\n+\t */\n+\tstd::optional<int32_t> notifyGainsUnity_;\n+\n private:\n \tvoid checkRequestCompleted();\n \tvoid fillRequestMetadata(const ControlList &bufferControls,\n@@ -1191,6 +1197,15 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp)\n \t/* Initialize the camera properties. */\n \tdata->properties_ = data->sensor_->properties();\n \n+\t/*\n+\t * The V4L2_CID_NOTIFY_GAINS control, if present, is used to inform the\n+\t * sensor of the colour gains. It is defined to be a linear gain where\n+\t * the default value represents a gain of exactly one.\n+\t */\n+\tauto it = data->sensor_->controls().find(V4L2_CID_NOTIFY_GAINS);\n+\tif (it != data->sensor_->controls().end())\n+\t\tdata->notifyGainsUnity_ = it->second.def().get<int32_t>();\n+\n \t/*\n \t * Set a default value for the ScalerCropMaximum property to show\n \t * that we support its use, however, initialise it to zero because\n@@ -1495,6 +1510,22 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &\n \tRequest *request = requestQueue_.front();\n \trequest->metadata().merge(controls);\n \n+\t/*\n+\t * Inform the sensor of the latest colour gains if it has the\n+\t * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).\n+\t */\n+\tif (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {\n+\t\tlibcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);\n+\t\t/* The control wants linear gains in the order B, Gb, Gr, R. */\n+\t\tControlList ctrls(sensor_->controls());\n+\t\tstd::array<int32_t, 4> gains = { static_cast<int32_t>(colourGains[1] * *notifyGainsUnity_),\n+\t\t\t\t\t\t *notifyGainsUnity_, *notifyGainsUnity_,\n+\t\t\t\t\t\t static_cast<int32_t>(colourGains[0] * *notifyGainsUnity_) };\n+\t\tctrls.set(V4L2_CID_NOTIFY_GAINS, Span<const int32_t>{ gains });\n+\n+\t\tsensor_->setControls(&ctrls);\n+\t}\n+\n \tstate_ = State::IpaComplete;\n \thandleState();\n }\n","prefixes":["libcamera-devel","v3","3/3"]}