用计算机程序制作三维立体画(2)
作者:佚名; 更新时间:2014-12-05
fits; /*byte offset from BITMAPFILEHEADER to bitmap p
ixel
data 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( BITMAPFILEHEADER.bfType1=='B' && BITMAPFILEHEADER.bfType2=='M'
&& BITMAPINFOHEADER.biWidth==WIDTH && BITMAPINFOHEADER.biHeight==NUM-
LINE
&& BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
&& BITMAPINFOHEADER.biCompression==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( BITMAPFILEHEADER.bfType1=='B' && BITMAPFILEHEADER.bfType2=='M'
&& BITMAPINFOHEADER.biWidth==WIDTH && BITMAPINFOHDADER.biHeight==NUM-LINE
&& BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
&& BITMAPINFOHEADER.biCompression==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);
}
ixel
data 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( BITMAPFILEHEADER.bfType1=='B' && BITMAPFILEHEADER.bfType2=='M'
&& BITMAPINFOHEADER.biWidth==WIDTH && BITMAPINFOHEADER.biHeight==NUM-
LINE
&& BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
&& BITMAPINFOHEADER.biCompression==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( BITMAPFILEHEADER.bfType1=='B' && BITMAPFILEHEADER.bfType2=='M'
&& BITMAPINFOHEADER.biWidth==WIDTH && BITMAPINFOHDADER.biHeight==NUM-LINE
&& BITMAPINFOHEADER.biBitCount==BITS-PER-PIXEL
&& BITMAPINFOHEADER.biCompression==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.
上一篇:一种启发式频率分配算法
下一篇:西方网络银行的发展战略及启示
热门论文