From patchwork Fri Dec 12 00:29:17 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: 25521 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 4906EBD1F1 for ; Fri, 12 Dec 2025 00:33:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 103BF61635; Fri, 12 Dec 2025 01:33:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="zLUyt7r8"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0031F61635 for ; Fri, 12 Dec 2025 01:33:41 +0100 (CET) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-7c66822dd6dso319338b3a.0 for ; Thu, 11 Dec 2025 16:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1765499620; x=1766104420; 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=zLUyt7r8h2WbEJlIa28BQ19Geegxn1w/seiUlg6COsvoKiO/KH0wEWdg0i0LsoD2CP sekiWqDWsejT+Ej332hOYKLj9G52A1l/2/X2smcgid9ZXjJeLkG/K9p9VAgNKzrI/qtW pHPnOhl7C/I6byYQdAHKoPF57ZwpS6Y2DBEdscVcdLOHRhpm64NwYmK/FLZDbm8mB+M3 ze2c8bCPh0YYc8c1zcReKidbU5AT1eUQbKHuy0PXD0ETee7bQZY0ordwO6FRLXR2N5T1 T02utBvKfPKtYaQIQc/v75k/8gLrCUhAhTRhwZF0OdLh0KhDckcQROz9xP/lEFT3dVGE AhHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765499620; x=1766104420; 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=LohoCzSsKhCEzFxQz4UKJisl3UG8zE15XnVX6rcZ690UfK6/eM0iyOGw4FvI+7DOFE MRegbq8D1/ZpI3BiBfgwv4Zkn/69qcfeVMJmk5kauaMHFtgsDmhdVf7qvlDic9hD5bkd J1VSuPlxoxkhyjbyeTdW9ceRp6dkZhdlSGb8ZPZaRBl/manHneD3N04/shXIWH4JkX31 VjPK05NoFE/Pa5maVAeoX85SAtcFklovEpmNInJYiUUxnwqgG6IYmnvYO5VjiFhgL/on Pklv48CeWxgpJrWz1z6Ld7+i7oPWOpg2Vs8u3q33+jH1l8n5xXYXbNrd23j4HHGVkswV zErA== X-Gm-Message-State: AOJu0YzsgsLdnAt65CI/9MS4aROXZT/ge9PeyPVQp7Kn+n715gxpVLPk 9qO+bibHmIs5sC73b6sZ5lJ7SI3q0od4Azl7nkB27v6gdeCKIRbteXUgs+wuLMRU4DKwsNVtFoZ S1ZA5 X-Gm-Gg: AY/fxX6uWJbj+rekotGGSvEy96cjoshd47g8wa1H/kIC68nx5bzqaa2I4RtDraTRbzy EoQVnoNENdAJAlpa5fZ9VTX9dFMtpP0kbq5RBVzm9ZGQYM8forFyXEnFAsne03WvgY0H3E0yzNL kjWlSy52cl27ugc0flyXypnaWGLQHAJQC7dd6Md/RnM6yg28V5XZIDyiq0E7KmzJJ9yKhOFkYIg RB5xTAERjoezBxk5kFW03+YAL3p+scyoo++1wdB6RK0jXn+KVoSqJftcRnFVPy/zVgdNOIbg7qE 8qNG7ESF28xwW2vxyO68dqFD4nep6pBOEuyDA662KaEotKbYB59nIrjFCRPhmlT1ULz3VwG5W/c 55EERy7m/+NDk7u8V81oKXtDkb7ih4seJ12HxIGzvxcu+rqSHmrJ3XmGezKRebigipRsCtBugM7 zBle0RngObfPNQh7b2rIpI2E8Xszy0zu+YsuAUKnhq6c150clBENdyMK37VJI= X-Google-Smtp-Source: AGHT+IGbB0YnSVpvwEyvcMRlLd5rVt5PKMwmgQaD6pvORp0rHSk/5draKAB+exmK07bhIXGl5ICRVA== X-Received: by 2002:a05:6a20:72aa:b0:35e:b02b:4efd with SMTP id adf61e73a8af0-368594b7cc0mr3840158637.27.1765499620247; Thu, 11 Dec 2025 16:33:40 -0800 (PST) Received: from inspiron14p-linux (p99250-ipoefx.ipoe.ocn.ne.jp. [153.246.134.249]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c0c26eb0f6bsm3317282a12.14.2025.12.11.16.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 16:33:39 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v8 06/26] libcamera: shaders: Extend debayer shaders to apply CCM gains Date: Fri, 12 Dec 2025 00:29:17 +0000 Message-ID: <20251212002937.3118-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251212002937.3118-1-bryan.odonoghue@linaro.org> References: <20251212002937.3118-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; }