wrote a optimized C conversation from yuv420p (which is really YCbCr to RGB32)
I'm not sure if I really understood the 420p format, so the conversion might be wrong. But it really looks nice git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6590 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bc3e91dcb6
commit
0a66a3e039
|
@ -176,6 +176,78 @@ void gfx_conv_yuv411p_rgb32_c(AVFrame *in, AVFrame *out, int width, int height)
|
|||
|
||||
void gfx_conv_yuv420p_rgb32_c(AVFrame *in, AVFrame *out, int width, int height)
|
||||
{
|
||||
gfx_conv_null_c(in, out, width, height);
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
|
||||
uint32 *pout = (uint32 *)(i * out->linesize[0] + (uint8 *)out->data[0]);
|
||||
uint8 *pi1 = i * in->linesize[0] + (uint8 *)in->data[0];
|
||||
uint8 *pi2 = (i/2) * in->linesize[1] + (uint8 *)in->data[1];
|
||||
uint8 *pi3 = (i/2) * in->linesize[2] + (uint8 *)in->data[2];
|
||||
|
||||
for (int j = 0; j < width; j+= 4) {
|
||||
|
||||
int32 Y, Cb, Cr, Y0, Y1, Y2, Y3, Cr_R, Cr_G, Cb_G, Cb_B, R, G, B;
|
||||
|
||||
Y = *(uint32 *)pi1;
|
||||
pi1 += 4;
|
||||
|
||||
Y3 = (((Y & 0xff000000) >> 24) - 16) * 38142;
|
||||
Y2 = (((Y & 0x00ff0000) >> 16) - 16) * 38142;
|
||||
Y1 = (((Y & 0x0000ff00) >> 8) - 16) * 38142;
|
||||
Y0 = ((Y & 0x000000ff) - 16) * 38142;
|
||||
|
||||
Cb = - 128 + *pi2;
|
||||
Cr = - 128 + *pi3;
|
||||
pi2 ++;
|
||||
pi3 ++;
|
||||
|
||||
Cr_R = Cr * 52298;
|
||||
Cr_G = Cr * -26640;
|
||||
Cb_G = Cb * -12845;
|
||||
Cb_B = Cb * 66493;
|
||||
|
||||
R = (Y0 + Cr_R) >> 15;
|
||||
if (R < 0) R = 0; else if (R > 255) R = 255;
|
||||
G = (Y0 + Cr_G + Cb_G) >> 15;
|
||||
if (G < 0) G = 0; else if (G > 255) G = 255;
|
||||
B = (Y0 + Cb_B) >> 15;
|
||||
if (B < 0) B = 0; else if (B > 255) B = 255;
|
||||
pout[j] = (R << 16) | (G << 8) | B;
|
||||
|
||||
R = (Y1 + Cr_R) >> 15;
|
||||
if (R < 0) R = 0; else if (R > 255) R = 255;
|
||||
G = (Y1 + Cr_G + Cb_G) >> 15;
|
||||
if (G < 0) G = 0; else if (G > 255) G = 255;
|
||||
B = (Y1 + Cb_B) >> 15;
|
||||
if (B < 0) B = 0; else if (B > 255) B = 255;
|
||||
pout[j + 1] = (R << 16) | (G << 8) | B;
|
||||
|
||||
Cb = - 128 + *pi2;
|
||||
Cr = - 128 + *pi3;
|
||||
pi2 ++;
|
||||
pi3 ++;
|
||||
|
||||
Cr_R = Cr * 52298;
|
||||
Cr_G = Cr * -26640;
|
||||
Cb_G = Cb * -12845;
|
||||
Cb_B = Cb * 66493;
|
||||
|
||||
R = (Y2 + Cr_R) >> 15;
|
||||
if (R < 0) R = 0; else if (R > 255) R = 255;
|
||||
G = (Y2 + Cr_G + Cb_G) >> 15;
|
||||
if (G < 0) G = 0; else if (G > 255) G = 255;
|
||||
B = (Y2 + Cb_B) >> 15;
|
||||
if (B < 0) B = 0; else if (B > 255) B = 255;
|
||||
pout[j + 2] = (R << 16) | (G << 8) | B;
|
||||
|
||||
R = (Y3 + Cr_R) >> 15;
|
||||
if (R < 0) R = 0; else if (R > 255) R = 255;
|
||||
G = (Y3 + Cr_G + Cb_G) >> 15;
|
||||
if (G < 0) G = 0; else if (G > 255) G = 255;
|
||||
B = (Y3 + Cb_B) >> 15;
|
||||
if (B < 0) B = 0; else if (B > 255) B = 255;
|
||||
pout[j + 3] = (R << 16) | (G << 8) | B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue