[{"id":38632,"web_url":"https://patchwork.libcamera.org/comment/38632/","msgid":"<85pl3tiibb.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2026-04-20T18:43:20","subject":"Re: [RFC PATCH v2 5/8] libcamera: shaders: Add LSC support","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Milan Zamazal <mzamazal@redhat.com> writes:\n\n> From: Xander Pronk <xander.c.pronk@gmail.com>\n>\n> Lens shading correction should be applied after black level\n> subtraction (in order to make the computations with meaningful values)\n> and before white balance (especially before white balance stats are\n> computed).\n>\n> Note that lens shading correction depends on temperature, which depends\n> on white balance, so there is a chicken-egg problem.  Currently, we\n> determine white balance and temperature from the preceding frame.\n>\n> TODO: It's unknown why the LSC is computed in the shader the way it is.\n>\n> Co-developed-by: Rick ten Wolde <rick_libcamera@wolde.info>\n> Signed-off-by: Rick ten Wolde <rick_libcamera@wolde.info>\n> Signed-off-by: Xander Pronk <xander.c.pronk@gmail.com>\n> Signed-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(+)\n>\n> diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag\n> index 23747f78a..efc2fec72 100644\n> --- a/src/libcamera/shaders/bayer_1x_packed.frag\n> +++ b/src/libcamera/shaders/bayer_1x_packed.frag\n> @@ -70,6 +70,10 @@ uniform vec3 blacklevel;\n>  uniform float gamma;\n>  uniform float contrastExp;\n>  \n> +#if defined(DO_LSC)\n> +uniform sampler2D lsc_tex;\n> +#endif\n> +\n>  float apply_contrast(float value)\n>  {\n>  \t// Apply simple S-curve\n> @@ -227,6 +231,10 @@ void main(void)\n>  \n>  \trgb = rgb - blacklevel;\n>  \n> +\t#if defined(DO_LSC)\n> +\trgb = rgb + rgb * 3.0 * texture2D(lsc_tex, textureOut).rgb;\n\nCould anybody explain this formula, please?\n\n> +\t#endif\n> +\n>  \t/*\n>  \t *   CCM is a 3x3 in the format\n>  \t *\n> diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag\n> index 1b85196ae..cc82e656c 100644\n> --- a/src/libcamera/shaders/bayer_unpacked.frag\n> +++ b/src/libcamera/shaders/bayer_unpacked.frag\n> @@ -29,6 +29,10 @@ uniform vec3            blacklevel;\n>  uniform float           gamma;\n>  uniform float           contrastExp;\n>  \n> +#if defined(DO_LSC)\n> +uniform sampler2D lsc_tex;\n> +#endif\n> +\n>  float apply_contrast(float value)\n>  {\n>      // Apply simple S-curve\n> @@ -130,6 +134,10 @@ void main(void) {\n>  \n>      rgb = rgb - blacklevel;\n>  \n> +    #if defined(DO_LSC)\n> +    rgb = rgb + rgb * 3.0 * texture2D(lsc_tex, center.xy).rgb;\n> +    #endif\n> +\n>      /*\n>       *   CCM is a 3x3 in the format\n>       *","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 1C6EAC324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Apr 2026 18:43:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 91D4162EF2;\n\tMon, 20 Apr 2026 20:43:35 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F02D62EE0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Apr 2026 20:43:33 +0200 (CEST)","from mail-pj1-f70.google.com (mail-pj1-f70.google.com\n\t[209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-17-07Po6C8hMhWDAsyHlCjokw-1; Mon, 20 Apr 2026 14:43:30 -0400","by mail-pj1-f70.google.com with SMTP id\n\t98e67ed59e1d1-358e95e81aeso7251808a91.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Apr 2026 11:43:30 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-3613f5766c4sm5831124a91.0.2026.04.20.11.43.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 20 Apr 2026 11:43:27 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"Lzfx6WaL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1776710612;\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\tin-reply-to:in-reply-to:references:references;\n\tbh=lFVrND+W/s9C1EWozXmtJsECgbgdjnGDcGCaR+G8XOg=;\n\tb=Lzfx6WaLUCYG0g6w2lKV6wtMx3g3VQuKRmri/nthZ45qrl6G7fmAfO9rWog/fUWB82WaTh\n\tNL7wJVIUH6r5aowOwbNIpx6xm8LFDppkoT1dFLMReV5zr9bQD5pzBi2V6MHwUn/8TYgM/q\n\tOgyyotyYpGNyZsHbvUEH36le/wSOXHc=","X-MC-Unique":"07Po6C8hMhWDAsyHlCjokw-1","X-Mimecast-MFC-AGG-ID":"07Po6C8hMhWDAsyHlCjokw_1776710610","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1776710609; x=1777315409;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=lFVrND+W/s9C1EWozXmtJsECgbgdjnGDcGCaR+G8XOg=;\n\tb=R+20drLw4edM35WqOdbvEqY8J6uE5zblhW0X/rXPxOWvJz5MMAGFDg/DZr8OmaSQ/J\n\t/WwpFyIGYtWxGFmASqW1Tc2+y00UErW/SgeZY98dEx8abFGhVgl7D4/NJWCd6Af0B34z\n\t5IphgcmJtlBxYfuoUjWArGrNT9qZwD74u3iGQZY9OG11xyiYWyapKDPrSW/HcU0cWcZu\n\txVOvYHHFthNJ9ICIeDMRi3zUlCTrZtQVz7PrtZkOEDozPm24hQjkdjSzZyy7QY8Uhchw\n\tNNGdKBx5vQ5B80s3wfQDwUD53+t+Yj6vlXx0ZfpjUJNRQ/p8fYGbe9FbGGxRI0uOQwHo\n\t0olA==","X-Gm-Message-State":"AOJu0Yy9glPtcstIXZYWcYsheEazLIf7CX79WTjZdqjveKz1ZnycD2BN\n\tqgBeGS6UuX3uwl1APH+IZTmRf9Is6JsDI27EF8mgJMqhV/pVOHSfEX9qnoGTwcmdZy6gvQxK+O0\n\tV604/z2oq+6yT68ixobxtgIS8HT2g3v1vHRajBm70fj5tThANZOuYTQGYeayhbNZ+CiH0Y0vA6l\n\thCCxdl8eA=","X-Gm-Gg":"AeBDiesAmfzElt+9UqJ7PHSRsTWTpk5OcvuU8qxKcV1rUHb7dsWrs27Z0GNl8AVck7J\n\tstDJ7es+PFh9CL4WR2mmRKkAt//dv600XyPhURTimUEewp67I/S4A7YxBv6aLcAwPFyANHtwI1y\n\tcSh1j2SwpIs/enGFL20qSwIYmKP+hkzo1OUGU4+36b5tLngM1mfhwtDlCjmTwUSKf5fiqPBpU+E\n\t28/kr2G/BisrjkuaICLxieX6Zk+3IxrpuJwdfmHlToYJh3b8ixzLmnvtsAFBj6/+kzqRsKq4LkA\n\tXocKUtggutz4iAiMExedzhy4lvbXODjeNYpabPAx9rJE0iTvzaTBIJC3uSOj3t8GOr0NnSVYMwW\n\tBzeSYR+xZFWLtSdpVShIOQpUPUetpxm9UpTNF+phbtqGTIE7S+wS4r2+qXf3GPnXaaKYimWNIJp\n\tLtYS58VoqZtA==","X-Received":["by 2002:a17:90a:d2c7:b0:35d:935f:2ff with SMTP id\n\t98e67ed59e1d1-361403ade81mr15689315a91.2.1776710609548; \n\tMon, 20 Apr 2026 11:43:29 -0700 (PDT)","by 2002:a17:90a:d2c7:b0:35d:935f:2ff with SMTP id\n\t98e67ed59e1d1-361403ade81mr15689289a91.2.1776710609042; \n\tMon, 20 Apr 2026 11:43:29 -0700 (PDT)"],"From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Xander Pronk <xander.c.pronk@gmail.com>,  Hans de Goede\n\t<johannes.goede@oss.qualcomm.com>,  Rick ten Wolde\n\t<rick_libcamera@wolde.info>","Subject":"Re: [RFC PATCH v2 5/8] libcamera: shaders: Add LSC support","In-Reply-To":"<20260420183949.110548-6-mzamazal@redhat.com> (Milan Zamazal's\n\tmessage of \"Mon, 20 Apr 2026 20:39:43 +0200\")","References":"<20260420183949.110548-1-mzamazal@redhat.com>\n\t<20260420183949.110548-6-mzamazal@redhat.com>","Date":"Mon, 20 Apr 2026 20:43:20 +0200","Message-ID":"<85pl3tiibb.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"40LbbioTZ-oSG1tWCS2H3kBHINRsdThRAC7SQIJYXnU_1776710610","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>"}}]