I420到UYVY的转换

忽然间觉得,有些东西还是集中起来记录比较好,查找方便,在这个网络时代,不写点博,似乎太OUT了。

 

YUVI420和UYVY示意图

 

下面的代码,是用来实现I420 Plannar到UYVY Packed的转换:

 

void transform_i420_to_uyvy (

                        uint8_t *y_plane,    //Y plane of I420

                        uint8_t *u_plane,    //U plane of I420

                        uint8_t *v_plane,    //V plane of I420

                        int          y_stride,    //Y stride of I420, in pixel

                        int          uv_stride,  //U and V stride of I420, in pixel

                        uint8_t *image,       //output UYVY image

                        int          width,        //image width

                        int          height)       //image height

{

    int row;

    int col;

    uint8_t *pImg = image;

 

    for (row = 0; row < height; row = row + 1)

    {

        for (col = 0; col < width; col= col + 2)

        {

            pImg[0] = u_plane[row / 2 * uv_stride + col / 2];

            pImg[1] = y_plane[row * y_stride + col];

            pImg[2] = v_plane[row / 2 * uv_stride + col / 2];

            pImg[3] = y_plane[row * y_stride + col + 1];

 

            pImg += 4;

        }

    }

}

 

这个函数没有返回值。各个参数的含义如下:

y_plane    指向I420格式中的Y平面;

u_plane    指向I420格式中的U平面;

v_plane    指向I420格式中的V平面;

y_stride    I420格式中Y平面的步长,以像素为单位;

uv_stride  I420格式中U平面和V平面的步长,以像素为单位;

image       指向用于存储转换后的UYVY紧缩格式颜色的存储空间;

width        图像的宽度,以像素为单位;

height       图像的高度,以像素为单位;

以上参数中,除了image以外,都是输入参数。

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值