| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1014 人关注过本帖
标题:[求助]急,tc下256色bmp图像的调用
只看楼主 加入收藏
carey520
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-10-1
收藏
 问题点数:0 回复次数:1 
[求助]急,tc下256色bmp图像的调用

我调用了以下这段代码,运行结果是 Usage: Showbmp Filename.BMP 还有不懂grac,grav,这两个出现在main函数里的形参是什么咚咚, 哪位侠客,能帮忙调试一下这段代码,在下感激不尽!!! #include<stdio.h> #include<dos.h> #include<stdio.h> #include<conio.h> #define NoError 0 #define ErrorFileOpen 1 #define ErrorFileType 2 #define ErrorImageColor 3

/*bmp位图结构信息*/ typedef struct tagBITMAPFILEHEADER{ unsigned int bfType; unsigned long bfSize; unsigned int bfReserved1; unsigned int bfReserved2; unsigned long bfoffBits; }BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER{ unsigned long biSize; unsigned long biWidth; unsigned long biHeight; unsigned int biPlanes; unsigned int biBitCount; unsigned long biCompression; unsigned long biSizeImage; unsigned long biXPelsPerMeter; unsigned long biYPelsPerMeter; unsigned long biClrUsed; unsigned long biClrImportant; }BITMAPINFOHEADER; typedef struct tagRGBQUAD{ unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved; }RGBQUAD;

void main(int argc,char *argv[]); int ShowBmp(char *FileName); int GetColor(unsigned char R,unsigned char G, unsigned char B,int X,int Y); void SetVideoMode(unsigned char Mode); void SetPalReg(unsigned char *palReg); void SetDacReg(unsigned char *DacReg, int Color, int Count); void PutPixel(int X, int Y,unsigned char Color); unsigned char PalReg[17]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}; unsigned char StandardPal[48]= {0,0,0,32,0,0,0,32,0,32,32,0,0,0,32,32,0,32,0,32,32,32,32,32,48,48,48,63,0,0,0,63,0,63,63,0,0,0,63,63,0,63,0,63,63,63,63,63,}; unsigned char LightnessMatrix [16][16]= { { 0,235,59,219,15,231,55,215,2,232,56,217,12,229,52,213}, {128,64,187,123,143,79,183,119,130,66,184,120,140,76,180,116}, {33,192,16,251,47,207,31,247,34,194,18,248,44,204,28,244}, {161,97,144,80,175,111,159,95,162,98,146,82,172,108,156,92}, {8,225,48,208,5,239,63,223,10,226,50,210,6,236,60,220}, {136,72,176,112,133,69,191,127,138,74,178,114,134,70,188,124}, {41,200,24,240,36,197,20,255,42,202,26,242,38,198,22,252}, {169,105,152,88,164,100,148,84,170,106,154,90,166,102,150,86}, {3,233,57,216,13,228,53,212,1,234,58,218,14,230,54,214}, {131,67,185,121,141,77,181,117,129,65,186,122,142,78,182,118}, {35,195,19,249,45,205,29,245,32,193,17,250,46,206,30,246}, {163,99,147,83,173,109,157,93,160,96,145,81,174,110,158,94}, {11,227,51,211,7,237,61,221,9,224,49,209,4,238,62,222}, {139,75,179,115,135,71,189,125,137,73,177,113,132,68,190,126}, {43,203,27,243,39,199,23,253,40,201,25,241,37,196,21,254}, {171,107,155,91,167,103,151,87,168,104,153,89,165,101,149,85}, }; unsigned char ColorTable[2][2][2]= {{{0,12},{10,14}},{{9,13},{11,15}}}; unsigned char ColorMap[256][3];

void main(int argc,char *argv[]) { if(argc!=2){ printf("Usage:\n\tShowbmp Filename.BMP\n"); getch(); exit(1); } ShowBmp(argv[1]); }

int ShowBmp(char *FileName) { FILE *Fp; BITMAPFILEHEADER FileHead; BITMAPINFOHEADER InfoHead; RGBQUAD RGB; int N, W,Y,X,C,Color; unsigned char Buffer[4096]; if((Fp=fopen(FileName,"rb"))==NULL){ printf("Cann't open file!\n"); return(ErrorFileOpen); } fread(&FileHead,sizeof(BITMAPFILEHEADER),1,Fp); if(FileHead.bfType!='BM'){ printf("Must be bmp file!\n"); return(ErrorFileType); } fread(&InfoHead,sizeof(BITMAPINFOHEADER),1,Fp); if(InfoHead.biBitCount!=8 && InfoHead.biBitCount!=24){ fclose(Fp); printf("BMP file's biBitCount must be 8 or 24!%d\n",InfoHead.biBitCount); return(ErrorImageColor); } SetVideoMode(0x12); SetPalReg(PalReg); SetDacReg(StandardPal,0,16); if(InfoHead.biBitCount==8){ for(N=0;N<256;N++){ fread(&RGB,sizeof(RGBQUAD),1,Fp); ColorMap[N][0]=RGB.rgbRed; ColorMap[N][1]=RGB.rgbGreen; ColorMap[N][2]=RGB.rgbBlue; } W=(InfoHead.biWidth+3)/4*4; for(Y=InfoHead.biHeight-1;Y>=480;Y--) fread(Buffer,sizeof(unsigned char),W,Fp); for(;Y>0;Y--){ fread(Buffer,sizeof(unsigned char),W,Fp); for(X=0;X<InfoHead.biWidth && X<640;X++){ C=Buffer[X]; Color=GetColor(ColorMap[C][0],ColorMap[C][1],ColorMap[C][2],X,Y); PutPixel(X,Y,Color); } } } else{ W=(InfoHead.biWidth*3+3)/4*4; for(Y=InfoHead.biHeight-1;Y>639;Y--) fread(Buffer,sizeof(unsigned char),W,Fp); for(;Y>=0;Y--){ fread(Buffer,sizeof(unsigned char),W,Fp); for (X=0;X<InfoHead.biWidth && X<640;X++){ C=X*3; Color=GetColor(Buffer[C+2],Buffer[C+1],Buffer[C],X,Y); PutPixel(X,Y,Color); } } } getch(); fclose(Fp); SetVideoMode(0x03); return(NoError); }

int GetColor(unsigned char R, unsigned char G,unsigned char B, int X,int Y) { unsigned int L=LightnessMatrix[Y & 0x0F][X & 0x0F]; return(ColorTable[(unsigned int)R*256/255>L][(unsigned int)G*256/255>L][(unsigned int)B*256/255>L]); }

void SetVideoMode(unsigned char Mode) { _AH=0x00; _AL=Mode; geninterrupt(0x10); }

void SetPalReg(unsigned char *PalReg) { _ES=FP_SEG((unsigned char far*)PalReg); _DX=FP_OFF((unsigned char far*)PalReg); _AX=0x1002; geninterrupt(0x10); }

void SetDacReg(unsigned char *DacReg,int Color,int Count) { _ES=FP_SEG((unsigned char far*)DacReg); _DX=FP_OFF((unsigned char far*)DacReg); _AX=0x1012; _BX=Color; _CX=Count; geninterrupt(0x10); }

void PutPixel(int X, int Y, unsigned char Color) { _AH=0x0C; _AL=Color; _CX=X; _DX=Y; geninterrupt(0x10); }

搜索更多相关主题的帖子: bmp 图像 define include grav 
2005-10-02 11:53
lujw911
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-10-4
收藏
得分:0 
谢谢

你这个程序很好嘛

它生成的EXE可在DOS下看BMP

用法:在CMD下找到生成的那个EXE(假设文件名是111.EXE),输入111  图片名

111 和图片名之间有且仅有一个空格
2005-10-05 02:18
快速回复:[求助]急,tc下256色bmp图像的调用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017151 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved