忽然间觉得,有些东西还是集中起来记录比较好,查找方便,在这个网络时代,不写点博,似乎太OUT了。
下面的代码,是用来实现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以外,都是输入参数。