libyuv接口I420Rotate的实际使用

本文详细介绍了如何使用libyuv库中的I420Rotate函数实现I420格式图片的旋转操作,包括函数参数说明及实际代码示例,帮助读者理解I420格式的存储方式和旋转原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I420Rotate

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);//这里根据实际旋转角度进行调整,主要是长和宽进行对调,填写正确的旋转角度即可

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值