32位图像旋转90度

1、顺时针旋转90度:

void RGB32RotateClockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
	int w;
	int h;
	int src_row_bytes;
	uint8_t* img;
	uint8_t* ptr;
	int i, j;
	unsigned int off1;
	unsigned int off2;
	int dst_row_bytes;

	w = height;
	h = width;
	src_row_bytes =  width << 2;
	dst_row_bytes =  w << 2;

	off1  = 0;
	off2 = (w - 1) << 2;
	for(i = 0; i < height; i++)
	{   
		ptr = dst + off2;
		img = src + off1;
		for(j = 0; j < width; j++)
		{
			*((uint32_t*)ptr) = *((uint32_t*)img);
			img += 4;
			ptr += dst_row_bytes;
		}
		off1 += src_row_bytes;
		off2 = (w - i - 1) * 4;
	}
}


2、逆时针旋转90度:

void RGB32RotateAntiClockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
	int w;
	int h;
	int src_row_bytes;
	uint8_t* img;
	uint8_t* ptr;
	int i, j;
	unsigned int off1;
	unsigned int off2;
	int dst_row_bytes;

	w = height;
	h = width;
	src_row_bytes =  width << 2;
	dst_row_bytes =  w << 2;

	off1  = (width-1) << 2;
	off2 = 0;
	for(i = 0; i < height; i++)
	{   
		ptr = dst + off2;
		img = src + off1;
		for(j = 0; j < width; j++)
		{
			*((uint32_t*)ptr) = *((uint32_t*)img);
			img -= 4;
			ptr += dst_row_bytes;
		}
		off1 += src_row_bytes;
		off2 = i * 4;
	}
}
32位位图没有字节对齐问题,处理相对简单。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值