我在网上找到如下 sourcevoid
yv12_to_rgb24_c(uint8_t * dst,
int dst_stride,
uint8_t * y_src,
uint8_t * u_src,
uint8_t * v_src,
int y_stride,
int uv_stride,
int width,
int height)
{
const uint32_t dst_dif = 6 * dst_stride - 3 * width;
int32_t y_dif = 2 * y_stride - width; uint8_t *dst2 = dst + 3 * dst_stride;
uint8_t *y_src2 = y_src + y_stride;
uint32_t x, y; if (height < 0) { /* flip image? */
height = -height;
y_src += (height - 1) * y_stride;
y_src2 = y_src - y_stride;
u_src += (height / 2 - 1) * uv_stride;
v_src += (height / 2 - 1) * uv_stride;
y_dif = -width - 2 * y_stride;
uv_stride = -uv_stride;
} for (y = height / 2; y; y--) {
/* process one 2x2 block per iteration */
for (x = 0; x < (uint32_t) width / 2; x++) {
int u, v;
int b_u, g_uv, r_v, rgb_y;
int r, g, b; u = u_src[x];
v = v_src[x]; b_u = B_U_tab[u];
g_uv = G_U_tab[u] + G_V_tab[v];
r_v = R_V_tab[v]; rgb_y = RGB_Y_tab[*y_src];
b = (rgb_y + b_u) >> SCALEBITS_OUT;
g = (rgb_y - g_uv) >> SCALEBITS_OUT;
r = (rgb_y + r_v) >> SCALEBITS_OUT;
dst[0] = MAX(0, MIN(255, b));
dst[1] = MAX(0, MIN(255, g));
dst[2] = MAX(0, MIN(255, r)); y_src++;
rgb_y = RGB_Y_tab[*y_src];
b = (rgb_y + b_u) >> SCALEBITS_OUT;
g = (rgb_y - g_uv) >> SCALEBITS_OUT;
r = (rgb_y + r_v) >> SCALEBITS_OUT;
dst[3] = MAX(0, MIN(255, b));
dst[4] = MAX(0, MIN(255, g));
dst[5] = MAX(0, MIN(255, r));
y_src++; rgb_y = RGB_Y_tab[*y_src2];
b = (rgb_y + b_u) >> SCALEBITS_OUT;
g = (rgb_y - g_uv) >> SCALEBITS_OUT;
r = (rgb_y + r_v) >> SCALEBITS_OUT;
dst2[0] = MAX(0, MIN(255, b));
dst2[1] = MAX(0, MIN(255, g));
dst2[2] = MAX(0, MIN(255, r));
y_src2++; rgb_y = RGB_Y_tab[*y_src2];
b = (rgb_y + b_u) >> SCALEBITS_OUT;
g = (rgb_y - g_uv) >> SCALEBITS_OUT;
r = (rgb_y + r_v) >> SCALEBITS_OUT;
dst2[3] = MAX(0, MIN(255, b));
dst2[4] = MAX(0, MIN(255, g));
dst2[5] = MAX(0, MIN(255, r));
y_src2++; dst += 6;
dst2 += 6;
} dst += dst_dif;
dst2 += dst_dif; y_src += y_dif;
y_src2 += y_dif; u_src += uv_stride;
v_src += uv_stride;
}
}但是我现在只有每一帧 yv12 (Planar 4:2:0) 的
BYTE *pBuf :图像的数据缓存
LONG dwSize :图像缓存大小
LONG dwWidth :图像宽度
LONG dwHeight :图像高度
如何得到上述函数的其他参数
int dst_stride,
uint8_t * y_src,
uint8_t * u_src,
uint8_t * v_src,
int y_stride,
int uv_stride

解决方案 »

  1.   

    y_src=pBuf,u_src=pBuf+dwWidth*dwHeight,v_src=pBuf+(dwWidth*dwHeight*5/4),y_stride=dwWidth,uv_stride=uv_stride,dst_stride=dwWidth/2
    是摘录自xVid吧,我这儿有针对MMX,SSE优化过的不过是汇编的,是我自己写的,经过测试的。
      

  2.   

    uv_stride=dwWidth;
    YV12在内存中的格式大致是
    YYYYYYYYYYYYYYYYY
    ......
    UUUUUUUUUUUUUUUUU
    ......
    VVVVVVVVVVVVVVVVV
    ......
    Y有dwHeight行,U,V都只有dwHeight/2行。
      

  3.   

    y_stride=dwWidth,uv_stride=uv_stride,uv_stride=dwWidth;
    是不是 y_stride == uv_stride ?
      

  4.   

    能否详细解释一下各个 stride 的意思和求得的原理
      

  5.   

    stride步长也,看看YV12内存中的分布就明白。不过y_src是height增加,y_src就增加一个步长,u_src,v_src,则是隔行增加一个步长。y_stride == uv_stride ?YV12是这样的。
      

  6.   

    最后问问为什么 dst_stride = dwWidth/2