Danh mục tài liệu

Xử lý ảnh màu part 2

Số trang: 10      Loại file: pdf      Dung lượng: 144.39 KB      Lượt xem: 15      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Biểu đồ màu cho các màu tính ra bằng vỉ mạch PIB được giới thiệu ở cuối cuốn sách này. Nếu bạn có phần kiểm tra vật lý của "độ sáng" (ví dụ như College Physic) bạn sẽ có thể so sánh biểu đồ màu của kiểm tra vật lý với kết quả rút ra từ chương trình 11.1. Nếu hệ thống có khả năng hiện nhiều màu hơn bạn sẽ có một sơ đồ dày đặc hơn.
Nội dung trích xuất từ tài liệu:
Xử lý ảnh màu part 2void SetMask(unsigned);void SetCamera(int);void SetPIBorEGA(int);void SetBlank(int);void FillPibRect(unsigned,int,int,int,int,int);void WaitEven(void);void WaitOdd(void);int InitPIB(void);int TestRow(int);int WaitVsync(void);void FillPibRow(unsigned,int,int,int,int);void FGetPibRow(char far *,int,int,int);void FPutPibRow(char far *,int,int,int);void GetPibRow(char far *,int,int,`int);void PutPibRow(char far *,int,int,int);unsigned GetPixel(unsigned *,int,int);void PutPixel(unsigned *,int,int,int);void SaveData(unsigned,unsigned,int);void SetBright(int); BiÓu ®å mµu cho c¸c mµu tÝnh ra b»ng vØ m¹ch PIB ®îc giíi thiÖu ëcuèi cuèn s¸ch nµy. NÕu b¹n cã phÇn kiÓm tra vËt lý cña ®é s¸ng (vÝ dônh College Physic) b¹n sÏ cã thÓ so s¸nh biÓu ®å mµu cña kiÓm tra vËtlý víi kÕt qu¶ rót ra tõ ch¬ng tr×nh 11.1. NÕu hÖ thèng cã kh¶ n¨ng hiÖnnhiÒu mµu h¬n b¹n sÏ cã mét s¬ ®å dµy ®Æc h¬n. B©y giê ta sÏ so s¸nh vØ m¹ch PIB víi vØ m¹ch VGA. §Ó lµm nh viÖcnµy b¹n sÏ ph¶i tÝnh ra mét b¶ng mµu cã cïng mét sè møc cña ®á, lôc,lam. NÕu c¸c mµu chÝnh cã 26 = 64 møc trªn VGA, b¹n cã thÓ chän c¸cmøc 0, 12, 24, 36, 48, vµ 60 cho tÊt c¶ c¸c mµu ®á, lôc, lam ®Ó x¸c lËp rab¶ng c©n b»ng mµu. V× vËy mµ ta cã tæng céng 6  6  6 = 216 mµu. B©ygiê ®a 216 mµu nµy vµo vØ m¹ch VGA. Khi tÝnh 32,680 mµu chochuyÓn ®æi 15 bit/ ®iÓm, b¹n nhãm 6 mµu l¹i víi nhau, ch¼ng h¹n, (R/6) 6 ,...v.v.., ë ®©y R,G,B lµ gi¸ trÞ nguyªn. NÕu ®îc biÓu diÔn ¶nh 5 bitmµu, b¹n cÇn nh©n kÕt qu¶ víi 2 ®Ó chuyÓn sang d¹ng 6 bit/mµu nhtrêng hîp t¬ng thÝch víi VGA. BiÕt R,G,B chóng ta cã thÓ tÝnh ®Þa chØcña b¶ng mµu dïng Address = (B/6+G+R6) / 2 M· ch¬ng tr×nh cho hiÖn s¬ ®å biÓu ®å trªn VGA nh vÝ dô trªn cho ëch¬ng tr×nh 11.2 237 Ch¬ng tr×nh 11.2 CHROMVGA.C. Displaying thechromaticity diagram on a VGA card./* Program for displaying chromaticitydiagram using a VGA. The program emulatesa video card capable of 15 bits/pixel.*/#include #include #include #include #include void main() { int xp,yp,l,R,G,B; unsigned i; float x,y,X,Y,Z,D; unsigned char a[648],b[648],display_mode,active_page; int color; char far *farptr; union REGS reg; struct SREGS sreg;clrscr(); /* Generate color palette. We assume 6 bits per color for VGA, and therefore the range will extend from 0 to 63per color. */l=0 ;for(R=0;Rdisplay_mode=reg.h.al;active_page=reg.h.bh;/* Setting display mode to 32Ox2OO. */reg.h.ah=0;reg.h.al=0x13;int86(0x10,®,®);/* Read color palette.*/reg.h.ah=0x10;reg.h.al=0x17;reg.x.bx=0;reg.x.cx=216;sreg.es=FP_SEG(b);reg.x.dx=FP_OFF(b);int86x(0x10,®,®,&sreg);/* Setting new color palette. */reg.h.ah=0x10;reg.h.al=0x12;reg.x.bx=0;reg.x.cx=216;sreg.es=FP_SEG(a);reg.x.dx=FP_OFF(a);int86x(0x10,®,®,&sreg);for(i=1;i> 5; G=(0x7C00 & i) >> 10; X=2.769*R+1.7518*G+1.1300*B; Y=R+4.5907*G+0.0601*B; Z=0.0565*G+5.5943*B; D=X+Y+Z; x=X/D; y=Y/D; xp=(int)(300.0*x+0.5); yp=(int)(190.0-y*190+0.5); /* Group every 6 colors in red, green and blue,i.e. (R/6)*6, and then multiply by 2 to spread the range from 0 to 63 (6-bits.) */ R=(R/6)*12; G=(G/6)*12; B=(B/6)*12; color=(B/6+G+R*6)/2; /* position in palette. */ reg.h.ah=0x0C; 239 reg.h.al=(char)color; reg.h.bh=0; reg.x.cx=xp; reg.x.dx=yp; int86(0x10,®,®); }getch();/* Restore previous color palette. */reg.h.ah=0x10;reg.h.al=0x12;reg.x.bx=0;reg.x.cx=216;sreg.es=FP_SEG(b);reg.x.dx=FP_OFF(b);int86x(0x10,®,®,&sreg);/* Restore previous mode and page. */ reg.h.ah=0x00; reg.h.al=display_mode; int86(0x10,®,®); reg.h.ah=0x05; reg.h.al=active_page; int86(0x10,®,®); }11.5 HiÓn thÞ ¶nh mµu trªn hÖ thèng mµu 15 bit vµ 8 bit PhÇn s¾p tíi chóng ta sÏ x©y dùng ch¬ng tr×nh cho hiÓn thÞ ¶nh vµ söal¹i mµu, ®é s¸ng ..., trªn vØ m¹ch PIB. Ch¬ng tr×nh còng bao gåm nÐn vµchøa ¶nh trªn mét file. Sau ®ã lµ mét ch¬ng tr×nh cho hiÓn thÞ ¶nh mµub»ng vØ m¹ch VGA. Ch¬ng tr×nh 11.3 DISPPIB.C. To display, freeze, and save animage on the PlB board./* Program for displaying images in live modethrough the PIB board. Through the program youcan adjust colors, brightness,etc..You are alsogiven the choices to freeze and save the imageto a file. */#include 240#include #include #include #include #include #define U_ARROW 0x48#define D_ARROW 0x50void main() { int ind,k1,k2,k3,k4,ind2,i; char a; char buff[1024],file_name[30]; FILE *fptro;clrscr();InitPIB();SetScreen(0);SetInDispMode();SetCamera(0);SetInterlace(0);SetLiveMode();k1=140; k2=126; k3=162; k4=44;SetHue(k1);SetContrast ...

Tài liệu có liên quan: