急:一个五子棋程序的winbmpshow的类 看不懂 求教
#define BMP_WINDOW_OPEN#include <windows.h >
#include <stdio.h >
#include <malloc.h>
typedef struct
{
unsigned char b;
unsigned char g;
unsigned char r;
}
rgb16M;
typedef struct {
FILE *fp ;
int WIDTH ;
int HEIGHT ;
long fix ;
int outx ;
int outy ;
int file_x1 ;
int file_y1 ;
int file_x2 ;
int file_y2 ;
int lucency ;
}BmpFile ;
HDC SBmp_hdc ;
/***********************************函数目录***********************************/
int drawBmpPixel(HDC hdc, FILE *fp
, long jump
, int draw_x , int draw_y
, int width_x, int height_y
, int lucency) ;
int drawBmp(HDC hdc, char filename[], int x0, int y0, int lucency ) ;
int swap_6num(int *x1, int *x2
, int *WIDTH
, int *y1, int *y2
, int *HEIGHT) ;
int drawPartBmp(HDC hdc, char filename[]
, int x0, int y0, int x1, int y1, int x2, int y2
, int lucency ) ;
int fopenBmpFile(char filename[]) ;
int getWidth(FILE *fp) ;
int getHeight( FILE *fp) ;
int noNameDraw(HDC hdc, BmpFile partview) ;
/******************************************************************************/
int drawBmpPixel(HDC hdc, FILE *fp
, long jump
, int draw_x , int draw_y
, int width_x, int height_y
, int lucency)
{
int i, j ;
rgb16M *buffer ;
long color_rbg ;
buffer = (rgb16M *)malloc(width_x*sizeof(rgb16M)) ;
for(j = height_y ; j >= 0 ; j--)
{
fread(buffer, 1, width_x*sizeof(rgb16M), fp) ;
for(i = 0 ; i < width_x ; i++)
{
color_rbg = RGB(buffer[i].r, buffer[i].g, buffer[i].b) ;
if(color_rbg+lucency)
SetPixel (hdc, draw_x + i, draw_y + j, color_rbg) ;
}
fseek(fp, jump, SEEK_CUR) ;
}
free(buffer) ;
return 0 ;
}
int drawBmp(HDC hdc, char filename[20], int x0, int y0, int lucency )
{
int WIDTH, HEIGHT ;
FILE *fp ;
long fix ;
if((fp = fopen(filename, "rb")) == NULL)
{
char str[20] ;
exit(1) ;
}
WIDTH = getWidth(fp) ;
HEIGHT = getHeight(fp) ;
fix = (long)WIDTH & 3 ;
fseek(fp, 54l+fix, SEEK_SET) ;
drawBmpPixel(hdc, fp, fix, x0, y0, WIDTH, HEIGHT - 1, lucency) ;
fclose(fp) ;
return 0 ;
}
int swap_6num(int *x1, int *x2
, int *WIDTH
, int *y1, int *y2
, int *HEIGHT)
{
int *t ;
if(*x1 > *x2)
{
*t = *x1 ;
*x1 = *x2 ;
*x2 = *t ;
}
if(*x1 > *WIDTH)
*x1 = *WIDTH ;
if(*x2 > *WIDTH)
*x2 = *WIDTH ;
if(*y1 > *y2)
{
*t = *y1 ;
*y1 = *y2 ;
*y2 = *t ;
}
if(*y1 > *HEIGHT)
*y1 = *HEIGHT ;
if(*y2 > *HEIGHT)
*y2 = *HEIGHT ;
return 0 ;
}
//x0,y0:图片的绘制位置,x1,y1--x2,y2图片文件剪切位置 lucency透明度
int drawPartBmp(HDC hdc, char filename[]
, int x0, int y0, int x1, int y1, int x2, int y2
, int lucency )
{
int WIDTH, HEIGHT ;
FILE *fp ;
long fix ;
int t ;
if((fp = fopen(filename, "rb")) == NULL)
{
char str[20] ;
exit(1) ;
}
WIDTH = getWidth(fp) ;
HEIGHT = getHeight(fp) ;
fix = (long) WIDTH & 3 ;
swap_6num(&x1, &x2, &WIDTH, &y1, &y2, &HEIGHT) ;
fseek(fp, 54l+(long)(HEIGHT-y2)*(WIDTH*3+fix)+x1*3, SEEK_SET) ;
drawBmpPixel(hdc, fp, (x1+WIDTH-x2)*3+fix, x0, y0, x2-x1, y2-y1, lucency) ;
fclose(fp) ;
return 0 ;
}
int fopenBmpFile(char filename[])
{
FILE *fp ;
if((fp = fopen(filename, "rb")) == NULL)
{
char str[20] ;
exit(0) ;
}
return 0 ;
}
int getWidth(FILE *fp)
{
int WIDTH ;
fseek(fp, 18l, SEEK_SET) ;
fread(&WIDTH, 4, 1, fp ) ;
return WIDTH ;
}
int getHeight( FILE *fp)
{
int HEIGHT ;
fseek(fp, 22l, SEEK_SET) ;
fread(&HEIGHT, 4, 1, fp ) ;
return HEIGHT ;
}
这里面用到的是C的写法是么 我很多地方看不懂
基本我就不理解这个类是用来干吗的 不知怎么修改
求教int swap_6num之后的每部注解 谢谢