From patchwork Wed Nov 18 09:57:17 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: 28972 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 1FE1BBDE17 for ; Wed, 18 Nov 2026 09:58:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D0186A8E1; Wed, 18 Nov 2026 10:58:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="nY9HBaKR"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 568576A8B1 for ; Wed, 18 Nov 2026 10:57:59 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso292796f8f.2 for ; Wed, 18 Nov 2026 01:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995879; x=1795600679; 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:content-type; bh=Y7APu1C+L8EW4xuPBVaUkON2MnXXNCiVAjDyQZBHTH8=; b=nY9HBaKRtbAQrJ6SJ1zr1OtfAdMlx4Yr8g533zhXbtinx/b0VEyX9sVEzXnZEyRQo8 k9XXZuPysmtydUDwlfNNb3V7hlLkjtUyNblWXJE22WSUSAj5OW/+xIOeMtp16IGpjjqe zHzvVKxUTs040OTbZyPcVUkljn/o+KOHwmdChb3aKglCGYIGkbxeg9C9NhpGtTJ7guge inp1BEMLP+Ohf+kzjyuo+KWABNFs/4NyT5sdAtKxsTojYXb7zeUMovQKnL3aFnYEeUuC M9t+ysfDwo4W4OKp7tlLurznqp4ZmWkLXGol40Kn+HmYhHddUWlLu9DNgIni71qb76Tm BRrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995879; x=1795600679; 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:content-type; bh=Y7APu1C+L8EW4xuPBVaUkON2MnXXNCiVAjDyQZBHTH8=; b=ARUdjyO4WQozOCfcejdnOCRpHLCTSRDamPkmp9bbqltLecJSM/1Lx7mMMhVNEsPTor 0BThkt7z6x5zAhar4mQJBEcONVnTuOKvd2UwgX+m4sLhvMiPt2HZmc35ESDyzlvr8Zz0 kiAqcvMhQYM6EBEfeGnt5QvxVznFx+D9HZdJpcLDH3l9LMCLizVm2wWh8wxn139eIHTL X++TVm2AQ2rBvACiiO48UfYoPRZ3vFXUSMmfAhwtHOu3th6imYxUqTn2JCWOSI/IUDaV R5P1ideNbLh7fw9HwKXAPV8cxGMcc3YPmLyUq2F4jhTzp7fkfSHiwuiZOVZm5eXzdtEP fDkQ== X-Gm-Message-State: APuU4Z9LdJD5YivMxzQnI/SILCLAA6I37EbyMBdoqNASLv5qvNLHK1KL qbtw2nKJTV113CGkY13wGLoLNNrxN/kodrVsHmiekzid46Q8+suap2iNzNbeCjTbkIZdOaIhZlA QoWwNkjY= X-Gm-Gg: AZFdTZfVtHNpjX9iw1yHe/ZMIP10NHFZ5VSaz1QGGW3nqa5mJ8mod+upakEiGRualh0 wK2kI3QpOlOvlhOILuMgnO43lg/A7kG4/Jqi9gxiorymdIoZsZZoNobKNN4AjgCC8sbF0S+ZOPk 7kWX59HqSNQORlTr3YSLmH4Ig5oO1cyjG1RVt3qmrsCi8jXoz+sJZbYFz8G/YcgRvqNO+DhHf2f 0KsmDpymhN9WfLw0FPKqvLDjjdOY01uDbNkMrUSJHzKAkWkSPVAox7kdd78l+Cy+2Yp9rBQX5p5 JwoqsTp4E6aMpSF+IqDLbSINzejvmj+pj35lnIzhSZjCGwF1MUtQetk3noxmXcoitbpg3823X8y 3HPro+SndSwrp1NtHsXuhuG8hsnkckzft23xx4s6ntv+h3hBnLplY7cGm5h2noBA0rA1AeTblTg g8Ce8XcqOXSANAKeWgaN645C4kZQVgPMMUDkupw+eOK8guuYkUgTzF5DHCVX2O7XOS2j6vTBnDK hechczJki9jdJqKODXQynAhYeZjgVH9ZteczIC1291FkCkqynEp9JVj1aZM0NIR1ZxbBEWIYRO4 pNOVojpNpdNOym4bYxO6fu7v54Ys/vd1WdufwL4pNcYqFj+ARaBcsOOcJvJ3dfH1lCM= X-Received: by 2002:a5d:5f51:0:b0:4a7:b365:19dd with SMTP id ffacd0b85a97d-4a7b3651a4dmr1175849f8f.53.1794995878731; Wed, 18 Nov 2026 01:57:58 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:57:58 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: rstrode@redhat.com, robert.mader@collabora.com, barnabas.pocze@ideasonboard.com, Bryan O'Donoghue Subject: [RFC PATCH v2 10/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Use bilinear filtering Date: Wed, 18 Nov 2026 10:57:17 +0100 Message-ID: <20261118095735.170587-11-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261118095735.170587-1-bryan.odonoghue@linaro.org> References: <20261118095735.170587-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" To create the multi-pass shader we used the bayer_1x_packed.frag and broke it into chunks. This original neighbour uses nearest-neighbour interpolation however the unpacked shader bayer_unpacked.frag has a nicer bilinear algorithm we can use instead. Replace the interpolation with the unpacked.frag version. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_glr16f_to_rgba.frag | 114 +++++++----------- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index f3883a82b..4a2e5af87 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -44,81 +44,53 @@ void main(void) { #define fetch(x, y) texture2D(tex_y, vec2(x, y)).r 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. + /* Which of the four CFA phases are we on (0 = even). Same as McGuire. */ vec2 alternate = mod(floor(center.zw), 2.0); + bool even_col = alternate.x < 1.0; + bool even_row = alternate.y < 1.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 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; - - 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) - + /* + * +----+----+----+ + * | D2 | A1 | D3 | + * +----+----+----+ + * | B0 | C | B1 | + * +----+----+----+ + * | D0 | A0 | D1 | + * +----+----+----+ + * + * patterns.x = (A0 + A1) / 2 vertical neighbours + * patterns.y = (B0 + B1) / 2 horizontal neighbours + * patterns.z = (A0+A1+B0+B1) / 4 cross average (green at R/B sites) + * patterns.w = (D0+D1+D2+D3) / 4 diagonal average (other colour at R/B sites) + * + * xCoord[1] = -1, xCoord[2] = +1, yCoord[1] = -1, yCoord[2] = +1 + * (xCoord[0]/[3] and yCoord[0]/[3] = +-2 are unused here; the vertex + * shader still emits them so the VS is identical to the McGuire path). + */ + vec4 patterns = vec4( + fetch(center.x, yCoord[1]), /* A0: ( 0,-1) */ + fetch(xCoord[1], center.y), /* B0: (-1, 0) */ + fetch(xCoord[1], yCoord[1]), /* D0: (-1,-1) */ + fetch(xCoord[2], yCoord[1])); /* D1: ( 1,-1) */ 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; - - // Conserve constant registers and take advantage of free swizzle on load - #define kE (kA.xywz) - #define kF (kB.xywz) - - 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]) - - // 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; - - 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)); + fetch(center.x, yCoord[2]), /* A1: ( 0, 1) */ + fetch(xCoord[2], center.y), /* B1: ( 1, 0) */ + fetch(xCoord[2], yCoord[2]), /* D3: ( 1, 1) */ + fetch(xCoord[1], yCoord[2])); /* D2: (-1, 1) */ + + patterns = (patterns + temp) * 0.5; + /* .x=(A0+A1)/2 .y=(B0+B1)/2 .z=(D0+D3)/2 .w=(D1+D2)/2 */ + patterns.w = (patterns.z + patterns.w) * 0.5; /* diagonal avg */ + patterns.z = (patterns.x + patterns.y) * 0.5; /* cross avg */ + + rgb = even_col ? + (even_row ? + vec3(C, patterns.zw) : + vec3(patterns.x, C, patterns.y)) : + (even_row ? + vec3(patterns.y, C, patterns.x) : + vec3(patterns.wz, C)); /* * CCM is a 3x3 in the format