Verwirrung bei der Konvertierung von YUV NV21 nach RGB
Gemäßhttp://developer.android.com/reference/android/graphics/ImageFormat.html#NV21, NV21 ist das standardmäßig verwendete Format.
Es gibt eine ganze Reihe von Code im Web bezüglich der Konvertierung von YUV NV21 in RGB. Wenn ich jedoch den Code durcharbeite, bezweifle ich die Richtigkeit des Codes.
Die erste Komponente V sollte zuerst kommen, gefolgt von der ersten Komponente U
Gemäßhttp://wiki.videolan.org/YUV#NV21, NV21 is like NV12, but with U and V order reversed: it starts with V.
Als ich jedoch durch die Code-Implementierung ging
R sollte die signifikanteste Position sein Entsprechend der Implementierung vonint argb
imColor.javaAngenommen, R befindet sich an der höchstwertigen Position. Ich habe jedoch die folgende Codeimplementierung durchgeführt
Ich habe mich gefragt, machen sie einen häufigen Fehler oder ich habe etwas übersehen?
Derzeit ist meine Implementierung wie folgt.
public static void YUV_NV21_TO_RGB(int[] argb, byte[] yuv, int width, int height) {
final int frameSize = width * height;
final int ii = 0;
final int ij = 0;
final int di = +1;
final int dj = +1;
int a = 0;
for (int i = 0, ci = ii; i < height; ++i, ci += di) {
for (int j = 0, cj = ij; j < width; ++j, cj += dj) {
int y = (0xff & ((int) yuv[ci * width + cj]));
int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0]));
int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1]));
y = y < 16 ? 16 : y;
int r = (int) (1.164f * (y - 16) + 1.596f * (v - 128));
int g = (int) (1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128));
int b = (int) (1.164f * (y - 16) + 2.018f * (u - 128));
r = r < 0 ? 0 : (r > 255 ? 255 : r);
g = g < 0 ? 0 : (g > 255 ? 255 : g);
b = b < 0 ? 0 : (b > 255 ? 255 : b);
argb[a++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
}