Patch Detail
Show a patch.
GET /api/1.1/patches/23532/?format=api
{ "id": 23532, "url": "https://patchwork.libcamera.org/api/1.1/patches/23532/?format=api", "web_url": "https://patchwork.libcamera.org/patch/23532/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20250611013245.133785-27-bryan.odonoghue@linaro.org>", "date": "2025-06-11T01:32:36", "name": "[26/35] libcamera: shaders: Extend debayer shaders to apply RGB gain values on output", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "ae3b92e6528942dc97fa0c49430e4e27ad8f13a3", "submitter": { "id": 175, "url": "https://patchwork.libcamera.org/api/1.1/people/175/?format=api", "name": "Bryan O'Donoghue", "email": "bryan.odonoghue@linaro.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/23532/mbox/", "series": [ { "id": 5212, "url": "https://patchwork.libcamera.org/api/1.1/series/5212/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5212", "date": "2025-06-11T01:32:10", "name": "Add GLES 2.0 GPUISP to libcamera", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5212/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/23532/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/23532/checks/", "tags": {}, "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 E8FEBC3331\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Jun 2025 01:34:17 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D043C68DF2;\n\tWed, 11 Jun 2025 03:34:16 +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 6C0B768DEF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Jun 2025 03:34:13 +0200 (CEST)", "by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-450cf214200so56603065e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Jun 2025 18:34:13 -0700 (PDT)", "from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4532514138asm5680625e9.3.2025.06.10.18.34.10\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 10 Jun 2025 18:34:12 -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=\"g4T9lbaZ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1749605653; x=1750210453;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=kou1M46O9tnzkm45TzkfsVRpNX7itRxzavLfzZx/hkQ=;\n\tb=g4T9lbaZ/vYURQCL1Gn1cjvRNhEChTRH/J0vZE6IWCvR5V9LiNAXcijAf7CaQUeGtK\n\tH+yJtC0jOUnBEx5ies/IewD4Uo3Jnpd0uA1cpi5uhLL1eN25g1bwwrbS8IxL3LIk6vtq\n\tAHFGwpqKmoW9eh1BAIlgNDXWRlX7MC8MFObBUIV2TR/12o874GCGkfFzEi24QGjoYmmG\n\tsZj9Ax7QUeNbBrb6sNngh4ZMOsYiigyJEfzk25L+uaHGTrQWFO2zmwIUbJXGePnf5lBB\n\tXoMsg2t/V32suGYGhApbJ54cE6NrUQEfeVDJK/ULIlLC67vZgBt0yczMSdbdimt1r3h9\n\tnG1g==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1749605653; x=1750210453;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=kou1M46O9tnzkm45TzkfsVRpNX7itRxzavLfzZx/hkQ=;\n\tb=KnZSljZighBmtTy2kKhGZ3/TPpvgZZoh2K4m4dmFj0Q6Y/SPEIJjien1L8slGn1C5m\n\tYGcrriUYodocga2Va2WT6u8E+2tjK3bFKQa+yftsLQOajDqJ3x3LP5h9nXqaElmpoVYJ\n\t07eefPu6dsIeoG1BQ6+QcJ17olAED9Xjq7GXxbzUI/wzoCn+KNvmNT/NNfuM6mmpXVtq\n\tsprEgC7Gg6mdsgrUFQuOo784/34jSBU4sBVR2xPkWpv4e1r9/EuIfF32QnLkKVWdOrfb\n\tL111nkF8/Ir0aZSJ9D6mBa4IiHIKDpsPvrVuw1e9+bgHAMLdXpIM55EU/OH8eNfeqlFs\n\tLOow==", "X-Gm-Message-State": "AOJu0Yx1GfCKZywA3NEztvtrOdPEkcX/PrmATYRIElAO2f3t/PRc189Z\n\taXlL1BTZIXG2UTO0LJE4j2ZuUlxDEN4RT9oEKdjSlBOzfV3l5YPyide9vDG99SWb0/lTiQq2g7+\n\tvrJyOdxo=", "X-Gm-Gg": "ASbGnct1+V4c0WGGYKJBS66O+y2oQvmrBXKodyV2KcfANQD1jg/WKib0U2VbYjA/lk2\n\tZ8r6GfxE4fbcjPMFea/uK0VNrNiHGVhwXUJvEaUTAopNLbyl7BwP9LZdoXuk7bOvg4Hm/06E8Wh\n\t6RibNcYVwjtbFgMWHWc4ItM1My/Vp44CdA2kgYTJN0IrAbp5Dp/QUYkxCVZo3NX4ER6n2tpoSwG\n\tNc4tiSUPO8Q0hb5XtuPdDsB/yWUpKDod6HpJK41Gbx2wI9hiFMLIceC6VbWJaxs65nT/kbV8Xoi\n\tZDJStHm2dBCFxoQaCSy3/T/eAaO8VEpjKlNmE6dj9lzYYDQVdJfTO1fsez3pF2DntGToiCIwHr8\n\tJ8/kcO/KZUkPcFSTYATxErv8Kmncj2sVDq2sLAIH/aA==", "X-Google-Smtp-Source": "AGHT+IE4aFfPCQTf035R8DBlYuxane9r27Xpk0diUUUxTvhvjyo/QIKBTm1B37uCXcX3SvRLnuDDlA==", "X-Received": "by 2002:a05:600c:8b13:b0:450:d3b9:4bac with SMTP id\n\t5b1f17b1804b1-45324f4f377mr4999125e9.28.1749605652599; \n\tTue, 10 Jun 2025 18:34:12 -0700 (PDT)", "From": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Bryan O'Donoghue <bryan.odonoghue@linaro.org>", "Subject": "[PATCH 26/35] libcamera: shaders: Extend debayer shaders to apply\n\tRGB gain values on output", "Date": "Wed, 11 Jun 2025 02:32:36 +0100", "Message-ID": "<20250611013245.133785-27-bryan.odonoghue@linaro.org>", "X-Mailer": "git-send-email 2.49.0", "In-Reply-To": "<20250611013245.133785-1-bryan.odonoghue@linaro.org>", "References": "<20250611013245.133785-1-bryan.odonoghue@linaro.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>" }, "content": "Extend out the bayer fragment shaders to take 3 x 256 byte inputs as\ntextures from the CPU.\n\nWe then use an index to the table to recover the colour-corrected values\nprovided by the SoftIPA thread.\n\nSigned-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n---\n .../internal/shaders/bayer_1x_packed.frag | 56 ++++++++++++++++\n .../libcamera/internal/shaders/bayer_8.frag | 62 ++++++++++++++++-\n src/libcamera/software_isp/debayer_egl.cpp | 67 +++++++++++++------\n src/libcamera/software_isp/debayer_egl.h | 7 +-\n 4 files changed, 169 insertions(+), 23 deletions(-)", "diff": "diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag\nindex 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 }\ndiff --git a/include/libcamera/internal/shaders/bayer_8.frag b/include/libcamera/internal/shaders/bayer_8.frag\nindex aa7a1b00..5955c2ea 100644\n--- a/include/libcamera/internal/shaders/bayer_8.frag\n+++ b/include/libcamera/internal/shaders/bayer_8.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 }\ndiff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 3fb15511..824cd6d3 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -99,6 +99,7 @@ int DebayerEGL::getShaderVariableLocations(void)\n \ttextureUniformRedLookupDataIn_ = glGetUniformLocation(programId_, \"red_param\");\n \ttextureUniformGreenLookupDataIn_ = glGetUniformLocation(programId_, \"green_param\");\n \ttextureUniformBlueLookupDataIn_ = glGetUniformLocation(programId_, \"blue_param\");\n+\tccmUniformDataIn_ = glGetUniformLocation(programId_, \"ccm\");\n \n \ttextureUniformStep_ = glGetUniformLocation(programId_, \"tex_step\");\n \ttextureUniformSize_ = glGetUniformLocation(programId_, \"tex_size\");\n@@ -111,6 +112,7 @@ int DebayerEGL::getShaderVariableLocations(void)\n \t\t\t << \" red_param \" << textureUniformRedLookupDataIn_\n \t\t\t << \" green_param \" << textureUniformGreenLookupDataIn_\n \t\t\t << \" blue_param \" << textureUniformBlueLookupDataIn_\n+\t\t\t << \" ccm \" << ccmUniformDataIn_\n \t\t\t << \" tex_step \" << textureUniformStep_\n \t\t\t << \" tex_size \" << textureUniformSize_\n \t\t\t << \" stride_factor \" << textureUniformStrideFactor_\n@@ -215,8 +217,13 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm\n \t\tbreak;\n \t};\n \n-\t// Flag to shaders that we have parameter gain tables\n-\tegl_.pushEnv(shaderEnv, \"#define APPLY_RGB_PARAMETERS\");\n+\tif (ccmEnabled_) {\n+\t\t// Run the CCM if available\n+\t\tegl_.pushEnv(shaderEnv, \"#define APPLY_CCM_PARAMETERS\");\n+\t} else {\n+\t\t// Flag to shaders that we have parameter gain tables\n+\t\tegl_.pushEnv(shaderEnv, \"#define APPLY_RGB_PARAMETERS\");\n+\t}\n \n \tif (egl_.compileVertexShader(vertexShaderId_, vertexShaderData, vertexShaderDataLen, shaderEnv))\n \t\tgoto compile_fail;\n@@ -266,6 +273,8 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \t\t\t const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs,\n \t\t\t bool ccmEnabled)\n {\n+\tGLint maxTextureImageUnits;\n+\n \tif (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0)\n \t\treturn -EINVAL;\n \n@@ -284,7 +293,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \tinputConfig_.stride = inputCfg.stride;\n \twidth_ = inputCfg.size.width;\n \theight_ = inputCfg.size.height;\n-\tccmEnabled_ = ccmEnabled = false;\n+\tccmEnabled_ = ccmEnabled = true;\n \n \tif (outputCfgs.size() != 1) {\n \t\tLOG(Debayer, Error)\n@@ -304,30 +313,35 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \tglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);\n \tLOG(Debayer, Debug) << \"Fragment shader maximum texture units \" << maxTextureImageUnits;\n \n-\tif (maxTextureImageUnits < DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS) {\n+\tif (!ccmEnabled && maxTextureImageUnits < DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS) {\n \t\tLOG(Debayer, Error) << \"Fragment shader texture unit count \" << maxTextureImageUnits\n \t\t\t\t << \" required minimum for RGB gain table lookup \" << DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS\n \t\t\t\t << \" try using an identity CCM \";\n \t\treturn -ENODEV;\n \t}\n+\n \t// Raw bayer input as texture\n \teglImageBayerIn_ = new eGLImage(width_, height_, 32, GL_TEXTURE0, 0);\n \tif (!eglImageBayerIn_)\n \t\treturn -ENOMEM;\n \n-\t/// RGB correction tables as 2d textures\n-\t// eGL doesn't support glTexImage1D so we do a little hack with 2D to compensate\n-\teglImageRedLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE1, 1);\n-\tif (!eglImageRedLookup_)\n-\t\treturn -ENOMEM;\n+\t// Only do the RGB lookup table textures if CCM is disabled\n+\tif (!ccmEnabled_) {\n \n-\teglImageGreenLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE2, 2);\n-\tif (!eglImageGreenLookup_)\n-\t\treturn -ENOMEM;\n+\t\t/// RGB correction tables as 2d textures\n+\t\t// eGL doesn't support glTexImage1D so we do a little hack with 2D to compensate\n+\t\teglImageRedLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE1, 1);\n+\t\tif (!eglImageRedLookup_)\n+\t\t\treturn -ENOMEM;\n \n-\teglImageBlueLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE3, 3);\n-\tif (!eglImageBlueLookup_)\n-\t\treturn -ENOMEM;\n+\t\teglImageGreenLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE2, 2);\n+\t\tif (!eglImageGreenLookup_)\n+\t\t\treturn -ENOMEM;\n+\n+\t\teglImageBlueLookup_ = new eGLImage(DebayerParams::kRGBLookupSize, 1, 32, GL_TEXTURE3, 3);\n+\t\tif (!eglImageBlueLookup_)\n+\t\t\treturn -ENOMEM;\n+\t}\n \n \t// Create a single BO (calling gbm_surface_lock_front_buffer() again before gbm_surface_release_buffer() would create another BO)\n \tif (gbmSurface_.mapSurface())\n@@ -440,9 +454,11 @@ void DebayerEGL::setShaderVariableValues(void)\n \t// To simultaneously sample multiple textures we need to use multiple\n \t// texture units\n \tglUniform1i(textureUniformBayerDataIn_, eglImageBayerIn_->texture_unit_uniform_id_);\n-\tglUniform1i(textureUniformRedLookupDataIn_, eglImageRedLookup_->texture_unit_uniform_id_);\n-\tglUniform1i(textureUniformGreenLookupDataIn_, eglImageGreenLookup_->texture_unit_uniform_id_);\n-\tglUniform1i(textureUniformBlueLookupDataIn_, eglImageBlueLookup_->texture_unit_uniform_id_);\n+\tif (!ccmEnabled_) {\n+\t\tglUniform1i(textureUniformRedLookupDataIn_, eglImageRedLookup_->texture_unit_uniform_id_);\n+\t\tglUniform1i(textureUniformGreenLookupDataIn_, eglImageGreenLookup_->texture_unit_uniform_id_);\n+\t\tglUniform1i(textureUniformBlueLookupDataIn_, eglImageBlueLookup_->texture_unit_uniform_id_);\n+\t}\n \n \t// These values are:\n \t// firstRed = tex_bayer_first_red - bayer_8.vert\n@@ -494,9 +510,18 @@ void DebayerEGL::debayerGPU(MappedFrameBuffer &in, MappedFrameBuffer &out, Debay\n \tegl_.createTexture2D(eglImageBayerIn_, inputConfig_.stride, height_, in.planes()[0].data());\n \n \t// Populate bayer parameters\n-\tegl_.createTexture2D(eglImageRedLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.red);\n-\tegl_.createTexture2D(eglImageGreenLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.green);\n-\tegl_.createTexture2D(eglImageBlueLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.blue);\n+\tif (ccmEnabled_) {\n+\t\tGLfloat ccm[] = {\n+\t\t\t1, 0, 0,\n+\t\t\t0, 1, 0,\n+\t\t\t0, 0, 1,\n+\t\t};\n+\t\tglUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm);\n+\t} else {\n+\t\tegl_.createTexture2D(eglImageRedLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.red);\n+\t\tegl_.createTexture2D(eglImageGreenLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.green);\n+\t\tegl_.createTexture2D(eglImageBlueLookup_, DebayerParams::kRGBLookupSize, 1, ¶ms.blue);\n+\t}\n \n \t// Setup the scene\n \tsetShaderVariableValues();\ndiff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h\nindex c0fc220f..94bc6fc4 100644\n--- a/src/libcamera/software_isp/debayer_egl.h\n+++ b/src/libcamera/software_isp/debayer_egl.h\n@@ -134,17 +134,22 @@ private:\n \tGLint textureUniformProjMatrix_;\n \n \tGLint textureUniformBayerDataIn_;\n+\n+\t// These textures will either point to simple RGB gains or to CCM lookup tables\n \tGLint textureUniformRedLookupDataIn_;\n \tGLint textureUniformGreenLookupDataIn_;\n \tGLint textureUniformBlueLookupDataIn_;\n \n+\t// Represent per-frame CCM as a uniform vector of floats 3 x 3\n+\tGLint ccmUniformDataIn_;\n+\tbool ccmEnabled_;\n+\n \tRectangle window_;\n \tstd::unique_ptr<SwStatsCpu> stats_;\n \teGL egl_;\n \tGBM gbmSurface_;\n \tuint32_t width_;\n \tuint32_t height_;\n-\tbool ccmEnabled_;\n \n \tGLfloat vcoordinates[DEBAYER_OPENGL_COORDS][2] = {\n \t\t{ -1.0f, -1.0f },\n", "prefixes": [ "26/35" ] }