jpeg格式解碼bmp文件初步使用筆記_第1頁
jpeg格式解碼bmp文件初步使用筆記_第2頁
jpeg格式解碼bmp文件初步使用筆記_第3頁
jpeg格式解碼bmp文件初步使用筆記_第4頁
jpeg格式解碼bmp文件初步使用筆記_第5頁
已閱讀5頁,還剩28頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

BMP文件初步使用筆BMP文件初步使用筆BMP文在c語言圖形編程中,640*48016色是極其常用的模式,具有足夠的分辨率,且為大多數(shù)顯卡所支持,下面將我最近在這一模式下使用16色bp文件的經(jīng)驗隨手記下來后來也擴展到了256色,不過以16色為基礎):一.BMP文件格式分析以及顯BMP文件由文件頭、位圖信息頭、顏色信息和圖形數(shù)據(jù)四部分組成BMP文件頭數(shù)據(jù)結構含有BMP文件的類型、文件大小和位圖起始位置等信息。其結構定義如下:typedefstructtagBITMAPFILEHEADER{WORDbfType;//位圖文件的類型,必須為BMDWORDbfSize位圖文件的大小,以字節(jié)為單位WORDbf1;//位圖文件保留字,必須為WORDbf2;//位圖文件保留字,必須為0DWORDbfOffBits位圖數(shù)據(jù)的起始位置,以相對于位圖//文件頭的偏移量表示,以字節(jié)為單}位圖信息BMP位圖信息頭數(shù)據(jù)用于說明位圖的尺寸等信息。typedefstructtagBITMAPINFOHEADER{DWORDbiSize;//本結構所占用字節(jié)數(shù)LONGbiWidth;//位圖的寬度,以像素為單位LONGbiHeight;//位圖的高度,以像素為單位WORDbines;//目標設備的級別,必須為1WORDbiBitCount//每個像素所需的位數(shù),必須是1(雙色//4(16色),8(256色)24(真彩色)之 pression;//位圖壓縮類型,必須是0(不壓縮//1(BI_RLE8壓縮類型)2(BI_RLE4壓縮類型)之一DWORDbiSizeImage;//位圖的大小,以字節(jié)為單位LONGbiXPelsPerMeter;//位圖水平分辨率,每米像素數(shù)LONGbiYPelsPerMeter;//位圖垂直分辨率,每米像素數(shù)DWORDbiClrUsed;//位圖實際使用的顏色表中的顏色數(shù)DWORDbiClrImportant位圖顯示過程中重要的顏色數(shù)}顏色顏色表用于說明位圖中的顏色,它有若干個表項,每一個表項是一個RGBUD類型的結構,定義一種顏色。RBUD結構的定義如下:typedefstructtagRGBQUAD{BYTErgbBlue;//藍色的亮度(值范圍為0-255)BYTErgbGreen綠色的亮度(值范圍為0-255)BYTErgbRed;//紅色的亮度(值范圍為0-255)BYTErgb;//保留,必須為}顏色表中RGBQUAD結構數(shù)據(jù)的個數(shù)有biBitCount來確定biBitCount=1,4,8時,分別有2,16,256個表項;biBitCount=24時,沒有顏色表項。位圖信息頭和顏色表組成位圖信息,BITMAPINFO結構定義如下typedefstructtagBITMAPINFO{BITMAPINFOHEADERbmiHeader位圖信息頭RGBQUADbmiColors[1];//顏色表}5.位圖數(shù)位圖數(shù)據(jù)記錄了位圖的每一個像素值,記錄順序是在掃描行內(nèi)是從左到右,掃描行之間是從下到上。位圖的一個像素值所占的字節(jié)數(shù):biBitCount=1時,8個像素占1個字節(jié);biBitCount=4時,2個像素占1個字節(jié);biBitCount=8時,1個像素占1個字節(jié);biBitCount=24時,1個像素占3個字節(jié)Winos規(guī)定一個掃描行所占的字節(jié)數(shù)必須是4的倍數(shù)即以long為單位不足的以0填充,一個掃描行所占的字節(jié)數(shù)計算方法:DataSizePerLine=(biWidth*//一個掃描行所占的字DataSizePerLineDataSizePerLine/4*4字節(jié)數(shù)必須是4的倍數(shù)DataSize=DataSizePerLine*在實際操作中采用了一些簡化的方法來進行圖像的顯示。顯示圖像文件的完全過程如1開圖像文2、分析文件頭,得到高、寬、色深等信3到位圖數(shù)據(jù)4、一位像素數(shù)5據(jù)數(shù)據(jù)中的顏色信息6、重復4、5的操作,直到數(shù)據(jù)區(qū)這里有一個需要注意地方的是BP文件數(shù)據(jù)的記錄順序在掃描行內(nèi)是從左到右掃描行之間是從下到上。這與屏幕上的坐標是不同的,需要進行坐標映射。二.16色位圖文件的顯位圖文件有2色、16色、256色(8位)、16位色、24位色、32位色等色度,分別指一個像素位所數(shù)據(jù)的顏色類,顏色種類越多,圖像就越真,但同時也使得圖像文件增大,這就需要考慮一種能滿足顯示要求并使圖像文件盡可能小的折衷方案。由于所采用的顯示器最多支持8色、640*480分辨率,決定使用640*480的16色位圖。在實踐中遇到幾個值得注意的地方一是如何將BP格式RB顏色數(shù)據(jù)轉(zhuǎn)換為uiel函數(shù)對應的顏色,沒有采用通常的設置調(diào)色板的方法,而是設置了一個函數(shù),直接將其映射過來。由于只有16種顏色,這是一個可以接受的方案:intchangecolor(unsignedchar{intif(c==0x00)co=16;if(c==0x0f)ifc==0x07co=16;/*8灰色變黑色*/if(c==0x08)co=10;/*7背景*/if(c==0x01)co=4;if(c==0x09)co=12;if(c==0x03)co=6;if(c==0x0b)co=14;if(c==0x02)co=2;if(c==0x0a)co=10;if(c==0x06)co=3;if(c==0x0e)co=11;if(c==0x04)co=1;if(c==0x0c)co=9;if(c==0x05)co=5;if(c==0x0d)co=13;returnco;二是C語言文件流系統(tǒng)一次只能讀入一個字節(jié)數(shù)據(jù),但16色P圖像每一像素只有4位即半個字節(jié)長,這樣在遇到掃描行像素為奇數(shù)時一般會出現(xiàn)問題。經(jīng)過反復試驗,得出一個經(jīng)驗修正量:ofs8idh8)%8,將這個修正量加到文件的實際掃描行像素寬度上就能簡單解決這一問題。下面給出16色位圖文件的具體顯示方voidputbmp1(char*name,intleft,inttop,intputwidth,int{FILEintx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;Squeeze_Mouse(MOUSE_HIDE,0,0,0);//隱藏鼠標指針if(putwidth>640)putwidth=640;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");}上面文章2,其實質(zhì)解決了bp文件的顯示問題,但速度卻太慢了;另外,640*48016片不壓縮時大約150k應想辦法進行壓縮。三.提高16色位圖文件的顯示速在文章2中提到的16色位圖文件的顯示方法,經(jīng)測試是可以穩(wěn)定的完成16色位圖文件的顯示的。但還存在一個明顯的缺陷,即顯示速度太慢,顯示一張640*480的竟需要0508秒,這就要求對顯示速度進行改進。顯示時間大部分是花在uiel函數(shù)上,由于它了調(diào)用IOS中斷,使執(zhí)行速度不高,不過平時顯示少量的像素時無法察覺到,當調(diào)用大量的utiel(時,這個問題就出來。解決的方案是:大部分窗口,屬于以背景為主色的,采取的辦法是先清背景,再畫除背景外部分,也就是在畫點之前,先檢測這個像素是否是背景色,如是就不畫,否則才畫點,在這一類窗口中,非背景色像素所占的比例一般不超過10%,所以采用這一方法可使速度提高將近1個數(shù)量級。對于以文字為主的窗口,如anel等,,采取的辦法是先清背景,再畫文字,也就是在畫點之前,先檢測這個像素是否是文字色,如是就畫點,否則不畫。原理和效果都和前面方案相似。源代碼參見putbmp()和putbmp2()四.我的16色位圖函數(shù)/*位圖#defineWZCOLOR#defineBJCOLORintchangecolor(unsignedchar{intif(c==0x00)co=16;if(c==0x0f)ifc==0x07co=16;/*8灰色變黑色*/if(c==0x08)co=10;/*7背景*/if(c==0x01)co=4;if(c==0x09)co=12;if(c==0x03)co=6;if(c==0x0b)co=14;if(c==0x02)co=2;if(c==0x0a)if(c==0x06)co=3;if(c==0x0e)co=11;if(c==0x04)co=1;if(c==0x0c)co=9;if(c==0x05)co=5;if(c==0x0d)co=13;returnco;voidputbmp(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*為了提高以背景為主色的速度,先清背景,再畫除背景外部分,用在大部分窗口*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;staticintflag=1;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");fseek(fp,118,SEEK_SET);/*printf("%ld,%ld",width,height);quit(0);*/{}voidputbmp1(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*不使用任何提速,直接畫,用在進度條上,如用putbmp(),會閃爍*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;if(putwidth>640)putwidth=640;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");fseek(fp,118,SEEK_SET);/*printf("%ld,%ld",width,height);quit(0);*/{}voidputbmp2(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*為了提高以文字的速度,先清背景,再畫文字,用在panel,文字上*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;staticintflag=1;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");fseek(fp,118,SEEK_SET);/*printf("%ld,%ld",width,height);quit(0);*/{}voidputbmp3(char*name,longFILE*fp;/*顯示256色位圖,用于幫助說明中的大位圖*/intx=1,y=1;staticflag=1;{charc;{intpx=x,py=480-y;}voidputbmp4(char*name,longFILE*fp;/*顯示256色位圖,用于表格的背景*/intx=1,y=1;staticflag=1;{charc;{intpx=x,py=480-y;}/*位圖函數(shù)庫中的um()已經(jīng)達到可用的水平,主要因為使用了文章3中的做法,但還是有不足的,一是只有在顯示以顏色簡單的文件是才能有效,2是仍沒對位圖進行壓縮。這對于應付我的畢業(yè)專題已經(jīng)綽綽有余,所以在《激光制導智能檢測設備》的界面中,得到了應用,并取得了很好的效果。一,速度的極限比照320*200256色下的情況,640*48016色因屏幕顏色空間大于64k而無法用直接寫顯存方式繪圖,因而無法照抄前者的繪圖方式。于是我仿照這種思路將平均屏幕分成3部分,分塊及繪制,并定義了一種新的圖形文件格式,專門針對640*48016色c圖形庫使用的。非常簡單,就是將y軸1-160,160-320,320-480三塊640寬的圖順序存在一個后綴img的文件中。畫時就順序讀putimg畫上去。以下是轉(zhuǎn)換程序/*圖形voidinit*初始化圖形模式{intvoidquit*退出圖形模式/*圖形/*位圖intchangecolor(unsignedchar{intif(c==0x00)co=16;if(c==0x0f)co=15;ifc==0x07co=8;/*灰色*/ifc==0x08co=7;/*背景*/if(c==0x01)co=4;if(c==0x09)co=12;if(c==0x03)co=6;if(c==0x0b)co=14;if(c==0x02)co=2;if(c==0x0a)co=10;if(c==0x06)co=3;if(c==0x0e)co=11;if(c==0x04)co=1;if(c==0x0c)co=9;if(c==0x05)co=5;if(c==0x0d)co=13;returnco;voidputbmp(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*不使用任何提速,直接畫*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;if(putwidth>640)putwidth=640;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");{}{intchar{FILE*fp;longi;}}{FILE*fp;longi;}}{FILE*fp;longi;}}{FILE*fp1;longi;}}}}getch();*/}以下是繪制時的程序/*圖形voidinit*初始化圖形模式{intvoidquit*退出圖形模式/*圖形{intchar{FILE*fp1;longi;}}}}}二單的壓如名字所示,這種文件使用2個字節(jié)為一個單位來一段相同的像素,即數(shù)量加顏色值,對于檢查儀中遇到的,這種壓縮方式的壓縮比一般能超過10。畫的時候也極其簡單。/*圖形voidinit*初始化圖形模式{int/*圖形intchangecolor(unsignedchar{intif(c==0x00)co=16;if(c==0x0f)co=15;ifc==0x07co=8;/*灰色*/ifc==0x08co=7;/*背景*/if(c==0x01)co=4;if(c==0x09)co=12;if(c==0x03)co=6;if(c==0x0b)co=14;if(c==0x02)co=2;if(c==0x0a)co=10;if(c==0x06)co=3;if(c==0x0e)co=11;if(c==0x04)co=1;if(c==0x0c)co=9;if(c==0x05)co=5;if(c==0x0d)co=13;returnco;voidputbmp(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*不使用任何提速,直接畫*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;if(putwidth>640)putwidth=640;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");{}{intx,y;inta,b;intc=1;intn=0;FILE*fp;}}}}}}}后來我又作了改進,終于找到一種比較好的屏幕文件格式,它有3個優(yōu)點:1,邏輯極其簡單,繪制,轉(zhuǎn)化代碼都在10行以內(nèi)。2,具有壓縮功能,壓縮率可以超過10。3,顯示速度足夠快,而且不針對某一顏色了。這種格式仍叫x,因為它仍是基于字節(jié)的。這種同時具有簡單,足夠的性能和通用性的方法應該能廣泛的使用他是將所有的像素集合都限定在一行中,這樣,這個像素集合就變成了直線,畫的時候,直接用lineto畫直線就行,由lineo是直接寫顯存的,于是速度提高了很多。代碼,值得推薦的算法:b2t2.c/*圖形voidinit*初始化圖形模式{int/*圖形intchangecolor(unsignedchar{intif(c==0x00)co=16;if(c==0x0f)co=15;ifc==0x07co=8;/*灰色*/ifc==0x08co=7;/*背景*/if(c==0x01)co=4;if(c==0x09)co=12;if(c==0x03)co=6;if(c==0x0b)co=14;if(c==0x02)co=2;if(c==0x0a)co=10;if(c==0x06)co=3;if(c==0x0e)co=11;if(c==0x04)co=1;if(c==0x0c)co=9;if(c==0x05)co=5;if(c==0x0d)co=13;returnco;voidputbmp(char*name,intleft,inttop,intputwidth,int{FILE*fp;/*不使用任何提速,直接畫*/intx,y,px,py,ofs;longwidth,height;unsignedcharc,c1,c2;if(putwidth>640)putwidth=640;if(putheight>480)putwidth=480;if(putwidth<left)putwidth=left;if(putheight<top)putwidth=top;fp=fopen(name,"rb");ofs=(8-{}{intx,y;inta,b;intc=1;intn=0;FILE*fp;}}}}}if(x<=640)gotol;}}//分離出來的畫txt格式圖形的函{intn,x,y,c;FILE*fp;}}這種方法仍存在的缺點就是沒文件的大小信息,只支持一種大小即640*480的文件。當然按這個思路加上這個特性也不是難事。思路1,能從bmp直接不經(jīng)過屏幕就進行轉(zhuǎn)換2,文件頭部加上格式標志和大小信息(long型3,能大于640*480的文4,能小于640*480的文5顯示大文件drawtxt(int六.最后的后來上了網(wǎng),發(fā)現(xiàn)原來世界上早就存在很好的函數(shù)庫了,北航那位哥們的neo使我內(nèi)心受盡了折磨,思考了很久自己是不是這個嚴肅的問題。不過那位老兄也是從外國人的源碼copy過來的,于是決定毫不客氣的copy他的源碼。neo和那些快速函數(shù)庫取得速度的秘訣就是自己用中斷寫個o畫點函數(shù),在此基礎上重寫line之類的函數(shù),對他們進行的優(yōu)化。在網(wǎng)上看見另一位老兄寫的640*480*256色函數(shù)庫,覺得是有用的,就留下來,簡化,改成純c版本(原來是++的),記下來,就有了一套小基礎繪圖庫,以后用(吧)。#if!defined(GRAPH_H)#defineGRAPH_H#definePALETTE_MASK#definePALETTE_REGISTER_RD0x3c7#definePALETTE_REGISTER_WR0x3c8#definePALETTE_DATA0x3c9typedef{unsignedcharred;unsignedchargreen;unsignedcharblue;RGB_color_typPaletteBuffer[256];longDisyAdd=0xa intCUR_PAGE=0;unsignedcharForColor=WHITE,BkColor=BLACK;floatsin_look[361];floatvoid{unionREGSr;{printf("Yourcandoesn'tsupport640*480*256mode!");}}void{unionREGSr;}voidSelectPage(int{unionREGSr;}/*voidPutPixel(longx,long{unsignedintpage,offset;longpixel;{SelectPage(page);}*(unsignedcharfar*)(DisvoidPutPixel(longx,longy,char{unsignedintpage,offset;longpixel;{}*(unsignedcharfar*)(DisintGetPixel(longx,long{unsignedintpage,offset;longpixel;{SelectPage(page);}return*(unsignedcharfar*)(Dis}/*voidPutPixelXor(longx,long{intScreenColor;unsignedintpage,offset;longpixel;{SelectPage(page);}*(unsignedcharfar*)(DisvoidPutPixelXor(longx,longy,char{intScreenColor;unsignedintpage,offset;longpixel;{SelectPage(page);}*(unsignedcharfar*)(DisvoidSet_Palette_Register(intindex,RGB_color_ptr{voidGet_Palette_Register(intindex,RGB_color_ptr{void{inti;{void{inti;{void{intindex,index0;RGB_color{{void{intindex,index0;RGB_color{{voidSetColor(char{voidSetBkColor(char{voidLine(longx1,longy1,longx2,long{inti;{}else{voidBLine(longx0,longy0,longx1,longy1,unsignedchar{intdx,dy;intintx_inc,y_inc;interror=0;{}{}{}{}{{{error-}}}{{{}}}}voidBar(longx1,longy1,longx2,long{inti;voidRectange(longx1,longy1,longx2,long{void{intindex;{voidCircle(intx,inty,intr,int{intx0,y0,x1,y1,index;{voidBCircle(intx,inty,intr,int{intx0,y0,x1,y1,index;{voidFillCircle(intx,inty,intr,int{intindex;{voidCircle2(intx_center,inty_center,intradius,int{intinty,delta;delta=3-for{if(delta<0)delta+=(x<<2)+6;else{delta+=((x-y)<<2)+10;y--;};doublevoidPlotCircle(intx,inty,intx_center,inty_center,int{doublestarty=y*asp_ratio;endy=(y+1)*asp_ratio;startx=x*asp_ratio;endx=(x+1)*asp_ratio;{{voidEllipse(intx_center,inty_center,intx_radius,inty_radius,int{registerintx,y,delta;delta=3-for{if(delta<0)delta+=(x<<2)+6;else{delta+=((x-y)<<2)+10;y--;};voidLineXor(longx1,longy1,longx2,long{inti;{}else{voidBLineXor(longx0,longy0,longx1,longy1,unsignedchar{intdx,dy;intintx_inc,y_inc;interror=0;{}{}{}{}{{{}}}{{{}}}}voidBarXor(longx1,longy1,longx2,long{inti;voidRectangeXor(longx1,longy1,longx2,long{voidCircleXor(intx,inty,intr,int{intx0,y0,x1,y1,index;{voidBCircleXor(intx,inty,intr,int{intx0,y0,x1,y1,index;{voidFillCircleXor(intx,inty,intr,int{intindex;{voidCircle2Xor(intx_center,inty_center,intradius,int{intinty,delta;for(x=0;x<=y;){if(delta<0)delta+=(x<<2)+6;else{delta+=((x-y)<<2)+10;y--;};voidPlotCircleXor(intx,inty,intx_center,inty_center,int{doublestarty=y*asp_ratio;endy=(y+1)*asp_ratio;startx=x*asp_ratio;endx=(x+1)*asp_ratio;{{void or(intx_center,inty_center,intx_radius,inty_radius,int{registerintfor(x=0;x<=y;){if(delta<0)delta+=(x<<2)+6;else{delta+=((x-y)<<2)+10;y--;};voidGetImage(longLeft,longTop,longRight,longBottom,char{intImageOffset=0;unsignedlongoffset,O,page;longpixel;longImageHigh=Bottom-Top;longImageWidth=Right-Left;{{{}Buffer[ImageOffset++]=*(unsignedcharfar*)(Dis}}}voidPutImage(longLeft,longTop,longRight,longBottom,char{intImageOffset=0;unsignedlongoffset,O,page;longpixel;longImageHigh=Bottom-longImageWidth=Right-{{{}*(unsignedcharfar*)(Dis}}}void{inti,j,k;{SetColor(i);{Line((i-100)*6,20,(i-Line((i-100)*6+1,20,(i-Line((i-100)*6+2,20,(i-/*/OutCharXY((i-100)*6,32,i-{Line((i-200)*6,40,(i-Line((i-200)*6+1,40,(i-Line((i-200)*6+2,40,(i-/*/OutCharXY((i-200)*6,52,i-#endif/*GRAPH_H這個庫在優(yōu)化方面不使很好,不過邏輯很簡單Neo的優(yōu)化就繁瑣而了,我只取了其中畫點和縣的函數(shù),改進前半部分利用neo的底層函數(shù)結合我的.l文件,總算實現(xiàn)了一個速度夠快,又夠小的版/*圖形驅(qū)動/*NEOSDKForTurboC2.x/WIN-TCCopyrightCkerHome2003-2005.OpenSourceObey文件名稱:本頭文件包含了NEOSDK里有關VESA底層操作的各種基本圖形函數(shù)、結構、全局變量的及定義當前版本作者:完成日期取代版本原作者:完成日期#ifndefN2D_H#define#ifdefinedNEO_color_depth_16_unused&&definedNEO_color_depth_8_unused#undefNEO_color_depth_8_unused#undefNEO_color_depth_16_unused#ifndefNEO_draw_optimization_unused#defineNEO_draw_optimization_used1#defineNEO_draw_optimization_used0#ifdefinedNEO_rect_unused#defineNEO_rect_used1#defineNEO_rect_used0#ifdefNEO_hi_graphics_h_used#ifdefUSER_CHAR_SIZE#if#errorPleasedon'tincludegraphics.h!#defineclosegraph()set_vbe_mode(0x3)#definegetgraphmode()#definesetgraphmode(mode)set_vbe_mode(mode)#definesetviewport(l,t,r,b,c)screen(l,t,r,b):0#definegetmaxx()max_x()#definegetmaxy()#definesetwritemode(mode)set_draw_mode(mode)#definesetcolor(color)(g_frt_color=color)#definesetbkcolor(color)clear_to_color(color)#definegetcolor(color)g_frt_color#definesetrgbpalette(cn,r,g,b)set_color(cn,r,g,b)#defineputpixel(x,y,color)dot(x,y,color)#definegetpixel(x,y)get_dot(x,#definebar(x0,y0,x1,y1)rectfill(x0-1,y0-1,x1-1,y1-1,g_frt_color)#definerectangle(x0,y0,x1,y1)rect(x0,y0,x1,y1,g_frt_color)#definetextcolor(color)set_str_color(color)#defineouttextxy(x,y,str)textout(str,x,y)#definetextwidth()textheight()#define_WHITE0xf#define_BLACK0#definemax_x()g_screen_h#definemax_y()#defineget_color_depth()#defineVBE320X200X2560X13#defineVBE640X400X2560X100#defineVBE640X480X2560X101#defineVBE800X600X2560X103#defineVBE1024X768X2560X105#defineVBE1280X1024X2560X107#defineVBE320X200X32K0X10D#defineVBE640X480X32K0X110#defineVBE800X600X32K0X113#defineVBE1024X768X32K0X116#defineVBE1280X1024X32K0X119#defineVBE320X200X64K0X10E#defineVBE640X480X64K0X111#defineVBE800X600X64K0X114#defineVBE1024X768X64K0X117#defineVBE1280X1024X64K0X11A#defineSCREEN_Wg_screen_h#defineSCREEN_Hg_screen_v/*#ifndefenumCOLORSenumTPT15=0X7C1F,TPT16=//TPT24=//TPT32=enumtypedefstruct{unsignedcharr;unsignedcharg;unsignedchar}RGB,typedefstruct{unsignedcharblue;unsignedchargreen;unsignedcharred;unsignedchar;}PIC_RGB,typedefstruct{unsignedshortmode_attributes;/*Modeattributes*/unsignedcharwin_a_attributes;/*WindowAattributes*/unsignedcharwin_b_attributes;/*WindowBattributes*/unsignedshortwin_granularity;/*Windowgranularityink*/unsignedshortwin_size;/*Windowsizeink*/unsignedshortwin_a_segment;/*WindowAsegment*/unsignedshortwin_b_segment;/*WindowBsegmentvoid(far*win_func_ptr)(void);/*Pointertowindowfunction*/unsignedshortbytes_per_scan_line;/*Bytesperscanline*/unsignedshortx_resolution;/*Horizontalresolution*/unsignedshorty_resolution;/*Verticalresolution*/unsignedcharx_char_size;/*Charactercellwidth*/unsignedchary_char_size;/*Charactercellheight*/unsignedcharnumber_of_nes;/*Numberofmemorynes*/unsignedcharbits_per_pixel;/*Bitsperpixel*/unsignedcharnumber_of_banks;/*NumberofCGAstylebanks*/unsignedcharmemory_model;/*Memorymodeltype*/unsignedcharbank_size;/*SizeofCGAstylebanksunsignedcharnumber_of_image_pages;/*Numberofimagespages*/unsignedcharres1;/**/unsignedcharred_mask_size;/*Sizeofdirectcolorredmask*/unsignedcharred_field_position;/*Bitposnoflsbofredmask*/unsignedchargreen_mask_size;/*Sizeofdirectcolorgreenmask*/unsignedchargreen_field_position;/*Bitposnoflsbofgreenmask*/unsignedcharblue_mask_size;/*Sizeofdirectcolorbluemask*/unsignedcharblue_field_position;/*Bitposnoflsbofbluemask*/unsignedcharrsvd_mask_size;/*Sizeofdirectcolorresmask*/unsignedcharrsvd_field_position;/*Bitposnoflsbofresmask*/unsignedchardirect_color_mode_info;/*Directcolormodeattributes*/unsignedcharres2[216];/*Padto256byteblocksize*/#definePAL_SIZEtypedefRGBPALLETE[PAL_SIZE];#definePALETTEPALLETE/*NEO的私有全局變量(擅自俢改,以免造成不可預料的錯誤 charfar*g_ptr=(charfar*)0xa charg_routines;charcharg_green_mask=0;charg_green_bit=0;charg_color_depth0*記錄當前圖形模式的色深,為0表示非圖形模式*/intg_screen_h;/*當前分辨率下的屏幕寬度*/intg_screen_v;/*當前分辨率下的屏幕高度longg_screen_size;/*記錄當前圖形模式的屏幕面積*/unsignedg_blit_fix*NEO目前用于blit()函數(shù)的臨時變量*/intg_cur_vbe_page=0;/*當前所處的顯示頁*/ intg_frt_color=intg_tptcolor0*本開發(fā)包指定透明色(Transparentcharg_draw_mode=0;/*繪圖模式,分為COPY_PUT,XOR_PUT,OR_PUT,AND_PUT,NOT_PUT,TC的繪圖模式意義相同/*以下4個變量用來支持裁剪輸出,分別代表裁剪區(qū)域的左上角及右下角坐標*/intg_rect_left;intg_rect_right;intg_rect_top;intcharg_dac_size_fix=2;/*記錄DAC調(diào)色板寬度修正值,由8-當前DAC寬度得來,默認為*函數(shù)(Functiondeclare)charset_vbe_mode(intmode);intget_vbe_mode();charcharscreen(unsignedleft,unsignedtop,unsignedright,unsignedbottom);voidset_vbe_page(charpage);#ifndefNEO_draw_mode_unusedvoidset_draw_mode(intdraw_mode);voidvoidset_palette_range(char*pal_buf,intfrom,intto,intvsync_flag);voidget_palette_range(char*pal_buf,intfrom,intto);charset_color(intindex,charred,chargreen,charblue);#ifndefNEO_palette_unusedvoidset_dac_size(unsignedcharsize);charget_dac_size();voidset_palette(char*pal_buf);voidget_palette(char*pal_buf);charget_red(intindex);charget_green(intindex);charget_blue(intindex);voidfade_out(unsignedchardest_color,longtimedelay);voiddot(intx,inty,intcolor);intget_dot(intx,inty);#ifndefNEO_basic_draw_unused#ifndefvoidline(intx1,inty1,intx2,inty2,unsignedvoidcircle(intc_x,intc_y,intr,unsignedcharvoidellipse(intx0,inty0,inta,intb,unsignedcharcolor);voidline(intx1,inty1,intx2,inty2);voidcircle(intc_x,intc_y,intr);voidellipse(intx0,inty0,inta,intb);charhline(intx,inty,intwidth,unsignedcolor);voidvline(intx,inty,intheight,unsignedcolor);voidrect(intx0,inty0,intx1,inty1,intcolor);voidtri(intxa,intya,intxb,intyb,intxc,intyc,intcol);voidrectfill(intx1,inty1,intx2,inty2,intcolor);voidcirclefill(intx,inty,intr,intc);void_dot(intx,inty,intcolor);voidvoidclear_to_color(intcolor);voidvsync();charg_en_slant=0; _size=1;intg_str_color=1;intg_text_bg=-1;externvoidshow_mouse();externvoidhide_mouse();void{while(inportb(0x3da)&0x08);while(!(inportb(0x3da)&0x08));}char{return0;}/*獲得ROM字符集首地址unsignedcharfar*get_asc_rom(unsignedint{structREGPACKreg;reg.r_ax=0x1130;reg.r_bx=bx;intr(0x10,®);return(unsignedcharfar*)MK_FP(reg.r_es,}/*選擇要使用的ASCIIROM字符集unsignedcharfar*cur_asc_rom(int{staticcharfault_ch=staticunsignedcharfar*romaddr=(unsignedcharfarif{switch(fault_ch={case8*獲得8*8ASCIIROM字符集首地址*/returnromaddr=get_asc_rom(0x0300);case14*獲得14*8ASCIIROM字符集首地址*/returnromaddr=get_asc_rom(0x0200);case16*獲得16*8ASCIIROM字符集首地址*/returnromaddr=get_asc_rom(0x0600);romaddr=*chose=fault_ch=8;returnromaddr;}}*chose=fault_ch;returnromaddr;}*函數(shù)定義(Functiondefinitions/*設置SVGA的顯示模式charset_vbe_mode(int{mode_info_tmode_info;structSREGSsegs;unionREGSr;charfar*modeinfo=(charfarr.x.ax=0x4f02;r.x.bx=mode;int86(0x10,&r,&r);if(mode<{if(mode=={g_color_depth=8;g_rect_left=g_rect_top=0;g_rect_right=(g_screen_h=320)-1;g_rect_bottom=(g_screen_v=200)-1;g_screen_size=g_screen_h*g_screen_v;g_tptcolor=TPT8;screen(0,0,g_rect_right,g_rect_bottom);return1;}return0;/*Ignorenon-VBEmodes}{r.x.ax=0x4f01;r.x.cx=mode;r.x.di=FP_OFF(modeinfo);segs.es=FP_SEG(modeinfo);int86x(0x10,&r,&r,&segs);if(r.x.ax!=0x4F)return0;}#ifndefNEO_bmp_masked_blit_unusedswitch(mode)/*臨時使用*/{case0x101:g_blit_fix=45056;case0x103:g_blit_fix=21248;case0x105:g_blit_fix=65534;g_blit_fix=}g_green_mask=mode_info.green_mask_size;g_color_depth=mode_info.bits_per_pixel;g_rect_left=g_rect_top=0;g_rect_right=(g_screen_h=mode_info.x_resolution)-1;g_rect_bottom=(g_screen_v=mode_info.y_resolution)-1;g_screen_size=g_screen_h*g_screen_v;screen(0,0,g_rect_right,switch{caseg_tptcolor=TPT8;caseg_tptcolor=TPT15;g_green_bit=3;caseg_tptcolor=TPT16;g_green_bit=2;case//g_tptcolor=TPT24;case//g_tptcolor=TPT32;g_tptcolor=TPT8;}g_routines|=g_page_num=get_page_num();return1;}intget_vbe_mode(void){_AX=intreturn}char{charpages[28]={4,5,4,8,6,12,10,20,-1,-1,-1,-1,-1,2,2,3,10,10,15,15,22,24,24,36,40,40,int_AX=intif((tmp=_BX)>={returnpages[tmp-}elseif(tmp=={return}return-}/*指定剪切輸出域(包括邊線charscreen(unsignedleft,unsignedtop,unsignedright,unsigned{g_rect_left=left;//=g_rect_top=top=0;g_rect_right=right;//=g_screen_h-1;g_rect_bottom=bottom;//=g_screen_v-1;return}/*顯存換頁函數(shù)voidset_vbe_page(char{unionREGSif(g_cur_vbe_page!={r.x.dx=g_cur_vbe_page=int86(0x10,&r,}}#ifndefNEO_draw_mode_unusedvoidset_draw_mode(intdraw_mode){(draw_mode>=COPY_PUT)&&(draw_mode<=NOT_PUT)?g_draw_mode=draw_mode:} *函數(shù)功能:將硬件調(diào)色板轉(zhuǎn)換為本SDK推薦的邏輯調(diào)色板*參數(shù)說明:無*返回說明:無 *:SDK推薦的調(diào)色板是由經(jīng)典游戲"仙劍奇?zhèn)b傳的調(diào)色板經(jīng)過分類排序等修改而來的,選色專業(yè),顏色齊,覆蓋性好;一般匹配其他可以達到90%以上的近似效果.所以本SDK將其定為推薦調(diào)色盤.用戶程序可直接調(diào)用 void{#ifndefNEO_sys_pal_unusedunsignedcharrgb[256][3]={5,63,0,0,63,0,0,63,14,11,63,18,15,63,22,19,63,22,18,63,32,28,63,37,33,63,43,39,18,5,2,2137,34,26,40,37,30,44,41,34,47,45,38,50,49,42,53,52,46,56,55,50,}voidset_palette_range(char*pal_buf,intfrom,intto,int{structREGPACKif(from<=to&&from>=0&&from<256&&to-from<{if(vsync_flag)reg.r_ax=0x1012;reg.r_bx=from;reg.r_cx=to-from+1;reg.r_es=FP_SEG(pal_buf);reg.r_dx=FP_OFF(pal_buf);}}voidget_palette_range(char*pal_buf,intfrom,int{structREGPACKif(from<=to&&from>=0&&from<256&&to-from<{regs.r_ax=0x1017;regs.r_bx=from;regs.r_cx=to-from+1;regs.r_es=FP_SEG(pal_buf);regs.r_dx=}} *函數(shù)功能:設置硬件調(diào)色板中指定顏色號的顏色分量*參數(shù)說明index為顏色號red,green,blue為此顏色號對應的紅,綠,蘭三原色分量,均應小于64)*返回說明:成功返回1;否則返回0*備注:顏色設置函數(shù).用戶程序可直接調(diào)用 charset_color(intindex,charred,chargreen,char{unsignedcharcolor[0]=red;color[1]=green;color[2]=blue;set_palette_range(color,index,index,0);return-1;}#ifndef *函數(shù)功能:設置硬件調(diào)色板為邏輯調(diào)色板*參數(shù)說明:pal_buf指向256種顏色分量數(shù)組的指針.*這個數(shù)組的形式一般可以有兩種:pal[256][3]和*返回說明:無*備注:顏色設置函數(shù).用戶程序可直接調(diào)用 voidset_palette(char{#ifndefNEO_draw_smooth_unusedset_palette_range(pal_buf,0,255,1);set_palette_range(pal_buf,0,255,0);}voidget_palette(char*pal_buf)/*獲取系統(tǒng)調(diào)色板{get_palette_range(pal_buf,0,}charget_red(int{unsignedcharget_palette_range(color,index,index);returncolor[0];}charget_green(int{unsignedcharget_palette_range(color,index,index);returncolor[1];}charget_blue(int{unsignedcharget_palette_range(color,index,index);returncolor[2];}voidset_dac_size(unsignedchar{_AX=_BL=_BH=intg_dac_size_fix=((size==6)||(size==8))?8-size:}char{_AX=_BL=intg_dac_size_fix=8-return8-}voidfade_out(unsignedchardest_color,long{#ifndefNEO_color_depth_8_unusedunsignedinti,j;unsignedchardac[256][3];unsignedcharrgb[3];rgb[0]=get_red(dest_color);rgb[1]=get_green(dest_color);rgb[2]=get_blue(dest_color);for(j=0;j<64;{for(i=0;i<256;{dac[i][0]>rgb[0]?dac[i][0]--dac[i][1]>rgb[1]?dac[i][1]--dac[i][2]>rgb[2]?dac[i][2]--}}dest_color+=timedelay+=0;}voiddot(intx,inty,int{longaddr;intpage;if((x<g_rect_left)||(y<g_rect_top)||(x>g_rect_right)||(y>g_rect_bottom))if(g_color_depth=={#ifndefpage=(int)((addr=(long)y*g_screen_h+x)>>if(g_cur_vbe_page!={_BX=_DX=g_cur_vbe_page=_AX=int}#ifndefNEO_draw_mode_unused{caseCOPY_PUT:*(g_ptr+(addr&0xffff))=caseXOR_PUT:*(g_ptr+(addr&0xffff))=*(g_ptr+(addr&0xffff))^(char)color;break;caseNOT_PUT:*(g_ptr+(addr&0xffff))=~*(g_ptr+(addr&0xffff));break;caseOR_PUT:*(g_ptr+(addr&0xffff))=*(g_ptr+(addr&0xffff))|(char)color;break;caseAND_PUT:*(g_ptr+(addr&0xffff))=*(g_ptr+(addr&0xffff))&(char)color;break;}*(g_ptr+(addr&0xffff))=(unsignedchar)color;x+=0;y+=0;color+=0;}else*ifg_color_depth16)*/*由于NEO1.1.00只支持25664K色,所以暫時注釋左邊一句{#ifndefintfar*ptr16=(intfar page=(int)((addr=(long)y*g_screen_h+x)>>if(g_cur_vbe_page!={_BX=_DX=g_cur_vbe_page=_AX=int}#ifndefNEO_draw_mode_unused{caseCOPY_PUT:*(ptr16+(addr&0xffff))=caseXOR_PUT:*(ptr16+(addr&0xffff))=*(ptr16+(addr&0xffff))^color;break;caseNOT_PUT:*(ptr16+(addr&0xffff))=~*(ptr16+(addr&0xffff));break;caseOR_PUT:*(ptr16+(addr&0xffff))=*(ptr16+(addr&0xffff))|color;break;caseAND_PUT:*(ptr16+(addr&0xffff))=*(ptr16+(addr&0xffff))&color;break;}*(ptr16+(addr&0xffff))=color;x+=0;y+=0;color+=0;}}voidputpixel(intx,inty,int}intget_dot(intx,int{/*unionREGSr;*/longaddr;intif((x<0)||(y<0)||(x>g_screen_h)||(y>g_screen_v))return-if(g_color_depth=={#ifndefpage=(int)((addr=(long)y*g_screen_h+x)>>16);if(g_cur_vbe_page!=page){_BX=_DX=g_cur_vbe_page=_AX=int}return(peekb(0xa000,addr&0xFFFF));x+=0;}{#ifndefintfar*ptr=(intfar page=(int)((addr=(long)y*g_screen_h+x)>>if(g_cur_vbe_page!={_BX=_DX=g_cur_vbe_page=_AX=int}return*(ptr+(addr&0xffff));x+=0;}}intgetpixel(intx,int{return}#ifndef#ifndef/*通用的畫線函數(shù),用color顏色由(x1,y1)畫到(x2,y2);速度:(16FPS)*/voidline(intx1,inty1,intx2,inty2,unsignedcolor){intdt_x=x2-x1,dt_y=y2-y1,step_x,step_y,if(dt_x<{dt_xdt_x*從右向左畫線*/step_x=-1;}elsestep_x1*從左向右畫線if(dt_y<{dt_ydt_y*從下向上畫線*/step_y=-1;}else{step_y=/*從上向下畫線ifdt_xdt_y*x改變得比y快{change=dt_x>>1;while(x1!=x2){dot(x1,y1,color);x1+=step_x;change+=dt_y;if(change>dt_x){y1+=step_y;change-=dt_x;}}}else*y改變得比x快{change=dt_y>>1;while(y1!=y2){dot(x1,y1,color);y1+=step_y;change+=dt_x;if(change>dt_y){x1+=step_x;change-=dt_y;}}}dot(x2,y2,}voidline(intx1,inty1,intx2,int{intdt_x=x2-x1,dt_y=y2-y1,step_x,step_y,if(dt_x<{dt_xdt_x*從右向左畫線*/step_x=-1;}elsestep_x1*從左向右畫線if(dt_y<{dt_ydt_y*從下向上畫線*/step_y=-1;}else{step_y=/*從上向下畫線ifdt_xdt_y*x改變得比y快{change=dt_x>>1;while(x1!=x2){dot(x1,y1,g_frt_color);x1+=step_x;change+=dt_y;if(change>{y1+=step_y;change-=dt_x;}}}else*y改變得比x快{change=dt_y>>1;while(y1!=y2){dot(x1,y1,g_frt_color);y1+=step_y;change+=dt_x;if(change>{x1+=step_x;change-=dt_y;}}}dot(x2,y2,}/*優(yōu)化后的畫水平線函數(shù),用color顏色由(x,y)向右畫長為width的水平線;速度:865FPS;1632FPS*/charhline(intx,inty,intwidth,unsignedcolor){lon

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論