YV12 to RGB - What is wrong with my algorithm?

I am attempting to convert YV12 to RGB using the following fragment shader:

precision mediump float;
uniform sampler2D tex0, tex1, tex2;
varying vec2 v_texCoord;

void main(void) {
float r, g, b, y, u, v;
y = texture2D(tex0, v_texCoord).x;
u = texture2D(tex1, v_texCoord).x;
v = texture2D(tex2, v_texCoord).x;

y = 1.1643 * (y - 0.0625);
u = u - 0.5;
v = v - 0.5;

r = y + 1.5958 * v;
g = y - 0.39173 * u - 0.81290 * v;
b = y + 2.017 * u;

gl_FragColor = vec4(r, g, b, 1.0);
}


Below is the original image followed by the converted image. Based on the output, can you determine where I might look to determine what is causing the improper decoding?

• As said by first responders, there is definitely a problem with the number of bytes per line. I wonder another thing. YV12 has subsampled U and V channels. How do you manage this dimension change with your shader? What are the sizes of your textures? Do you let OpenGL handle this? – Stéphane Péchard Oct 5 '11 at 9:40
• In the draw loop, image data is given to me in a 3 element array where the order is always YUV (regardless of YV12 or YUV420p etc). I use the full width/height for the Y element and shift the width/height right 1 (divide by 2) for the UV elements. These textures are then bound to the shader which handles the rest. Texture sizes that I've been working with are typically 1280x720. – Error 454 Oct 5 '11 at 17:21