[{"id":36316,"web_url":"https://patchwork.libcamera.org/comment/36316/","msgid":"<855xceewfv.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-16T14:46:28","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Bryan,\n\nBryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> Extend out the bayer fragment shaders to take 3 x 256 byte inputs as\n> textures from the CPU.\n>\n> We then use an index to the table to recover the colour-corrected values\n> provided by the SoftIPA thread.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  .../internal/shaders/bayer_1x_packed.frag     | 56 +++++++++++++++++\n>  .../internal/shaders/bayer_unpacked.frag      | 62 ++++++++++++++++++-\n>  2 files changed, 117 insertions(+), 1 deletion(-)\n>\n> diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> index 19b13ad0..90bd6457 100644\n> --- a/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> +++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> @@ -65,6 +65,10 @@ uniform vec2 tex_step;\n>  uniform vec2 tex_bayer_first_red;\n>  \n>  uniform sampler2D tex_y;\n> +uniform sampler2D red_param;\n> +uniform sampler2D green_param;\n> +uniform sampler2D blue_param;\n> +uniform mat3 ccm;\n>  \n>  void main(void)\n>  {\n> @@ -212,5 +216,57 @@ void main(void)\n>  \t\t\tvec3(patterns.y, C, patterns.x) :\n>  \t\t\tvec3(patterns.wz, C));\n>  \n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n\nThe ordering of the values is tricky.  I performed some testing and it\nseems to work as expected with GPU ISP.\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\nUnrelated to this patch and branch, we have some problem with CPU ISP\nCCM.  The matrix\n\n  [ 0, 1, 0,\n    0, 0, 0,\n    0, 0, 0]\n\nproduces a blue rather than red picture in my environment (unlike when 1\nis in other positions of the first row), which is weird.  I'll look at\nit.\n\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(green_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(blue_param, vec2(rgb.b, 0.5)).b;\n> +#endif\n> +\n>  \tgl_FragColor = vec4(rgb, 1.0);\n>  }\n> diff --git a/include/libcamera/internal/shaders/bayer_unpacked.frag b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> index aa7a1b00..5955c2ea 100644\n> --- a/include/libcamera/internal/shaders/bayer_unpacked.frag\n> +++ b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> @@ -21,11 +21,17 @@ precision highp float;\n>  \n>  /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/\n>  uniform sampler2D       tex_y;\n> +uniform sampler2D\tred_param;\n> +uniform sampler2D\tgreen_param;\n> +uniform sampler2D\tblue_param;\n>  varying vec4            center;\n>  varying vec4            yCoord;\n>  varying vec4            xCoord;\n> +uniform mat3\t\tccm;\n>  \n>  void main(void) {\n> +    vec3 rgb;\n> +\n>      #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r\n>  \n>      float C = texture2D(tex_y, center.xy).r; // ( 0, 0)\n> @@ -97,11 +103,65 @@ void main(void) {\n>      PATTERN.xw  += kB.xw * B;\n>      PATTERN.xz  += kF.xz * F;\n>  \n> -    gl_FragColor.rgb = (alternate.y == 0.0) ?\n> +    rgb =  (alternate.y == 0.0) ?\n>          ((alternate.x == 0.0) ?\n>              vec3(C, PATTERN.xy) :\n>              vec3(PATTERN.z, C, PATTERN.w)) :\n>          ((alternate.x == 0.0) ?\n>              vec3(PATTERN.w, C, PATTERN.z) :\n>              vec3(PATTERN.yx, C));\n> +\n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;\n> +#endif\n> +\n> +    gl_FragColor.rgb = rgb;\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 AFED5BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Oct 2025 14:46:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 977C960684;\n\tThu, 16 Oct 2025 16:46: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 C412D605D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Oct 2025 16:46:33 +0200 (CEST)","from mail-wr1-f71.google.com (mail-wr1-f71.google.com\n\t[209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-543-VBo0i-n6OHyVEXyGw1Eo3g-1; Thu, 16 Oct 2025 10:46:31 -0400","by mail-wr1-f71.google.com with SMTP id\n\tffacd0b85a97d-426ff8fa3a6so669306f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Oct 2025 07:46:31 -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\t5b1f17b1804b1-47114460fe1sm33358445e9.17.2025.10.16.07.46.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 16 Oct 2025 07:46:29 -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=\"DcNPQMkD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760625992;\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=dvY5SRAYXBiJ0awmp79/gBPw736OLWDByLhbdpfFdJc=;\n\tb=DcNPQMkDkwiqUsdvAift+jHHdRg0weGlhyMSx0UI4zpYBugBnwZE67Fak3C6H/HnJX6Ym0\n\tmxYk1usgh1XPQTA8BDAgjHTCifmxN9Ap6SX2HmKOIrbL5vBwbsyT0dQ+toX/i1U5ncPTSe\n\t11RDo7+idAJjb+v2loXo21F3vmPFOos=","X-MC-Unique":"VBo0i-n6OHyVEXyGw1Eo3g-1","X-Mimecast-MFC-AGG-ID":"VBo0i-n6OHyVEXyGw1Eo3g_1760625990","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760625990; x=1761230790;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=dvY5SRAYXBiJ0awmp79/gBPw736OLWDByLhbdpfFdJc=;\n\tb=D96/IR9MISH4+PJ7vha+BXbOdHUeyY/flZUE899Dpb5c5D5yr3LxP+ExRuGXhzvWAR\n\tHmYVRtm1qSd03sNzYnXgjTGwxUURJpEKUn+PmQNTRV47u8k37wJGEQGU+nMTplf18N7E\n\tiJnoWYE2m+TDpZJPw2F5hSY1ZLkMhjGyf+A5DyBvQGrItU2z6HeELQX51MV4kH9yBSUP\n\tr5fy8qdpCc8YxRq9slNfLqa29TlBWzXxiXU2g3eVV144dINz12GxiTYHpOhMTV9P09Kt\n\tVwmPQDVQY1lvRFuAav8YFic9CnUh+dAz+K1Dqf/SWsMYkl83K16FBOHaIOn86QDyN9Fv\n\t76/Q==","X-Gm-Message-State":"AOJu0Yw1UaejghXUbhngJbC96xiWTHwzGaZDNvcoeENwNFkKDQMGoRrX\n\txeXQrjf2zIdV+IzndH+vPbZsHFMmVnE2UAA/o2xowPZpuXMvztHElcTQ+aWqsApzbb++MAgQYQy\n\tAC1R2RwRWsqE8apdddyHOf4dgEgemANDK4kFUnkAt8eQrT5dujJ4nUYFwqDABQ/zZExm6JdOqQl\n\tk=","X-Gm-Gg":"ASbGnctcZoRJCqWs6xc7OkwjihcR+s6nKRKRwUsD4n2RCNCxYdb5Wmmlo/H0lmVBb6G\n\tZyuZKqN9TcuDKM3s0icjw6qURfGJTRmYqS/UFw4rLlQm11PssJKPGxJx7mFR9tEvgNYlg+RFn3J\n\tJH0plBSRmfC5wsr8Ipcpy68ajtN6slW5rGOXXTcRAJCfDdlVbmk2U1ZGvOnHIEIF58FkrsgJ4wA\n\tqILY8gBBdtcphBBl30c7zxogQg/O7DxIwpN20VqvhYSrD9uftCSIJ/GydzhVXDZ0QuaXj5KRQof\n\t97a8aqDnC5MxUdNf8DClbqeI19ZYJhW8ZPvRcYWYiieCZ6UulFiVAfk9MDdfXT1BSNhrmAHGt1o\n\tjeawe+sF6lunIXt3oTiguFGSEQA+71CJh/SgwTWCaYy49sdQm9Chd","X-Received":["by 2002:a05:600c:8b16:b0:46e:384f:bd86 with SMTP id\n\t5b1f17b1804b1-4711787070amr1875105e9.5.1760625990269; \n\tThu, 16 Oct 2025 07:46:30 -0700 (PDT)","by 2002:a05:600c:8b16:b0:46e:384f:bd86 with SMTP id\n\t5b1f17b1804b1-4711787070amr1874795e9.5.1760625989733; \n\tThu, 16 Oct 2025 07:46:29 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IFp2ee3W7opI+oImCLap+JVLGbbOVXJiEeLM021Moh5mHzMCo/sFsiM8Gz22s8Bar3aeeIGWQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","In-Reply-To":"<20251015012251.17508-30-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Wed, 15 Oct 2025 02:22:41 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>","Date":"Thu, 16 Oct 2025 16:46:28 +0200","Message-ID":"<855xceewfv.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":"U88EgSEmIbIegpDIddTa_bFWOvWD0aQlwpB1KNEOApw_1760625990","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>"}},{"id":36337,"web_url":"https://patchwork.libcamera.org/comment/36337/","msgid":"<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-17T18:53:16","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> Extend out the bayer fragment shaders to take 3 x 256 byte inputs as\n> textures from the CPU.\n>\n> We then use an index to the table to recover the colour-corrected values\n> provided by the SoftIPA thread.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  .../internal/shaders/bayer_1x_packed.frag     | 56 +++++++++++++++++\n>  .../internal/shaders/bayer_unpacked.frag      | 62 ++++++++++++++++++-\n>  2 files changed, 117 insertions(+), 1 deletion(-)\n>\n> diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> index 19b13ad0..90bd6457 100644\n> --- a/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> +++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> @@ -65,6 +65,10 @@ uniform vec2 tex_step;\n>  uniform vec2 tex_bayer_first_red;\n>  \n>  uniform sampler2D tex_y;\n> +uniform sampler2D red_param;\n> +uniform sampler2D green_param;\n> +uniform sampler2D blue_param;\n> +uniform mat3 ccm;\n>  \n>  void main(void)\n>  {\n> @@ -212,5 +216,57 @@ void main(void)\n>  \t\t\tvec3(patterns.y, C, patterns.x) :\n>  \t\t\tvec3(patterns.wz, C));\n>  \n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n\nI think black level must be subtracted and gamma applied here, e.g.\n\n  rgb = rgb - vec3(blackLevel);  // blackLevel must be passed from the IPA\n  rgb = pow(rgb, vec3(gamma));   // gamma = 0.5 in CPU ISP\n\nSee lut.cpp, where with CCM the gamma lookup table is passed separately\nfrom the CCM lookup tables to debayer_cpu.cpp and incorporates the black\nlevel correction.\n\nWith these two changes + the awb change in the other patch,\nAPPLY_CCM_PARAMETERS output seems to be similar to APPLY_RGB_PARAMETERS\noutput in my environment.  I'm not sure I'm 100% correct and it needs a\nbit more testing but I think these are the basic ideas what fixes are\nneeded for the CCM output.\n\nThe same for the other shader.\n\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(green_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(blue_param, vec2(rgb.b, 0.5)).b;\n> +#endif\n> +\n>  \tgl_FragColor = vec4(rgb, 1.0);\n>  }\n> diff --git a/include/libcamera/internal/shaders/bayer_unpacked.frag b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> index aa7a1b00..5955c2ea 100644\n> --- a/include/libcamera/internal/shaders/bayer_unpacked.frag\n> +++ b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> @@ -21,11 +21,17 @@ precision highp float;\n>  \n>  /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/\n>  uniform sampler2D       tex_y;\n> +uniform sampler2D\tred_param;\n> +uniform sampler2D\tgreen_param;\n> +uniform sampler2D\tblue_param;\n>  varying vec4            center;\n>  varying vec4            yCoord;\n>  varying vec4            xCoord;\n> +uniform mat3\t\tccm;\n>  \n>  void main(void) {\n> +    vec3 rgb;\n> +\n>      #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r\n>  \n>      float C = texture2D(tex_y, center.xy).r; // ( 0, 0)\n> @@ -97,11 +103,65 @@ void main(void) {\n>      PATTERN.xw  += kB.xw * B;\n>      PATTERN.xz  += kF.xz * F;\n>  \n> -    gl_FragColor.rgb = (alternate.y == 0.0) ?\n> +    rgb =  (alternate.y == 0.0) ?\n>          ((alternate.x == 0.0) ?\n>              vec3(C, PATTERN.xy) :\n>              vec3(PATTERN.z, C, PATTERN.w)) :\n>          ((alternate.x == 0.0) ?\n>              vec3(PATTERN.w, C, PATTERN.z) :\n>              vec3(PATTERN.yx, C));\n> +\n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;\n> +#endif\n> +\n> +    gl_FragColor.rgb = rgb;\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 B45EAC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Oct 2025 18:53:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64A1E606BF;\n\tFri, 17 Oct 2025 20:53:25 +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 68D78606B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Oct 2025 20:53:24 +0200 (CEST)","from mail-wr1-f69.google.com (mail-wr1-f69.google.com\n\t[209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-437-GFsq55hHOQumJsaEfpEU9g-1; Fri, 17 Oct 2025 14:53:19 -0400","by mail-wr1-f69.google.com with SMTP id\n\tffacd0b85a97d-426ec5e9278so3445199f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Oct 2025 11:53:19 -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\tffacd0b85a97d-427f00b9fa8sm657165f8f.38.2025.10.17.11.53.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 17 Oct 2025 11:53:17 -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=\"MzPpcqGI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760727203;\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=SBr65k34zTyCIpKB7p6mxgGC03Jp86li35UaCMlkVSs=;\n\tb=MzPpcqGI3nsQfNaFTerLV7LyMlex0rvOLM7gmlKr7EBOvdeh7X+Tib2Fc0VviBhafb2ncM\n\thECdun6gD7xYJ76r3e2i+Diyysw+jOXWFYjvaZGcY+2WsuBmScECIH6awWF3PECsLu5fRz\n\tt3gYQlk5YLMAXA4IKp3yXQzqyth5+dI=","X-MC-Unique":"GFsq55hHOQumJsaEfpEU9g-1","X-Mimecast-MFC-AGG-ID":"GFsq55hHOQumJsaEfpEU9g_1760727198","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760727198; x=1761331998;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=SBr65k34zTyCIpKB7p6mxgGC03Jp86li35UaCMlkVSs=;\n\tb=tTvf9OmrT6OQ3UNbIJkdrB9NboFILwoX6d41eTnFMPAaCK2CMG+uFptVF8AY1OHmOS\n\tctk3uqni9kopHtGzpGLJgS1l1HsXzhOk0bY8jDrseHx1ewj5z/+NS0Fic04dwYQjshiz\n\tligzVYikv9Toyj+udMOGMpjlSMIwpD6VdTsBsAY7ZsdASRlGkLp7a3do/hjJkDN514+W\n\tHifke3JlIobtmeWueNbK7Rl6WLBQFs4sWrENZdAg7bdUjD/PgMIQ1HI0XiEhXQuCzEMR\n\tDxY+VvDa1lMt/NOyKCs3DhGSI+Hl/kkFnZIDWZHExF5z6V5DQm7KUE7IkbhxTe1akXdO\n\tzO0A==","X-Gm-Message-State":"AOJu0YzDUJIaGQa5qtqikcDdnetAvhmw929Iy+6Q0Qm2JvwWyzcXZ8yz\n\tr7t6B10XDvVZVdaDdapUSetwH47dW0fCJIvZwO6MG/ZkUJlJbZzw+Vsx4cdnhgqu/4UgE56BPED\n\t3a7HRYEdZ5vGO8a6y6gwe4Hz7ijArjaChF7Squl7HcpVuoedj+3mY7eFcYKEMJk1970Hx1K4LF0\n\tIRT07lVJc=","X-Gm-Gg":"ASbGnculA7puCEF6zXHwh2vMtcMvMWQCJGQ4MLahJTmlV3WTSK9YSQqvhhTzulpO++Q\n\t6BLNRT6amJWi/V6CAXafzI0jmsSP3RXTyPpA8v0HYgZI2HzVKV1tZTzOYpqwQGZvxEacp8RJhu2\n\tX7ayw/jNfD1yOVX5bVV8urX+ErsJouhUZGIxtDniv0VweRFUrHR3LFgNkbxp9pepVGBFBhPn1q/\n\t48czX4EkwNZvVirqhVUVU/CU2RbXqj7hmhZS3FuYRmVKHFVWyCWRJq6pgIoMW0Q+9wx6eqkgCs7\n\tVwecv0XkQvpyPyjuERlKl22kfx4ZVYYRKP7X6f4CA4E8W8dkm4PxXZFHUOekORLEPoFyGhgk8KD\n\tjXEUhxjwgBPwnfwklvcAooXfV3ZJCRE6r+q0whISJGUCM2VFmlous","X-Received":["by 2002:a05:6000:258a:b0:427:247:4eda with SMTP id\n\tffacd0b85a97d-42704dd6c2fmr3292972f8f.55.1760727197992; \n\tFri, 17 Oct 2025 11:53:17 -0700 (PDT)","by 2002:a05:6000:258a:b0:427:247:4eda with SMTP id\n\tffacd0b85a97d-42704dd6c2fmr3292963f8f.55.1760727197602; \n\tFri, 17 Oct 2025 11:53:17 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IFmOZ6c+JYEfjgydNwWuymKBu0UjbAfrZw3rh3JbAF8fx5EHasTkNm8LQUg6F/Yb0fJMbRqug==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","In-Reply-To":"<20251015012251.17508-30-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Wed, 15 Oct 2025 02:22:41 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>","Date":"Fri, 17 Oct 2025 20:53:16 +0200","Message-ID":"<85sefhnyw3.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":"mqZm-v2FKFL2sBvp8djOQV5RSd1kco3u-58WFszip6s_1760727198","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>"}},{"id":36339,"web_url":"https://patchwork.libcamera.org/comment/36339/","msgid":"<85zf9osckj.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-18T10:56:28","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> Extend out the bayer fragment shaders to take 3 x 256 byte inputs as\n> textures from the CPU.\n>\n> We then use an index to the table to recover the colour-corrected values\n> provided by the SoftIPA thread.\n>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  .../internal/shaders/bayer_1x_packed.frag     | 56 +++++++++++++++++\n>  .../internal/shaders/bayer_unpacked.frag      | 62 ++++++++++++++++++-\n>  2 files changed, 117 insertions(+), 1 deletion(-)\n>\n> diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> index 19b13ad0..90bd6457 100644\n> --- a/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> +++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n> @@ -65,6 +65,10 @@ uniform vec2 tex_step;\n>  uniform vec2 tex_bayer_first_red;\n>  \n>  uniform sampler2D tex_y;\n> +uniform sampler2D red_param;\n> +uniform sampler2D green_param;\n> +uniform sampler2D blue_param;\n> +uniform mat3 ccm;\n>  \n>  void main(void)\n>  {\n> @@ -212,5 +216,57 @@ void main(void)\n>  \t\t\tvec3(patterns.y, C, patterns.x) :\n>  \t\t\tvec3(patterns.wz, C));\n>  \n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(green_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(blue_param, vec2(rgb.b, 0.5)).b;\n> +#endif\n> +\n>  \tgl_FragColor = vec4(rgb, 1.0);\n>  }\n> diff --git a/include/libcamera/internal/shaders/bayer_unpacked.frag b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> index aa7a1b00..5955c2ea 100644\n> --- a/include/libcamera/internal/shaders/bayer_unpacked.frag\n> +++ b/include/libcamera/internal/shaders/bayer_unpacked.frag\n> @@ -21,11 +21,17 @@ precision highp float;\n>  \n>  /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/\n>  uniform sampler2D       tex_y;\n> +uniform sampler2D\tred_param;\n> +uniform sampler2D\tgreen_param;\n> +uniform sampler2D\tblue_param;\n>  varying vec4            center;\n>  varying vec4            yCoord;\n>  varying vec4            xCoord;\n> +uniform mat3\t\tccm;\n>  \n>  void main(void) {\n> +    vec3 rgb;\n> +\n>      #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r\n>  \n>      float C = texture2D(tex_y, center.xy).r; // ( 0, 0)\n> @@ -97,11 +103,65 @@ void main(void) {\n>      PATTERN.xw  += kB.xw * B;\n>      PATTERN.xz  += kF.xz * F;\n>  \n> -    gl_FragColor.rgb = (alternate.y == 0.0) ?\n> +    rgb =  (alternate.y == 0.0) ?\n>          ((alternate.x == 0.0) ?\n>              vec3(C, PATTERN.xy) :\n>              vec3(PATTERN.z, C, PATTERN.w)) :\n>          ((alternate.x == 0.0) ?\n>              vec3(PATTERN.w, C, PATTERN.z) :\n>              vec3(PATTERN.yx, C));\n> +\n> +#if defined(APPLY_CCM_PARAMETERS)\n> +\t/*\n> +\t *   CCM is a 3x3 in the format\n> +\t *\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n> +\t *   +--------------+----------------+---------------+\n> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n> +\t *   +--------------+----------------+---------------+\n> +\t *\n> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n> +\t *\n> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n> +\t *\n> +\t *   CPU\n> +\t *   float ccm [] = {\n> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n> +\t *   };\n> +\t *\n> +\t *   GPU\n> +\t *   ccm = {\n> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n> +\t *   }\n> +\t *\n> +\t *   However the indexing for the mat data-type is column major hence\n> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n> +\t *\n> +\t */\n> +\tfloat rin, gin, bin;\n> +\trin = rgb.r;\n> +\tgin = rgb.g;\n> +\tbin = rgb.b;\n> +\n> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n> +\n> +#elif defined(APPLY_RGB_PARAMETERS)\n> +\t/* Apply bayer params */\n> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n> +\trgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;\n> +\trgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;\n\nAll the lookups are mistakenly on red_param rather than\nred/green/blue_param here.\n\n(Commented previously on v1 by mistake.)\n\n> +#endif\n> +\n> +    gl_FragColor.rgb = rgb;\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 BD416BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 18 Oct 2025 10:56:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0BA2D606DC;\n\tSat, 18 Oct 2025 12:56:37 +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 3CCC9606A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 12:56:35 +0200 (CEST)","from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n\t[209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-665-kSX7kZToNR6EDkoYykB9fw-1; Sat, 18 Oct 2025 06:56:32 -0400","by mail-wm1-f70.google.com with SMTP id\n\t5b1f17b1804b1-471201dc0e9so17373195e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 03:56:32 -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\t5b1f17b1804b1-4711442dbaesm129853395e9.8.2025.10.18.03.56.29\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 18 Oct 2025 03:56:29 -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=\"IN9HurKZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760784994;\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=U9PpalwDb8oopJQJACHueutA5SFk7mCseD6EhVFBVzY=;\n\tb=IN9HurKZGrUnD3U/apRReimqnVYFmyLDzko0pK9wwdPrZtmpmjeIrusWflEh0jVm2lQaNO\n\trs/Hf9xLsPIvAvgMWGXzhuAUBiq8D0iOQwIZfpvhWJaouGMH4YQNhyYQEIkj3uJDmWlkKa\n\tWs07B/2F9XyiYofgBWp/mkaLzc8J8sY=","X-MC-Unique":"kSX7kZToNR6EDkoYykB9fw-1","X-Mimecast-MFC-AGG-ID":"kSX7kZToNR6EDkoYykB9fw_1760784991","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760784991; x=1761389791;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=U9PpalwDb8oopJQJACHueutA5SFk7mCseD6EhVFBVzY=;\n\tb=RsHeE6bK44dGDXC0wUW3Ccxx686QFddtHuddZj0vVSepwLDqlaCeKNPEbqR0cmu//o\n\tQMjlhju4T5eR1YHT9UFOBvIFBYaeCmJQ1/oLz9Ujucr2+YAQhDcG7x6RHiPARLsyOCv7\n\tfF9ERiH9JT4MWadZiiJLh/XgQqelK7knSIjScV/WSGCWB/H4QWxMLO180b5QEasHQDw4\n\toSPJYSrc8Osz5UzO80Zek/Mh6Oae+KTlguqROKwssILCYBpSJwSD+9UpN36+dVrg/Utd\n\tWa5n2qGo34rGXEUnrKcCMB6miwDOAPNImbQxZP1J69jrbnln8qwgo9PU6WP3ExmBY7id\n\tZ7jA==","X-Gm-Message-State":"AOJu0YxSmIMtNW4N+Rb9tttP0w86zXCPseReD01m/SVqd6FRoFcq438I\n\t7gwBaVsqwsNdmsw0rU7KPV/gVEJDxPjGfhj4mpMKHyI6N0vOcCRNvZS1SQrfnjMvKVYaBVgC1Qf\n\tqrrad3epVNKEXj099w2dFPEM8AhKgRaXlC7msY7q1ifbpAaf5npWnUmjZS1fJKZO1EWJ9O2f+Ls\n\tRRD+0QTOk=","X-Gm-Gg":"ASbGnctQCSuLrz/8uDEdXF/343jwJCMngkOINaLYBf7flf0V+Fv3zNTEbpAlfp/Qgdj\n\tqhbYPCa3/QYrY1ACgTVbihzUti+ekgHlB5NfbxkG953V7OoHDLARxqa3SyrooAwzIQ9Szdu1Eqw\n\t6tz+4M+fMjn9r8lJRBakeKD3kqEmRusazL5L0IjGQKmosQVAvBnPmjcxkvGt/saptqq/+It/7jl\n\t1xQeXufaUnRnBomBpN3P7VEAzqnBvmmZ+zZocuIGffOcSDFdk5ZDfSh9twB8x2Mh1JFPYZ9+YE/\n\t9nal0jaajWIMrzayYV4TDLYG8g6VDO9OyXbaR826UycXawgzVy85t+xl7ZkorXKnY7gygbgvnAq\n\tNo0rIz4PNYTA7mntiz7365rTZcTNOwNH47tPO8NzOWxlQuni+bJ3g","X-Received":["by 2002:a05:600c:45c9:b0:46e:4b79:551 with SMTP id\n\t5b1f17b1804b1-47117913764mr51895545e9.31.1760784990731; \n\tSat, 18 Oct 2025 03:56:30 -0700 (PDT)","by 2002:a05:600c:45c9:b0:46e:4b79:551 with SMTP id\n\t5b1f17b1804b1-47117913764mr51895345e9.31.1760784990340; \n\tSat, 18 Oct 2025 03:56:30 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IGy+3VREE3EcJjQFUWV84JFts/JmHTiz/nMwz6EhHrE7cVNOIM5SrUgT0I48GKxELj6RYGnGQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","In-Reply-To":"<20251015012251.17508-30-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Wed, 15 Oct 2025 02:22:41 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>","Date":"Sat, 18 Oct 2025 12:56:28 +0200","Message-ID":"<85zf9osckj.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":"z1WTCayM_doUkqEiXqLTXSU8YYMvEhL7PTjK_OpPnBQ_1760784991","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>"}},{"id":36343,"web_url":"https://patchwork.libcamera.org/comment/36343/","msgid":"<e4608bcd-5377-4600-b2cb-b5c94852209b@linaro.org>","date":"2025-10-18T12:14:06","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"content":"On 18/10/2025 11:56, Milan Zamazal wrote:\n>> +#elif defined(APPLY_RGB_PARAMETERS)\n>> +\t/* Apply bayer params */\n>> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n>> +\trgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;\n>> +\trgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;\n> All the lookups are mistakenly on red_param rather than\n> red/green/blue_param here.\n> \n> (Commented previously on v1 by mistake.)\n\nAnd I fixed that...\n\nObviously managed to not commit this change ... :(\n\n---\nbod","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 988A6C3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 18 Oct 2025 12:14:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 60256606E7;\n\tSat, 18 Oct 2025 14:14:10 +0200 (CEST)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AA50F606CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 14:14:08 +0200 (CEST)","by mail-wm1-x32c.google.com with SMTP id\n\t5b1f17b1804b1-471bde1e8f8so1246005e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 05:14:08 -0700 (PDT)","from [192.168.0.163] (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-4283e7804f4sm2489038f8f.10.2025.10.18.05.14.07\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tSat, 18 Oct 2025 05:14:07 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"tzUV//mU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1760789648; x=1761394448;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Ezc3O5FruEFQ8cUTpuA0KOmm3dczFE4rzK58iv3u7fI=;\n\tb=tzUV//mULNvwTb3rSngnEmDrfklP+xWmXAqLwIhWif9+Om0OWRJpPjn02879Q0kGHp\n\tyAoVjvKOdfjEYDoDNFYjFGWF8E6cZCbiqVHtqEmvb+O3FuIKZJi2sCV6Ufbcra71lUAY\n\tTjFP6BDiaWwsIBwHHalKtf52T+tqgHFbSSwppvbAkoN4A/XWAZPHfhrGJsh7AEZWdmt3\n\tkiP+hX4dRvbYhghKG0abRYUnJxVs5RbvWAWVvD7hSPyjmnCU9oktAr8iHE0Lk4b7nBVN\n\tAXE+Ucq4IXm96uCdm5Tc7arZe5DnJfe4vLLc90lCb82+VFg4JPNyk/VW0BdISKo/xjzu\n\t88JQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760789648; x=1761394448;\n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Ezc3O5FruEFQ8cUTpuA0KOmm3dczFE4rzK58iv3u7fI=;\n\tb=PLdPlViFIXhXdZMSa/VqCPYYFWuw9gJeteCWgbQeY3DADncLObUlFDi1ObsFGlVJEs\n\tC8vVi9+/4FWHpBNoZ8eo1yEFHd/j/aXHfmNvOhucs6Xc8qOQE+APlui5e6HRD4/6442p\n\tDEHj4YkKQkBue0F5kt7CkE6hS+b1jPtkKPSn8EQGDLEdJIcipSADSKwes1N7wU/JpaJd\n\tIaPo9+be5vVIB47zNpzsx7ly6VPTDVZKevJmpTUDHzSDDDhE7/7VW2Faf+KvAVUKD+WC\n\tXcbiI2BNeABWpfwiAVW2d7OFm1CuWDNd+rakeAt/p5sHT/i0dgt22i+WYc2nsgdxaMph\n\tPb9Q==","X-Gm-Message-State":"AOJu0YyE7fno7aK6lhu2mLVLzszaWYO480EqBfvRe8HUM/lbX8ghflMP\n\tY+ZzSKtdlUBvL+GuZ55+JRtjLSJiE8vuJ/x+x8uWuRtRL18lv45iJ1+cP5UrKjCMB1w=","X-Gm-Gg":"ASbGncuVlpYzMv3p2G4Vje4g/3JXNn35D8wq6Lp1/vZbU3XQdaxly9b3VFDwPyaZwln\n\tnLn9j5ggMiBWORBtM4ygQQmvHf3oaVw+ENJiKrNYEw41Q8ETRxRm38xtV14DokrhXOzVZM7VBAS\n\to9D8roUAThlS5HceYEKmtjidXNTfzF74LPb4Eq+21pZqyDfrZfxFz/CZrPvnX1Zgv/Yp+hJZ0j0\n\tFmpVTt5orztAr2VysHuq66cIRLOlPBmfVhPWfB2w/LjIUJXAehbZJskF/8l6VQGFXUD3gnf2ZbS\n\t5aTC6Gy4pr4Wqh1gxVmweXhuBJCMPjWJ8eCVKf120Pqk+OTjd6sxrv2yc3a57CTnSrMOXRCjz1q\n\tTbsBmRPpT4jaZCCgiN19OIwQHl1+tuKfuGLPx7pr4z1bw0YNKGq0KwYYzhu+SwmtFniPaNleDr2\n\tSnw5kxwnowLc1oq/pN/q63BIu05q1z/i3J6XAWlMqHT8A=","X-Google-Smtp-Source":"AGHT+IHBi5G3JzbrcZWi//hbA/j1PD4pJBdQWMMrJhBAKHmAQAyIl6ffo1wVjb1lGVXNR+PbM0CQNg==","X-Received":"by 2002:a05:600c:548a:b0:471:ff3:7514 with SMTP id\n\t5b1f17b1804b1-47117877736mr49780925e9.12.1760789648104; \n\tSat, 18 Oct 2025 05:14:08 -0700 (PDT)","Message-ID":"<e4608bcd-5377-4600-b2cb-b5c94852209b@linaro.org>","Date":"Sat, 18 Oct 2025 13:14:06 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org, hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>\n\t<85zf9osckj.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Content-Language":"en-US","In-Reply-To":"<85zf9osckj.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}},{"id":36345,"web_url":"https://patchwork.libcamera.org/comment/36345/","msgid":"<85jz0srsxd.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-18T18:00:46","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","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> Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n>\n>> Extend out the bayer fragment shaders to take 3 x 256 byte inputs as\n>> textures from the CPU.\n>>\n>> We then use an index to the table to recover the colour-corrected values\n>> provided by the SoftIPA thread.\n>>\n>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n>> ---\n>>  .../internal/shaders/bayer_1x_packed.frag     | 56 +++++++++++++++++\n>>  .../internal/shaders/bayer_unpacked.frag      | 62 ++++++++++++++++++-\n>>  2 files changed, 117 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n>> index 19b13ad0..90bd6457 100644\n>> --- a/include/libcamera/internal/shaders/bayer_1x_packed.frag\n>> +++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag\n>> @@ -65,6 +65,10 @@ uniform vec2 tex_step;\n>>  uniform vec2 tex_bayer_first_red;\n>>  \n>>  uniform sampler2D tex_y;\n>> +uniform sampler2D red_param;\n>> +uniform sampler2D green_param;\n>> +uniform sampler2D blue_param;\n>> +uniform mat3 ccm;\n>>  \n>>  void main(void)\n>>  {\n>> @@ -212,5 +216,57 @@ void main(void)\n>>  \t\t\tvec3(patterns.y, C, patterns.x) :\n>>  \t\t\tvec3(patterns.wz, C));\n>>  \n>> +#if defined(APPLY_CCM_PARAMETERS)\n>> +\t/*\n>> +\t *   CCM is a 3x3 in the format\n>> +\t *\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *\n>> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n>> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n>> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n>> +\t *\n>> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n>> +\t *\n>> +\t *   CPU\n>> +\t *   float ccm [] = {\n>> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n>> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n>> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n>> +\t *   };\n>> +\t *\n>> +\t *   GPU\n>> +\t *   ccm = {\n>> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n>> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n>> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n>> +\t *   }\n>> +\t *\n>> +\t *   However the indexing for the mat data-type is column major hence\n>> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n>> +\t *\n>> +\t */\n>> +\tfloat rin, gin, bin;\n>> +\trin = rgb.r;\n>> +\tgin = rgb.g;\n>> +\tbin = rgb.b;\n>> +\n>> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n>> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n>> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n>\n> I think black level must be subtracted and gamma applied here, e.g.\n>\n>   rgb = rgb - vec3(blackLevel);  // blackLevel must be passed from the IPA\n>   rgb = pow(rgb, vec3(gamma));   // gamma = 0.5 in CPU ISP\n>\n> See lut.cpp, where with CCM the gamma lookup table is passed separately\n> from the CCM lookup tables to debayer_cpu.cpp and incorporates the black\n> level correction.\n\nAnother thing missing is applying the contrast control with CCM, it is\navailable but no-op.  See Lut::updateGammaTable for how contrast is\ncomputed in CPU ISP, together with gamma.  (Without CCM, it's\nincorporated in the lookup tables and it works.)\n\n> With these two changes + the awb change in the other patch,\n> APPLY_CCM_PARAMETERS output seems to be similar to APPLY_RGB_PARAMETERS\n> output in my environment.  I'm not sure I'm 100% correct and it needs a\n> bit more testing but I think these are the basic ideas what fixes are\n> needed for the CCM output.\n>\n> The same for the other shader.\n>\n>> +\n>> +#elif defined(APPLY_RGB_PARAMETERS)\n>> +\t/* Apply bayer params */\n>> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n>> +\trgb.g = texture2D(green_param, vec2(rgb.g, 0.5)).g;\n>> +\trgb.b = texture2D(blue_param, vec2(rgb.b, 0.5)).b;\n>> +#endif\n>> +\n>>  \tgl_FragColor = vec4(rgb, 1.0);\n>>  }\n>> diff --git a/include/libcamera/internal/shaders/bayer_unpacked.frag b/include/libcamera/internal/shaders/bayer_unpacked.frag\n>> index aa7a1b00..5955c2ea 100644\n>> --- a/include/libcamera/internal/shaders/bayer_unpacked.frag\n>> +++ b/include/libcamera/internal/shaders/bayer_unpacked.frag\n>> @@ -21,11 +21,17 @@ precision highp float;\n>>  \n>>  /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/\n>>  uniform sampler2D       tex_y;\n>> +uniform sampler2D\tred_param;\n>> +uniform sampler2D\tgreen_param;\n>> +uniform sampler2D\tblue_param;\n>>  varying vec4            center;\n>>  varying vec4            yCoord;\n>>  varying vec4            xCoord;\n>> +uniform mat3\t\tccm;\n>>  \n>>  void main(void) {\n>> +    vec3 rgb;\n>> +\n>>      #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r\n>>  \n>>      float C = texture2D(tex_y, center.xy).r; // ( 0, 0)\n>> @@ -97,11 +103,65 @@ void main(void) {\n>>      PATTERN.xw  += kB.xw * B;\n>>      PATTERN.xz  += kF.xz * F;\n>>  \n>> -    gl_FragColor.rgb = (alternate.y == 0.0) ?\n>> +    rgb =  (alternate.y == 0.0) ?\n>>          ((alternate.x == 0.0) ?\n>>              vec3(C, PATTERN.xy) :\n>>              vec3(PATTERN.z, C, PATTERN.w)) :\n>>          ((alternate.x == 0.0) ?\n>>              vec3(PATTERN.w, C, PATTERN.z) :\n>>              vec3(PATTERN.yx, C));\n>> +\n>> +#if defined(APPLY_CCM_PARAMETERS)\n>> +\t/*\n>> +\t *   CCM is a 3x3 in the format\n>> +\t *\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | RedRedGain   | RedGreenGain   | RedBlueGain   |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | GreenRedGain | GreenGreenGain | GreenBlueGain |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *   | BlueRedGain  |  BlueGreenGain | BlueBlueGain  |\n>> +\t *   +--------------+----------------+---------------+\n>> +\t *\n>> +\t *   Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin\n>> +\t *   Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin\n>> +\t *   Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin\n>> +\t *\n>> +\t *   We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm);\n>> +\t *\n>> +\t *   CPU\n>> +\t *   float ccm [] = {\n>> +\t *             RedRedGain,   RedGreenGain,   RedBlueGain,\n>> +\t *             GreenRedGain, GreenGreenGain, GreenBlueGain,\n>> +\t *             BlueRedGain,  BlueGreenGain,  BlueBlueGain,\n>> +\t *   };\n>> +\t *\n>> +\t *   GPU\n>> +\t *   ccm = {\n>> +\t *             RedRedGain,   GreenRedGain,   BlueRedGain,\n>> +\t *             RedGreenGain, GreenGreenGain, BlueGreenGain,\n>> +\t *             RedBlueGain,  GreenBlueGain,  BlueBlueGain,\n>> +\t *   }\n>> +\t *\n>> +\t *   However the indexing for the mat data-type is column major hence\n>> +\t *   ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain\n>> +\t *\n>> +\t */\n>> +\tfloat rin, gin, bin;\n>> +\trin = rgb.r;\n>> +\tgin = rgb.g;\n>> +\tbin = rgb.b;\n>> +\n>> +\trgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]);\n>> +\trgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]);\n>> +\trgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]);\n>> +\n>> +#elif defined(APPLY_RGB_PARAMETERS)\n>> +\t/* Apply bayer params */\n>> +\trgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;\n>> +\trgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;\n>> +\trgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;\n>> +#endif\n>> +\n>> +    gl_FragColor.rgb = rgb;\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 88354C3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 18 Oct 2025 18:00:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E09A606E6;\n\tSat, 18 Oct 2025 20:00:54 +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 84DF0606E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 20:00:52 +0200 (CEST)","from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-607-2vcfNHneOTe7TgV9-vTAZw-1; Sat, 18 Oct 2025 14:00:50 -0400","by mail-wr1-f70.google.com with SMTP id\n\tffacd0b85a97d-427a125c925so689324f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Oct 2025 11:00:50 -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\tffacd0b85a97d-427f00ce3aesm6140432f8f.48.2025.10.18.11.00.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 18 Oct 2025 11:00:47 -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=\"M23uFJ+w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760810451;\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=Vnj0/1HEvuJE9v/peq+KmUd9hVLU2HGK+70IbBwHQJ8=;\n\tb=M23uFJ+wEqnN2XRNomJZMJ3mVyWivFlQbdr4FKSKSaGqDgPxmwiFWW2CCuLWsYOODLHncn\n\trfD9pdn1/320Mcn+o562QJYgLOJRKwyAat+sxnqCuwHClU2t7FakzfFAB3L60fu9AIA+z+\n\txXM2KRSJh5lFna4SrakhppXZwYDciuE=","X-MC-Unique":"2vcfNHneOTe7TgV9-vTAZw-1","X-Mimecast-MFC-AGG-ID":"2vcfNHneOTe7TgV9-vTAZw_1760810449","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760810449; x=1761415249;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Vnj0/1HEvuJE9v/peq+KmUd9hVLU2HGK+70IbBwHQJ8=;\n\tb=iPqBUP4J5s5EUtDu0r0CvmzTDFdRZq+NvXzOHMW29mcc0KodBWo3g22L/i+ZJPTAvb\n\t+TopI0PzP6gw8llGTMnpbXIxo5fWTolewM1wlyFZTpXWfE4WrHtoetyY/qsZlX7RVhFV\n\tYYIqrmIFG9smBU0sWSOFkEtMSJBm+S/SWJZQtLxa2cC0/0+L1ypwK7DUNoAvzQZUtqlr\n\t/Nd+Xi3Lt6SUVSyMgYZFOFXm331TJXQQq8a0Js9uLGvTEwiMoyV7fRzsA1LCHS91y3kt\n\t6cV3zC/uCm3I3dEez59SEt5HF9JpHtMpAab5LQbE/ATAWME/5JyhXPUtC32IWJ3ah8i8\n\t9QEg==","X-Gm-Message-State":"AOJu0YxNQtknb2sUn3OU5JMsc/GFPCiWcf5t49gDltFaVfmoKUAOausJ\n\ttQfj8cC6kkauZt9STvcXpHHOtVp8t6LKoXGQU/Vf+CcuxHATZ5XMHo8k0KMEUKIj7ABv3pfm99X\n\tGQMeGRnLlpx/RdxM+aVW4U9m+A1WojVpP1hMP8UuG5fKFvdrgI2MjYV5iUNQAIg7xOoN40hooq2\n\tx3aRYzE+w=","X-Gm-Gg":"ASbGncu9scujij2/Qo0KGYXCROv8OQ3g44XQ8kHKHmNkGyNHL6yb3N7joJVLL7Ts7YK\n\tu5lJPpiP6hjkXc/1xhameTX4pMM8l0pvJI7cjbl7YW2l+BDjT+6a+r444VU7GcXPWZ4jUtsIcX5\n\tkM+XYRY3CIi87GDEZjglNlmr9nZ0CC4Xvjmk7Mp8cV6WCOy9wOY3KS44hNmuFm4F/pTj6GDIuwA\n\tuX6vNtC2mBPFW78qhFMQX00l46siS4PuOPsjpP/s476S67yGXZekXXGgj6qlyNq/faPygMc7jc1\n\tIN42HdBmsF07+Ww5/F0NaUOXfse2bqJQuFNXcN8HBZvyk/7SyqAVii7BS0lmFLn5H9VUKJwjQrZ\n\t31op9UN2acBfaX1/S4O+OH/BywnCxxqOYsqNfk8KJRBnP0AXa9deO","X-Received":["by 2002:a5d:5888:0:b0:3f4:5bda:271a with SMTP id\n\tffacd0b85a97d-42704d50de5mr4928495f8f.6.1760810448285; \n\tSat, 18 Oct 2025 11:00:48 -0700 (PDT)","by 2002:a5d:5888:0:b0:3f4:5bda:271a with SMTP id\n\tffacd0b85a97d-42704d50de5mr4928479f8f.6.1760810447834; \n\tSat, 18 Oct 2025 11:00:47 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHSNBK+422L+oRFDSMleqCDqqVduD51OwB7g2GMQW3v8QUlTH9QqFP1mlysxsVAXbKqF4eX4g==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","In-Reply-To":"<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb> (Milan\n\tZamazal's message of \"Fri, 17 Oct 2025 20:53:16 +0200\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>\n\t<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","Date":"Sat, 18 Oct 2025 20:00:46 +0200","Message-ID":"<85jz0srsxd.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":"cavXrhg3GW1R8GivwbAP7eMfu10CSiVqq1yqiLFJJ8c_1760810449","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>"}},{"id":36347,"web_url":"https://patchwork.libcamera.org/comment/36347/","msgid":"<20ff1cd8-a4b1-4625-bd3e-0adf77649c8b@linaro.org>","date":"2025-10-19T22:40:15","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"content":"On 17/10/2025 19:53, Milan Zamazal wrote:\n>    rgb = rgb - vec3(blackLevel);  // blackLevel must be passed from the IPA\n\nSo my best guess for that to pass here is \ncontext.activeState.gamma.blackLevel / 256\n\nSince this is a unit8 we want to normalise it to between 0.0f and 1.0f\n>    rgb = pow(rgb, vec3(gamma));   // gamma = 0.5 in CPU ISP\n\nLooking at the code in lut.cpp it seems to me when the gpuisp is running \nwe should not calculate at least some of these lookup tables you mentioned.\n\nSeems like wasted cycles, I don't know the code as well as you but.\n\nvoid Lut::updateGammaTable(IPAContext &context)\n{\n\t/* The loop setting this */\n\tgammaTable[i] = UINT8_MAX *\n\tstd::pow(normalized, context.configuration.gamma);\n}\n\nvoid Lut::prepare(IPAContext &context,\n                   [[maybe_unused]] const uint32_t frame,\n                   IPAFrameContext &frameContext,\n                   DebayerParams *params)\n{\n\t/* And this assignment in the containing loop */\n\tparams->gammaLut[i] = gammaTable[i / div];\n}\n\ncan be avoided iff GPUISP is active.\n\n---\nbod","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 7A931BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 19 Oct 2025 22:40:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 718B1606F7;\n\tMon, 20 Oct 2025 00:40:19 +0200 (CEST)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A8727606E2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Oct 2025 00:40:17 +0200 (CEST)","by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-4710665e7deso12399655e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 19 Oct 2025 15:40:17 -0700 (PDT)","from [192.168.0.163] (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-427f00b988dsm12398686f8f.35.2025.10.19.15.40.15\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tSun, 19 Oct 2025 15:40:15 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"uNKZbdhr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1760913617; x=1761518417;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=AXTf6wSgzVJOc6re4b9yomx4GIZgQcJluyedpliHkWI=;\n\tb=uNKZbdhrTAit6W96h5uIIOSG6SI21Pw+on3U33v4Py8UEigrnLpTF/JvFgZM5peEo2\n\tEo062sYGtKunGRreOM/sv/zwA4YiLVRaAmpBObod4OUgzhRd1EPeyqUmwoY0lfKx9xUq\n\tgScx4pAPsaTYmBMbwe4hSQxpjVD8kCPHQq0VpqXPd+Yka+7JpckZ6mVhjWKcaE4IeM2q\n\t3M2hF9yrvJTKEqokAHlfhJ+eXEtKu2u79QaJyFMjkz+mwdwu+ZL4WCvflUeIUjEbRh9o\n\tgWExRm3HGR7YiUPoS7QY2a1IzMhnVo4vnxy4kFbfMVKyTAeOd3Ea5IuNSTZ84Hl/fZiS\n\tFB0A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760913617; x=1761518417;\n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=AXTf6wSgzVJOc6re4b9yomx4GIZgQcJluyedpliHkWI=;\n\tb=rXnmJIL1rPQT7BCNsRKAEeG7W0gkBJyOXCyXbY4hm4L/bu9aUqA6hGdOmjo+8aQqts\n\tQ/7NUt4JFl5OC+GLDfvdHjmS71EeLR+5HIwIeoFHc8zsBI4laBL4PswYyhb3oxvON3My\n\t5JWWWSFtOS5rUGIr6mUoOjkCXqieIW5Yz+tKYoiVkXHd/m0v0eL6eoDfnTqbQx1Npb+d\n\ttyOB2L0HTRw+XACUYuvfYcBXizf2+YxhPLXAVypxH01nwKr15rBcImyBYeEsFBXDcGi1\n\tBp3kq7o21/4gClcwwK7p295EyXLF8t6i7bym2K9Dg4adsz4XbUX8sl1XXx/GtRNZiHe8\n\tJnxQ==","X-Gm-Message-State":"AOJu0Yygj3nrW9CWoPUaOO+tnZBtjpSCV8yDnGrwB/CfzcZlVOdTNtpX\n\tZERwSJYDg6VhcWeCdDxnVD3N06zQvlbq+nGgn9RzA0pLm2vQbUbRFDYWlhKhlX6e4TY=","X-Gm-Gg":"ASbGncv8cLad6MtRaos1eLd4KlEy5CG8Jcw+AzI5tG5G5v25DxiLCtyM15L6tTuFuD7\n\ttg7PLBlFFenKaz9iwbw/7E2UpnHbUQZGMlqqpKsr3fsuAV/z0LSgR8wdNAYyFmRBBiU2fa3F21i\n\tcx9cw4wcbBKW/DEGRBWyBNApVqMsgH7a4Iy3CbwZO0nDwJMDP57HYy5s5NJkS6Lsslh3AYfeiw9\n\tYs/IV3QLtVu1bZ1d6Yo6Gi0rl7FqSpR7bnl0zy93OVU3aIIQ9IRgjnwd/sG1ufHRH5NtySfK/kn\n\tDRbSr0elRfk+kt+3bABKsOzoQZu4XN+lCHHmkhY8Uq0qZsQZkFDjRrpk32+63KzlafBnIrFOkuz\n\tLoxBDTKdJGwzSqWadsdlWsY2bkc0INRM4jq+wAXHzWeQiTnWz26WJW+EL6MKvKwy735vnMrremG\n\t8ynXYvKm/qnkaVPWYzMn/1X4GteKHVoJf61kKCGZxtpgsc0t5cgf0VRA==","X-Google-Smtp-Source":"AGHT+IHyQwxEAVNrqZvCzbIK4dBguQkY81e1JrRWM2lLMBNFOKBD6aUlFaKX+ixt4j/o0N5MYSdPag==","X-Received":"by 2002:a05:600c:458b:b0:46f:b32e:5094 with SMTP id\n\t5b1f17b1804b1-4711791cb4cmr99758325e9.32.1760913617051; \n\tSun, 19 Oct 2025 15:40:17 -0700 (PDT)","Message-ID":"<20ff1cd8-a4b1-4625-bd3e-0adf77649c8b@linaro.org>","Date":"Sun, 19 Oct 2025 23:40:15 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org, hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>\n\t<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Content-Language":"en-US","In-Reply-To":"<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}},{"id":36348,"web_url":"https://patchwork.libcamera.org/comment/36348/","msgid":"<85o6q29h1x.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-20T07:19:06","subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> On 17/10/2025 19:53, Milan Zamazal wrote:\n>>    rgb = rgb - vec3(blackLevel);  // blackLevel must be passed from the IPA\n>\n> So my best guess for that to pass here is context.activeState.gamma.blackLevel / 256\n\ncontext.activeState.blc.level / 256.0\n\ncontext.activeState.gamma.blackLevel is used only to check for change of\nthe gamma table parameters and is not set if the gamma table is not\ncomputed.\n\n> Since this is a unit8 we want to normalise it to between 0.0f and 1.0f\n>>    rgb = pow(rgb, vec3(gamma));   // gamma = 0.5 in CPU ISP\n>\n> Looking at the code in lut.cpp it seems to me when the gpuisp is running we should not calculate at least some of\n> these lookup tables you mentioned.\n>\n> Seems like wasted cycles, I don't know the code as well as you but.\n>\n> void Lut::updateGammaTable(IPAContext &context)\n> {\n> \t/* The loop setting this */\n> \tgammaTable[i] = UINT8_MAX *\n> \tstd::pow(normalized, context.configuration.gamma);\n> }\n>\n> void Lut::prepare(IPAContext &context,\n>                   [[maybe_unused]] const uint32_t frame,\n>                   IPAFrameContext &frameContext,\n>                   DebayerParams *params)\n> {\n> \t/* And this assignment in the containing loop */\n> \tparams->gammaLut[i] = gammaTable[i / div];\n> }\n>\n> can be avoided iff GPUISP is active.\n\nYes.","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 6682DC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Oct 2025 07:19:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D31B606F2;\n\tMon, 20 Oct 2025 09:19:15 +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 7A6A3605F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Oct 2025 09:19:13 +0200 (CEST)","from mail-ej1-f69.google.com (mail-ej1-f69.google.com\n\t[209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-447-eBIcacS9P0WgDd33SqkI6w-1; Mon, 20 Oct 2025 03:19:10 -0400","by mail-ej1-f69.google.com with SMTP id\n\ta640c23a62f3a-b548c516b79so464884366b.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Oct 2025 00:19:09 -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\ta640c23a62f3a-b65ebc474c6sm694609066b.78.2025.10.20.00.19.07\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 20 Oct 2025 00:19:07 -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=\"d3cvbgeh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1760944752;\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=0U3bOgW1IUm5xP2WrENzrpg8ZgKonAOi7hg80KGC3h8=;\n\tb=d3cvbgeh9j5qPTltkFTGBONVRsPcVwqeuoI8g3Sr064guwGttzdvVinExbR6youkXrIhi6\n\tlhR1RFXMlYkQGzrPizr6Ah+tF0Zt8u0gJ15oWBs7MMdnCk78PNb99xEp2UH4kCuq/ssfXb\n\tWmqj+OUFSHtla02+VlUppBmxPr9IBq8=","X-MC-Unique":"eBIcacS9P0WgDd33SqkI6w-1","X-Mimecast-MFC-AGG-ID":"eBIcacS9P0WgDd33SqkI6w_1760944749","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760944749; x=1761549549;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=0U3bOgW1IUm5xP2WrENzrpg8ZgKonAOi7hg80KGC3h8=;\n\tb=ZN/vJxwKdk7xSG9GlMi55HX2UV/QbOrL20h8Xg6v2jwqyfy/2LCD7xQPggtF9vPueJ\n\thNMB60NMDYHuJQy3cJS4D07iJ1a3JTmXWsTLhgzkF/8oUysXXEsswfzVvYP66hmIEJpy\n\tWrweItMmX0jgZTPqdOwTXqa1ihTI2XEInxF8wcnXSZiLxgVCgRrERQ3JbvPxJ2ABV4Id\n\tn93TKV5xjQ6Fmr66jRXfdrM3y/r9+oX8LDB6QQtjhfmeGTHizMnuB6EL1j+M5h1dA1Ne\n\tX1W3cJdXO6lqlj56+3U58IRDgL5XkuoCn7oBh4nWK1lH4JVIVTdGaX49/3W2gqlBmrLz\n\tbloQ==","X-Gm-Message-State":"AOJu0YyPGvbu38Xs0tAhoaD+ah+QyQSFz5djxT7CJxXcwwcLqvrJxAv7\n\t1xvmW2ErBxCMtp9j5cjquQlsxtAl6TgJlsH2VADcsMocA7ca1mDvibPEeS/CNp7398Q7Z8Ap6J2\n\tdRdRJwopAV7VTgpjFBo32V36/zYS4GzQzEMIfpO49tIT4PSgufEx/NDfN74/HHpPFYvKm//pU07\n\tE=","X-Gm-Gg":"ASbGnctW/0/mv7nuZ9+f1DrmARTFPbIQo+hUgGvOT4ohxTTNbglmwq3GuoQJn0eYiQb\n\tDV+rOJBGY8YFbRFmFvj/T0RzI+qSaHMPfCdtzc0ttvsYcVl+G1Ae9FV9gGKBKpTLtONxqxW2xhI\n\tFMJYEmTTTwwCAW1FoecYt4vTF3N228OMXFUl5u+1TR3yxWeu/512LI9KwyAAA5hTo15AnsnIUAg\n\tRZVc92c68c1IFrZ7zmhM5L0qp6HbkhK4ghlO5cXFWppJMRhl2WNWDGK06iAJWR8oQYnCmJRvsVw\n\tODdrUp/v9GEOl8SFlH79+EkVQd4oNCA6eAQjxHv3/MFnktSf+on9Ufnrg/i/7EE8yAQsZ7rKz5n\n\tdzYxCdO7RCOT3I7JJl5d1jJtu4WGFf4XWc63RXPWnvkoTkY3jHWqn","X-Received":["by 2002:a17:907:7f8e:b0:b60:4161:5f24 with SMTP id\n\ta640c23a62f3a-b647324281bmr1412659066b.19.1760944748805; \n\tMon, 20 Oct 2025 00:19:08 -0700 (PDT)","by 2002:a17:907:7f8e:b0:b60:4161:5f24 with SMTP id\n\ta640c23a62f3a-b647324281bmr1412657266b.19.1760944748388; \n\tMon, 20 Oct 2025 00:19:08 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IEiCcPfhFN3Jur2FydCEnoVfT/9B7hLU6vsPpQREOcSapl18DHMvPi4EEEXvtnC1N44O4z6bg==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 29/39] libcamera: shaders: Extend debayer shaders to\n\tapply RGB gain values on output","In-Reply-To":"<20ff1cd8-a4b1-4625-bd3e-0adf77649c8b@linaro.org> (Bryan\n\tO'Donoghue's message of \"Sun, 19 Oct 2025 23:40:15 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-30-bryan.odonoghue@linaro.org>\n\t<85sefhnyw3.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>\n\t<20ff1cd8-a4b1-4625-bd3e-0adf77649c8b@linaro.org>","Date":"Mon, 20 Oct 2025 09:19:06 +0200","Message-ID":"<85o6q29h1x.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":"ZQQrtA4dZ7_S4Zxi884jrJuD36qi-EYoSk-9XyU3qL0_1760944749","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>"}}]