Created
August 26, 2012 11:56
-
-
Save seiketkm/3478073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// YUV形式からrgbに変換して戻します。 | |
public static void decodeYCbCr(final int[] rgb, final byte[] yuv, int width, int height) { | |
int y = 0, u = 0, v = 0, r = 0, g = 0, b = 0; | |
int yp = 0, uvp = width * (height - 1); | |
for (int j = 0; j < height; j++) { | |
if ((j & 1) == 0) { | |
uvp += width; | |
} | |
for (int i = 0; i < width; i++) { | |
if ((i & 1) == 0) { | |
v = (yuv[uvp + i] & 0xff) - 128; | |
u = (yuv[uvp + i + 1] & 0xff) - 128; | |
} | |
y = ((yuv[yp] & 0xff) - 16) * 1192; | |
r = y + 1634 * v; | |
g = y - 833 * v - 400 * u; | |
b = y + 2066 * u; | |
r = r < 0 ? 0 : (r > 0xff << 10 ? 0xff : r >> 10); | |
g = g < 0 ? 0 : (g > 0xff << 10 ? 0xff : g >> 10); | |
b = b < 0 ? 0 : (b > 0xff << 10 ? 0xff : b >> 10); | |
rgb[yp++] = 0xff << 24 | r << 16 | g << 8 | b; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment