Search This Blog

Dec 13, 2007

Currently Yuv2RGB convert

Since I think the bottomnect is decode part. I will no put more attention on YUV2RGB convert. FFMPEG yuv2rgb is too slow, so I write one, it is faster than FFMPEG.

void yuv_convert_rgb(AVPicture *dst, const AVPicture *src,
int width, int height)
{
const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
uint8_t *d, *d1, *d2;
int w, y, width2;
int v1,uv,u2;
int dst_linesize,src_linesize,src_uvlinesize;

d = dst->data[0];
y1_ptr = src->data[0];
cb_ptr = src->data[1];
cr_ptr = src->data[2];
width2 = (width + 1) >> 1;
dst_linesize = dst->linesize[0];
src_linesize = src->linesize[0];
src_uvlinesize = src_linesize >> 1;
for(;height >= 2; height -= 2) {
d1 = d;
d2 = d + dst_linesize;
y2_ptr = y1_ptr + src_linesize;
for(w = width; w >= 2; w -= 2) {
v1 = a1[cr_ptr[0]];
u2 = a4[cb_ptr[0]];
uv = a2[cr_ptr[0]] + a3[cb_ptr[0]];

((uint32_t *)(d1))[0] = ((((y1_ptr[0] + v1) >> 3) << 11) | (((y1_ptr[0] - uv) >> 2) << 5) | ((y1_ptr[0] + u2) >> 3))
|(((((y1_ptr[1] + v1) >> 3) << 11) | (((y1_ptr[1] - uv) >> 2) << 5) | ((y1_ptr[1] + u2) >> 3)) << 16);

((uint32_t *)(d2))[0] = ((((y2_ptr[0] + v1) >> 3) << 11) | (((y2_ptr[0] - uv) >> 2) << 5) | ((y2_ptr[0] + u2) >> 3))
|(((((y2_ptr[1] + v1) >> 3) << 11) | (((y2_ptr[1] - uv) >> 2) << 5) | ((y2_ptr[1] + u2) >> 3)) << 16);

d1 += 2 * 2;
d2 += 2 * 2;

y1_ptr += 2;
y2_ptr += 2;
cb_ptr++;
cr_ptr++;
}
d += (dst_linesize<<1);
y1_ptr += (src_linesize<<1) - width;
cb_ptr += src_uvlinesize - width2;
cr_ptr += src_uvlinesize - width2;
}
}
Post a Comment