{"id":19232,"url":"https://patchwork.libcamera.org/api/patches/19232/?format=json","web_url":"https://patchwork.libcamera.org/patch/19232/","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":"<20231123130905.103934-2-david.plowman@raspberrypi.com>","date":"2023-11-23T13:09:05","name":"[libcamera-devel,v2,2/2] ipa: rpi: awb: Make it possible to set the colour temperature directly","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9312eae606b6cebd560d7453713427ba2dc0639a","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/19232/mbox/","series":[{"id":4083,"url":"https://patchwork.libcamera.org/api/series/4083/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4083","date":"2023-11-23T13:09:04","name":"[libcamera-devel,v2,1/2] libcamera: controls: Update the ColourTemperature control to be writable","version":2,"mbox":"https://patchwork.libcamera.org/series/4083/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19232/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19232/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 7CB81C328F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Nov 2023 13:09:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 92A7B629C2;\n\tThu, 23 Nov 2023 14:09:14 +0100 (CET)","from mail-lf1-x135.google.com (mail-lf1-x135.google.com\n\t[IPv6:2a00:1450:4864:20::135])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79744629AF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Nov 2023 14:09:12 +0100 (CET)","by mail-lf1-x135.google.com with SMTP id\n\t2adb3069b0e04-507cee17b00so1069430e87.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Nov 2023 05:09:12 -0800 (PST)","from pi5-davidp.pitowers.org\n\t([2a00:1098:3142:14:183e:6cc8:a436:a27c])\n\tby smtp.gmail.com with ESMTPSA id\n\tv10-20020adff68a000000b00332c0e934aasm1593380wrp.44.2023.11.23.05.09.10\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 23 Nov 2023 05:09:10 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1700744954;\n\tbh=j0v0QcAOb0Zkm1Suzr7Srtec8wOMOhVyl34G5ZzYNrc=;\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=UQ02cHRnY140SHbSA79RlY4QPjWVMa2Ij9b+ZZ8viPJ9Z+BE0R3mqOyNonLyDManp\n\tcavD4gCpK7Jo6jVtNVab5n67OtJgMj/O1mGLMpafQd8f1ipDEVc/DYQNMe7lAm2NQD\n\t1YBCaqWKoFdMvobSty39r0XB30tFi4Wk8VWKD6ybtLIA7jlYHjgugt1JcQIsnInNa+\n\tH1hnVrY0gvYoj3sfA8YPFvXMLuwFitBILO23knEiy/jGHj6grC4vOVCjqRqtqvRC33\n\t+qSwec35C8X+ARbLVr/gc1CE1md36rtvqtPQvM2JqJUf0vbzL9EcOVnd9TGV90sW29\n\t5wan5eK5bxTfQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1700744951; x=1701349751;\n\tdarn=lists.libcamera.org; \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=8vWp/RL4W/zGsrOGnV1iqQZwboW+fjAjWQ/4xn9gKZ0=;\n\tb=NxjnIUx9zWJBjO1IPgClZ+iq1bYpfCp7zCAhoG0zKs+G+yUqmohcNnJNiWVJcnm2M0\n\tq2rrqkmg8vUcebeiQWLbwzH+3JF/jr+tNpbLL1lB6aTv/Q5I2vhCimTB/GGHPObl8+Lv\n\t7iAsDZvgWpy8NY0Qrk1uSxLGB1L/YtzgfCcW+Xna5E8HXKjtkTGYUpTIZlM8KgTbl7ge\n\tzP0fj+9Q7vYmZDitFZ6whBg7X7TdIcg1vC7pmpdM+yHxg6uDF+JiL223cjwgsouaduey\n\t9u72rTFl1X5bZL2Saa1KvsHSHO/MSqUANj9FwN+TcUpO7USyD3MIJyUen848Z6QcgTvY\n\tzULQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"NxjnIUx9\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1700744951; x=1701349751;\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=8vWp/RL4W/zGsrOGnV1iqQZwboW+fjAjWQ/4xn9gKZ0=;\n\tb=SIL2l0skak3i/LtsYMO3X+eRR67VMM05xGUluBR5he8+JHiMlWyDmTvzl1rbMswXi3\n\tJSr7/1DJzfu2vhRG/crUbeumbNovnJ+q1Xl6zhBEuL9uaNwTEE3+bNx9MwgTyLNwbMZQ\n\tFTZcntZiyeBcqUdKeTQLL5zJmbQ51T7xUolVAttQSG9VYtRho9j8YxDz+MjzG9k8xRhJ\n\tfXFL25LoI8R+CiX+awC1EvctiM2tU326oZOMbarQgACe4Q0Mqf4IiQCA3/8RksnNkbeo\n\tSdTKgDFpgAtwEDc55dAg9690A7xjtVQoldhS3d1TWbOWR9buVCfq8yLulciDcftSTsyS\n\tBBCg==","X-Gm-Message-State":"AOJu0YzSvuATeKs3vkZVbxDeDKpp4E5q9Am1Qv9V85DXENYND+FPEHu4\n\tey/p6f5S3FQLETDNx0Xn9p61Gx6Ksut4vXC1ZHA=","X-Google-Smtp-Source":"AGHT+IEPRhD/KQhxCoa4eNsxlseoAtxXlQQTv8vUkNEQEvLKKQwmwRyUL6KpX5ZTFMGB/2Xgx/bFaQ==","X-Received":"by 2002:a05:6512:3248:b0:503:654:cf27 with SMTP id\n\tc8-20020a056512324800b005030654cf27mr3612222lfr.28.1700744951075; \n\tThu, 23 Nov 2023 05:09:11 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 23 Nov 2023 13:09:05 +0000","Message-Id":"<20231123130905.103934-2-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.39.2","In-Reply-To":"<20231123130905.103934-1-david.plowman@raspberrypi.com>","References":"<20231123130905.103934-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 2/2] ipa: rpi: awb: Make it possible to\n\tset the colour temperature directly","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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"ColourTemperature is now exported as a writable control so that\napplications can set it directly. The AWB algorithm class now requires\na method to be provided to perform this operation. The method should\nclamp the passed value to the calibrated range known to the algorithm.\n\nThe default range is set very wide to cover all conceivable future AWB\ncalibrations. It will always be clamped before use.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/rpi/common/ipa_base.cpp        | 20 ++++++++++++++++++++\n src/ipa/rpi/controller/awb_algorithm.h |  1 +\n src/ipa/rpi/controller/rpi/awb.cpp     | 18 ++++++++++++++++++\n src/ipa/rpi/controller/rpi/awb.h       |  1 +\n 4 files changed, 40 insertions(+)","diff":"diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp\nindex 97a32522..cd1d6e3d 100644\n--- a/src/ipa/rpi/common/ipa_base.cpp\n+++ b/src/ipa/rpi/common/ipa_base.cpp\n@@ -80,6 +80,7 @@ const ControlInfoMap::Map ipaColourControls{\n \t{ &controls::AwbEnable, ControlInfo(false, true) },\n \t{ &controls::AwbMode, ControlInfo(controls::AwbModeValues) },\n \t{ &controls::ColourGains, ControlInfo(0.0f, 32.0f) },\n+\t{ &controls::ColourTemperature, ControlInfo(100, 100000) },\n \t{ &controls::Saturation, ControlInfo(0.0f, 32.0f, 1.0f) },\n };\n \n@@ -972,6 +973,25 @@ void IpaBase::applyControls(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::COLOUR_TEMPERATURE: {\n+\t\t\t/* Silently ignore this control for a mono sensor. */\n+\t\t\tif (monoSensor_)\n+\t\t\t\tbreak;\n+\n+\t\t\tauto temperatureK = ctrl.second.get<int32_t>();\n+\t\t\tRPiController::AwbAlgorithm *awb = dynamic_cast<RPiController::AwbAlgorithm *>(\n+\t\t\t\tcontroller_.getAlgorithm(\"awb\"));\n+\t\t\tif (!awb) {\n+\t\t\t\tLOG(IPARPI, Warning)\n+\t\t\t\t\t<< \"Could not set COLOUR_TEMPERATURE - no AWB algorithm\";\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tawb->setColourTemperature(temperatureK);\n+\t\t\t/* This metadata will get reported back automatically. */\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tcase controls::BRIGHTNESS: {\n \t\t\tRPiController::ContrastAlgorithm *contrast = dynamic_cast<RPiController::ContrastAlgorithm *>(\n \t\t\t\tcontroller_.getAlgorithm(\"contrast\"));\ndiff --git a/src/ipa/rpi/controller/awb_algorithm.h b/src/ipa/rpi/controller/awb_algorithm.h\nindex 8462c4db..d966dfa8 100644\n--- a/src/ipa/rpi/controller/awb_algorithm.h\n+++ b/src/ipa/rpi/controller/awb_algorithm.h\n@@ -18,6 +18,7 @@ public:\n \tvirtual unsigned int getConvergenceFrames() const = 0;\n \tvirtual void setMode(std::string const &modeName) = 0;\n \tvirtual void setManualGains(double manualR, double manualB) = 0;\n+\tvirtual void setColourTemperature(double temperatureK) = 0;\n \tvirtual void enableAuto() = 0;\n \tvirtual void disableAuto() = 0;\n };\ndiff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\nindex 5ae0c2fa..0918e20d 100644\n--- a/src/ipa/rpi/controller/rpi/awb.cpp\n+++ b/src/ipa/rpi/controller/rpi/awb.cpp\n@@ -275,6 +275,24 @@ void Awb::setManualGains(double manualR, double manualB)\n \t}\n }\n \n+void Awb::setColourTemperature(double temperatureK)\n+{\n+\tif (!config_.bayes) {\n+\t\tLOG(RPiAwb, Warning) << \"AWB uncalibrated - cannot set colour temperature\";\n+\t\treturn;\n+\t}\n+\n+\ttemperatureK = config_.ctR.domain().clip(temperatureK);\n+\tmanualR_ = 1 / config_.ctR.eval(temperatureK);\n+\tmanualB_ = 1 / config_.ctB.eval(temperatureK);\n+\n+\tsyncResults_.temperatureK = temperatureK;\n+\tsyncResults_.gainR = manualR_;\n+\tsyncResults_.gainG = 1.0;\n+\tsyncResults_.gainB = manualB_;\n+\tprevSyncResults_ = syncResults_;\n+}\n+\n void Awb::switchMode([[maybe_unused]] CameraMode const &cameraMode,\n \t\t     Metadata *metadata)\n {\ndiff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h\nindex e7d49cd8..dbd79eda 100644\n--- a/src/ipa/rpi/controller/rpi/awb.h\n+++ b/src/ipa/rpi/controller/rpi/awb.h\n@@ -97,6 +97,7 @@ public:\n \tunsigned int getConvergenceFrames() const override;\n \tvoid setMode(std::string const &name) override;\n \tvoid setManualGains(double manualR, double manualB) override;\n+\tvoid setColourTemperature(double temperatureK) override;\n \tvoid enableAuto() override;\n \tvoid disableAuto() override;\n \tvoid switchMode(CameraMode const &cameraMode, Metadata *metadata) override;\n","prefixes":["libcamera-devel","v2","2/2"]}