From patchwork Mon Apr 20 18:39:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26527 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 74E4FC32F6 for ; Mon, 20 Apr 2026 18:40:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 132FC62EEC; Mon, 20 Apr 2026 20:40:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="FU4P/QHl"; 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 050B862EE9 for ; Mon, 20 Apr 2026 20:40:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776710414; 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=aMbR13c8I7W4CyhZ/3vdhASfNbiIUev0l3DpXlfWP64=; b=FU4P/QHlyj7Pf9CnUPVNHyoLwUHXQU5DZS8vg0BvItssW+0Jtp1gKcboLxSfQoZ1r0r6k5 NOj6atkE+jg72emj3t2930g7LkU7GRQ2jgGz9KY47x46c1adEl8nUAVs7uVf37ZbS2/9kl DkA6yjfFDGAwE7fVWnPKNlLCx2o2mog= Received: from mx-prod-mc-01.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-76-50JmUzGLNraqIG55M5F94g-1; Mon, 20 Apr 2026 14:40:11 -0400 X-MC-Unique: 50JmUzGLNraqIG55M5F94g-1 X-Mimecast-MFC-AGG-ID: 50JmUzGLNraqIG55M5F94g_1776710410 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 75D5219560A3; Mon, 20 Apr 2026 18:40:10 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.48.16]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 645BC1800357; Mon, 20 Apr 2026 18:40:08 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Xander Pronk , Hans de Goede , Rick ten Wolde , Milan Zamazal Subject: [RFC PATCH v2 5/8] libcamera: shaders: Add LSC support Date: Mon, 20 Apr 2026 20:39:43 +0200 Message-ID: <20260420183949.110548-6-mzamazal@redhat.com> In-Reply-To: <20260420183949.110548-1-mzamazal@redhat.com> References: <20260420183949.110548-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: D8mSwy68doD1yvz1hWSqZCHy8BerTsKyVUWLtSxJPtE_1776710410 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. TODO: It's unknown why the LSC is computed in the shader the way it is. Co-developed-by: Rick ten Wolde Signed-off-by: Rick ten Wolde Signed-off-by: Xander Pronk Signed-off-by: Milan Zamazal --- src/libcamera/shaders/bayer_1x_packed.frag | 8 ++++++++ src/libcamera/shaders/bayer_unpacked.frag | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 23747f78a..efc2fec72 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(DO_LSC) +uniform sampler2D lsc_tex; +#endif + float apply_contrast(float value) { // Apply simple S-curve @@ -227,6 +231,10 @@ void main(void) rgb = rgb - blacklevel; + #if defined(DO_LSC) + 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..cc82e656c 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(DO_LSC) +uniform sampler2D lsc_tex; +#endif + float apply_contrast(float value) { // Apply simple S-curve @@ -130,6 +134,10 @@ void main(void) { rgb = rgb - blacklevel; + #if defined(DO_LSC) + rgb = rgb + rgb * 3.0 * texture2D(lsc_tex, center.xy).rgb; + #endif + /* * CCM is a 3x3 in the format *