linux 电子相册

album.h
3.21

#ifndef __ALBUM_H__
#define __ALBUM_H__


typedef char* Elemtype;

struct node
{
	Elemtype data;
	struct node *next;
	struct node *prev;
};
typedef struct node Node;

struct head
{
	Node *first;
	Node *last;
	int n;
};

typedef struct head Head;



void printfl(Head *l);

void tailinsert(Head* l,Elemtype x);

Head* creathead();

int opendirs(const char* path,Head* l);

int lcdInit(const char * pathname);

void lcdClose(int fd);


void displayPoint(int x,int y,int color);

void lcdClear(int color);

void displayBmp(const char * bmpPN,int x0,int y0);

void displayChar(const unsigned char *name,int x0,int y0);

int getDirection();





#endif


main.c

#include <stdio.h>
#include "album.h"


Node *pp;
char *h;


int main()
{
	Head* l = creathead();

	printf("请输入路径: \n");
	char a[100];
	scanf("%s",a);
	opendirs(a,l);

	printfl(l);

	int fd = lcdInit("/dev/fb0");

	pp =l->first;
	int m = 0,n =0;

	while(1)
	{
		printf("flag2\n");
		lcdClear(0x00);
		printf("flag3\n");
		h = pp->data;
		displayBmp(h,m,n);
		printf("----%s\n",pp->data);
		getDirection();
	}
	lcdClose(fd);
}


album.c

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "album.h"
#include <linux/input.h>

int * p;
extern Node *pp;

int opendirs(const char* path,Head* l)
{
	DIR *r = opendir(path);
	if(r == NULL)
	{
		perror(" ");
		return -1;
	}
	struct dirent *q;
	struct stat st;
	int m;
	int len;
	char *flag;
	while(1)
	{
		q = readdir(r);
		if(q == NULL)
		{
			break;
		}
		if(strcmp(q->d_name,".")==0 ||strcmp(q->d_name,"..")==0)
		{
			continue;
		}
		char pathname[100];
		strncpy(pathname,path,100);
		strcat(pathname,"/");
		strcat(pathname,q->d_name);
		m = stat(pathname,&st);
		if(m == -1)
		{
			continue;
		}
		if(S_ISREG(st.st_mode))
		{
			char *p = (char *)malloc(100);
			strncpy(p,pathname,100);
			//printf("----%s--------\n",p);
			len = strlen(p);
			flag = p + len - 4;
			if(strcmp(flag,".bmp") == 0)
			{
				tailinsert(l,p);
			}
		}
		if(S_ISDIR(st.st_mode))
		{
			opendirs(pathname,l);
		}
		
		
	}
	
}



Head* creathead()
{
	Head *l = (Head *)malloc(sizeof(Head));

	l->first = l->last =NULL;

	l->n = 0;

	return l;
}


void tailinsert(Head* l,Elemtype x)
{
	if(l == NULL)
	{
		return;
	}
	Node * p = (Node *)malloc(sizeof(Node));
	p->next = p->prev = NULL;
	p->data = x;
	//printf("%s\n",p->data);
	if(l->n == 0)
	{
		l->first = l->last = p;
		//printf("%s----\n",l->first->data);
	}
	else
	{
		l->last->next = p;
		p->prev = l->last;

		l->last = p;
		l->first->prev =l->last;
		l->last->next = l->first;
		//printf("%s\n",l->last->data);
	}
	l->n++;
}


void printfl(Head *l)
{
	Node *p = l->first;
	//printf("%s\n",p->data);
	int i = l->n;
	while(i)
	{
		printf("%s\n",p->data);
		//printf("1111\n");
		p = p->next;
		i--;
	}
}



int lcdInit(const char * pathname)
{
	int fd = open(pathname,O_RDWR);
	if(fd == -1)
	{
		perror("open lcd failed");
		return -1;
	}
	
	p = (int *)mmap(NULL,//表示由操作系统帮我们分配一段内存,用于映射
		480*800*4,//文件长度,有480*800个像素点,一个像素点4个字节
		PROT_READ | PROT_WRITE, //可读可写权限
		MAP_SHARED,//共享
		fd,//要映射的文件的文件描述符
		0//偏移量为0,表示从该文件的第1个字节开始映射
		);
		
	if(p == NULL)
	{
		perror("mmap failed");
		return -1;
	}
	
	return fd;
}

void lcdClose(int fd)
{
	munmap(p,480*800*4);
	close(fd);
}


void displayPoint(int x,int y,int color)
{
	if(y>=0 && y<480 && x>=0 && x<800)
		*(p+800*y+x)=color;
}		


void lcdClear(int color)
{
	int x,y;
	for(y=0;y<480;y++)
	{
		for(x=0;x<800;x++)
		{
			displayPoint(x,y,color);
		}
	}
}


//111111111111111111
void displayBmp(const char * bmpPN,int x0,int y0)
{
	//打开bmp图片
	int fd = open(bmpPN,O_RDONLY);
	if(fd == -1)
	{
		perror("");
		return ;
	}
	
	//获取图片的宽度和高度
	lseek(fd,0x12,SEEK_SET);
	
	int width;
	read(fd,&width,4);
	x0 = (800-width)/2;
	
	int height;
	read(fd,&height,4);
	y0 = (480-height)/2;
	
	printf("width=%d,height=%d\n",width,height);
	
	
	//获取图片像素数组数据
	unsigned char buf[width*height*3];
	lseek(fd,54,SEEK_SET);//跳过文件头
	read(fd,buf,width*height*3);
	
	
	//开始显示
	int x,y;
	int color;
	int n = 0;
	for(y=0;y<height;y++)
	{
		for(x=0;x<width;x++)
		{
			color = buf[n++]|buf[n++]<<8|buf[n++]<<16;
			//displayPoint(x,y,color);//上下颠倒	
			displayPoint(x+x0,height-1-y+y0,color);
			
		}
	}
	printf("flag1\n");
	close(fd);
}



void displayChar(const unsigned char *name,int x0,int y0)
{
	
	int i,j;
	int x,y,color;
	for(i=0;i<24*24/8;i++)//依次把数组中的元素拿出来进行判断
	{
		//判断 li[i]
		//依次判断 li[i] 8个bit ,并且要从左到右  bit7 ~ bit0
		for(j=7;j>=0;j--)
		{
			if(name[i]&(1<<j))
			{
				x = (i%3)*8+(7-j);
				y = i/3;
				color = 0xaabbcc;
				displayPoint(x+x0,y+y0,color);
			}
		}
		
	}
	
	
}




int getDirection()
{

	printf("进入地址:%s\n",pp->data);

	int fd = open("/dev/input/event0",O_RDONLY);
	if(fd == -1)
	{
		perror("");
		return -1;
	}

	int x1=-1,y1=-1;//用来保存起点坐标
	int x2,y2;//用来保存终端坐标
	struct input_event ev;
	//1,得到起点坐标和终点坐标
	while(1)
	{
		read(fd,&ev,sizeof(ev));
		printf("type=%d,code=%d,value=%d\n",ev.type,ev.code,ev.value);

		if(ev.type==3&&ev.code==0)
		{
			x2 = ev.value;
		}
		if(ev.type==3&&ev.code==0 &&x1==-1)
		{
			x1 = ev.value;
			printf("x1 = %d\n",x1);
		}
		
		if(ev.type==3&&ev.code==1)
		{
			y2 = ev.value;
		}
		if(ev.type==3&&ev.code==1 &&y1==-1)
		{
			y1 = ev.value;
			printf("x2 = %d\n",x2);
		}
		
		if(ev.type==1&&ev.code==0x14a&&ev.value==0)
		{
			break;
		}
	}

	printf("胡波好样的\n");
	printf("x1 = %d\n",x1);
	printf("x2 = %d\n",x2);
	if((x1-x2)>0)//显示下一张
		{
			//*pp = *pp->next;
			pp = pp->next;
			printf("123 :%s",pp->data);
			printf("杨洋好样的\n");
			
		}
		else if((x1-x2)<0)//显示上一张
		{
			//*pp = *pp->prev;
			pp = pp->prev;
			
		}

}














  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
嵌入式Linux电子相册是一款基于嵌入式Linux操作系统开发的电子相册软件,用于在嵌入式设备上展示照片和图片。 嵌入式Linux电子相册具有以下特点和功能: 1. 轻量级:嵌入式Linux操作系统通常采用轻量级的内核和系统组件,使得电子相册软件在资源占用方面更加节省,能够在资源有限的嵌入式设备上运行。 2. 图片浏览:电子相册软件可以方便地浏览设备中的照片和图片,通过图形界面展示照片的缩略图,并支持放大、缩小、旋转、浏览等操作,让用户可以轻松查看和管理照片。 3. 幻灯片播放:电子相册软件支持幻灯片播放模式,可以设置图片切换的时间和效果,自动播放设备中的照片,将照片以流畅的动画形式展示给用户。 4. 多媒体支持:电子相册软件能够支持不同格式的图片文件,包括常见的JPG、PNG等,以及动态图片格式如GIF。同时,它还可以支持音乐的播放,用户可以通过设置背景音乐为相册添加更多的氛围。 5. 传输和存储:电子相册软件支持通过USB、蓝牙等接口将照片从其他设备传输到嵌入式设备上,也可以将照片保存到SD卡或其他存储媒体中进行备份,方便用户的照片管理和存储。 嵌入式Linux电子相册通过其简洁的界面和丰富的功能,使得用户可以在嵌入式设备上完美展示自己的照片收藏,无论是家庭相册、旅行照片,还是艺术作品,都可以通过这款软件得到优雅的展示和呈现。温馨提示:电子相册软件的具体功能和界面可能因开发者和设备而有所不同,以上仅供参考描述。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值