📄 ico.h
字号:
#define ICO_SIDE 32
typedef struct RGB_ico_typ
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_ico,*RGB_ico_ptr;
typedef struct Ico_file_head
{
short uo_0,u2_1;
short image_count;
}file_head,*file_head_ptr;
typedef struct Ico_file_dir
{
char width,height;
short num_colors;
short u4_0,u6_0;
long ico_size;
long icon_offset;
}file_dir,*file_dir_ptr;
typedef struct Ico_head
{
long head_size;
long width,height;
short planes;
short bits_per_pixel;
long compression;
long image_size;
short reserved[8];
}ico_head,*ico_head_ptr;
typedef struct ico_picture_typ
{
file_head fhead;
file_dir fdir;
ico_head ihead;
RGB_ico palette[16];
unsigned char map[512];
unsigned char mask[128];
char far *buffer;
} ico_picture, *ico_picture_ptr;
void Set_ICO_Palette_Register(int index,RGB_ico_ptr color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,index);
outp(PALETTE_DATA,color->red>>2);
outp(PALETTE_DATA,color->green>>2);
outp(PALETTE_DATA,color->blue>>2);
}
void Get_Palette_Register(int index,RGB_ico_ptr color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_RD,index);
color->red=inp(PALETTE_DATA);
color->green=inp(PALETTE_DATA);
color->blue=inp(PALETTE_DATA);
}
void ICO_Load_Screen(char *name,int x,int y)
{
unsigned char r,g,b;
int BK = 256,k=0,i,j,old_x=x;
//read the source information of pattern
ico_picture ico;
FILE *fp;
//open ico file
fp = fopen(name,"rb");
//load the head information of ico file
fread(&ico.fhead,1,sizeof(struct Ico_file_head),fp);
//load the struct information of ico file
fread(&ico.fdir,1,sizeof(struct Ico_file_dir),fp);
//load the head information of ico
fread(&ico.ihead,1,sizeof(struct Ico_head),fp);
//load the pattern of ico
fread(&ico.palette,1,16*sizeof(struct RGB_ico_typ),fp);
//load the color embattle of ico
fread(&ico.map,1,512,fp);
fread(&ico.mask,1,128,fp);
fclose(fp);
// Get_Palette_Register(1,(RGB_color_ptr)&color_1);
//set new pattern
for(i=0;i<16;i++)
{
//除以4是为了移位
Set_ICO_Palette_Register(i,(RGB_ico_ptr)&ico.palette[i]);
}
for(i=32;i>0;i--)
for(j=0;j<32;j=j+2)
{
video_buffer[((y+i<<8)+(y+i<<6))+x+j]=ico.map[k]>>4;
video_buffer[((y+i<<8)+(y+i<<6))+x+(j+1)]=ico.map[k++]&0x0f;
}
for(i=124;i>=0;i=i-4)
{
for(j=i;j<=i+3;j++)
{
unsigned char m=0x80;
for(k=0;k<8;k++)
{
if(ico.mask[j]&m)
video_buffer[((y+1<<8)+(y+1<<6))+x]=BLACK;
x++;
m>>=1;
}
}
y++;
x=old_x;
}
fclose(fp);
}
void ICO_Init(ico_picture_ptr image)
//申请图像大小的内存空间
{
unsigned int a=(unsigned int)(ICO_SIDE * ICO_SIDE + 1);
if((image->buffer = (char far *)malloc(a))==NULL)
{
printf("\ncouldn't allocate screen buffer");
exit(1);
}
}
void ICO_Load(char *name,ico_picture_ptr ico)
{
unsigned char r,g,b;
int BK = 256,k=0,i,j,x=0,y=0;
//read the source information of pattern
FILE *fp;
//open ico file
fp = fopen(name,"rb");
//load the head information of ico file
fread(&ico->fhead,1,sizeof(struct Ico_file_head),fp);
//load the struct information of ico file
fread(&ico->fdir,1,sizeof(struct Ico_file_dir),fp);
//load the head information of ico
fread(&ico->ihead,1,sizeof(struct Ico_head),fp);
//load the pattern of ico
fread(&ico->palette,1,16*sizeof(struct RGB_ico_typ),fp);
//load the color embattle of ico
fread(&ico->map,1,512,fp);
fread(&ico->mask,1,128,fp);
fclose(fp);
// Get_Palette_Register(1,(RGB_color_ptr)&color_1);
//set new pattern
for(i=0;i<16;i++)
{
//除以4是为了移位
Set_ICO_Palette_Register(i,(RGB_ico_ptr)&ico->palette[i]);
}
for(i=31;i>=0;i--)
for(j=0;j<32;j=j+2)
{
ico->buffer[i*32+j]=ico->map[k]>>4;
ico->buffer[i*32+(j+1)]=ico->map[k++]&0x0f;
}
for(i=124;i>=0;i=i-4)
{
for(j=i;j<=i+3;j++)
{
unsigned char m=0x80;
for(k=0;k<8;k++)
{
if(ico->mask[j]&m)
ico->buffer[y*32+x]=BLACK;
x++;
m>>=1;
}
}
y++;
x=0;
}
fclose(fp);
}
void ICO_Show_Buffer(ico_picture_ptr image,int x,int y)
//将内存中的图像显示
{
int index;
char far *data;
data=image->buffer;
for(index=0;index<ICO_SIDE;index++)
memcpy((char far *)&video_buffer[y*SCREEN_WIDTH+x+index*SCREEN_WIDTH],(char far *)&image->buffer[index*ICO_SIDE],ICO_SIDE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -