当前位置:   article > 正文

linux 电子相册_linux电子相册

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


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

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);
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

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;
			
		}

}














  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/47914
推荐阅读
相关标签
  

闽ICP备14008679号