From patchwork Wed Nov 18 09:57:32 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: 28987 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 0DE35BDE17 for ; Wed, 18 Nov 2026 09:58:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E98A6A905; Wed, 18 Nov 2026 10:58:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LJczs1ov"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 66A166A8DF for ; Wed, 18 Nov 2026 10:58:15 +0100 (CET) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-48dee593f18so582827f8f.3 for ; Wed, 18 Nov 2026 01:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794995895; x=1795600695; 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=eUAfO7ZC79LR1j54ugGOe9gxt5LvymPyktJgvVW7Gs8=; b=LJczs1ovBVJnFaJh5E773RON6lQzoeMmGx5QIgrZ3MYXcLWQaR9hCHReAZtNf4Nf6F BYM8n3r7E9G/3E4WQPGQkH/q0Kw07SXbVG3Ml/PzWZ6/Twu50WyoG7ajsEABzJEThtze 44YJkinBBwhejJWIkmLmalq7AwzzZ8H/Z1fPPMCwTl5c+IetS3dzJBmzeG4chffCDQNF 8s06c+Cae7r7pyxSfokXBhQfBnrAv3/rzDBzIJYfNM0XEc/vmSdVHEFMmMXkhGsuzimP 1XhG4wMV8CDxY6TyWYBEF4RgTbxIZ8Re77REgfrSE5FKb3e6niXqZiEHTmGrgWjR7UKQ dtTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794995895; x=1795600695; 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=eUAfO7ZC79LR1j54ugGOe9gxt5LvymPyktJgvVW7Gs8=; b=exoO2NwOamryTnVoHxf0wuIxf063jp6CGycXmpK5x5xWSEYiqNbCbFqWlImeRKEK2x T8yFD6V0d4ZDPkRz4aKuZnGpMYyduJjqXg7a0o9UX15QfmBvsZGxwwt6GW2e05w4HunT HQc+6f7RYzfsh3eeZYCZiMNCPwWlb7BQ18ePHfEy+2oEgT5qtiEZ96RvwbjEtpNCpoVc O2Gn1TJ0VJVncVNNLhW+JZHXyB0PHPqrzECyIphA1zhQrTPePXuE6Iy0Dq1+XabY/zEp HmHNhk5GXvyp688py4SZqyLGrRSplS72Zt6llQNH9yhvTNdxjXhXImUGc2iDzrlG2o1G OzuQ== X-Gm-Message-State: APuU4Z+U+71M03t/Ww/EX/R/dHjCp/kIw9EYoLJlXyT2I12Q6Z/e1MrN bDXxNtXth1bPh7ECqOEDVhByRrqS3IjeubLmoG+nNQkisCmnOXzS2xeJ43VxU9SzktNviThu7Zg QjT8ceTk= X-Gm-Gg: AZFdTZcWOPCONQoHLoW3tfiUJEK664Dz2xWwLyE884VPmso00wTW5QfaNUqiuWtkKvf 6yBW7RpoBi5bm6cn6xl7/KVjGpyCwb1htwS6BwmGvc1JhMX9/aVtILiInr2JXeWNl3zd7YQ+Xf1 PQrDP1VPjQv3FLSyphwSpifASPMnhCDbXlxCT+2m0uTpZnPVHA1fN6BercgelNMfnA0n7Yif18X y7p5q4kuZufBXEhorfFuY/BYkset4scZ9r88PWBWNuSjM/JIAMFg5MxV7t6Erjdq3+zxmHfwX8C vl96pnMIKfAEpYOq2FLU28dVOht9uR+QSRsl2FGQDnsjw2p4OwiCRK+j8ZEZReaQG9Z9bO7/vjy jZFtfHFyyTYAK9ytghqkE4TaaOIEc5A2mF/a+7iAXZrZDD4mdK0HNVzvwosg6+HslL9TsnNo6DA alWnXShqJskA5BBEd/6WdzhoF3z3MzJkbKUWpnW+wuMRpYarW7pKGoyDcCRsfaXB+Hu1pYenXU7 HJtSBDzIYHMm4ZK8P9iHAvJq7++RCA9vP8+aBLwjbLmbNQWC25SwfdLxCTaVk6NhlZwXx8LhKPk DE6WxjRD8vjKlwzkXLKcoxpYiJKb0PvDoa9EFXEP7fCn2Q== X-Received: by 2002:a05:6000:240e:b0:48e:4f1e:5e24 with SMTP id ffacd0b85a97d-4a638339786mr4604981f8f.14.1794995894749; Wed, 18 Nov 2026 01:58:14 -0800 (PST) Received: from inspiron14p-linux ([109.76.187.112]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a655f9f4a7sm3940871f8f.34.2026.11.18.01.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:58:14 -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 25/26] libcamera: shaders: bayer_glr16_to_rgba.frag: Use center.zw to derive 3x3 texel center Date: Wed, 18 Nov 2026 10:57:32 +0100 Message-ID: <20261118095735.170587-26-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" Currently both center.zw and XCoord/YCoord are used to determine where the sample texel should be. We end up sampling in the range 0.0f..1.0f so when the sample lands on a line the XCoord/YCoord and center.zw can disagree on what is being sampled. Switch entirely to center.zw using a similar algorithm blc-normalise logic; specifically to add 0.5f to the calculated center byte before dividing - thus ensuring we always hit in the middle of the range of the texel we are targetting when dividing down to 0.0f..1.0f not at the edge. As a result we can drop XCoord/YCoord. Signed-off-by: Bryan O'Donoghue --- .../shaders/bayer_glr16f_to_rgba.frag | 51 ++++++++++++++++--- src/libcamera/shaders/bayer_unpacked.vert | 14 ----- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag index c613e9842..a3cd71a4b 100644 --- a/src/libcamera/shaders/bayer_glr16f_to_rgba.frag +++ b/src/libcamera/shaders/bayer_glr16f_to_rgba.frag @@ -22,11 +22,11 @@ precision highp float; /** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/ uniform sampler2D tex_y; varying vec4 center; -varying vec4 yCoord; -varying vec4 xCoord; uniform mat3 ccm; uniform float gamma; uniform float contrastExp; +uniform vec2 tex_size; +uniform vec2 tex_bayer_first_red; struct samples_3x3 { float row0a, row0b, row0c; @@ -50,14 +50,51 @@ float fetch(float x, float y) void sample_3x3(inout samples_3x3 samples) { + /* + * @pos comes from bayer_unpacked.vert + * which then feeds into bayer_1x_packed_to_blc_glr16f.frag + * + * Where center.zw = textureIn * tex_size + tex_bayer_first_red; + * + * @texel_center has 0.5 added to it to ensure when we convert + * from a texel to a float in the range 0.0f..1.0f that we land + * in the middle of the texel we are sampling before divinding + * down to the 0.0..1.0f range. + * + * @texel_step because texture2D() above annoyingly operates on + * the range 0.0f..1.0f so we have to convert every texel + * into a number between 0.0f and 1.0f + * + * @xCoord and yCoord taking xCoord as the example. + * texel_center.x is the center of the pixel which we added 0.5f + * to ensure it is center as a fraction of the + * image width. + * texel_step.x is the width of one pixel as a fraction 1.0f / width + * xCoord therefore is the vector of the surrounding pixels centered. + * + * e.g. + * Width 1928, sample pixel 100: + * + * texel_center.x = 100.5 / 1928 + * texel_step.x = 1 / 1928 + * xCoord => adjacent pixels (98.5, 99.5, 101.5, 102.5) / 1928 + * + * The division by width is necessary because we sample between 0.0f..1.0f + */ + vec2 pos = floor(center.zw); + vec2 texel_center = (pos - tex_bayer_first_red + 0.5) / tex_size; + vec2 texel_step = 1.0 / tex_size; + vec4 xCoord = texel_center.x + vec4(-2.0, -1.0, 1.0, 2.0) * texel_step.x; + vec4 yCoord = texel_center.y + vec4(-2.0, -1.0, 1.0, 2.0) * texel_step.y; + samples.row0a = fetch(xCoord[1], yCoord[2]); - samples.row0b = fetch(center.x, yCoord[2]); + samples.row0b = fetch(texel_center.x, yCoord[2]); samples.row0c = fetch(xCoord[2], yCoord[2]); - samples.row1a = fetch(xCoord[1], center.y); - samples.center = fetch(center.x, center.y); - samples.row1c = fetch(xCoord[2], center.y); + samples.row1a = fetch(xCoord[1], texel_center.y); + samples.center = fetch(texel_center.x, texel_center.y); + samples.row1c = fetch(xCoord[2], texel_center.y); samples.row2a = fetch(xCoord[1], yCoord[1]); - samples.row2b = fetch(center.x, yCoord[1]); + samples.row2b = fetch(texel_center.x, yCoord[1]); samples.row2c = fetch(xCoord[2], yCoord[1]); } diff --git a/src/libcamera/shaders/bayer_unpacked.vert b/src/libcamera/shaders/bayer_unpacked.vert index 423dde0fa..72a6d1bc2 100644 --- a/src/libcamera/shaders/bayer_unpacked.vert +++ b/src/libcamera/shaders/bayer_unpacked.vert @@ -22,7 +22,6 @@ attribute vec2 textureIn; uniform mat4 proj_matrix; uniform vec2 tex_size; /* The texture size in pixels */ -uniform vec2 tex_step; /** Pixel position of the first red pixel in the */ /** Bayer pattern. [{0,1}, {0, 1}]*/ @@ -32,24 +31,11 @@ uniform vec2 tex_bayer_first_red; .zw = ...on the range [0, sourceSize], offset by firstRed */ varying vec4 center; -/** center.x + (-2/w, -1/w, 1/w, 2/w); These are the x-positions */ -/** of the adjacent pixels.*/ -varying vec4 xCoord; - -/** center.y + (-2/h, -1/h, 1/h, 2/h); These are the y-positions */ -/** of the adjacent pixels.*/ -varying vec4 yCoord; - uniform float stride_factor; void main(void) { center.xy = vec2(textureIn.x * stride_factor, textureIn.y); center.zw = textureIn * tex_size + tex_bayer_first_red; - xCoord = center.x + vec4(-2.0 * tex_step.x, - -tex_step.x, tex_step.x, 2.0 * tex_step.x); - yCoord = center.y + vec4(-2.0 * tex_step.y, - -tex_step.y, tex_step.y, 2.0 * tex_step.y); - gl_Position = proj_matrix * vertexIn; }