From patchwork Wed Dec 17 10:01:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 25579 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 4EE38C326C for ; Wed, 17 Dec 2025 10:02:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE18861ABD; Wed, 17 Dec 2025 11:02:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VzOeDH5k"; 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 72EBA61A5C for ; Wed, 17 Dec 2025 11:01:50 +0100 (CET) Received: by mail-wm1-x344.google.com with SMTP id 5b1f17b1804b1-47775fb6cb4so39071675e9.0 for ; Wed, 17 Dec 2025 02:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765965710; x=1766570510; 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=VzOeDH5kBINuxbv/4m1l48PCe9GYJ0bnuyQUB/YQhUoYmagPK/tHDI0+/EHvpiUAQv cQhQgyGABxKkHPRaZppwbCDtHKAQSfhSeMUcJdqm18brntUAcmjIv5agAFDJZa6aR76r MCgpoSk333ETTiA13RjIqDLVFUpN//9U0r2FGSyr7Zf553oW7TQYufrfFsv7CI/seUus vbpf5WDzJzosTkY/afbw93URA+sXdnA5n8rPoDd19BH9vEPODWNDM6eIX4gTpvlvF1y+ 9iq+fog9iOVy9cseolHuqIhu4QsMGpIfUq6/53ADxKA6SdspI3BN6XnPbr5M98XDsIkB WgJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765965710; x=1766570510; 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=Dc6SGo/hXFi6MMJMtEDNa37d1Nkfu2XK1t5QeKx0XpsW3EzD0MhQ3ICbV3yfM9eknW 91cYj0ezv8pybEL1HG3sWW9U7sgD7QIi+8mOvUdDCrXVxts9M+eBXrgJwqMoLvELgPm8 iEbf4ImPBdfcPEnYncKYMfnqc6l+CjCYByfFi3e5t2oa7oNqxsuZ9wTUM4w1inKAfGSR MM4pL49eH1A40ukREwtNfwRnCYv61uHlj4lCT444dE+TEsNe5QY9bLPSW2n5SJjPBXG7 LQTGKz2x4CTPLNqEK+rcoNMpU1h/l0lGTZKpO97MfbUlFWnP9RAvVKwyX0tsnSdJUCAO jwdg== X-Gm-Message-State: AOJu0YxUQ4jFpiLaeE0MemQzoSz276sdfecuQuHQShIBP1BuyqGCNhy+ OOHgbGIJ4cOBIRJ57b0ipHfdnp74HZFD5pqEIBNCeDQT3pMfQcSWd8dbIaplzkkxfa+1yeteBRu i0IjZC28= X-Gm-Gg: AY/fxX5d1YoiNJawUcdvVBzfuE8UqZS0fAm0llb241mLrmiin5rxW7/FRXgnZmAuEXA 0pQmSWg6m+Fho12x3B5vbz8Xu+YWV16V+B36lrvSXEG5DHgTG6BGHUxH5q0S1EuTgH2HA3fGDDW QO5K37EXXwHt1sRFBceN71nJXr6MoGbytQDl453rPd9NjxqFafm1LmgDeqeHglaFb/lWDnlepZ6 ZIGUkGzqj4ubSIs6xrgS9MmVNbroAykg8YNFihaQpjL7w/jsZpb0AH75gaq5MqPgfhOjH4WLhmC Qn2AFXS+1QGyz0j1mwMbjWwIb88h+Pf69xImrZ40FcEC4IMhQVYZsNF0YLCT1JSdxh5YGhmok44 tKeC6/QXC7N6CukFK2Ffm6Xc5ViPhoYb+gqRkEUxVUh0S6I60T5HbcmOgaWnKar/OH1t1UmD757 Au7rt9KW1EuensJMS+TFVVsZYdtMNy5TzBUCQ5TxmNL7Pza4FUp6q6MxY2Qg1D0tUGY6Ou+BUk0 Z9tBQ== X-Google-Smtp-Source: AGHT+IF03kRrjPlt40PtVFkP72T6S43oPtDLssb2CttrBH9TpI8EvOpY2X5eIDWFkqDfXQVWAF0Jpw== X-Received: by 2002:a05:600c:19c6:b0:45c:4470:271c with SMTP id 5b1f17b1804b1-47a8f90598emr172228595e9.18.1765965709648; Wed, 17 Dec 2025 02:01:49 -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 5b1f17b1804b1-47bdc1583fbsm32292585e9.0.2025.12.17.02.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 02:01:49 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v9 06/26] libcamera: shaders: Extend debayer shaders to apply CCM gains Date: Wed, 17 Dec 2025 10:01:18 +0000 Message-ID: <20251217100138.82525-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251217100138.82525-1-bryan.odonoghue@linaro.org> References: <20251217100138.82525-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; }