粤嵌gec6818开发板自动切换图片

粤嵌gec6818开发板自动切换图片

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>

void show_bmp(char path)
{
char bmp_buf[800
4803];
int lcd_buf[800
480];

bzero(bmp_buf,sizeof(bmp_buf));
bzero(lcd_buf,sizeof(lcd_buf));

//1、打开LCD
int lcd_fd = open("/dev/fb0",O_RDWR);
if(lcd_fd < 0)
{
	perror("open LCD");
	return -1;
}
//2、打开图片
int bmp_fd = open("path,O_RDONLY);
if(bmp_fd < 0)
{
	perror("open BMP");
	return -2;
}

//3、去掉不是像素的字节
int ret = lseek(bmp_fd,54,SEEK_SET);
if(ret < 0)
{
	perror("lseek");
	return -3;
}

//4、读图片像素
int ret1 = read(bmp_fd,bmp_buf,sizeof(bmp_buf));
if(ret1 < 0)
{
	perror("read");
	return -4;
}

//5、关闭图片
close(bmp_fd);

//6、将RGB ----> ARGB
int i;
for(i=0; i<800*480; i++)
{
	lcd_buf[i] = bmp_buf[i*3]<<0 | bmp_buf[i*3+1]<<8 | bmp_buf[i*3+2]<<16;
}

//7、内存映射
int *fd_map = NULL; 
fd_map = mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,lcd_fd,0);
if(fd_map == NULL)
{
	perror("mmap");
	return -1;
}	

//8、将图片翻转
int x,y;
for(y=0; y<480; y++)
{
	for(x=0; x<800; x++)
	{
		*(fd_map+(479-y)*800+x) = lcd_buf[800*y+x];
	}
}

​ //9、解除映射
​ munmap(fd_map,8004804);
​ //10、关闭LCD
​ close(lcd_fd);

}
int man(void){

show_bmp("./01.bmp");
sleep(1);
show_bmp("./02.bmp");
sleep(1);
show_bmp("./03.bmp");
sleep(1);

}

  • 5
    点赞
  • 77
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值