⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readfile.h

📁 嵌入式arm机开发的五子棋游戏
💻 H
字号:
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define COLLOR 3
static FILE *my_file=NULL;

int fileopen(char *filename);
int fileclose();
int GetOffSet();
int GetWidth();
int GetLength();
int GetConfectionary();
void fileread(unsigned int  (*buffer),int length,unsigned int position ,int  confectionary_length);





//////////////////////////////////////////////////////////////

int  fileopen(char *filename)
{  
  if( (my_file = fopen(filename,"r")) == NULL )
		return 0;
  return 1;

}

/////////////////////////////////////////////////////////////
int fileclose()
{
  if(my_file==NULL)
  {   
		printf("Unable to closefile source_data %s\n");
		return 0;
  }
  fclose(my_file);
  return 1;
  
}
///////////////////////////////////////////////////////
 int GetWidth()
{
      int width =0;
  	if(my_file==NULL)
	{
	  printf("Unable to read file source_data \n");
	  exit(0);
	}
	else
	{ 	  
	  fseek(my_file,18L,SEEK_SET);//bmp文件表示宽度的开始
	  fread(&width,4,1,my_file);	  
	}
	return width;

}
///////////////////////////////////////////////////////////
int GetLength()
{
      int length =0;
  	if(my_file==NULL)
	{
	  printf("Unable to read file source_data \n");
	  exit(0);
	}
	else
	{ 	  
	  fseek(my_file,22L,SEEK_SET);//bmp文件表示宽度的开始
	  fread(&length,4,1,my_file);	  
	}
	return  length;

}
////////////////////////////////////////////////////////
 int GetOffSet()
{
	  int offset =0;
  	if(my_file==NULL)
	{
	  printf("Unable to read file source_data \n");
	  exit(0);
	}
	else
	{ 	  
	  fseek(my_file,10L,SEEK_SET);//bmp文件表示宽度的开始
	  fread(&offset,4,1,my_file);	  
	}
	return  offset;
}
/////////////////////////////////////////////////////////
 int GetConfectionary()
{
  	  int confectionary = 0;
  	if(my_file==NULL)
	{
	  printf("Unable to read file source_data \n");
	  exit(0);
	}
	else
	{ 	  
	  fseek(my_file,28L,SEEK_SET);//bmp文件表示宽度的开始
	  fread(&confectionary,2,1,my_file);	  
	}
	return  confectionary;
}
//////////////////////////////////////////////////////
void fileread(unsigned int (*buffer),int length,unsigned int position,int  confectionary_length)
{
	int row;
	int red = 0;
    int green =0;
	int blue =0;
	
	if(my_file==NULL)
	{
	  printf("Unable to read file source_data \n");
	  exit(0);
	}
	else
	{ 	   
		  fseek(my_file,position,SEEK_SET);
		   for(row=0;row<length;row++)					                  
		   {
			   fread(&blue,1,1,my_file);
			   fread(&green,1,1,my_file);
			   fread(&red,1,1,my_file);
			   buffer[row]=((int)(0.122*red)<<11)+((int)(green*0.244)<<5)+(int)(0.122*blue);	   
		   }
	}
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -