美文网首页
UVC usb摄像头YUV422数据转NV21

UVC usb摄像头YUV422数据转NV21

作者: l900 | 来源:发表于2020-04-22 15:11 被阅读0次
void yuyv_to_nv21(char * image_in, char* image_out, int width, int height, unsigned long int filesize)
{
     
    int pixNUM = width * height;
    unsigned int cycleNum = filesize /pixNUM/2;
    printf("cycleNUM = %d\n",cycleNum);

     
    char *y = image_out;
    char *uv = image_out + pixNUM ;

    char *start = image_in;
    unsigned int i =0;
    int j =0,k =0;

     
    for(i= 0; i<cycleNum ;i++)
    {
        int index =0;
        for(j =0; j< pixNUM*2; j=j+2)  
        {
            *(y+index) = *(start + j);
            index ++;
        }
        start = image_in + pixNUM*2*i;
        y= y + pixNUM*3/2;
    }

  
    start = image_in;
    for(i= 0; i<cycleNum ;i++)
    {
        int uv_index = 0;
        for(j=0; j< height; j =j+2)   
        {
            for(k = j*width*2+1; k< width*2*(j+1); k=k+4)  
            {
                *(uv+ uv_index) = *(start + k +2);
                *(uv +uv_index+1) = *(start +k );
                uv_index += 2;
            }
        }
        start = image_in + pixNUM*2*i;
        uv =uv + pixNUM*3/2;
    }
}

相关文章

网友评论

      本文标题:UVC usb摄像头YUV422数据转NV21

      本文链接:https://www.haomeiwen.com/subject/vvmiihtx.html