From patchwork Wed Jan 5 15:55:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15253 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 13EFBBE080 for ; Wed, 5 Jan 2022 15:55:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 51A7F60929; Wed, 5 Jan 2022 16:55:56 +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="Fl0C7v90"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8AC406091E for ; Wed, 5 Jan 2022 16:55:53 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id o3so25767175wrh.10 for ; Wed, 05 Jan 2022 07:55:53 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=6I2BI1zfIjVzPL34bFfXVjP3zHJicz/y3mpIIBe39+c=; b=Fl0C7v90JdXsZTpGcsTIhkhOzG5eTLhnE4B91Ucf51jfTAp4YweQ8rjH09DL4cqatT iCG5BrHq27F6qEJ9/Kx+fQyNTMuZhvjY8laZ+Yu5fFGEZ5N9z44NK+PR8jLeZ4hmEZzE 390BobRL0mKZdzaShcntM1Hx6ZM4rR7keGxkap4eoGuzFoZIug/zVADFbkMOGLhDoTrN 8JFIxiHD1gAjTv1fC0wIHgJNFv7NOeHuts4FZcWeBxiqYrmkxLMIWLmPyqnpA6ZyPLAI 9bsQhzeZsdiO+9FHTxWV6mCf76TpPL8rkxemxGqs4ePdeyjwxoGZ4FkVEvssEBpNBHas 9wmw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=6I2BI1zfIjVzPL34bFfXVjP3zHJicz/y3mpIIBe39+c=; b=7iqaBb+hMMTG2hK/u4DKF5Y+WTZFrl3K0vGLUeopWVa8VsQM95y1bw7be3ej6PlOSl px2f1MyQ3ihSZUENQnTTSOqFZ7Skpf5asu7WLjaRcSVzlxbcc5jdodlFCH5Elp8OYw2Z dWwGeH+7bKFUqeD9xP5+TpOFt7o+2FS6AcxxxiGrLxD98Vqvu7OMdMvS9WsmOsCimnbd DK2pBg38FWVSazCTtwtK6lZ/w0/CmmTGWmdW6bZiv0F0QHGXInmjrSFAz2J/BaUKBX/b 3LVBMCeQn+btb/fe9vQHUOb+x1kGgUH4IzdPMxCkpSwIuLwecOIlqSzSrcDjJW7oc1Vb 6/tQ== X-Gm-Message-State: AOAM530IYqoWCt4+P8WY7Bdi2SGEUGA2Ub9gXlVMG8sUoQ56uZ/vAXdA o4L09eYZIsUlXmQirFiktoIvgYIShDcxLIiT X-Google-Smtp-Source: ABdhPJzcT5uSMb5QVyk5odGAYP4fWLsKR90EYml403+DkT2SxA9zweIXIFrtSUTXaqOBDvPE2ylmlw== X-Received: by 2002:a05:6000:15cd:: with SMTP id y13mr47750066wry.28.1641398153146; Wed, 05 Jan 2022 07:55:53 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id g18sm3387491wmq.5.2022.01.05.07.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 07:55:52 -0800 (PST) From: David Plowman 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 Subject: [libcamera-devel] [PATCH v3 3/3] libcamera: pipeline: raspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control 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 sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it means the sensor wants to be told the latest colour gains. We store whether the control exists and if so its default value, to save us checking for it on every frame. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b5c687da..4adef952 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -264,6 +264,12 @@ public: unsigned int dropFrameCount_; + /* + * If set, this stores the value that represets a gain of one for + * the V4L2_CID_NOTIFY_GAINS control. + */ + std::optional notifyGainsUnity_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -1191,6 +1197,15 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp) /* Initialize the camera properties. */ data->properties_ = data->sensor_->properties(); + /* + * The V4L2_CID_NOTIFY_GAINS control, if present, is used to inform the + * sensor of the colour gains. It is defined to be a linear gain where + * the default value represents a gain of exactly one. + */ + auto it = data->sensor_->controls().find(V4L2_CID_NOTIFY_GAINS); + if (it != data->sensor_->controls().end()) + data->notifyGainsUnity_ = it->second.def().get(); + /* * Set a default value for the ScalerCropMaximum property to show * that we support its use, however, initialise it to zero because @@ -1495,6 +1510,22 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList & Request *request = requestQueue_.front(); request->metadata().merge(controls); + /* + * Inform the sensor of the latest colour gains if it has the + * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set). + */ + if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) { + libcamera::Span colourGains = controls.get(libcamera::controls::ColourGains); + /* The control wants linear gains in the order B, Gb, Gr, R. */ + ControlList ctrls(sensor_->controls()); + std::array gains = { static_cast(colourGains[1] * *notifyGainsUnity_), + *notifyGainsUnity_, *notifyGainsUnity_, + static_cast(colourGains[0] * *notifyGainsUnity_) }; + ctrls.set(V4L2_CID_NOTIFY_GAINS, Span{ gains }); + + sensor_->setControls(&ctrls); + } + state_ = State::IpaComplete; handleState(); }