Created
October 11, 2010 15:26
-
-
Save shomah4a/620690 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
package path.to.pkg; | |
public final class Utils | |
{ | |
static void YUV422toARGB8888(byte[] src, int[] dest, int w, int h) | |
{ | |
final int fsize = w * h; | |
for (int y=0, p=0; y<h; ++y) | |
{ | |
int uvp = fsize + (y >> 1) * w, U = 0, V = 0; | |
for (int x=0; x<w; ++x) | |
{ | |
int Y = ((int)src[p] & 0xff) - 16; | |
if (Y < 0) | |
{ | |
Y = 0; | |
} | |
final int UVp = fsize + (y >> 1) * w + (x & ~1); | |
if ((x & 1) == 0) | |
{ | |
V = (0xff & src[uvp++]) - 128; | |
U = (0xff & src[uvp++]) - 128; | |
} | |
final int y1192 = 1192 * Y; | |
int r = y1192 + 1634 * V; | |
int g = y1192 - 833 * V - 400 * U; | |
int b = y1192 + 2066 * U; | |
if (r < 0) | |
{ | |
r = 0; | |
} | |
else if (r > 262143) | |
{ | |
r = 262143; | |
} | |
if (g < 0) | |
{ | |
g = 0; | |
} | |
else if (g > 262143) | |
{ | |
g = 262143; | |
} | |
if (b < 0) | |
{ | |
b = 0; | |
} | |
else if (b > 262143) | |
{ | |
b = 262143; | |
} | |
dest[p] = 0xff000000 | |
| ((r << 6) & 0x00ff0000) | |
| ((g >> 2) & 0x0000ff00) | |
| ((b >> 10) & 0x000000ff); | |
p++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment