{"id":27381,"url":"https://patchwork.libcamera.org/api/patches/27381/?format=json","web_url":"https://patchwork.libcamera.org/patch/27381/","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":"<20260720095951.49979-5-mzamazal@redhat.com>","date":"2026-07-20T09:59:48","name":"[RFC,v9,4/6] libcamera: shaders: Add LSC support","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c95ad522484f67c3d1de215636e79ac11de81dda","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27381/mbox/","series":[{"id":6062,"url":"https://patchwork.libcamera.org/api/series/6062/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6062","date":"2026-07-20T09:59:44","name":"LSC for SoftISP simple pipeline","version":9,"mbox":"https://patchwork.libcamera.org/series/6062/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27381/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27381/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 BB16DBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jul 2026 10:00:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7451D66149;\n\tMon, 20 Jul 2026 12:00:18 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 501766612C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jul 2026 12:00:17 +0200 (CEST)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-470-ipOzHVvgPCWFJqESmww7eg-1;\n\tMon, 20 Jul 2026 06:00:14 -0400","from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 1CCDD1944AAF; Mon, 20 Jul 2026 10:00:13 +0000 (UTC)","from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.33.73])\n\tby mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id E2E8530002D6; Mon, 20 Jul 2026 10:00:09 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"AIazvqDK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1784541616;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=QRuJ5/9KcNuHCpobXEKvlUmLimeiVOhqvPLI+TvS71g=;\n\tb=AIazvqDKYxWQiKCF8SVQY6hCrct56h358UF5pOcn1D0qn2uA0Pdy2c11EOfp6HWfg+0XPA\n\teG2R5PfwDIBrplyisT/V5+cIRkAuaBvYTWoW5/znn0RlQJ0WjKOHi5meRn028CMN+m3gxQ\n\tFlmxjqj5mJSxCxdz48HhwD61UcEL640=","X-MC-Unique":"ipOzHVvgPCWFJqESmww7eg-1","X-Mimecast-MFC-AGG-ID":"ipOzHVvgPCWFJqESmww7eg_1784541613","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Xander Pronk <xander.c.pronk@gmail.com>,\n\tBryan O'Donoghue <bod.linux@nxsw.ie>,\n\tHans de Goede <johannes.goede@oss.qualcomm.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tRick ten Wolde <rick_libcamera@wolde.info>,\n\tMilan Zamazal <mzamazal@redhat.com>","Subject":"[RFC PATCH v9 4/6] libcamera: shaders: Add LSC support","Date":"Mon, 20 Jul 2026 11:59:48 +0200","Message-ID":"<20260720095951.49979-5-mzamazal@redhat.com>","In-Reply-To":"<20260720095951.49979-1-mzamazal@redhat.com>","References":"<20260720095951.49979-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.4","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"GvXGfsUaj7Nz1G31GcNI7VElMOSWZqYbNUJ-h26F8ow_1784541613","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=\"US-ASCII\"; x-default=true","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":"From: Xander Pronk <xander.c.pronk@gmail.com>\n\nLens shading correction should be applied after black level\nsubtraction (in order to make the computations with meaningful values)\nand before white balance (especially before white balance stats are\ncomputed).\n\nNote that lens shading correction depends on temperature, which is\ncomputed from the preceding, rather than current, frame (this is due to\nhow white balance is currently computed).\n\nThe shaders are compiled on initialisation, while lens shading\ncorrection can be enabled or disabled dynamically, using the\ncorresponding control.  The whole correction in the shader is wrapped by\na conditional macro to be able to disable it and all the related\noverheads if Lsc algorithm is not enabled at all.\n\nIf Lsc algorithm is enabled, the correction is always applied, whether\nthe given control is enabled or not.  If it is not, 1.0 multipliers are\nexpected to be provided.  This is because lens shading correction is\nsupposed to be rarely switched off using the runtime control when Lsc\nalgorithm is enabled, e.g. only for demoing or debugging purposes.\nWe prefer accepting the performance penalty of applying a no-op\ncorrection in such cases rather than disturbing GPU computation in the\nregular flow by introducing a runtime `if'.\n\nCo-developed-by: Rick ten Wolde <rick_libcamera@wolde.info>\nSigned-off-by: Rick ten Wolde <rick_libcamera@wolde.info>\nSigned-off-by: Xander Pronk <xander.c.pronk@gmail.com>\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/libcamera/shaders/bayer_1x_packed.frag | 8 ++++++++\n src/libcamera/shaders/bayer_unpacked.frag  | 8 ++++++++\n 2 files changed, 16 insertions(+)","diff":"diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag\nindex 0b641a5f3..e1c6fad4c 100644\n--- a/src/libcamera/shaders/bayer_1x_packed.frag\n+++ b/src/libcamera/shaders/bayer_1x_packed.frag\n@@ -71,6 +71,10 @@ uniform vec3 blacklevel;\n uniform float gamma;\n uniform float contrastExp;\n \n+#if defined(APPLY_LSC)\n+uniform sampler2D lsc_tex;\n+#endif\n+\n float apply_contrast(float value)\n {\n \t// Apply simple S-curve\n@@ -232,6 +236,10 @@ void main(void)\n \t */\n \trgb = (rgb - blacklevel) / (1.0 - blacklevel);\n \n+#if defined(APPLY_LSC)\n+        rgb = rgb * texture2D(lsc_tex, textureOut).rgb;\n+#endif\n+\n \t/* Apply AWB gains, and saturate each channel at sensor range */\n \trgb = clamp(rgb * awb, vec3(0.0), vec3(1.0));\n \ndiff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag\nindex 10c5e941b..5b870fb2c 100644\n--- a/src/libcamera/shaders/bayer_unpacked.frag\n+++ b/src/libcamera/shaders/bayer_unpacked.frag\n@@ -30,6 +30,10 @@ uniform vec3            blacklevel;\n uniform float           gamma;\n uniform float           contrastExp;\n \n+#if defined(APPLY_LSC)\n+uniform sampler2D lsc_tex;\n+#endif\n+\n float apply_contrast(float value)\n {\n     // Apply simple S-curve\n@@ -135,6 +139,10 @@ void main(void) {\n      */\n     rgb = (rgb - blacklevel) / (1.0 - blacklevel);\n \n+#if defined(APPLY_LSC)\n+    rgb = rgb * texture2D(lsc_tex, center.xy).rgb;\n+#endif\n+\n     /* Apply AWB gains, and saturate each channel at sensor range */\n     rgb = clamp(rgb * awb, vec3(0.0), vec3(1.0));\n \n","prefixes":["RFC","v9","4/6"]}