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!