From patchwork Fri Jul 31 21:10:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 27536 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 2EAAABDE4C for ; Fri, 31 Jul 2026 21:11:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB96667FF7; Fri, 31 Jul 2026 23:11:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MNoT6sbC"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8CCC665F9F for ; Fri, 31 Jul 2026 23:11:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785532275; 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=XCLpKcs91jMicTKWtWmaiC1wmcx0TjaG3ltJWpZep0Q=; b=MNoT6sbCe3VOpZM5AmbkHbpkenkgekgBlKT5MLRmdjWnCjfOEiPwHtt/XVI79SrV2dW42L f0BvCx3t1RpXlzKECHqsALeMwtfp+PA9jC+6TTT3kNlrvtbMqmclgaKBHTLOrD95UN2/ak VMj5qjQDZ3ZkLITj2qnVYCZ5FTu4UHo= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-T00zBtpJMdSGuDOT3HmBtw-1; Fri, 31 Jul 2026 17:11:12 -0400 X-MC-Unique: T00zBtpJMdSGuDOT3HmBtw-1 X-Mimecast-MFC-AGG-ID: T00zBtpJMdSGuDOT3HmBtw_1785532270 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34D4F18002C3; Fri, 31 Jul 2026 21:11:10 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.42]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E0EB8180036E; Fri, 31 Jul 2026 21:11:06 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Xander Pronk , Bryan O'Donoghue , Hans de Goede , Laurent Pinchart , Robert Mader , Rick ten Wolde , Milan Zamazal , Bryan O'Donoghue Subject: [RFC PATCH v10 4/6] libcamera: shaders: Add LSC support Date: Fri, 31 Jul 2026 23:10:41 +0200 Message-ID: <20260731211044.135970-5-mzamazal@redhat.com> In-Reply-To: <20260731211044.135970-1-mzamazal@redhat.com> References: <20260731211044.135970-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FaBp3UWBrcqSIRc8jzNYfvCHw-4Syflskpkcv70Yvck_1785532270 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 is computed from the preceding, rather than current, frame (this is due to how white balance is currently computed). The shaders are compiled on initialisation, while lens shading correction can be enabled or disabled dynamically, using the corresponding control. The whole correction in the shader is wrapped by a conditional macro to be able to disable it and all the related overheads if Lsc algorithm is not enabled at all. If Lsc algorithm is enabled, the correction is always applied, whether the given control is enabled or not. If it is not, 1.0 multipliers are expected to be provided. This is because lens shading correction is supposed to be rarely switched off using the runtime control when Lsc algorithm is enabled, e.g. only for demoing or debugging purposes. We prefer accepting the performance penalty of applying a no-op correction in such cases rather than disturbing GPU computation in the regular flow by introducing a runtime `if'. lsc_tex texture contains 8-bit UQ<2, 6> quantized data as provided by the IPA algorithm. It is converted to float in the shader by multiplying it by 4.0. Co-developed-by: Rick ten Wolde Signed-off-by: Rick ten Wolde Signed-off-by: Xander Pronk Signed-off-by: Milan Zamazal Reviewed-by: Bryan O'Donoghue --- 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 0b641a5f3..765fc8e88 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -71,6 +71,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 @@ -232,6 +236,11 @@ void main(void) */ rgb = (rgb - blacklevel) / (1.0 - blacklevel); +#if defined(APPLY_LSC) + /* Multiple by 4.0 for UQ<2, 6> -> float conversion */ + rgb = rgb * (texture2D(lsc_tex, textureOut).rgb * 4.0); +#endif + /* Apply AWB gains, and saturate each channel at sensor range */ rgb = clamp(rgb * awb, vec3(0.0), vec3(1.0)); diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index 10c5e941b..be2f89dd0 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -30,6 +30,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 @@ -135,6 +139,11 @@ void main(void) { */ rgb = (rgb - blacklevel) / (1.0 - blacklevel); +#if defined(APPLY_LSC) + /* Multiple by 4.0 for UQ<2, 6> -> float conversion */ + rgb = rgb * (texture2D(lsc_tex, center.xy).rgb * 4.0); +#endif + /* Apply AWB gains, and saturate each channel at sensor range */ rgb = clamp(rgb * awb, vec3(0.0), vec3(1.0));