{"id":27374,"url":"https://patchwork.libcamera.org/api/patches/27374/?format=json","web_url":"https://patchwork.libcamera.org/patch/27374/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260716222515.251464-7-mzamazal@redhat.com>","date":"2026-07-16T22:25:13","name":"[RFC,v8,6/6] libcamera: software_isp: debayer_egl: Add LSC support","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d5c6f17410f769929bcc559e1cea7ef7e4f48d54","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27374/mbox/","series":[{"id":6060,"url":"https://patchwork.libcamera.org/api/series/6060/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6060","date":"2026-07-16T22:25:07","name":"LSC for SoftISP simple pipeline","version":8,"mbox":"https://patchwork.libcamera.org/series/6060/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27374/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27374/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 DE540C330A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Jul 2026 22:25:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6A2E267E3E;\n\tFri, 17 Jul 2026 00:25:52 +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 B1A7C67E39\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jul 2026 00:25:49 +0200 (CEST)","from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-691-o_GrI66bPeKpk_tm4GVrwg-1;\n\tThu, 16 Jul 2026 18:25:47 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.111])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id C74081955F13; Thu, 16 Jul 2026 22:25:45 +0000 (UTC)","from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.11])\n\tby mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 1FD77180034C; Thu, 16 Jul 2026 22:25:42 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"KX3w96v3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1784240748;\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\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=svwuyErI49pirVq3y1FGDE03cuDDC4L/PIzoDvqJpgI=;\n\tb=KX3w96v3DExwidU8UdYRwuzmfqdkrAHRSWhWPr2x7NC0yVuafdQUc8y2wt7LI39f5sWZXR\n\txCaRqHJYR29KzAetXU6iJDnqkEgF3H5OuX79JcIz9wYfCpJ6Dr/Vm8JCvxocNUtU1tdVlk\n\tsaaY6w876gjOwFMaTaSMuPoNkR5v5tw=","X-MC-Unique":"o_GrI66bPeKpk_tm4GVrwg-1","X-Mimecast-MFC-AGG-ID":"o_GrI66bPeKpk_tm4GVrwg_1784240746","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Xander Pronk <xander.c.pronk@gmail.com>,\n\tBryan O'Donoghue <bod.linux@nxsw.ie>,\n\tHans de Goede <johannes.goede@oss.qualcomm.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tRick ten Wolde <rick_libcamera@wolde.info>,\n\tMilan Zamazal <mzamazal@redhat.com>","Subject":"[RFC PATCH v8 6/6] libcamera: software_isp: debayer_egl: Add LSC\n\tsupport","Date":"Fri, 17 Jul 2026 00:25:13 +0200","Message-ID":"<20260716222515.251464-7-mzamazal@redhat.com>","In-Reply-To":"<20260716222515.251464-1-mzamazal@redhat.com>","References":"<20260716222515.251464-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"MLRICTglFPy_XcjdU1vFRvZW63LEtS3nHvIrEBMqcOM_1784240746","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=\"US-ASCII\"; x-default=true","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<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":"From: Xander Pronk <xander.c.pronk@gmail.com>\n\nAdd support for passing the LSC table from debayerParams to the shaders.\n\nThe LSC table values are floats, we must add `type' parameter to\ncreateTexture2D to support this.  Moreover, we use 16-bit internal\nformat for the values, primarily because this works for me, unlike\n32-bit floats.\n\nWhen LSC is disabled by the runtime control, we provide a constant 1.0\ncorrection table, i.e. a no-op table.  This is preferred to having a\nruntime flag, to not disturb GPU computation with runtime switches,\nassuming that disabling LSC in runtime is not a common use case.\n\nCo-developed-by: Rick ten Wolde <rick_libcamera@wolde.info>\nSigned-off-by: Rick ten Wolde <rick_libcamera@wolde.info>\nSigned-off-by: Xander Pronk <xander.c.pronk@gmail.com>\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n include/libcamera/internal/egl.h              |  6 +++-\n .../internal/software_isp/debayer_params.h    |  2 ++\n src/ipa/simple/algorithms/lsc.cpp             | 11 ++++---\n src/libcamera/egl.cpp                         | 10 +++++--\n src/libcamera/software_isp/debayer.cpp        |  5 ++++\n src/libcamera/software_isp/debayer_egl.cpp    | 29 +++++++++++++++++--\n src/libcamera/software_isp/debayer_egl.h      |  6 ++++\n 7 files changed, 60 insertions(+), 9 deletions(-)","diff":"diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h\nindex 030c813a5..37da2b18a 100644\n--- a/include/libcamera/internal/egl.h\n+++ b/include/libcamera/internal/egl.h\n@@ -107,7 +107,11 @@ public:\n \n \tint createInputDMABufTexture2D(eGLImage &eglImage, int fd);\n \tint createOutputDMABufTexture2D(eGLImage &eglImage, int fd);\n-\tvoid createTexture2D(eGLImage &eglImage, void *data, GLint filter);\n+\tvoid createTexture2D(eGLImage &eglImage,\n+\t\t\t     GLint internalFormat,\n+\t\t\t     GLenum type,\n+\t\t\t     const void *data,\n+\t\t\t     GLint filter);\n \n \tvoid pushEnv(std::vector<std::string> &shaderEnv, const char *str);\n \tvoid makeCurrent();\ndiff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h\nindex e3e01bc04..76825e6c8 100644\n--- a/include/libcamera/internal/software_isp/debayer_params.h\n+++ b/include/libcamera/internal/software_isp/debayer_params.h\n@@ -29,6 +29,8 @@ struct DebayerParams {\n \n \tstatic constexpr unsigned int kLscGridSize = 16;\n \tstatic constexpr unsigned int kLscValuesPerCell = 3;\n+\tstatic constexpr unsigned int kLscBytesPerCell =\n+\t\tkLscValuesPerCell * sizeof(float);\n \tusing LscLookupTable =\n \t\tstd::array<float, kLscGridSize * kLscGridSize * kLscValuesPerCell>;\n \tLscLookupTable lscLut{};\ndiff --git a/src/ipa/simple/algorithms/lsc.cpp b/src/ipa/simple/algorithms/lsc.cpp\nindex c531937c7..51c5b63d5 100644\n--- a/src/ipa/simple/algorithms/lsc.cpp\n+++ b/src/ipa/simple/algorithms/lsc.cpp\n@@ -46,13 +46,16 @@ void Lsc::prepare([[maybe_unused]] IPAContext &context,\n \t\t  IPAFrameContext &frameContext,\n \t\t  DebayerParams *params)\n {\n-\tparams->lscEnabled = frameContext.lsc.enabled;\n-\n \tunsigned int ct = frameContext.awb.colourTemperature;\n \tconstexpr unsigned int minTemperatureChange = 100;\n \n-\tif (!frameContext.lsc.enabled ||\n-\t    utils::abs_diff(ct, lastAppliedCt_) < minTemperatureChange)\n+\tif (!frameContext.lsc.enabled) {\n+\t\tparams->lscLut.fill(1.0);\n+\t\tlastAppliedCt_ = 0;\n+\t\treturn;\n+\t}\n+\n+\tif (utils::abs_diff(ct, lastAppliedCt_) < minTemperatureChange)\n \t\treturn;\n \n \tconst lsc::Components<uint8_t> &set = lscAlgo_.interpolateComponents(ct);\ndiff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp\nindex aeac5d313..c2a158ce7 100644\n--- a/src/libcamera/egl.cpp\n+++ b/src/libcamera/egl.cpp\n@@ -241,6 +241,8 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)\n /**\n  * \\brief Create a 2D texture from a memory buffer\n  * \\param[in,out] eglImage EGL image to associate with the texture\n+ * \\param[in] internalFormat OpenGL internal storage format (e.g., GL_RGB8, GL_RGBA8)\n+ * \\param[in] type OpenGL pixel data type (e.g., GL_UNSIGNED_BYTE, GL_FLOAT)\n  * \\param[in] data Pointer to pixel data, or nullptr for uninitialised texture\n  * \\param[in] filter GL texture filter setting\n  *\n@@ -249,7 +251,11 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd)\n  * is useful for uploading static data like lookup tables or uniform color\n  * matrices to the GPU.\n  */\n-void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)\n+void eGL::createTexture2D(eGLImage &eglImage,\n+\t\t\t  GLint internalFormat,\n+\t\t\t  GLenum type,\n+\t\t\t  const void *data,\n+\t\t\t  GLint filter)\n {\n \tASSERT(tid_ == Thread::currentId());\n \n@@ -257,7 +263,7 @@ void eGL::createTexture2D(eGLImage &eglImage, void *data, GLint filter)\n \tglBindTexture(GL_TEXTURE_2D, eglImage.texture_);\n \n \t// Generate texture, bind, associate image to texture, configure, unbind\n-\tglTexImage2D(GL_TEXTURE_2D, 0, eglImage.format_, eglImage.width_, eglImage.height_, 0, eglImage.format_, GL_UNSIGNED_BYTE, data);\n+\tglTexImage2D(GL_TEXTURE_2D, 0, internalFormat, eglImage.width_, eglImage.height_, 0, eglImage.format_, type, data);\n \n \t// Nearest filtering\n \tglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);\ndiff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp\nindex 5ae9f032f..70c0e3336 100644\n--- a/src/libcamera/software_isp/debayer.cpp\n+++ b/src/libcamera/software_isp/debayer.cpp\n@@ -53,6 +53,11 @@ namespace libcamera {\n  * \\brief Number of pixel values per each of the lens shading grid areas\n  */\n \n+/**\n+ * \\var DebayerParams::kLscBytesPerCell\n+ * \\brief Number of bytes per each of the lens shading grid areas\n+ */\n+\n /**\n  * \\typedef DebayerParams::LscLookupTable\n  * \\brief Lookup table for lens shading correction\ndiff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 562e9fc7a..0fdf0e6e8 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -128,6 +128,8 @@ int DebayerEGL::getShaderVariableLocations(void)\n \ttextureUniformBayerFirstRed_ = glGetUniformLocation(programId_, \"tex_bayer_first_red\");\n \ttextureUniformProjMatrix_ = glGetUniformLocation(programId_, \"proj_matrix\");\n \n+\ttextureUniformLsc_ = glGetUniformLocation(programId_, \"lsc_tex\");\n+\n \tLOG(Debayer, Debug) << \"vertexIn \" << attributeVertex_ << \" textureIn \" << attributeTexture_\n \t\t\t    << \" tex_y \" << textureUniformBayerDataIn_\n \t\t\t    << \" awb \" << awbUniformDataIn_\n@@ -139,7 +141,8 @@ int DebayerEGL::getShaderVariableLocations(void)\n \t\t\t    << \" tex_size \" << textureUniformSize_\n \t\t\t    << \" stride_factor \" << textureUniformStrideFactor_\n \t\t\t    << \" tex_bayer_first_red \" << textureUniformBayerFirstRed_\n-\t\t\t    << \" proj_matrix \" << textureUniformProjMatrix_;\n+\t\t\t    << \" proj_matrix \" << textureUniformProjMatrix_\n+\t\t\t    << \" tex_lsc \" << textureUniformLsc_;\n \treturn 0;\n }\n \n@@ -156,6 +159,9 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm\n \t/* Specify GL_OES_EGL_image_external */\n \tegl_.pushEnv(shaderEnv, \"#extension GL_OES_EGL_image_external: enable\");\n \n+\tif (lscEnabled_)\n+\t\tegl_.pushEnv(shaderEnv, \"#define APPLY_LSC\");\n+\n \t/*\n \t * Tell shaders how to re-order output taking account of how the pixels\n \t * are actually stored by EGL.\n@@ -348,6 +354,18 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,\n \t */\n \tstats_->setWindow(Rectangle(window_.size()));\n \n+\tif (lscEnabled_) {\n+\t\tconstexpr unsigned int gridSize = DebayerParams::kLscGridSize;\n+\t\tconst unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell;\n+\t\teglImageLscLookup_ =\n+\t\t\tstd::make_unique<eGLImage>(GL_RGB,\n+\t\t\t\t\t\t   gridSize,\n+\t\t\t\t\t\t   gridSize,\n+\t\t\t\t\t\t   stride,\n+\t\t\t\t\t\t   GL_TEXTURE2,\n+\t\t\t\t\t\t   2);\n+\t}\n+\n \treturn 0;\n }\n \n@@ -483,6 +501,12 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams &params)\n \tglUniformMatrix3fv(ccmUniformDataIn_, 1, GL_TRUE, params.combinedMatrix.data().data());\n \tLOG(Debayer, Debug) << \" ccmUniformDataIn_ \" << ccmUniformDataIn_ << \" data \" << params.combinedMatrix;\n \n+\tif (lscEnabled_) {\n+\t\tegl_.createTexture2D(*eglImageLscLookup_, GL_RGB16F, GL_FLOAT,\n+\t\t\t\t     params.lscLut.data(), GL_LINEAR);\n+\t\tglUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_);\n+\t}\n+\n \t/*\n \t * 0 = Red, 1 = Green, 2 = Blue\n \t */\n@@ -530,7 +554,8 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye\n \t\t\tLOG(Debayer, Error) << \"mmap-ing buffer(s) failed\";\n \t\t\treturn -ENODEV;\n \t\t}\n-\t\tegl_.createTexture2D(*eglImageBayerIn_, inMapped->value().planes()[0].data(), GL_NEAREST);\n+\t\tegl_.createTexture2D(*eglImageBayerIn_, glFormat_, GL_UNSIGNED_BYTE,\n+\t\t\t\t     inMapped->value().planes()[0].data(), GL_NEAREST);\n \t}\n \n \t/* Generate the output render framebuffer as render to texture */\ndiff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h\nindex 82ed1305d..f3913d564 100644\n--- a/src/libcamera/software_isp/debayer_egl.h\n+++ b/src/libcamera/software_isp/debayer_egl.h\n@@ -78,7 +78,10 @@ private:\n \tstd::unique_ptr<eGLImage> eglImageBayerIn_;\n \tstd::unique_ptr<eGLImage> eglImageBayerOut_;\n \n+\t/* LSC lookup table */\n+\tstd::unique_ptr<eGLImage> eglImageLscLookup_;\n \tbool lscEnabled_;\n+\n \t/* Shader parameters */\n \tfloat firstRed_x_;\n \tfloat firstRed_y_;\n@@ -95,6 +98,9 @@ private:\n \t/* Per-frame AWB gains */\n \tGLint awbUniformDataIn_;\n \n+\t/* Lens shading correction */\n+\tGLint textureUniformLsc_;\n+\n \t/* Represent per-frame CCM as a uniform vector of floats 3 x 3 */\n \tGLint ccmUniformDataIn_;\n \n","prefixes":["RFC","v8","6/6"]}