I’m developing an app using java which convert a YUV pixel(x,y) into a RGB pixel, here is what I did:(data is YUV byte array)
int Y = data[ y * width + x];
int U = data[ (int) (width * height + Math.floor(y/2) * Math.floor(width/2) + Math.floor(x/2) + 1)];
int V = data[ (int) (width * height + Math.floor(y/2) * (width/2) + Math.floor(x/2) + 0)];
int B = (int) (1.164*(Y - 16)+ 2.018*(U - 128));
int G = (int) (1.164*(Y - 16) - 0.813*(V - 128) - 0.391*(U - 128));
int R = (int) (1.164*(Y - 16) + 1.596*(V - 128));
But in the end, I found that the RGB values I got are negative. Can someone help me with this?
Thank you!
There are many “flavors” of YUV, and sometimes these get mixed up with YCbCr. Your formula appears appropriate for formats where Y is in [16,235], but, I can tell you that this is not correct for the NV21 image format (a type of standard YUV planar) returned in Android.