1.接口定义:
// Rotate I420 frame.
LIBYUV_API
int I420Rotate(const uint8* src_y, int src_stride_y,
const uint8* src_u, int src_stride_u,
const uint8* src_v, int src_stride_v,
uint8* dst_y, int dst_stride_y,
uint8* dst_u, int dst_stride_u,
uint8* dst_v, int dst_stride_v,
int src_width, int src_height, enum RotationMode mode);
2.实际使用
首先弄清楚i420图片格式的存储格式:
i420_image = (uint8*)malloc(image->width * image->height * 3);
//原i420
uint8* i420_image_y_ptr = i420_image;
uint8* i420_image_u_ptr = i420_image_y_ptr + (image->width * image->height);
uint8* i420_image_v_ptr = i420_image_u_ptr + (int)(image->width * image->height * 0.25);
//旋转后i420
uint8 *i420_image_rotated = i420_image + ((image->width * image->height * 3) >> 1);//原i420的大小
uint8* i420_image_rotated_y_ptr = i420_image_rotated;
uint8* i420_image_rotated_u_ptr = i420_image_rotated_y_ptr + (image->height * image->width);
uint8* i420_image_rotated_v_ptr = i420_image_rotated_u_ptr + (int)(image->height * image->width * 0.25);
libyuv::I420Rotate(
i420_image_y_ptr, image->width,
i420_image_u_ptr, (image->width >> 1),
i420_image_v_ptr, (image->width >> 1),
i420_image_rotated_y_ptr, image->height,
i420_image_rotated_u_ptr, (image->height >> 1),
i420_image_rotated_v_ptr, (image->height >> 1),
image->width, image->height, libyuv::kRotate90);//这里根据实际旋转角度进行调整
注意:
libyuv::I420Rotate(
i420_image_y_ptr, image->width,
i420_image_u_ptr, (image->width >> 1),
i420_image_v_ptr, (image->width >> 1),
i420_image_rotated_y_ptr, image->height,
i420_image_rotated_u_ptr, (image->height >> 1),
i420_image_rotated_v_ptr, (image->height >> 1),
image->width, image->height, libyuv::kRotate90);//这里根据实际旋转角度进行调整,主要是长和宽进行对调,填写正确的旋转角度即可