将YUV数据转换为RGB数据

void NV12_T_RGB(unsigned int width , unsigned int height , unsigned char *yuyv , unsigned char *rgb)

{

const int nv_start = width * height ;

uint32_t  i, j, index = 0, rgb_index = 0;

uint8_t y, u, v;

int r, g, b, nv_index = 0;

for(i = 0; i <  height ; i++)

{

for(j = 0; j < width; j ++){

//nv_index = (rgb_index / 2 - width / 2 * ((i + 1) / 2)) * 2;

nv_index = i / 2  * width + j - j % 2;

y = yuyv[rgb_index];

u = yuyv[nv_start + nv_index + 1];

v = yuyv[nv_start + nv_index ];

r = y + (140 * (v-128))/100;  //r

g = y - (34 * (u-128))/100 - (71 * (v-128))/100; //g

b = y + (177 * (u-128))/100; //b

if(r > 255)  r = 255;

if(g > 255)  g = 255;

if(b > 255)  b = 255;

if(r < 0)    r = 0;

if(g < 0)    g = 0;

if(b < 0)    b = 0;

index = rgb_index % width + (height - i - 1) * width;

rgb[index * 3+0] = b;

rgb[index * 3+1] = g;

rgb[index * 3+2] = r;

rgb_index++;

}

}

}

你可能感兴趣的:(将YUV数据转换为RGB数据)