DrFooMod2

06-28-2011, 02:36 PM

I have a working fragment shader for translating YUV 420 YCbCr Biplanar iPhone 4 camera frames to RGB. I was able to read enough samples, and the YUV (http://en.wikipedia.org/wiki/YUV) page at Wikipedia to get what I needed:

#ifdef GL_ES

precision mediump float;

#endif

varying vec2 textureCoordinate;

uniform sampler2D videoFrame;

uniform sampler2D videoFrameUV;

const mat3 yuv2rgb = mat3(

1, 0, 1.2802,

1, -0.214821, -0.380589,

1, 2.127982, 0

);

void main() {

vec3 yuv = vec3(

1.1643 * (texture2D(videoFrame, textureCoordinate).r - 0.0625),

texture2D(videoFrameUV, textureCoordinate).r - 0.5,

texture2D(videoFrameUV, textureCoordinate).a - 0.5

);

vec3 rgb = yuv * yuv2rgb;

gl_FragColor = vec4(rgb, 1.0);

}

My question is why the math for the Y, U, and V components? That I couldn't find. Thanks!

FYI, the matrix values are based on Rec. 709.

#ifdef GL_ES

precision mediump float;

#endif

varying vec2 textureCoordinate;

uniform sampler2D videoFrame;

uniform sampler2D videoFrameUV;

const mat3 yuv2rgb = mat3(

1, 0, 1.2802,

1, -0.214821, -0.380589,

1, 2.127982, 0

);

void main() {

vec3 yuv = vec3(

1.1643 * (texture2D(videoFrame, textureCoordinate).r - 0.0625),

texture2D(videoFrameUV, textureCoordinate).r - 0.5,

texture2D(videoFrameUV, textureCoordinate).a - 0.5

);

vec3 rgb = yuv * yuv2rgb;

gl_FragColor = vec4(rgb, 1.0);

}

My question is why the math for the Y, U, and V components? That I couldn't find. Thanks!

FYI, the matrix values are based on Rec. 709.