From patchwork Tue Apr 7 22:01:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 26484 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 77517BDCBD for ; Tue, 7 Apr 2026 22:02:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9105962D66; Wed, 8 Apr 2026 00:02:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nfUN0mOK"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E855562CF8 for ; Wed, 8 Apr 2026 00:02:40 +0200 (CEST) Received: from [192.168.0.204] (ams.linuxembedded.co.uk [209.38.108.23]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1411C6A6; Wed, 8 Apr 2026 00:01:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1775599273; bh=oE3seNGpVKrTZwrJbFVl1Kzr/R9vtqYUaf0XvehVwrk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nfUN0mOKd7g9xsyN/CnRHtXTZ73qsL3MBt55n1vacQXnuO1UF+XJ4DWBVCDD8oxMq GA6301xqBttOXZWVii4MhkfkTBX6gaPLlRR6OvsMgyYZX0R9mZiVCRJF5BImSzUU9k Iz560a8vpBTs1LMYAuPcEtFFm9rJnRLhUNXKkCVo= From: Kieran Bingham Date: Tue, 07 Apr 2026 23:01:04 +0100 Subject: [PATCH 01/13] libcamera: shaders: unpacked: Fix indentations MIME-Version: 1.0 Message-Id: <20260407-kbingham-awb-split-v1-1-a39af3f4dc20@ideasonboard.com> References: <20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com> In-Reply-To: <20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775599359; l=11533; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=oE3seNGpVKrTZwrJbFVl1Kzr/R9vtqYUaf0XvehVwrk=; b=h0BSXZwD51H236n8YlJbmBFC/LjIo2JtKDbT7Sbi5/aAH9G+BoQRJd8Shn64l23FIlqX9LYNn kYe/eeH0lqMBj/zXSsl2jCYch4omwTlaB/OONdg7NAdWhDVmrzUAxls X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY= 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" Reflow the unpacked bayer shader to use tabs for indentation and match the style of the bayer_packed fragment shader. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/shaders/bayer_unpacked.frag | 264 +++++++++++++++--------------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index 1b85196ae16130670eb3d1c077ab4884119ae63c..76ffc47a8a29f242c1fba88f32bd8db731edeee0 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -31,163 +31,163 @@ uniform float contrastExp; float apply_contrast(float value) { - // Apply simple S-curve - if (value < 0.5) - return 0.5 * pow(value / 0.5, contrastExp); - else - return 1.0 - 0.5 * pow((1.0 - value) / 0.5, contrastExp); + // Apply simple S-curve + if (value < 0.5) + return 0.5 * pow(value / 0.5, contrastExp); + else + return 1.0 - 0.5 * pow((1.0 - value) / 0.5, contrastExp); } void main(void) { - vec3 rgb; + vec3 rgb; - #if defined(RAW10P) - #define pixel(p) p.r / 4.0 + p.g * 64.0 - #define fetch(x, y) pixel(texture2D(tex_y, vec2(x, y))) - #elif defined(RAW12P) - #define pixel(p) p.r / 16.0 + p.g * 16.0 - #define fetch(x, y) pixel(texture2D(tex_y, vec2(x, y))) - #else - #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r - #endif + #if defined(RAW10P) + #define pixel(p) p.r / 4.0 + p.g * 64.0 + #define fetch(x, y) pixel(texture2D(tex_y, vec2(x, y))) + #elif defined(RAW12P) + #define pixel(p) p.r / 16.0 + p.g * 16.0 + #define fetch(x, y) pixel(texture2D(tex_y, vec2(x, y))) + #else + #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r + #endif - float C = fetch(center.x, center.y); // ( 0, 0) - const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; + float C = fetch(center.x, center.y); // ( 0, 0) + const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0; - // Determine which of four types of pixels we are on. - vec2 alternate = mod(floor(center.zw), 2.0); + // Determine which of four types of pixels we are on. + vec2 alternate = mod(floor(center.zw), 2.0); - vec4 Dvec = vec4( - fetch(xCoord[1], yCoord[1]), // (-1,-1) - fetch(xCoord[1], yCoord[2]), // (-1, 1) - fetch(xCoord[2], yCoord[1]), // ( 1,-1) - fetch(xCoord[2], yCoord[2])); // ( 1, 1) + vec4 Dvec = vec4( + fetch(xCoord[1], yCoord[1]), // (-1,-1) + fetch(xCoord[1], yCoord[2]), // (-1, 1) + fetch(xCoord[2], yCoord[1]), // ( 1,-1) + fetch(xCoord[2], yCoord[2])); // ( 1, 1) - vec4 PATTERN = (kC.xyz * C).xyzz; + vec4 PATTERN = (kC.xyz * C).xyzz; - // Can also be a dot product with (1,1,1,1) on hardware where that is - // specially optimized. - // Equivalent to: D = Dvec[0] + Dvec[1] + Dvec[2] + Dvec[3]; - Dvec.xy += Dvec.zw; - Dvec.x += Dvec.y; + // Can also be a dot product with (1,1,1,1) on hardware where that is + // specially optimized. + // Equivalent to: D = Dvec[0] + Dvec[1] + Dvec[2] + Dvec[3]; + Dvec.xy += Dvec.zw; + Dvec.x += Dvec.y; - vec4 value = vec4( - fetch(center.x, yCoord[0]), // ( 0,-2) - fetch(center.x, yCoord[1]), // ( 0,-1) - fetch(xCoord[0], center.y), // (-2, 0) - fetch(xCoord[1], center.y)); // (-1, 0) + vec4 value = vec4( + fetch(center.x, yCoord[0]), // ( 0,-2) + fetch(center.x, yCoord[1]), // ( 0,-1) + fetch(xCoord[0], center.y), // (-2, 0) + fetch(xCoord[1], center.y)); // (-1, 0) - vec4 temp = vec4( - fetch(center.x, yCoord[3]), // ( 0, 2) - fetch(center.x, yCoord[2]), // ( 0, 1) - fetch(xCoord[3], center.y), // ( 2, 0) - fetch(xCoord[2], center.y)); // ( 1, 0) + vec4 temp = vec4( + fetch(center.x, yCoord[3]), // ( 0, 2) + fetch(center.x, yCoord[2]), // ( 0, 1) + fetch(xCoord[3], center.y), // ( 2, 0) + fetch(xCoord[2], center.y)); // ( 1, 0) - // Even the simplest compilers should be able to constant-fold these to - // avoid the division. - // Note that on scalar processors these constants force computation of some - // identical products twice. - const vec4 kA = vec4(-1.0, -1.5, 0.5, -1.0) / 8.0; - const vec4 kB = vec4( 2.0, 0.0, 0.0, 4.0) / 8.0; - const vec4 kD = vec4( 0.0, 2.0, -1.0, -1.0) / 8.0; + // Even the simplest compilers should be able to constant-fold these to + // avoid the division. + // Note that on scalar processors these constants force computation of some + // identical products twice. + const vec4 kA = vec4(-1.0, -1.5, 0.5, -1.0) / 8.0; + const vec4 kB = vec4( 2.0, 0.0, 0.0, 4.0) / 8.0; + const vec4 kD = vec4( 0.0, 2.0, -1.0, -1.0) / 8.0; - // Conserve constant registers and take advantage of free swizzle on load - #define kE (kA.xywz) - #define kF (kB.xywz) + // Conserve constant registers and take advantage of free swizzle on load + #define kE (kA.xywz) + #define kF (kB.xywz) - value += temp; + value += temp; - // There are five filter patterns (identity, cross, checker, - // theta, phi). Precompute the terms from all of them and then - // use swizzles to assign to color channels. - // - // Channel Matches - // x cross (e.g., EE G) - // y checker (e.g., EE B) - // z theta (e.g., EO R) - // w phi (e.g., EO R) - #define A (value[0]) - #define B (value[1]) - #define D (Dvec.x) - #define E (value[2]) - #define F (value[3]) + // There are five filter patterns (identity, cross, checker, + // theta, phi). Precompute the terms from all of them and then + // use swizzles to assign to color channels. + // + // Channel Matches + // x cross (e.g., EE G) + // y checker (e.g., EE B) + // z theta (e.g., EO R) + // w phi (e.g., EO R) + #define A (value[0]) + #define B (value[1]) + #define D (Dvec.x) + #define E (value[2]) + #define F (value[3]) - // Avoid zero elements. On a scalar processor this saves two MADDs - // and it has no effect on a vector processor. - PATTERN.yzw += (kD.yz * D).xyy; + // Avoid zero elements. On a scalar processor this saves two MADDs + // and it has no effect on a vector processor. + PATTERN.yzw += (kD.yz * D).xyy; - PATTERN += (kA.xyz * A).xyzx + (kE.xyw * E).xyxz; - PATTERN.xw += kB.xw * B; - PATTERN.xz += kF.xz * F; + PATTERN += (kA.xyz * A).xyzx + (kE.xyw * E).xyxz; + PATTERN.xw += kB.xw * B; + PATTERN.xz += kF.xz * F; - 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)); + 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)); - rgb = rgb - blacklevel; + rgb = rgb - blacklevel; - /* - * 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; + /* + * 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]); + 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]); - /* - * Contrast - */ - rgb = clamp(rgb, 0.0, 1.0); - rgb.r = apply_contrast(rgb.r); - rgb.g = apply_contrast(rgb.g); - rgb.b = apply_contrast(rgb.b); + /* + * Contrast + */ + rgb = clamp(rgb, 0.0, 1.0); + rgb.r = apply_contrast(rgb.r); + rgb.g = apply_contrast(rgb.g); + rgb.b = apply_contrast(rgb.b); - /* Apply gamma after colour correction */ - rgb = pow(rgb, vec3(gamma)); + /* Apply gamma after colour correction */ + rgb = pow(rgb, vec3(gamma)); #if defined (SWAP_BLUE) - gl_FragColor = vec4(rgb.bgr, 1.0); + gl_FragColor = vec4(rgb.bgr, 1.0); #else - gl_FragColor = vec4(rgb, 1.0); + gl_FragColor = vec4(rgb, 1.0); #endif }