在开发板上进行图片循环播放c语言(800*480)

阅读: 评论:0

在开发板上进行图片循环播放c语言(800*480)

在开发板上进行图片循环播放c语言(800*480)

在开发板上进行图片循环播放c语言(800*480)
代码如下:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <error.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
char* buf[10];
int lcd_fd = -1; 	//帧缓冲文件描述符
int * plcd = NULL;  //帧缓冲设备
//初始化帧缓冲设备
void Lcd_init()
{int fd = open("/dev/fb0",O_RDWR);if(fd == -1 )                    //打开屏幕出错{perror("open pingmv shibai ");}lcd_fd = fd;plcd = mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);  //映射到屏幕if(plcd == MAP_FAILED)         //映射出错{perror("mmap fail");return ;}
}//画点函数
void Lcd_Draw_Point(int x0, int y0, int color)
{if (x0 >= 0 && x0 < 800 && y0 >= 0 && y0 < 480){*(plcd + y0 * 800 + x0) = color;}
}//显示图片
void bmp_play(char* bmp_name,int x0,int y0)
{int fd = open(bmp_name,O_RDONLY);if(fd == -1){perror("open bmp error");}	int width,height;          //用来保存宽度及高度short depth;               // 保存色深unsigned char buf[4];lseek(fd,0x12,SEEK_SET);   //偏移到宽度read(fd,buf,4);width = (buf[3]<< 24 | buf[2] << 16 |buf[1] << 8 | buf[0]); //保存宽度lseek(fd,0x16,SEEK_SET);  //偏移到高度read(fd,buf,4);height = (buf[3]<< 24 | buf[2] << 16 |buf[1] << 8 | buf[0]); //保存高度lseek(fd,0x1c,SEEK_SET); //偏移到色深read(fd,buf,2);depth = (buf[1] << 8 | buf[0]);   //保存色深int line_youxiao=width * depth / 8;//一行的有效字节数int laizi =0;if(line_youxiao%4){laizi=4-line_youxiao % 4;}int line_zong = line_youxiao + laizi; //一行的总字数int xiangsu =  height * line_zong ; //像素数组的大小unsigned char * piexls = malloc(xiangsu); //保存像素数组lseek(fd,0x36,SEEK_SET);         //偏移到像素数组read(fd,piexls,xiangsu);unsigned char a ,r ,g ,b; //小端模式存储int color = 0;int k = 0;for(int i = 0; i< abs(height) ; i++){for(int j = 0; j< abs(width);j++){	//高地址存低字节b = piexls[k++];  //蓝颜色分量g = piexls[k++];  //绿颜色分量r = piexls[k++];  //红颜色分量if(depth == 32){a = piexls[k++];}else{a = 0;}color = (a << 24 | r << 16 | g << 8 | b );Lcd_Draw_Point(width>0 ? x0 +j :x0+abs(width)-1-j,height>0 ? y0 + abs(height)-1-i:y0+i ,color);	}k=k+laizi;}free(piexls);close(fd);
}// //搜索图片路径
// void sousuo_bmp(char** buf)
// {
// buf[0] = "1.bmp";
// buf[1] = "2.bmp";
// buf[2] = "3.bmp";
// buf[3] = "4.bmp";
// }// //图片循环显示
// void xunhuan(char** buf)
// {
// int i = 0;
// for(i = 0;i<10;i++)
// {
// bmp_play(buf[i],0,0);
// sleep(2);
// if(i==4)
// {
// i=0;
// }
// }
// }//关闭屏幕
void Lcd_uninit()
{munmap(plcd,800*480*4);//解映射plcd = NULL;close(lcd_fd);
}void chushihua()
{int color = 0x00ffffff;for(int i = 0;i<480;i++){for(int j = 0;j<800;j++){Lcd_Draw_Point(j,i,color);}}
}int main()
{Lcd_init();chushihua();// sousuo_bmp(buf);// xunhuan(buf);while(1)
{
bmp_play("./1.bmp",0,0);
sleep(2);
bmp_play("./2.bmp",0,0);
sleep(2);
bmp_play("./3.bmp",0,0);
sleep(2);
bmp_play("./4.bmp",0,0);
sleep(2);
}Lcd_uninit();
}

图片循环可用while循环,或者通过搜索图片路径来达到循环目的,把代码中注释部分取消注释即可,while 部分记得注释。

本文发布于:2024-01-27 10:31:22,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063226801182.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:板上   语言   图片
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23