{"id":20503,"url":"https://patchwork.libcamera.org/api/1.1/patches/20503/?format=json","web_url":"https://patchwork.libcamera.org/patch/20503/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20240703104004.184783-4-stefan.klug@ideasonboard.com>","date":"2024-07-03T10:39:50","name":"[v2,3/6] ipa: rkisp1: blc: Query black levels from camera sensor helper","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"52a7a768cb6d6a074e41c2ce84c3e5ffa6471e6e","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20503/mbox/","series":[{"id":4435,"url":"https://patchwork.libcamera.org/api/1.1/series/4435/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4435","date":"2024-07-03T10:39:47","name":"ipa: Add black level to camera sensor helpers","version":2,"mbox":"https://patchwork.libcamera.org/series/4435/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20503/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20503/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 0FBEBBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Jul 2024 10:40:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B614262E25;\n\tWed,  3 Jul 2024 12:40:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CC86E62E27\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Jul 2024 12:40:20 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9263:c199:9587:576])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B9BD53E6;\n\tWed,  3 Jul 2024 12:39:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"KXwVq3Xp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720003192;\n\tbh=bEemI1oYKmHfWod+RJxLxtC1lGGLWuKyrT+kIYXOPoo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KXwVq3Xp2O/ZHhcVZe+AxBsc7J5Cs9+kQSkYyTHgIqm00VazcFe+EUYPly09QGqNF\n\tBU+gWYVzwZOCSac766p5WT3xlrTwlY8LyAVPRJdAgIzzCRUbE6JmRqyeuewlz140nx\n\t5WUiEXvrR+px37ILp1y/RUmHV8MKa+kbxLFjZqu0=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v2 3/6] ipa: rkisp1: blc: Query black levels from camera\n\tsensor helper","Date":"Wed,  3 Jul 2024 12:39:50 +0200","Message-ID":"<20240703104004.184783-4-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>","References":"<20240703104004.184783-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"As the camera sensor helper now has the ability to provide the black\nlevel, use them. Black levels can still be overwritten by the tuning\nfile. But the direction is to remove them from the tuning files and move\nthem into the sensor helpers.\n\nAdditionally interpret all values based on 16bits. The conversion to the\nscale required by the hardware is done in process(). It ensures all the\nvalues inside libcamera are the same scale and is in preparation for the\ni.MX8MP where black levels are based on a 20bit scale. Note that this\nbreaks existing tuning files. The tuning files distributed with\nlibcamera will be fixed in a later patch.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/blc.cpp | 54 ++++++++++++++++++++++++++-----\n 1 file changed, 46 insertions(+), 8 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp\nindex d2e743541c99..87025e4f8c72 100644\n--- a/src/ipa/rkisp1/algorithms/blc.cpp\n+++ b/src/ipa/rkisp1/algorithms/blc.cpp\n@@ -46,10 +46,47 @@ BlackLevelCorrection::BlackLevelCorrection()\n int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context,\n \t\t\t       const YamlObject &tuningData)\n {\n-\tblackLevelRed_ = tuningData[\"R\"].get<int16_t>(256);\n-\tblackLevelGreenR_ = tuningData[\"Gr\"].get<int16_t>(256);\n-\tblackLevelGreenB_ = tuningData[\"Gb\"].get<int16_t>(256);\n-\tblackLevelBlue_ = tuningData[\"B\"].get<int16_t>(256);\n+\tstd::optional<int16_t> levelRed = tuningData[\"R\"].get<int16_t>();\n+\tstd::optional<int16_t> levelGreenR = tuningData[\"Gr\"].get<int16_t>();\n+\tstd::optional<int16_t> levelGreenB = tuningData[\"Gb\"].get<int16_t>();\n+\tstd::optional<int16_t> levelBlue = tuningData[\"B\"].get<int16_t>();\n+\tbool tuningHasLevels = levelRed && levelGreenR && levelGreenB && levelBlue;\n+\n+\tauto blackLevel = context.camHelper->blackLevel();\n+\tif (!blackLevel) {\n+\t\t/*\n+\t\t * Not all camera sensor helpers have been updated with black\n+\t\t * levels. Print a warning and fall back to the levels from the\n+\t\t * tuning data to preserve backward compatibility. This should\n+\t\t * be removed once all helpers provide the data.\n+\t\t */\n+\t\tLOG(RkISP1Blc, Warning)\n+\t\t\t<< \"No black levels provided by camera sensor helper\"\n+\t\t\t<< \", please fix\";\n+\n+\t\tblackLevelRed_ = levelRed.value_or(4096);\n+\t\tblackLevelGreenR_ = levelGreenR.value_or(4096);\n+\t\tblackLevelGreenB_ = levelGreenB.value_or(4096);\n+\t\tblackLevelBlue_ = levelBlue.value_or(4096);\n+\t} else if (tuningHasLevels) {\n+\t\t/*\n+\t\t * If black levels are provided in the tuning file, use them to\n+\t\t * avoid breaking existing camera tuning. This is deprecated and\n+\t\t * will be removed.\n+\t\t */\n+\t\tLOG(RkISP1Blc, Warning)\n+\t\t\t<< \"Deprecated: black levels overwritten by tuning file\";\n+\n+\t\tblackLevelRed_ = *levelRed;\n+\t\tblackLevelGreenR_ = *levelGreenR;\n+\t\tblackLevelGreenB_ = *levelGreenB;\n+\t\tblackLevelBlue_ = *levelBlue;\n+\t} else {\n+\t\tblackLevelRed_ = *blackLevel;\n+\t\tblackLevelGreenR_ = *blackLevel;\n+\t\tblackLevelGreenB_ = *blackLevel;\n+\t\tblackLevelBlue_ = *blackLevel;\n+\t}\n \n \ttuningParameters_ = true;\n \n@@ -77,10 +114,11 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n \t\treturn;\n \n \tparams->others.bls_config.enable_auto = 0;\n-\tparams->others.bls_config.fixed_val.r = blackLevelRed_;\n-\tparams->others.bls_config.fixed_val.gr = blackLevelGreenR_;\n-\tparams->others.bls_config.fixed_val.gb = blackLevelGreenB_;\n-\tparams->others.bls_config.fixed_val.b = blackLevelBlue_;\n+\t/* The rkisp1 uses 12bit based black levels. Scale down accordingly. */\n+\tparams->others.bls_config.fixed_val.r = blackLevelRed_ << 4;\n+\tparams->others.bls_config.fixed_val.gr = blackLevelGreenR_ << 4;\n+\tparams->others.bls_config.fixed_val.gb = blackLevelGreenB_ << 4;\n+\tparams->others.bls_config.fixed_val.b = blackLevelBlue_ << 4;\n \n \tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_BLS;\n \tparams->module_ens |= RKISP1_CIF_ISP_MODULE_BLS;\n","prefixes":["v2","3/6"]}