c# - Converting a NV12 (YUV4:2:0) Byte array to RGB byte Array -


i have stream of bytes captured webcam (using aforge.net library). image captured returned in nv12 or yuv

i need convert rgb byte stream.in order can achieve transform, need know how read / interpret byte array.

i'm hoping implement function this

byte[] converttorgb(byte[] ycbcrarray) {  //read byte array , encode in rgb format , return byte array      return rgbarray;   } 

this best done in c++ - can use microsoft's directxtex library (if want tested code).

you can convert using formulas below:

clip(x) ( (x) > 255 ? 255 : (x) < 0 ? 0 : x) // ycbcr -> rgb cycbcr2r(y, cb, cr) clip( y + ( 91881 * cr >> 16 ) - 179 ) cycbcr2g(y, cb, cr) clip( y - (( 22544 * cb + 46793 * cr ) >> 16) + 135) cycbcr2b(y, cb, cr) clip( y + (116129 * cb >> 16 ) - 226 ) 

note need dimensions of image, not byte size. y channel in nv12 located first (1 byte per pixel), uv (2bytes per 4 pixels) explained here: http://www.fourcc.org/yuv.php#nv12


Comments