[PATCH 27/27] shaders: Extend debayer shaders to apply RGB gain values on output
Bryan O'Donoghue
bryan.odonoghue at linaro.org
Tue Apr 22 23:59:20 CEST 2025
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue at linaro.org>
---
.../internal/shaders/bayer_1x_packed.frag | 10 ++++++++++
include/libcamera/internal/shaders/bayer_8.frag | 16 +++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/libcamera/internal/shaders/bayer_1x_packed.frag b/include/libcamera/internal/shaders/bayer_1x_packed.frag
index 19b13ad0..9a2389f7 100644
--- a/include/libcamera/internal/shaders/bayer_1x_packed.frag
+++ b/include/libcamera/internal/shaders/bayer_1x_packed.frag
@@ -65,6 +65,9 @@ uniform vec2 tex_step;
uniform vec2 tex_bayer_first_red;
uniform sampler2D tex_y;
+uniform sampler2D red_param;
+uniform sampler2D green_param;
+uniform sampler2D blue_param;
void main(void)
{
@@ -212,5 +215,12 @@ void main(void)
vec3(patterns.y, C, patterns.x) :
vec3(patterns.wz, C));
+#if defined(APPLY_BAYER_PARAMETERS)
+ /* Apply bayer params */
+ rgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;
+ rgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;
+ rgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;
+#endif
+
gl_FragColor = vec4(rgb, 1.0);
}
diff --git a/include/libcamera/internal/shaders/bayer_8.frag b/include/libcamera/internal/shaders/bayer_8.frag
index aa7a1b00..a7ed75c8 100644
--- a/include/libcamera/internal/shaders/bayer_8.frag
+++ b/include/libcamera/internal/shaders/bayer_8.frag
@@ -21,11 +21,16 @@ precision highp float;
/** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/
uniform sampler2D tex_y;
+uniform sampler2D red_param;
+uniform sampler2D green_param;
+uniform sampler2D blue_param;
varying vec4 center;
varying vec4 yCoord;
varying vec4 xCoord;
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 +102,20 @@ 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));
+
+#if defined(APPLY_BAYER_PARAMETERS)
+ /* Apply bayer params */
+ rgb.r = texture2D(red_param, vec2(rgb.r, 0.5)).r;
+ rgb.g = texture2D(red_param, vec2(rgb.g, 0.5)).g;
+ rgb.b = texture2D(red_param, vec2(rgb.b, 0.5)).b;
+#endif
+
+ gl_FragColor.rgb = rgb;
}
--
2.49.0
More information about the libcamera-devel
mailing list