From patchwork Tue Dec 2 13:45:26 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: 25315 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 47408C32E0 for ; Tue, 2 Dec 2025 13:46:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3B4DB60D26; Tue, 2 Dec 2025 14:46:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QGB2nxL7"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 33E9B60C77 for ; Tue, 2 Dec 2025 14:46:01 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-477a219db05so35538735e9.2 for ; Tue, 02 Dec 2025 05:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764683160; x=1765287960; 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=Ar/9Plv8U/t5q9HLAAZVcFMeUCSIVj27Ri9+oiHLDzQ=; b=QGB2nxL7Z8VQgJeKQWrReu9wKIMGvRRfrSeaV9/6tL8lqJmZ+iCHYHf1mxvzRaVNgp HAQPRvHniLvdz/2+OegUBhmt2qnULraPdQNaNQjZBPqUI7sCrgSPc+69Ome/6IZ35uIN /i0/eN3V1VgwkYjONg4wICPCiqn6TZWo4NZvIGR2F6xjj5B97AYSlRUcnxfnwEGVUG6b CTP+9lt+/WmFPAj+bxvNClda/iXzBJmMuwmYGLJXniRBX9ex2ihWNdNLoZqISeijGDd9 65ArydcWIwCk9XMrMZ3ya9LVGt2jb1DqhOA8+Y2IrFkrMa7rwQtgnoSm8NTq7MxKJl/V iRGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764683160; x=1765287960; 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=Ar/9Plv8U/t5q9HLAAZVcFMeUCSIVj27Ri9+oiHLDzQ=; b=IqmaFBePdFu0DmuQcNby2f4E6BzoT1F3p/zr/XjDI/y5CD70CtZnexVg/hxaWPA1Qb RadT24rmqKBzBZZECyAMsYBP3GeS/wiaXIXA81Vq50JGp+42xA7dFHat+97cot4dkblr LCEq4uuv3PUGOXzIxpo4bzewMlK4NvNOKcDdEpiCcZX0ZSKHFd04b2oKe3gg0HmjEYSy Lgff1vG4Mr30ZaNXCu4HL3YSdokf0I3jOSd2Cx4JHfba5aF8Em/RPYzQoAvGWZVxcM8Q 9CPz8mJqQPIMNz3I7L6BJ34JKBsbA0QPbsmfnLjvaA22vdmZeqJJwcj/IzxsRIxbmIei og8Q== X-Gm-Message-State: AOJu0Ywl1eigpyUm4Rj2o12c30/8wAWa3jJoUz+yphZW1dgy6y/0BqFR 4cMolXCmauByZHGz5O2l1UfSI5tuVuzhqPLsQUZ8FgcBIixF2mb6xnW8uC019mCuXTi1FGNuGEe a8aBj X-Gm-Gg: ASbGncvEPgqW7wD2s6CgRtqOarfuJFYjPIQPOTveF9E4BfJygxmqhRLQJlkBE8JoGUB 8MHO3wiWwIe7p4YmEXM1wfDGUhahbC6X1qGo7JD2PyJKK8RJwQBYrtQyq8MgAKbd77DtDIi2o5h iWxVQCOx/9313ZVJOp+2zn7KmIddVPuG0epqHL20gJYyXtu5WbyFdZPfY2/V2VuOnVkBTHMWIbv wTrnZwJhWkUJUBxhwr3vilx2ykj0vlJElOUyKu4vM70yJDDt4uqMZYwRogSl7HTj8PptzpFHF/H PL+q6yeoxGWgjB9F7LXeOGII+HH5KLuFFeS8X2Q0xlpXTyHQ3bAQA+Ejwz+hvjKeKD19I3wzVwg XBsElBsc5R7WmnEem4fja0Pp62rHqiEckTrM7SLHP5XrtQ6QTLfr0DPjdGApQbxdlSIgd0ncI13 OgTjjWzZpnwKZTVrRT88ioA+v+Pqly2aAk68Q3I/Pck7HrKC4UWxDOett0omAKX6TUFzmGCQWV8 qQDfA== X-Google-Smtp-Source: AGHT+IGVhzau5WJ5THeB6e3QlSM041Xe70HBvcou3dSZl47PJsnc7QYmtc1STMJZAxDl3kMIMrzF5g== X-Received: by 2002:a05:600c:470a:b0:45d:dc85:c009 with SMTP id 5b1f17b1804b1-477c10d49b5mr365686655e9.10.1764683160452; Tue, 02 Dec 2025 05:46:00 -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-47926f0ec69sm19383375e9.1.2025.12.02.05.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 05:45:59 -0800 (PST) From: Bryan O'Donoghue To: libcamera-devel@lists.libcamera.org Cc: pavel@ucw.cz, Bryan O'Donoghue , Milan Zamazal Subject: [PATCH v6 06/24] libcamera: shaders: Extend debayer shaders to apply RGB gain values on output Date: Tue, 2 Dec 2025 13:45:26 +0000 Message-ID: <20251202134544.662446-7-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251202134544.662446-1-bryan.odonoghue@linaro.org> References: <20251202134544.662446-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 out the bayer fragment shaders to take 3 x 256 byte inputs as textures from the CPU. We then use an index to the table to recover the colour-corrected values provided by the SoftIPA thread. 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; }