libcamera: shaders: Extend debayer shaders to apply CCM gains
Extend Bayer shaders to support application of a passed CCM table. Reviewed-by: Milan Zamazal <mzamazal@redhat.com> Tested-by: Robert Mader <robert.mader@collabora.com> Tested-by: Hans de Goede <johannes.goede@oss.qualcomm.com> # ThinkPad T14s gen 6 (arm64) ov02c10 + X1c gen 12 ov08x40 Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> # Lenovo X13s Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
committed by
Kieran Bingham
parent
c9954de93d
commit
a4e82c950b
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user