#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include<dlfcn.h>
int all_dir(char *dirpath);
int *lcd_p=NULL;
int show_24bmp(char *bmp_path)
{
//1.打开图片
int fd=open(bmp_path,O_RDWR);
if(fd < 0)
{
perror("open bmp fail\n");
return 0;
}
printf("正在显示的图片 %s\n",bmp_path);
//2.读取tupian 54个字节头数据
char head[54];
read(fd,head,54);
//3.读取图片像素数据
char buf24[800*480*3]={0}; //rgb 三个字节
read(fd,buf24,sizeof(buf24));
int x=0;
int y=0;
//32位颜色
int color;
for(y=0;y<480;y++)
{
for(x=0;x<800;x++) //(800*480)
{ //y*800*3 跳到下一行
*((char *)&color+0) = buf24[0+x*3+y*800*3];// b
*((char *)&color+1) = buf24[1+x*3+y*800*3];// g
*((char *)&color+2) = buf24[2+x*3+y*800*3];// r
*((char *)&color+3) = 0;
// printf("color = 0x%x\n",color);
*(lcd_p + x+ ((479-y)*800)) = color; //把颜色值放到映射空间中
}
}
}
int main(int argc,char *argv[])
{
int lcd_fd=open("/dev/fb0",O_RDWR);
if(lcd_fd < 0)
{
perror("打开LCD设备失败\n");
return 0;
}
lcd_p = (int *)mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,lcd_fd,0);
DIR *dp=opendir(argv[1]);
if(dp == NULL)
{
perror("打开目录失败\n");
return 0;
}
while (1)
{
struct dirent *p=readdir(dp);
if(p==NULL)
{
break;
}
if(p->d_type==DT_DIR)
{
//拼接新的目录路径名
char new_path[2048]={0};
sprintf(new_path,"%s/%s",argv[1],p->d_name);
//递归
all_dir(new_path);
}
if(strstr(p->d_name,".jpg")||strstr(p->d_name,".bmp"))
{
printf("pic=%s\n",p->d_name);
}
printf("pic=%s\n",p->d_name);
//字符串拼接
char n_path[1024]={0};
sprintf(n_path,"%s/%s",argv[1],p->d_name);
show_24bmp(n_path);
sleep(2);
}
closedir(dp);
}
all_dir 函数接口呢?