📄 linfei.bak
字号:
/*******************************************************************/
/* NAME: LINFEI.C */
/* DEDCRIPTION:This program can transfer monochrome BMP to HEX file*/
/* AUTHOR: linfei */
/* DATE: 2005.3.31 */
/*******************************************************************/
#include "stdio.h"
main()
{
FILE *fp,*fout;
int i,j,k;
unsigned short width,height,widthbyte,heightbyte;
unsigned char ch1,ch2;
unsigned char bmpbit[1280]; /*the Bytes of BMP file*/
unsigned char bitdata[10240]; /*the Bits of BMP file*/
unsigned char lcd_data[1280]; /*the Bytes of LCD data*/
if((fp=fopen("bmptest.bmp","rb"))==NULL) /*是否存在该文件*/
{
printf("\n Can't open BMP file!");
exit(1);
}
ch1=fgetc(fp);
ch2=fgetc(fp);
if((ch1!='B')||(ch2!='M')) /*是否是BMP文件?*/
{
printf("It's Not BMP file!\n");
exit(1);
}
fseek(fp,0x1c,0);
ch1=fgetc(fp);
if(ch1!=0x01) /*是否是单色BMP?*/
{
printf("It's Not monochrome BMP file!\n");
exit(1);
}
if((fout=fopen("bmptest.h","wt"))==NULL) /*创建数据头文件*/
{
printf("Can't create bmptest.h file\n");
exit(1);
}
fseek(fp,0x12,0); /*获取位图宽度*/
width=fgetc(fp);
fseek(fp,0x16,0); /*获取位图高度*/
height=fgetc(fp);
if((width>0x80)||(height>0x50)) /*位图大小是否合适(128*80)*/
{
printf("The size of BMP is too big!\n");
exit(1);
}
if(width%32==0) /*每扫描行位数是32的倍数(4B)*/
widthbyte=width/8;
else
widthbyte=(width/32)*4+4;
if(height%8==0) /*每列位数是8的倍数(1B)*/
heightbyte=height/8;
else
heightbyte=height/8+1;
fseek(fp,0x0a,0); /*提取位图数据偏移量*/
ch1=fgetc(fp);
fseek(fp,ch1,0);
fread(bmpbit,1,1280,fp); /*读位图数据到数组*/
for(i=0;i<height;i++) /*提取位图数据位*/
for(j=0;j<widthbyte;j++)
for(k=0;k<8;k++)
bitdata[8*j+k+i*widthbyte*8]=((bmpbit[j+i*widthbyte]>>(7-k))&0x1);
for(i=0;i<10240;i++) /*位图数据位取反*/
bitdata[i]=(~bitdata[i])&0x01;
for(i=0;i<heightbyte;i++) /*将位图数据位整合为LCD的显示字节数据*/
for(j=0;j<width;j++)
{
lcd_data[i*width+j]=0;
for(k=0;k<8;k++)
lcd_data[i*width+j]+=bitdata[j+k*widthbyte*8+i*8*widthbyte*8]<<k;
}
fprintf(fout,"/*The info of BMPDATA:width=%d heightbyte=%d*/\n",width,heightbyte);
fprintf(fout,"const unsigned char screen[%d]={%d,%d,\n",width*heightbyte+2,width,heightbyte);
for(i=0;i<heightbyte;i++) /*输出16进制数据*/
{
for(j=0;j<width;j++)
{
fprintf(fout,"0x%x,",lcd_data[j+i*width]);
if((j+1)%8==0)
fprintf(fout,"\n");
}
fprintf(fout,"\n");
}
fprintf(fout,"};\n");
fclose(fp);
fclose(fout);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -