From patchwork Fri Apr 24 20:02:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26566 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 122E4BE173 for ; Fri, 24 Apr 2026 20:03:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2EE6D62FB1; Fri, 24 Apr 2026 22:03:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="WIcHJA+m"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E8E962FB1 for ; Fri, 24 Apr 2026 22:03:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777061002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CZ7QdUTosb/wnFlS+CPfQHThU4s9kC4aSrnDIroq7E0=; b=WIcHJA+mVMzWPyJp1AOVGNOvMsuLbQX9lGKfWw71xuwpYbsHruwhHo1wU8wU7oKiB/QUHg RlI+fJyb0VIRwO4NC9Q5/enNwea1PMDB2kbnGowCfQCg/EMQMpUs6X6aUyV6zJ6PmHO2pd Ke397EbCgOsffuEw0aveI5BPIGQYUDU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-k8x0zHbOMP2Syyawr50uqQ-1; Fri, 24 Apr 2026 16:03:18 -0400 X-MC-Unique: k8x0zHbOMP2Syyawr50uqQ-1 X-Mimecast-MFC-AGG-ID: k8x0zHbOMP2Syyawr50uqQ_1777060997 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C2059195606E; Fri, 24 Apr 2026 20:03:16 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.33]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 51AF23007572; Fri, 24 Apr 2026 20:03:14 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Xander Pronk , Bryan O'Donoghue , Hans de Goede , Rick ten Wolde , Milan Zamazal Subject: [RFC PATCH v3 5/7] libcamera: shaders: Add LSC support Date: Fri, 24 Apr 2026 22:02:51 +0200 Message-ID: <20260424200255.356798-6-mzamazal@redhat.com> In-Reply-To: <20260424200255.356798-1-mzamazal@redhat.com> References: <20260424200255.356798-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: gE8O9jJXX6slIhLPBdH_ZYDacmiyT0NXkT9li76KW1o_1777060997 X-Mimecast-Originator: redhat.com 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Xander Pronk Lens shading correction should be applied after black level subtraction (in order to make the computations with meaningful values) and before white balance (especially before white balance stats are computed). Note that lens shading correction depends on temperature, which depends on white balance, so there is a chicken-egg problem. Currently, we determine white balance and temperature from the preceding frame. Co-developed-by: Rick ten Wolde Signed-off-by: Rick ten Wolde Signed-off-by: Xander Pronk Signed-off-by: Milan Zamazal Reviewed-by: Laurent Pinchart --- src/libcamera/shaders/bayer_1x_packed.frag | 9 +++++++++ src/libcamera/shaders/bayer_unpacked.frag | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 23747f78a..dfa787c22 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -70,6 +70,10 @@ uniform vec3 blacklevel; uniform float gamma; uniform float contrastExp; +#if defined(APPLY_LSC) +uniform sampler2D lsc_tex; +#endif + float apply_contrast(float value) { // Apply simple S-curve @@ -227,6 +231,11 @@ void main(void) rgb = rgb - blacklevel; + #if defined(APPLY_LSC) + /* Transformation of the lsc_tex value range: 0.0..1.0 -> 1.0..3.0 */ + rgb = rgb + rgb * 3.0 * texture2D(lsc_tex, textureOut).rgb; + #endif + /* * CCM is a 3x3 in the format * diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index 1b85196ae..e10d55c0a 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -29,6 +29,10 @@ uniform vec3 blacklevel; uniform float gamma; uniform float contrastExp; +#if defined(APPLY_LSC) +uniform sampler2D lsc_tex; +#endif + float apply_contrast(float value) { // Apply simple S-curve @@ -130,6 +134,11 @@ void main(void) { rgb = rgb - blacklevel; + #if defined(APPLY_LSC) + /* Transformation of the lsc_tex value range: 0.0..1.0 -> 1.0..3.0 */ + rgb = rgb + rgb * 3.0 * texture2D(lsc_tex, center.xy).rgb; + #endif + /* * CCM is a 3x3 in the format *