From patchwork Tue Jan 6 17:00:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25660 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 81949BDCC0 for ; Tue, 6 Jan 2026 17:01:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AD6861FD8; Tue, 6 Jan 2026 18:01:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="oUdIK4yz"; dkim-atps=neutral Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E18FD61FF4 for ; Tue, 6 Jan 2026 18:01:11 +0100 (CET) Received: by mail-wm1-x344.google.com with SMTP id 5b1f17b1804b1-477563e28a3so118815e9.1 for ; Tue, 06 Jan 2026 09:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1767718871; x=1768323671; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zkzu0tqbzAOlMWvnkw6w2p9R2Nid+3zoTkR/m4lKMgE=; b=oUdIK4yzbMx259SE4ES9Qv6NSn+FjIRkPeATu8tA91bvOyqOOViBgdWTauZpZTHdkk niIe8I1Onvtm0hy/P3J4I0P/3FIY7P58GG8euYjZGYP5I6mbnmu7ajqeXcGRmt6GE+Ld rUeHqQv9E2/FnArlb78O0QyusKotmN2np/rIevqmDNf6JN1hiUL/RZJDWa18GD+BOLPZ BWdeEzU/eKgY5tywd2ktdPLqR0uvuxo2auw1owhbHDWG1hlqGUdBkXvhxUl8RixHchSK SwAsHFwXln5QMyuVFw+f38srWZVjJhblVmZDNmJq8+wOXsaMP5Yx8Xd1nhuFUBfmsGtm qPzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767718871; x=1768323671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Zkzu0tqbzAOlMWvnkw6w2p9R2Nid+3zoTkR/m4lKMgE=; b=EMqbq8JTKc0TC9osxJjkpngafoi9qxysH3YdftYoeEkzmXnZ3ZrgGdBJLZFCU+jmWr mOgOQ7DIftJRt71F4Vexn5khxEkdu2++DvBa4wOZg++jYgpMNefvhg18u+kFZui/UgJh CkmG+OqaXGfyw7CsDJhcDF7iHU+cxQR596lqgCGV5873VxFnrv+PPyqr74z6EKJACKda vcc/9hPhK537HQOn5vrTlE0G+/qz/Jh/XBfL10JBzNLEkF8eqyGAUp8A/fx0l6WERAtr PkAbBsDpzaHrFweNpptS2CoHmyh+C4q3on2YCM/BGdWyNzjG6cUOheZKqbYmKgHz8Ewf XpNA== X-Gm-Message-State: AOJu0YxACYJ072j86j2BakbnkLDFFcK+hXrCa1z7K/k82zSueJkGO2QR /ib5sUg0H0j677P08qcJzST1r+e1rFoS8BhTx6SnkfSvNK8IazDPwGmVBxRi6ovwsHhVFa5BkcO DTr3SQnlz9A== X-Gm-Gg: AY/fxX6UNxAtEuP4nCtcgY1QZ6yXqGhUrivyn3N+hcRYKcBGPflGo+giWW8FxV5HJA9 rNJurawubz3kXYxlg+4NO2jlFQ6sIuzmc9jrc1i1dfPe5dsxrIpZiXXRJZ5Mz9JhLDuj12A4iRr kC9ueRmqQ9fCSjS53nkF542r5JFvrsQA9tstqjVvx1vs2NEJQ7rWKMVnhc7Z+UKSGC8jKBXz3If 3bQ8uNrM2jTGFRtLtLyimc+wxsS83ZhiDu8YaXUvKjr6xd5CZ48FA5oBwFnakjYUtu9TI1O6t55 Z6M9JHK/ooIYYANZXQLxOPHTa81mujTSAI1SuEDIAJX7L6ZJYyXFO+5VjqlTNUfNH/UHyFUMNIt O95/+aXERfucRgjyT0+9OKyASfLa4Rd3kwEpm9CKznGbl1MuPZfGPC7kKlJcZ+IAYo6NTv6fox3 af/JlEP9almszWF400rsBMSimnd2goPaD2XjttWlPvH5g77JFqPdA9mHE0L9GNSJqm8Do= X-Google-Smtp-Source: AGHT+IEWPolcrFllHr3v0D6uzYIpQTLfwLZCcALuhj+gPP98jVMpl1F+4EM2hYPqMYtYmPtqiFrmwg== X-Received: by 2002:a05:600c:46c3:b0:477:a2f7:74de with SMTP id 5b1f17b1804b1-47d7f404854mr51238645e9.3.1767718871170; Tue, 06 Jan 2026 09:01:11 -0800 (PST) Received: from inspiron14p-linux.ht.home (188-141-3-146.dynamic.upc.ie. [188.141.3.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd0dadcfsm5515322f8f.3.2026.01.06.09.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 09:01:10 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v11 07/24] libcamera: shaders: Extend debayer shaders to apply CCM gains Date: Tue, 6 Jan 2026 17:00:42 +0000 Message-ID: <20260106170059.56193-8-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260106170059.56193-1-bryan.odonoghue@linaro.org> References: <20260106170059.56193-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend Bayer shaders to support application of a passed CCM table. Reviewed-by: Milan Zamazal Signed-off-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_1x_packed.frag | 45 +++++++++++++++++++ src/libcamera/shaders/bayer_unpacked.frag | 51 +++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 19b13ad08..171a928c2 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -65,6 +65,7 @@ uniform vec2 tex_step; uniform vec2 tex_bayer_first_red; uniform sampler2D tex_y; +uniform mat3 ccm; void main(void) { @@ -212,5 +213,49 @@ void main(void) vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); + /* + * CCM is a 3x3 in the format + * + * +--------------+----------------+---------------+ + * | RedRedGain | RedGreenGain | RedBlueGain | + * +--------------+----------------+---------------+ + * | GreenRedGain | GreenGreenGain | GreenBlueGain | + * +--------------+----------------+---------------+ + * | BlueRedGain | BlueGreenGain | BlueBlueGain | + * +--------------+----------------+---------------+ + * + * Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin + * Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin + * Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin + * + * We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm); + * + * CPU + * float ccm [] = { + * RedRedGain, RedGreenGain, RedBlueGain, + * GreenRedGain, GreenGreenGain, GreenBlueGain, + * BlueRedGain, BlueGreenGain, BlueBlueGain, + * }; + * + * GPU + * ccm = { + * RedRedGain, GreenRedGain, BlueRedGain, + * RedGreenGain, GreenGreenGain, BlueGreenGain, + * RedBlueGain, GreenBlueGain, BlueBlueGain, + * } + * + * However the indexing for the mat data-type is column major hence + * ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain + * + */ + float rin, gin, bin; + rin = rgb.r; + gin = rgb.g; + bin = rgb.b; + + rgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]); + rgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]); + rgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]); + gl_FragColor = vec4(rgb, 1.0); } diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index aa7a1b004..c41d72f4f 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -24,8 +24,11 @@ uniform sampler2D tex_y; varying vec4 center; varying vec4 yCoord; varying vec4 xCoord; +uniform mat3 ccm; void main(void) { + vec3 rgb; + #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r float C = texture2D(tex_y, center.xy).r; // ( 0, 0) @@ -97,11 +100,57 @@ void main(void) { PATTERN.xw += kB.xw * B; PATTERN.xz += kF.xz * F; - gl_FragColor.rgb = (alternate.y == 0.0) ? + rgb = (alternate.y == 0.0) ? ((alternate.x == 0.0) ? vec3(C, PATTERN.xy) : vec3(PATTERN.z, C, PATTERN.w)) : ((alternate.x == 0.0) ? vec3(PATTERN.w, C, PATTERN.z) : vec3(PATTERN.yx, C)); + + /* + * CCM is a 3x3 in the format + * + * +--------------+----------------+---------------+ + * | RedRedGain | RedGreenGain | RedBlueGain | + * +--------------+----------------+---------------+ + * | GreenRedGain | GreenGreenGain | GreenBlueGain | + * +--------------+----------------+---------------+ + * | BlueRedGain | BlueGreenGain | BlueBlueGain | + * +--------------+----------------+---------------+ + * + * Rout = RedRedGain * Rin + RedGreenGain * Gin + RedBlueGain * Bin + * Gout = GreenRedGain * Rin + GreenGreenGain * Gin + GreenBlueGain * Bin + * Bout = BlueRedGain * Rin + BlueGreenGain * Gin + BlueBlueGain * Bin + * + * We upload to the GPU without transposition glUniformMatrix3f(.., .., GL_FALSE, ccm); + * + * CPU + * float ccm [] = { + * RedRedGain, RedGreenGain, RedBlueGain, + * GreenRedGain, GreenGreenGain, GreenBlueGain, + * BlueRedGain, BlueGreenGain, BlueBlueGain, + * }; + * + * GPU + * ccm = { + * RedRedGain, GreenRedGain, BlueRedGain, + * RedGreenGain, GreenGreenGain, BlueGreenGain, + * RedBlueGain, GreenBlueGain, BlueBlueGain, + * } + * + * However the indexing for the mat data-type is column major hence + * ccm[0][0] = RedRedGain, ccm[0][1] = RedGreenGain, ccm[0][2] = RedBlueGain + * + */ + float rin, gin, bin; + rin = rgb.r; + gin = rgb.g; + bin = rgb.b; + + rgb.r = (rin * ccm[0][0]) + (gin * ccm[0][1]) + (bin * ccm[0][2]); + rgb.g = (rin * ccm[1][0]) + (gin * ccm[1][1]) + (bin * ccm[1][2]); + rgb.b = (rin * ccm[2][0]) + (gin * ccm[2][1]) + (bin * ccm[2][2]); + + gl_FragColor.rgb = rgb; }