PDA

View Full Version : UYVY -> RGB Conversion



ddv2005
11-02-2017, 07:22 AM
Hello,

My program receiving NDI video in UYVY pixel format and then use OPENGL shader to draw it on the screen. The problem is that I can't find correct way to convert UYVY to RGB.
For HD content I use following code:
===========
yuv.x = texture2D(u_texture, v_texCoord).g-0.0625;
yuv.yz = texture2D(u_texture_uv, v_texCoord).rb-0.5;
rgb = mat3( 1.1643, 1.1643, 1.1643,
0, -0.213, 2.115,
1.793, -0.534, 0) * yuv;
};
rgb = clamp(rgb,0.0, 1.0);
===========
It works but picture still have little difference in details with RGB picture that directly provided by NDI SDK

What the correct way to do UYVY -> RGB Conversion?

Best Regards,
Dmitry

Arzoo
11-03-2017, 12:20 AM
Hi Dmitry, try these links :



https://www.xaymar.com/2017/07/06/how-to-converting-rgb-to-yuv-and-yuv-to-rgb/
https://github.com/leadedge/ofxNDI/blob/master/src/ofxNDIutils.cpp

ddv2005
11-03-2017, 01:25 PM
Hi Arzoo,

Thanks for you links.
Also yesterday Andrew have provided me a shader that used by Studio Monitor
==========================
varying vec4 tx_coord;

uniform sampler2D video_Y, video_CbCr;

mat3 ycbcr_to_rgb_mat = mat3(1.16414, -0.0011, 1.7923, 1.16390, -0.2131, -0.5342, 1.16660, 2.1131, -0.0001);
vec3 ycbcr_to_rgb_vec = vec3(-0.9726, 0.3018, -1.1342);

void main()
{
vec3 col_y_cbcr = vec3(texture2D(video_Y, tx_coord.xy).r, texture2D(video_CbCr, tx_coord.xy).rg);
vec3 col_rgb = vec3( dot( ycbcr_to_rgb_mat[0], col_y_cbcr ), dot( ycbcr_to_rgb_mat[1], col_y_cbcr ), dot( ycbcr_to_rgb_mat[2], col_y_cbcr ) ) + ycbcr_to_rgb_vec;
gl_FragData[0] = vec4( col_rgb, 1.0 );
}
==========================