inline unsigned char clip(int valid)
{
return (valid < 0 ? 0 : (valid > 255 ? 255 : valid));
}
void Yuv2Bgr(unsigned char *bgr24, unsigned char *yuv420, int width, int height)
{
unsigned char Y, U, V;
unsigned char *ybase, *ubase, *vbase;
int x, y, hx, hy, i = 0, hw = (width >> 1);
ybase = yuv420;
ubase = ybase + width * height;
vbase = ubase + ((width * height) >> 2);
for(y = 0; y < height; ++y)
{
hy = (y >> 1);
for(x = 0; x < width; ++x)
{
hx = (x >> 1);
Y = ybase[y * width + x];
U = ubase[hy * hw + hx];
V = vbase[hy * hw + hx];
bgr24[i++] = clip((int)(Y + 1.772 * (U - 128)));
bgr24[i++] = clip((int)(Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)));
bgr24[i++] = clip((int)(Y + 1.402 * (V - 128)));
}
}
}
/*======================邪恶分割线======================*/
#define clip(n) (unsigned char)((0 <= (n) && (n) <= 255) ? (n) : ((n) > 255 ? 255 : 0))
float U1[256], U2[256];
float V1[256], V2[256];
void Init_Yuv2Bgr_Table()
{
for(short i = 0; i < 256; ++i)
{
U1[i] = (float)(1.772 * (i - 128));
U2[i] = (float)(0.34414 * (i - 128));
V1[i] = (float)(0.71414 * (i - 128));
V2[i] = (float)(1.402 * (i - 128));
}
}
void Yuv2Bgr(unsigned char *bgr24, unsigned char *yuv420, int width, int height)
{
float R, G, B;
unsigned char Y, U, V;
unsigned char *ybase, *ubase, *vbase;
const int hw = (width >> 1);
int y, hx, hy = 0, m = 0, n = 0, i = 0;
ybase = yuv420;
ubase = ybase + width * height;
vbase = ubase + ((width * height) >> 2);
for(y = 0; y < height; )
{
for(hx = 0; hx < hw; ++hx)
{
Y = ybase[n];
U = ubase[m];
V = vbase[m];
B = Y + U1[U];
G = Y - U2[U] - V1[V];
R = Y + V2[V];
bgr24[i++] = clip(B);
bgr24[i++] = clip(G);
bgr24[i++] = clip(R);
Y = ybase[++n];
B = Y + U1[U];
G = Y - U2[U] - V1[V];
R = Y + V2[V];
bgr24[i++] = clip(B);
bgr24[i++] = clip(G);
bgr24[i++] = clip(R);
++m, ++n;
}
if(++y % 2 == 0) ++hy;
else m -= hw;
}
}
{
return (valid < 0 ? 0 : (valid > 255 ? 255 : valid));
}
void Yuv2Bgr(unsigned char *bgr24, unsigned char *yuv420, int width, int height)
{
unsigned char Y, U, V;
unsigned char *ybase, *ubase, *vbase;
int x, y, hx, hy, i = 0, hw = (width >> 1);
ybase = yuv420;
ubase = ybase + width * height;
vbase = ubase + ((width * height) >> 2);
for(y = 0; y < height; ++y)
{
hy = (y >> 1);
for(x = 0; x < width; ++x)
{
hx = (x >> 1);
Y = ybase[y * width + x];
U = ubase[hy * hw + hx];
V = vbase[hy * hw + hx];
bgr24[i++] = clip((int)(Y + 1.772 * (U - 128)));
bgr24[i++] = clip((int)(Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)));
bgr24[i++] = clip((int)(Y + 1.402 * (V - 128)));
}
}
}
/*======================邪恶分割线======================*/
#define clip(n) (unsigned char)((0 <= (n) && (n) <= 255) ? (n) : ((n) > 255 ? 255 : 0))
float U1[256], U2[256];
float V1[256], V2[256];
void Init_Yuv2Bgr_Table()
{
for(short i = 0; i < 256; ++i)
{
U1[i] = (float)(1.772 * (i - 128));
U2[i] = (float)(0.34414 * (i - 128));
V1[i] = (float)(0.71414 * (i - 128));
V2[i] = (float)(1.402 * (i - 128));
}
}
void Yuv2Bgr(unsigned char *bgr24, unsigned char *yuv420, int width, int height)
{
float R, G, B;
unsigned char Y, U, V;
unsigned char *ybase, *ubase, *vbase;
const int hw = (width >> 1);
int y, hx, hy = 0, m = 0, n = 0, i = 0;
ybase = yuv420;
ubase = ybase + width * height;
vbase = ubase + ((width * height) >> 2);
for(y = 0; y < height; )
{
for(hx = 0; hx < hw; ++hx)
{
Y = ybase[n];
U = ubase[m];
V = vbase[m];
B = Y + U1[U];
G = Y - U2[U] - V1[V];
R = Y + V2[V];
bgr24[i++] = clip(B);
bgr24[i++] = clip(G);
bgr24[i++] = clip(R);
Y = ybase[++n];
B = Y + U1[U];
G = Y - U2[U] - V1[V];
R = Y + V2[V];
bgr24[i++] = clip(B);
bgr24[i++] = clip(G);
bgr24[i++] = clip(R);
++m, ++n;
}
if(++y % 2 == 0) ++hy;
else m -= hw;
}
}