Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created October 11, 2010 15:26
Show Gist options
  • Save shomah4a/620690 to your computer and use it in GitHub Desktop.
Save shomah4a/620690 to your computer and use it in GitHub Desktop.
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