该程序寄生在windows 3.1中的pbrush软件上。借助于它来构筑立体形体(即立体形体水平剖面高低坐标数据文件图8),设计原始图案(图9)。程序运行后,逐行输入并处理以上两个文件中的图形,然后输出立体画结果文件(图10)。最后,用pbrush来观赏立体画result.bmp。当然,要设计出令人赏心悦目的立体画,必须在立体形体和图案素材的选择和搭配上做到天衣无缝,独具匠心。@@;图8@@@@;图9@@@@;图10程序清单@@/*--from 1995.4.19--to 1995.5.18----*/include<stdio.h>#define compression 0#define size-of-bitmapfileheader 14#define size-of-bitmapinfoheader 40#define size-of-rgbquad 4#define pixel-date-offset 14+40+4*16/*size-of-bitmapfileheader+size-of-bitmapinfoheader+bits-per-pixel*num-color*/#define num-color 16#define num-line 400#define width 640#define bits-per-pixel 4#define pixel-per-byte 2 /*8/bits-per-pixel*/#define byte-per-line 320 /*((width*bits-per-pixel-1)/32+1)*4 */#define no-dot width+1#define eye-space 128struct{unsignde char color ;unsigned int pri-x ;unsigned int nxt-x ;}dot[width];main(){struct tagbitmapfileheader{unsigned char bftype1,bftype2; /* always equal to'bm'*/unsigned long int bfsize; /*size of file */unsigned int bfreserved1,bfreserved2; /* set to zero */unsiged long int bfoffits; /*byte offset from bitmapfileheader to bitmap pixeldata in the file */}bitmapfileheader;struct tagbitmapinfoheader{unsigned long int bisize,/* size of bitmapinfoheader */biwidth;/* width in pixels biheight;/* height in pixels */unsigned int biplanes, /* always 1 */bibitcount; /* color bits per pixel must be 1,4,8 or 24 */unsigned long int bicompression, /*bi-rgb,bi-rle 8 or 4*/bisizeimage, /*total bytes in image */bixpelspermeter,/* 0,or opt,h res. */biypelspermeter,/* 0,or opt,h res. */biclrused, /* normally 0,can set a lower no. colors than bibitcount */biclrimportant; /* normally 0 */}bitmapinfoheader;struct tagrgbquad{unsigned char rgbblue, /* blue intensity,0-255 */rgbgreen, /* green intensity,0-255 */rgbred, /* red intensity,0-255 */rgbreserved; /* reserved,set to zero */}rgbquad[num-color];char *fn-layer="layer.bmp";char *fn-org="origin.bmp";char *fn-result="result.bmp";file *flayer,*forigin, *fresult;unsigned char tmp-byte1,tmp-byte2;unsigned int line,i-byte,i-pixel,x;unsigned int layer;int left-x,right-x;tmp-x;unsigned long int cur-offset;unsigned char h[width],org-color[width];puts("---wintrick---");puts("---by li jisong ---");if( (flayer=fopen(fn-layer,"rb") )!=null) {fread(&bitmapfileheader,size-of-bitmapfilehader,1,flayer);fread(&bitmapinfoheader,size-of-bitmapinfoheader,1,flayer);if( 1=='b' && 2=='m'&& h==width && ht==num-line&& ount==bits-per-pixel&& ression==compression)fread(rgbquad,size-of-rgbquad,num-color,flayer);else{fclose(flayer);printf("file %s is not fit for this program!\n",fn-layer);getch();exit(1);}}else{printf("file %s does not exist!\n",fn-layer);getch();exit(2);}if( (forigin=fopen(fn-org,"rb"))!=null) {fread(& bitmapfileheader,size-of-bitmapfileheader,1,forigin);fread(& bitmapinfoheader,size-of-bitmapinfoheader,1,forigin);if( 1=='b' && 2=='m'&& h==width && ht==num-line&& ount==bits-per-pixel&& ression==compression)fread(rgbquad,size-of-rgbquad,num-color,forigin);else {fclose(forigin);printf("file %s is not fit for this program!\n",fn-org);getch();exit(3);}}else {printf("file %s does not exist!\n",fn-org);getch();exit(4);}if( (fresult=fopen(fn-result,"wb"))!=null){fwrite(&bitmapfileheader,size-of-bitmapfileheader,1,fresult);fwrite(& bitmapinfohiader,size-of-bitmapinfoheader,1,fresult);fwrite(rgbquad,size-of-rgbquad,num-color,fresult);}else {printf("file %s open error!\n",fn-result);getch();exit(5);}for(line=0;line<num-line;line++){printf("line=%d\n",line);cur-offset=(unsigned long int)pixel-data-offset+(unsigned long int)byte-per-line*line;fseek (flayer,cur-offset,seek-set);fseek (forigin,cur-offset,seek-set);for(i-byte=0;i-byte<byte-per-line;i-byte++) {fread(&tmp-byte1,1,1,flayer);fread(&tmp-byte2,1,1,forigin);for(i-pixel=0;i-pixel<pixel-per-byte;i-pixel++) {x=i-byte*pixel-per-byte+i-pixel;if(x<width) {h[x]=(unsigned char) (tmp-byte1<<(bits-per-pixel*i-pixel)) /((unsigned char)0x80>>(bits-per-pixel-1));org-color[x]=(unsigned char) (tmp-byte2<<(bits-per-pixel*i-pixel))/((unsigned char)0x80>>(bits-per-pixel-1));}}}for(x=0;x<width;x++) {dot[x].color=0;dot[x].nxt-x=no-dot;dot[x].pri-x=no-dot;if((x+eye-space)<width) dot[x].nxt-x=x+eye-space;if((signed)x-eye-space)>=0)dot[x].pri-x=x-eye-space;}for(layer=1;layer<num-color;layer++)for(x=0;x<width;x++) {left-x=x-eye-space/2+(layer/2);right-x=x+eye-space/2-((layer+1)/2);if((h[x]==layer)&&(left-x>=0)&&(rignt-x<width)) {if (dot[left-x].nxt-x!=no-dot) dot[dot[left-x].nxt-x].pri-x=no-dot;dot[left-x].nxt-x=right-x;if (dot[right-x].pri-x!=no-dot) dot[dot[right-x].nxt-x].nxt-x=no-dot;dot[right-x].pri-x=left-x;}}for(x=0;x<width;x++) {if(dot[x].pri-x==no-dot) {dot[x].color=org-color[x];tmp-x=x;while( dot[tmp-x].nxt-x!=no-dot) {tmp-x=dot[tmp-x].nxt-x;dot[tmp-x].color=org-color[x];}}}fseek(fresult,cur-offset,seek-set);for(i-byte=0;i-byte<byte-per-line;i-byte++) {tmp-bytel=0;for(i-pixel=0;i-pixel<pixel-per-byte;i-pixel++) {x=i-byte*pixel-per-byte+i-pixel;if(x<width)tmp-byte1=(unsigned char) (tmp-byte1<<(bits-per-pixel*i-pixel)) +dot[x].color;}fwirte(&tmp-byte1,1,1,fresult);}}fclose(flayer);fclose(forigin);fclose(fresult);}
参考文献孙志辉、王萃寒、王茜.实用windows 3.1详解.北京:电子工业出版社,1994.
中国论文网(www.lunwen.net.cn)免费学术期刊论文发表,目录,论文查重入口,本科毕业论文怎么写,职称论文范文,论文摘要,论文文献资料,毕业论文格式,论文检测降重服务。 返回电子论文列表