/* imvis.c imv1.bat = cl /AL imvis.c alb_elip vimage3 graphlib last update 11/25/91 by Russell A. Ambroziak, Ph. D. U. S. Geological Survey Office of Energy and Marine Geology National Center , STOP 915 Reston, VA 22092 Tel: 703-648-6168 Fax: 703-648-5464 FORMAT for PROJECTION DATA: (all entries must be present as shown below) Projection = Albers equal area eliptical 23.0 Lat0 29.5 Lat1 45.5 Lat2 -96.0 Lon0 -2630000 X0 3328046 Y0 2000 PixelSize (meters) 7 ellipsoid (Clark 1866) [0-10] */ #include #include #include #include #include #include #include "font.h" #define MAX_BUFF 32768 #define MENU_I 10 #define MENUXC 550 #define MENU_C 5 #define MENU_S 3 #define NUM_IMAGE 15 #define S_SIZE 40 #define F_SIZE 20 #define T_SIZE 15 #define PAUSE printf("HIT ANY KEY TO CONTINUE.\n");getch() #define MAX_LL 6 #define NUM_DP 100 #define STR_LEN 100 #define MAX_NUM 300 #define S_SIZE 40 #define NAME_SIZE 100 #define NUM_TYPE 25 #define NUM_SIZE 25 #define R 6367.40 #define PI 3.1415927 #define BLACK 0 #define D_GREY 1 #define L_GREY 2 #define WHITE 3 #define BUFF 4 #define L_BUFF 5 #define BROWN 6 #define RED 7 #define ORANGE 8 #define YELLOW 9 #define GREEN 10 #define D_GREEN 11 #define VD_GREEN 12 #define BLUE 13 #define D_BLUE 14 #define MAGENTA 15 char *UpDate="4/08/92"; int Mouse=0; char Group_Name[NUM_TYPE][30]; struct line_name { char filename[54]; float max_pix,min_pix; int color; }MapFile[NUM_TYPE][NUM_SIZE]; int Vector=0; int Ns[NUM_TYPE]; float MaxLat=180.0,MinLat=-180.0,MaxLon=360.0,MinLon=-360.0; extern char GF_String[MAX_NUM][S_SIZE]; int GF_Order[MAX_NUM]; long Hist[256],Delay; float Fhist[3][256],Fsum[3],Ftot[3]; struct file_id { char name[S_SIZE]; long size; unsigned date,time; }; extern struct file_id GF_File[300]; struct board { int row,col,color; }B_Id; int FontSize=2; char *menu_s[MENU_S]= { "display image", "cycle images", "exit set" }; struct navigation { int numlat,numlon,numx,numy; double B_Lat[MAX_LL],B_Lon[MAX_LL]; double B_Y[MAX_LL],B_X[MAX_LL]; }Nav; int NumPath=1; char Path[NUM_DP][STR_LEN]; char String[100]; int PathOn=0; int Num_Active_Image=1; char *LastFile; char *menu_l[NUM_IMAGE+1]= { "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 ", "\0 " }; char *menu_i[MENU_I]= {"zoom", /* 0 */ "change color", /* 1 */ "pixel info", /* 2 */ "output Targa file", /* 3 */ "histogram", /* 4 */ "Shade", /* 5 */ "smooth", /* 6 */ "boundary plot", /* 7 */ "rescale image", /* 8 */ "exit image" /* 9 */ }; char *menu_c[MENU_C]= {"change +/-,789,123","stretch RGB","reset","save new table","exit color"}; float Hue[256],Sat[256]; int Max[256],Mid[256],Min[256]; char VideoType='X'; int OneImage=0; char OneImageName[100]; int Black=0,White=191,Center=128,Num_Color=256; int D_Grey=46,L_Grey=191,M_Grey=128; int ScreenXs=640,ScreenYs=480; struct Color { unsigned char r, g, b; }; struct Color Vcolor[16]= { { 0, 0, 0}, { 46, 46, 46}, { 128,128,128}, { 255,255,255}, { 105, 90, 75}, { 130,111, 93}, { 96, 28, 14}, { 255, 0, 0}, { 255,128, 0}, { 160,160, 0}, { 0,200, 0}, { 0,120, 0}, { 0, 72, 0}, { 0, 0,200}, { 0, 20, 60}, { 255, 0,255} }; struct Color Blk={ 0, 0, 0}; struct Color D_G={ 46, 46, 46}; struct Color M_G={127,127,127}; struct Color L_G={191,191,191}; struct Color Wht={255,255,255}; unsigned char ActiveLut; struct image_header { int row,col; int sample; int record_bytes,file_records; int record_col_header; int row_col_header; long header_bytes; int imbedded_header; int sample_bits; int data_max,data_min; char infile[100],image[100],Lut[100],pal_type,label[100]; int vga_color[256]; struct Color lut[256],lutm[256],lutc[256]; }Hdr[NUM_IMAGE]; char ProjType; int P; double X0,Y0,PixelSize; /* Albers elip */ struct Color Qlut[256]; int Scale[NUM_IMAGE][256]; int Range[NUM_IMAGE][3],Reverse[NUM_IMAGE]; char Channel[3][100],ChannelOn=0; long Sample_Rate=1; int Img=0,Sample=1,Xc=0,Yc=0,Speed=16,Row,Col,ZoomSample=1,ScreenZoom=1; unsigned char Mbuff[MAX_BUFF],Ibuff[MAX_BUFF],Buffer[4096],OutBuff[1024][4]; int TgaHdr[9]={0,2,0,0,0,0,640,480,32}; unsigned char MaxHues[256][3]= { 255, 0, 0,255, 32, 0,255, 42, 0,255, 53, 0,255, 60, 0,255, 68, 0, 255, 73, 0,255, 80, 0,255, 84, 0,255, 90, 0,255, 94, 0,255,100, 0, 255,103, 0,255,108, 0,255,112, 0,255,116, 0,255,121, 0,255,124, 0, 255,128, 0,255,132, 0,255,135, 0,255,139, 0,255,143, 0,255,146, 0, 255,150, 0,255,154, 0,255,157, 0,255,161, 0,255,164, 0,255,168, 0, 255,172, 0,255,176, 0,255,179, 0,255,183, 0,255,186, 0,255,190, 0, 255,194, 0,255,198, 0,255,202, 0,255,206, 0,255,210, 0,255,214, 0, 255,218, 0,255,222, 0,255,227, 0,255,231, 0,255,236, 0,255,241, 0, 255,245, 0,255,250, 0,254,255, 0,249,255, 0,244,255, 0,240,255, 0, 234,255, 0,229,255, 0,224,255, 0,220,255, 0,214,255, 0,209,255, 0, 204,255, 0,199,255, 0,194,255, 0,190,255, 0,184,255, 0,179,255, 0, 174,255, 0,169,255, 0,164,255, 0,158,255, 0,152,255, 0,147,255, 0, 141,255, 0,135,255, 0,130,255, 0,123,255, 0,116,255, 0,109,255, 0, 102,255, 0, 94,255, 0, 87,255, 0, 78,255, 0, 68,255, 0, 58,255, 0, 42,255, 0, 23,255, 0, 0,255, 36, 0,255, 58, 0,255, 73, 0,255, 87, 0,255,101, 0,255,113, 0,255,125, 0,255,135, 0,255,146, 0,255,156, 0,255,166, 0,255,176, 0,255,186, 0,255,196, 0,255,204, 0,255,214, 0,255,224, 0,255,233, 0,255,243, 0,255,252, 0,248,255, 0,239,255, 0,230,255, 0,222,255, 0,214,255, 0,207,255, 0,200,255, 0,194,255, 0,187,255, 0,181,255, 0,174,255, 0,169,255, 0,163,255, 0,157,255, 0,152,255, 0,146,255, 0,141,255, 0,136,255, 0,131,255, 0,126,255, 0,121,255, 0,116,255, 0,111,255, 0,106,255, 0,101,255, 0, 96,255, 0, 92,255, 0, 86,255, 0, 81,255, 0, 77,255, 0, 71,255, 0, 66,255, 0, 60,255, 0, 53,255, 0, 48,255, 0, 39,255, 0, 32,255, 0, 23,255, 0, 0,255, 16, 0,255, 23, 0,255, 28, 0,255, 32, 0,255, 36, 0,255, 39, 0,255, 42, 0,255, 45, 0,255, 48, 0,255, 50, 0,255, 53, 0,255, 58, 0,255, 60, 0,255, 62, 0,255, 64, 0,255, 66, 0,255, 68, 0,255, 70, 0,255, 73, 0,255, 75, 0,255, 77, 0,255, 78, 0,255, 81, 0,255, 83, 0,255, 84, 0,255, 87, 0,255, 89, 0,255, 92, 0,255, 93, 0,255, 94, 0,255, 97, 0,255, 98, 0,255,101, 0,255,103, 0,255,105, 0,255, 107, 0,255,109, 0,255,111, 0,255,113, 0,255,115, 0,255,117, 0,255, 119, 0,255,122, 0,255,124, 0,255,126, 0,255,129, 0,255,131, 0,255, 134, 0,255,135, 0,255,138, 0,255,140, 0,255,143, 0,255,145, 0,255, 148, 0,255,151, 0,255,154, 0,255,156, 0,255,160, 0,255,163, 0,255, 166, 0,255,169, 0,255,173, 0,255,176, 0,255,179, 0,255,183, 0,255, 188, 0,255,192, 0,255,196, 0,255,200, 0,255,204, 0,255,209, 0,255, 214, 0,255,220, 0,255,225, 0,255,231, 0,255,237, 0,255,244, 0,255, 250, 0,255,255, 0,252,255, 0,245,255, 0,238,255, 0,231,255, 0,224, 255, 0,217,255, 0,210,255, 0,203,255, 0,196,255, 0,190,255, 0,183, 255, 0,176,255, 0,170,255, 0,163,255, 0,156,255, 0,151,255, 0,144, 255, 0,137,255, 0,131,255, 0,125,255, 0,118,255, 0,112,255, 0,105, 255, 0, 98,255, 0, 90,255, 0, 83,255, 0, 77,255, 0, 68,255, 0, 60, 255, 0, 50,255, 0, 42,255, 0, 28,255, 0, 23 }; char SubType[20]; unsigned char getpt(); int set_lut(); double clat(); double clon(); double cx(); double cy(); char fsplit(char *,char *,char *,char *); FILE *open_to_read_binary(char *); FILE *open_to_read_text(char *); FILE *open_to_write_text(char *); FILE *open_to_write_binary(char *); long set_time(long); char set_point(); char change_range(); main(argc,argv) int argc; char *argv[]; { int i,i1,j,k; char string[100],ans; int numfile,scan=0; FILE *fp; char pathbuffer[101]; long li; Delay=set_time((long)10000); if(argc>1) { for(i=1;i0;i--) strcpy(Path[i],Path[i-1]); NumPath+=1; /* add '?mp\' to a new set of Paths */ for(i=2;i0) { video_on(); set_lut('G'); for(i1=0;i10) set_lut(Hdr[0].pal_type); else { if(set_lut('P',Hdr[0].Lut)<0) set_lut('G'); } Row=Hdr[0].row; Col=Hdr[0].col; Sample=0; do { Sample+=1; Row=Hdr[0].row/Sample; Col=Hdr[0].col/Sample; }while(Col>ScreenXs||Row>ScreenYs); fp=open_to_read_binary(Hdr[0].image); if(fp) { if(plot_full_image(fp,Sample,0)<0) break; fclose(fp); plot_font_h(White,2,2,Hdr[0].image,FontSize,Font); for(li=0;li=0) break; if(numfile<0&&i==NumPath-1) { printf("\n\nHit 'Esc' to quit\n"); printf("Any other key to continue\n\n"); if(getch()==27) exit(0); i=-1; } } } strcpy(Hdr[Img].label,Hdr[Img].infile); if(numfile>=0) { for(k=0;k=0&&OneImage==0); } /************************************************************************** ** ** ** ************************************************************************* */ int video_on() { int i,ret; i=GetVideoBoardID(); if(i==0) VideoType='E'; if(i==1&&(VideoType=='X'||VideoType=='Y')) VideoType='S'; if(i<0) { printf("Computer will not support enough colors.\n\n"); exit(0); } if(VideoType=='X') { SetVideoMode(480,&B_Id); if(B_Id.row==480) { set_lut('G'); strcpy(SubType,".xmg"); } else { if(i>1) VideoType='Y'; else if(i==1) VideoType='V'; else if(i==0) VideoType='E'; } } if(VideoType=='V') { ret=SetVideoMode(0x12,&B_Id); strcpy(SubType,".vmg"); } if(VideoType=='Y') { ret=SetVideoMode(400,&B_Id); strcpy(SubType,".ymg"); } if(VideoType=='S') { ret=SetVideoMode(0x13,&B_Id); set_lut('G'); strcpy(SubType,".smg"); FontSize=3; } if(VideoType=='E') { ret=SetVideoMode(0x10,&B_Id); strcpy(SubType,".emg"); } ScreenXs=B_Id.col; ScreenYs=B_Id.row; Num_Color=B_Id.color; if(ret>=0) return(1); else { SetVideoMode(0,&B_Id); printf("Could not boot video board\n\n"); exit(0); } } /*********************************************************************** ** ** ** ** ************************************************************************/ int tip(img) { } /*********************************************************************** ** ** ** ** ************************************************************************/ long set_time(delay) long delay; { int i,j,k; struct timeb t1,t2; long li,ds,dm,dt; ftime(&t1); for(li=0;li0) { delay=3000*delay; delay/=dt; } return(delay); } /*********************************************************************** ** ** ** ** ************************************************************************/ int process_set() { int i,j,k; char ans,choice[100],string[100]; int val,val2; FILE *fp; int sample=0,smp; int num=0; long li; int r,g,b; char *fstring[NUM_IMAGE],points[50]; long lpoints; int row=Hdr[0].row,col=Hdr[0].col; for(k=0;k<3;k++) { Range[k][0]=0; Range[k][1]=127; Range[k][2]=255; } if(VideoType=='X'||VideoType=='Y'||VideoType=='S') strcpy(GF_String[num++],"display quick color"); strcpy(GF_String[num++],"make 8-bit color image"); strcpy(GF_String[num++],"make RGB composit file"); if(VideoType=='X'||VideoType=='Y'||VideoType=='S') strcpy(GF_String[num++],"scale image set"); strcpy(GF_String[num++],"scan set -- full image"); if(row>ScreenYs||col>ScreenXs) strcpy(GF_String[num++],"scan set -- sub image"); strcpy(GF_String[num++],"x -- exit set"); for(i=0;iScreenXs||Row>ScreenYs); if(Hdr[i].pal_type>0) set_lut(Hdr[i].pal_type); else { if(set_lut('P',Hdr[i].Lut)<0) set_lut('G'); } for(i=0;i0) { printf("Input Images:\n"); printf(" RED -- '%s'\n",Hdr[r].image); printf(" GREEN -- '%s'\n",Hdr[g].image); printf(" BLUE -- '%s'\n",Hdr[b].image); printf("Give output image file name.\n\n"); scanf("%s",string); printf("Give sample rate. ( 1 = full res 2 = 1/2 size etc.)\n"); scanf("%d",&smp); if(strcmpi(choice,"make 8-bit color image")==0) { lpoints=(long)Hdr[0].row*(long)Hdr[0].col; lpoints/=25000; if(lpoints<10) lpoints=10; sprintf(points,"%ld",lpoints); printf("Making 24 bit image file -- 'imvis.cmg'"); printf(" and info file 'imvis.chn'\n"); make_cmg_image(r,g,b,smp,"imvis"); fcloseall(); execlp("img8bit.exe","img8bit","imvis",string,"5", "/m",points,"/c","240",NULL); } else { printf("Making 24 bit image file -- '%s.cmg'\n",string); printf(" and info file '%s.chn'\n",string); make_cmg_image(r,g,b,smp,string); fcloseall(); } } } } if(strcmpi(choice,"display quick color")==0) { ClearBox(40,79,0,0,7); sprintf(string,"Choose RED plane image"); WriteStringAtxy(40,0,39,(char)4,string); r=scroll_any_list(40,1,40,21,fstring,Num_Active_Image,string, 71,4,14,63,7); if(r<0) return(0); sprintf(string,"Choose GREEN plane image"); WriteStringAtxy(40,0,39,(char)2,string); g=scroll_any_list(40,1,40,21,fstring,Num_Active_Image,string, 32,2,14,63,7); if(g<0) return(0); sprintf(string,"Choose BLUE plane image"); WriteStringAtxy(40,0,39,(char)23,string); b=scroll_any_list(40,1,40,21,fstring,Num_Active_Image,string, 23,1,14,63,7); if(b<0) return(0); ClearScreen(0x7); printf("Your choices are:\n\n"); printf(" RED -- '%s'\n",Hdr[r].image); printf(" GREEN -- '%s'\n",Hdr[g].image); printf(" BLUE -- '%s'\n",Hdr[b].image); printf("\nIs this what you want? (y or n)\n\n"); ans=getch(); if(ans=='y') { load_quick_color_image(r,g,b); getch(); SetVideoMode(0,&B_Id); } } if(strcmpi(choice,"scan set -- full image")==0) { video_on(); set_lut('G'); for(i=0;i=0&&strcmpi(choice,"x -- exit set")!=0); } /*********************************************************************** ** ** ** ** ************************************************************************/ int scale_rgb(r,g,b) int r,g,b; { int i,j,k,m,n; int num=0,val,c[3]; char string[100],choice[100],ans; float point[3]; FILE *fp; int dn,num_item,ispeed=2; float speed=0.05; char *fstring[10]; int row=Hdr[0].row,col=Hdr[0].col,aimg=0; point[0]=0.05; point[1]=0.50; point[2]=0.95; strcpy(GF_String[num++],"Use Current Parameters"); strcpy(GF_String[num++],"Histogram from full image files"); if(row>ScreenYs||col>ScreenXs) strcpy(GF_String[num++],"Histogram from Sub Images"); strcpy(GF_String[num++],"Input Scale Parameters"); strcpy(GF_String[num++],"Exit Scale Option"); print_range(r,g,b,point,0); for(j=0;j<256;j++) { Scale[r][j]=j; Scale[g][j]=j; Scale[b][j]=j; } do { c[0]=r;c[1]=g,c[2]=b; val=scroll_list_color(40,1,40,21,GF_String,num,choice,63,124,14,63,3); if(strcmpi(choice,"Use Current Parameters")==0) { scale(r); scale(g); scale(b); return(1); } if(strcmpi(choice,"Histogram from full image files")==0) { if(load_Fhist("full",c)<0) return(-1); set_Range(point,c); SetCursor(0,3); print_range(r,g,b,point,1); scale(r); scale(g); scale(b); } if(strcmpi(choice,"Histogram from Sub Images")==0) { if(load_Fhist("sub",c)<0) return(-1); set_Range(point,c); SetCursor(0,3); print_range(r,g,b,point,1); scale(r); scale(g); scale(b); } /* set scaling for histogram */ if(strcmpi(choice,"Histogram from full image files")==0|| strcmpi(choice,"Histogram from Sub Images")==0) { fstring[0]="Use as is"; fstring[1]="Change table"; fstring[2]="Change image"; num_item=3; ClearBox(40,79,0,0,3); sprintf(string,"Choose an Option"); WriteStringAtxy(40,0,39,(char)4,string); scroll_any_list(40,1,40,21,fstring,num_item,string, 63,4,14,63,7); if(strcmpi(string,"Change table")==0) { do { ans=set_point(point,&speed); set_Range(point,c); SetCursor(0,3); print_range(r,g,b,point,1); }while(ans!=13&&ans!=27); if(ans!=27) { scale(r); scale(g); scale(b); } } for(i=0;i<16;i++) { Qlut[i].r=Vcolor[i].r; Qlut[i].g=Vcolor[i].g; Qlut[i].b=Vcolor[i].b; } if(strcmpi(string,"Change image")==0) { for(i=0;i<64;i++) { for(k=0;k<3;k++) { Qlut[i+(k+1)*64].r=i*4; Qlut[i+(k+1)*64].g=i*4; Qlut[i+(k+1)*64].b=i*4; } } video_on(); WritePalette(Qlut); plot_image(r,0,0,64,RED); plot_image(g,ScreenXs/2,0,128,GREEN); plot_image(b,0,ScreenYs/2,192,BLUE); plot_Range(ScreenXs/2,ScreenYs/2,c,aimg); getch(); point[0]=0.01;point[1]=0.50;point[2]=0.99; set_Range(point,c); scale(r); scale(g); scale(b); for(i=0;i<64;i++) { for(k=0;k<3;k++) { Qlut[i+(k+1)*64].r=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].g=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].b=Scale[c[k]][i*4]; } } WritePalette(Qlut); do { ans=change_range(&aimg,c,&ispeed); if(ans=='r'||ans=='R') { set_Range(point,c); scale(r); scale(g); scale(b); for(i=0;i<64;i++) { for(k=0;k<3;k++) { Qlut[i+(k+1)*64].r=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].g=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].b=Scale[c[k]][i*4]; } } } else { scale(c[aimg]); k=aimg; for(i=0;i<64;i++) { Qlut[i+(k+1)*64].r=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].g=Scale[c[k]][i*4]; Qlut[i+(k+1)*64].b=Scale[c[k]][i*4]; } } WritePalette(Qlut); plot_Range(ScreenXs/2,ScreenYs/2,c,aimg); }while(ans!=27); SetVideoMode(0,&B_Id); } } }while(val>=0&&strcmpi(choice,"Exit Scale Option")!=0); return(1); } /*********************************************************************** ** ** ** ** ************************************************************************/ char change_range(img,c,speed) int *img,*c,*speed; { int i,j,k=*img; char ans; ans=getch(); if(ans=='n'||ans=='N') { if(Reverse[c[k]]==0) Reverse[c[k]]=1; else Reverse[c[k]]=0; } if(ans==13) { if(k<2) k+=1; else k=0; } if(ans==8) { if(k>0) k-=1; else k=2; } if(ans==0) { ans=getch(); if(ans==71)Range[c[k]][0]+=*speed; if(ans==72)Range[c[k]][1]+=*speed; if(ans==73)Range[c[k]][2]+=*speed; if(ans==79)Range[c[k]][0]-=*speed; if(ans==80)Range[c[k]][1]-=*speed; if(ans==81)Range[c[k]][2]-=*speed; } else { if(ans=='7')Range[c[k]][0]+=*speed; if(ans=='8')Range[c[k]][1]+=*speed; if(ans=='9')Range[c[k]][2]+=*speed; if(ans=='1')Range[c[k]][0]-=*speed; if(ans=='2')Range[c[k]][1]-=*speed; if(ans=='3')Range[c[k]][2]-=*speed; } for(i=0;i<3;i++) { if(Range[c[k]][i]<0)Range[c[k]][i]=0; if(Range[c[k]][i]>255)Range[c[k]][i]=255; } if(ans=='+'&&*speed<16) *speed*=2; if(ans=='-'&&*speed>1) *speed/=2; *img=k; return(ans); } /*********************************************************************** ** ** ** ************************************************************************/ int plot_Range(xc,yc,c,on) int xc,yc,*c,on; { int i,j,k; int xs=ScreenXs/2,ys=ScreenYs/2; char string[100]; int color[3]; color[0]=RED;color[1]=GREEN;color[2]=BLUE; for(k=0;k<3;k++) { if(Reverse[c[k]]==0) sprintf(string,"%3d %3d %3d ", Range[c[k]][0],Range[c[k]][1],Range[c[k]][2]); else sprintf(string,"%3d %3d %3d N", Range[c[k]][0],Range[c[k]][1],Range[c[k]][2]); if(on==k) { paint_box(0,BLACK,Mbuff,xc+3,yc+3+k*45/FontSize, strlen(string)*15/FontSize+10,32/FontSize); box(0,xc+3,yc+3+k*45/FontSize,WHITE, strlen(string)*15/FontSize+19,32/FontSize-1); } else paint_box(0,D_GREY,Mbuff,xc+3,yc+3+k*45/FontSize, strlen(string)*15/FontSize+20,32/FontSize); plot_font_h(color[k],xc+10,yc+5+k*45/FontSize,string,FontSize,Font); } } /*********************************************************************** ** ** ** ** ************************************************************************/ char set_point(point,speed) float *point,*speed; { int k; char ans; ans=getch(); if(ans==0) { ans=getch(); if(ans==71)point[0]+=*speed; if(ans==72)point[1]+=*speed; if(ans==73)point[2]+=*speed; if(ans==79)point[0]-=*speed; if(ans==80)point[1]-=*speed; if(ans==81)point[2]-=*speed; } else { if(ans=='7')point[0]+=*speed; if(ans=='8')point[1]+=*speed; if(ans=='9')point[2]+=*speed; if(ans=='1')point[0]-=*speed; if(ans=='2')point[1]-=*speed; if(ans=='3')point[2]-=*speed; } for(k=0;k<3;k++) { if(point[k]<0.001)point[k]=0.001; if(point[k]>1.000)point[k]=1.000; } if(ans=='+'&&*speed<0.1) *speed*=2.0; if(ans=='-'&&*speed>0.01) *speed/=2.0; return(ans); } /*********************************************************************** ** ** ** ***********************************************************************/ int set_Range(point,c) float *point; int *c; { int i,j,k; int dn; for(k=0;k<3;k++) { Fsum[k]=0.0; Range[c[k]][0]=Range[c[k]][1]=Range[c[k]][2]=-1; for(dn=0;dn<256;dn++) { Fsum[k]+=Fhist[k][dn]/Ftot[k]; for(i=0;i<3;i++) if(Range[c[k]][i]<0&&Fsum[k]>=point[i]) Range[c[k]][i]=dn; } } } /*********************************************************************** ** ** ** ***********************************************************************/ int load_Fhist(type,c) char *type; int *c; { int i,j,k,m,n; int dn,row,col; char string[100],cr=0xd; FILE *fp; for(k=0;k<3;k++) { for(dn=0;dn<256;dn++) Fhist[k][dn]=0; Ftot[k]=0; if(strcmpi(type,"full")==0) { strcpy(string,Hdr[c[k]].image); if(strlen(string)<1) { printf("Bad file name -- too short!\n\n"); return(-1); } if(strlen(string)>99) { printf("Bad file name -- too long!\n\n"); exit(0); } fp=open_to_read_binary(string); if(!fp) { printf("Could not find '%s'.\n",string); return(-1); } row=Hdr[0].row; col=Hdr[0].col; fseek(fp,Hdr[0].header_bytes,SEEK_SET); } else if(strcmpi(type,"sub")==0) { strcpy(string,Hdr[c[k]].image); if(strlen(string)<1) { printf("Bad file name -- too short!\n\n"); return(-1); } if(strlen(string)>99) { printf("Bad file name -- too long!\n\n"); exit(0); } for(m=0;mScreenYs||col>ScreenXs) /* use sample image */ { strcpy(string,Hdr[img].image); for(k=0;k1) { fseek(fpred,offset,SEEK_CUR); fseek(fpgrn,offset,SEEK_CUR); fseek(fpblu,offset,SEEK_CUR); for(j=0;jScreenXs||Row>ScreenYs); Hdr[filenum].sample=sample; fcloseall(); plot_full_qc_image(sample,r,g,b,qr,qg,qb); /* if(sample>1) { sample=ZoomSample; if(limit_area_fixed(&Xc,&Yc,&xs,&ys,&Speed,&sample)!=27) { ZoomSample=sample; plot_sub_qc_image(fp,sample,filenum); } else { ZoomSample=Sample; } } */ } /************************************************************************** ** ** ** ************************************************************************* */ int plot_full_qc_image(sample,r,g,b,qr,qg,qb) int sample,r,g,b,qr,qg,qb; { int i,j,k; int ir,ig,ib; long offset; char string[100]; int row,col,val,filenum=0; FILE *fpsubr,*fpsubg,*fpsubb,*fpr,*fpg,*fpb; int dr=255/qr+1,dg=255/qg+1,db=255/qb+1; int xr=255/(qr-1),xg=255/(qg-1),xb=255/(qg-1); unsigned offsetr,offsetg,offsetb; strcpy(string,Hdr[r].image); for(i=0;i0) { val=getch(); if(val==27) return(-2); } for(j=0;j0) fseek(fpr,offset,SEEK_SET); offset=Hdr[g].header_bytes; if(offset>0) fseek(fpg,offset,SEEK_SET); offset=Hdr[b].header_bytes; if(offset>0) fseek(fpb,offset,SEEK_SET); offset=(sample-1); offset*=Hdr[r].col; for(i=0;i0) { val=getch(); if(val==27) return(-2); } if(offset>0) { fseek(fpr,offset,SEEK_CUR); fseek(fpg,offset,SEEK_CUR); fseek(fpb,offset,SEEK_CUR); } if(sample>1) { for(j=0;jnum-1) { n2=num-1; n1=n2-(nlines-1); } /* 3 */ ClearBox(x1+1,x2-1,y1+1,y2+2,menu); DoubleBox(xc,xc+xs-1,yc,yc+ys-1,box); WriteStringAtxy(x1,y2+2,xs,highlight,"'Esc'=Quit 'Enter'=Choose file"); for(i=0;i='a'&&ans<='z')||(ans>='A'&&ans<='Z')) { n=0; i=1; instring[0]=ans; instring[1]='\0'; ClearBox(x1,x2,y2+1,y2+1,3); WriteStringAtxy(x1,y2+1,xs,highlight,instring); do { if(i>0) { for(j=n;j=0) { n=j; if(strnicmp(instring,string[j],i)==0) break; } else break; } n1=n-nlines/2; if(n1<0)n1=0; n2=n1+nlines-1; if(n2>num-1) { n2=num-1; n1=n2-(nlines-1); } ClearBox(x1+1,x2-1,y1+1,y2-1,menu); for(j=0;j31&&ansc<127) { instring[i]=ansc; i+=1; instring[i]='\0'; ClearBox(x1,x2,y2+1,y2+1,menu); WriteStringAtxy(x1,y2+1,xs,highlight,instring); } if(ansc==8) { n=0; if(i>0) { i-=1; instring[i]='\0'; ClearBox(x1,x2,y2+1,y2+1,menu); WriteStringAtxy(x1,y2+1,xs,highlight,instring); } } }while(ansc!=13&&ansc!=27&&ansc!=83&&ans!=82); if(ansc==27||ansc==83||ansc==82) ans=ansc; ClearBox(x1,x2,y2+1,y2+1,menu); } /* 1 */ if(ans==0) { ans=getch(); WriteStringAtxy(xc+1,yc+1+(n-n1),xs-2,menu,string[n]); if(ans==80&&n0) /* 8 */ n-=1; if(n>n2) { n2=n; n1=n2-(nlines-1); ScrollUp(1,x1+1,x2-1,y1+1,y2-1,menu); } if(n0&&n==n1) { n1-=nlines; if(n1<0)n1=0; n2=n1+nlines-1; n=n1; ClearBox(x1+1,x2-1,y1+1,y2-1,menu); for(i=0;in1) n=n1; } if(ans==71) { if(n1>0) { n1=0; n2=n1+nlines-1; n=0; ClearBox(x1+1,x2-1,y1+1,y2-1,menu); for(i=0;i0) n=0; } if(ans==81) { if(n2num-1)n2=num-1; n1=n2-(nlines-1); n=n2; ClearBox(x1+1,x2-1,y1+1,y2-1,menu); for(i=0;imax) max=Hist[k]; if(max<150000)del=25000; if(max< 75000)del=12500; if(max< 37500)del= 5000; if(max< 18750)del= 2500; if(max< 9375)del= 2000; if(max< 2344)del= 500; if(max< 1172)del= 200; if(max< 586)del= 100; if(max< 293)del= 50; if(max< 146)del= 25; if(max< 73)del= 10; if(max< 36)del= 5; if(max< 18)del= 2; if(max< 9)del= 1; for(lk=0;lk=bxs) x=bxs-1-strlen(string)*csize; plot_font_h(White,bxc+x,byc+bys+4,string, size,Font); } for(k=Hdr[img].data_min;k<=Hdr[img].data_max;k++) { fval=Hist[k]; fval*=bys; fval/=(float)max; y=fval; fval=k; fval*=bxs; fval/=(float)(Hdr[img].data_max-Hdr[img].data_min+1); x=fval; plotln(0,bxc+x,byc+bys-y,bxc+x,byc+bys,val); } } /************************************************************************** ** ** ** ************************************************************************* */ int add_disk_path(string) char *string; { int i,j,k; char dsk,pth[STR_LEN],nam[10],typ[10],str[STR_LEN]; int match,add=0; dsk=fsplit(string,pth,nam,typ); if(dsk>0) sprintf(str,"%c:%s",dsk,pth); else sprintf(str,"%s",pth); if((dsk>0||strlen(pth)>0)&&NumPath0) { offset=Hdr[filenum].header_bytes; fseek(fp,offset,SEEK_SET); } do { Sample=sample+=1; Row=Hdr[filenum].row/sample; Col=Hdr[filenum].col/sample; offset=(sample-1); offset*=Hdr[filenum].col; }while(Col>ScreenXs||Row>ScreenYs); ScreenZoom=Hdr[filenum].sample=sample; if(Hdr[filenum].pal_type>0) set_lut(Hdr[filenum].pal_type); else { if(set_lut('P',Hdr[filenum].Lut)<0) set_lut('G'); } ret=plot_full_image(fp,sample,filenum); fclose(fp); return(ret); } /************************************************************************** ** ** ** ************************************************************************* */ int open_image(fp,filenum) FILE *fp; int filenum; { fp=open_to_read_binary(Hdr[filenum].image); if(!fp) return(-1); return(1); } /************************************************************************** ** ** ** ************************************************************************* */ int split(string,path,name,type) char *string,*path,*name,*type; { int i,j,k; int dot=-1,last_slash=-1,len=strlen(string),num=0; for(i=0;i0) { for(i=0;i0) num+=1; if(strlen(type)>0) num+=1; return(num); } /************************************************************************** ** ** ** ************************************************************************* */ int process_image(filenum) int filenum; { int i,j,k; int num=0; int ix=ScreenXs/2,iy=ScreenYs/2,speed=16/(FontSize-1); FILE *fpout; char string[100],ans,string1[100],string2[100]; int val; int xc=0,yc=0,xs,ys,sample=0,scale=1; int bxc,byc,bxs,bys,wxc,wyc,wxs,wys; int npt=Hdr[filenum].data_max-Hdr[filenum].data_min+1; int chigh=24/FontSize,cwide=15/FontSize; int contrast; bxs= npt/(FontSize-1)+45/(FontSize+1); bxc=ScreenXs-(npt/(FontSize-1)+45/(FontSize+1)+1); bys= 128/(FontSize-1)+30/(FontSize+1)+4; byc=ScreenYs-(128/(FontSize-1)+30/(FontSize+1)+5); wys=wxs=wyc=wxc=ScreenYs/6; /* ZoomSample=1;*/ if(load_image(filenum)<0) return(-1); do { num=do_menu_buff(menu_i,MENU_I,MENUXC,25,num,D_Grey,L_Grey,White,Font); if(num==0) { /* ZoomSample=1;*/ load_image(filenum); } if(num==1) { Img=filenum; if(change_color()==0) { /* ZoomSample=1;*/ return(0); } } if(num==2) { pixel_locate(&ix,&iy,&speed,filenum); } if(num==4) { sprintf(string,"Size and Place graph on screen"); xc=yc=5; ys=20;xs=(strlen(string)+2)*7; save_sub_mem(xc,yc,xs,ys); paint_box(0,D_Grey,Buffer,xc,yc,xs,ys); plot_font_h(White,xc+7,yc+4,string,2,Font); limit_area_all(&bxc,&byc,&bxs,&bys,&speed,ScreenXs,ScreenYs, 1,Buffer,Black,White,Center); paint_box(0,Black,Buffer,bxc,byc,bxs,bys); box(0,bxc,byc,D_Grey,bxs-1,bys-1); recall_sub_mem(xc,yc,xs,ys); do { if(VideoType=='S') sprintf(string,"area to process + 'Enter': 'Esc' to exit)"); else sprintf(string, "Limit area to process for Histogram ('Enter' to Process 'Esc' to exit)"); xc=yc=0; ys=40/FontSize; xs=(strlen(string)+2)*cwide; save_sub_mem(xc,yc,xs,ys); paint_box(0,D_Grey,Buffer,xc,yc,xs,ys); plot_font_h(White,xc+cwide,yc+1,string,FontSize,Font); ans=limit_area_all(&wxc,&wyc,&wxs,&wys,&speed,ScreenXs,ScreenYs, 1,Buffer,Black,White,Center); recall_sub_mem(xc,yc,xs,ys); if(ans!=27&&wxs>4&&wys>4) { paint_box(0,Black,Buffer,bxc,byc,bxs,bys); box(0,bxc,byc,D_Grey,bxs-1,bys-1); histo(wxc,wyc,wxs,wys,bxc,byc,bxs,bys,White,filenum); } }while(ans!=27); paint_box(0,Black,Buffer,bxc,byc,bxs,bys); } if(num==3) { k=0; do { if(k>0) fclose(fpout); sprintf(string,"imvis%d.tga",k++); fpout=open_to_read_binary(string); }while(fpout); fclose(fpout); fpout=open_to_write_binary(string); if(!fpout) { SetVideoMode(0,&B_Id); printf("Could not open output file.\n\n"); exit(0); } TgaHdr[6]=ScreenXs; TgaHdr[7]=ScreenYs; fwrite((char *)TgaHdr,sizeof(int),9,fpout); for(i=0;i1) speed/=2.0; for(k=0;k<3;k++) { if(Range[0][k]<0) Range[0][k]=0; if(Range[0][k]>255) Range[0][k]=255; } if(Range[0][1]=n1&&buffer[i%3][j]<=n2) { sum=num=0; for(m=-1;m<=1;m++) { for(n=-1;n<=1;n++) { if(buffer[(i+m)%3][j+n]>=n1&&buffer[(i+m)%3][j+n]<=n2) { sum+=buffer[(i+m)%3][j+n]; num+=1; } } } if(num>1) buffer[3][j]=sum/num; } } plotrow(0,1,ScreenXs-2,i,buffer[3]+1); } } /*********************************************************************** ** ** ** ** ************************************************************************/ int shade(img,scale) int img,scale; { int i,j,k; int j1,j2; int n1=Hdr[img].data_min,n2=Hdr[img].data_max,num=n2-n1; int val,val1,val2,mid=n1+num/2; for(i=0;i<256;i++) { Hdr[img].lutc[i].r=Hdr[img].lut[i].r; Hdr[img].lutc[i].g=Hdr[img].lut[i].g; Hdr[img].lutc[i].b=Hdr[img].lut[i].b; } for(i=n1;i<=n2;i++) { val=i-n1; val*=255; val/=num; Hdr[img].lutc[i].r=Hdr[img].lutc[i].g=Hdr[img].lutc[i].b=val; } WritePalette(Hdr[Img].lutc); for(i=0;in2) val1=0; val2=Buffer[j+1]; if(val2n2) val2=0; val=val2-val1; val*=scale; val+=mid; if(valn2) val=n2; Buffer[j]=val; } plotrow(0,0,ScreenXs-1,i,Buffer); } } /*********************************************************************** ** ** ** ** ************************************************************************/ int set_mmll() { double lat,lon,x,y; double mxlt=-180.0,mnlt=180.0,mxln=-360.0,mnln=360.0; int n_pole=0,s_pole=0,ix,iy; /* check for N Pole */ lat=90.0;lon=0.0; ll_xy(&x,&y,lat,lon); ix=x;iy=y; if(ix>=0&&ix=0&&iy=0&&ix=0&&iymxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(latmxlt)mxlt=lat;if(lon>mxln)mxln=lon; if(lat=MapFile[i][j].min_pix) { strcpy(string,MapFile[i][j].filename); strcat(string,".bin"); fp=open_to_read_binary(string); strcpy(string,MapFile[i][j].filename); strcat(string,".hdr"); fphdr=open_to_read_binary(string); if(fp&&fphdr) { val=MapFile[i][j].color; fread((char *)&numsec,sizeof(int),1,fp); fread((char *)&numsec,sizeof(int),1,fphdr); for(k=0;k0) { fclose(fp); fclose(fphdr); val=getch(); if(val==27) return(-2); } fread((char *)&offset,sizeof(long),1,fphdr); fread((char *)mll,sizeof(float),4,fphdr); doit=1; mnln=mll[0];mxln=mll[1];mnlt=mll[2];mxlt=mll[3]; if(mnln>MaxLon||mnlt>MaxLat||mxln0) { if((ix =0&&iy =0)|| (ixo=0&&iyo=0)) plotln(0,ix,iy,ixo,iyo,val); } ixo=ix; iyo=iy; } } } } fclose(fphdr); fclose(fp); } } } }while(num2048) ccolor=Black; else ccolor=White; tcursor(0,*x,*y,csize,buffer); cursor(0,*x,*y,ccolor,csize); paint_box(0,Black,buff,0,ScreenYs-35,121,35); sprintf(string,"x=%3d y=%3d",*x,*y); plot_font_h(White,2,ScreenYs-33,string,2,Font); do { ans=getch(); if(ans=='-'&&*speed>1) *speed/=2; if(ans=='+'&&*speed=ScreenXs) *x=ScreenXs-1; if(*y<0) *y=0; if(*y>=ScreenYs) *y=ScreenYs-1; uncursor(0,xo,yo,csize,buffer); cval=getpt(0,*x,*y); if(((int)Hdr[Img].lut[cval].r*10+ (int)Hdr[Img].lut[cval].g*8+(int)Hdr[Img].lut[cval].b*2)>2048) ccolor=Black; else ccolor=White; tcursor(0,*x,*y,csize,buffer); cursor(0,*x,*y,ccolor,csize); paint_box(0,Black,buff,0,ScreenYs-35,221,35); val=getpt(0,*x,*y); fx=(float)(*x-x1)*delx; fy=(float)(*y-x1)*dely; sprintf(string,"x=%3d y=%3d fx=%0.5f fy=%0.5f",*x,*y,val,fx,fy); plot_font_h(White,2,ScreenYs-33,string,2,Font); ix=Xc*Sample+*x*ZoomSample; iy=Yc*Sample+*y*ZoomSample; sprintf(string,"%5d %5d",ix,iy); plot_font_h(White,2,ScreenYs-16,string,2,Font); xo=*x; yo=*y; } }while(ans!=27&&ans!=13); uncursor(0,xo,yo,csize,buffer); paint_box(0,Black,buff,0,ScreenYs-33,121,30); } /*********************************************************************** ** ** ** ** ************************************************************************/ int get_xy(x,y,speed,imgx,imgy) int *x,*y,*speed,*imgx,*imgy; { char ans,ans2; int cval,ccolor,csize=6; int ix,iy,xo,yo; do { ans=getch(); if(ans=='-'&&*speed>1) *speed/=2; if(ans=='+'&&*speed=ScreenXs) *x=ScreenXs-1; if(*y<0) *y=0; if(*y>=ScreenYs) *y=ScreenYs-1; uncursor(0,xo,yo,csize,Buffer); cval=getpt(0,*x,*y); if(((int)Hdr[Img].lut[cval].r*10+ (int)Hdr[Img].lut[cval].g*8+(int)Hdr[Img].lut[cval].b*2)>2048) ccolor=Black; else ccolor=White; tcursor(0,*x,*y,csize,Buffer); cursor(0,*x,*y,ccolor,csize); ix=Xc*Sample+*x*ZoomSample; iy=Yc*Sample+*y*ZoomSample; xo=*x; yo=*y; } }while(ans!=27&&ans!=13); uncursor(0,xo,yo,csize,Buffer); *imgx=ix; *imgy=iy; } /******************************************************************** ** ** ** ********************************************************************* */ int video_off() { SetVideoMode(0,&B_Id); } /******************************************************************** ** ** ** ********************************************************************* */ int pixel_locate(x,y,speed,img) int *x,*y,*speed; { char ans,ans2,string[100],string2[100]; unsigned char buffer[100],buff[640]; int csize=6,xo=*x,yo=*y,ix,iy,val; int cval,ccolor; unsigned char r,g,b; long offset,lx,ly,row=Hdr[img].row,col=Hdr[img].col; FILE *fpr,*fpg,*fpb; int sample=ScreenZoom,nsample=ScreenZoom*-1+2; if(ChannelOn==1) /* RGB channel file names available */ { fpr=fopen(Channel[0],"rb"); fpg=fopen(Channel[1],"rb"); fpb=fopen(Channel[2],"rb"); if(!fpr||!fpg||!fpb) ChannelOn=0; /* at least one file missing */ } cval=getpt(0,*x,*y); if(((int)Hdr[Img].lut[cval].r*10+ (int)Hdr[Img].lut[cval].g*8+(int)Hdr[Img].lut[cval].b*2)>2048) ccolor=Black; else ccolor=White; tcursor(0,*x,*y,csize,buffer); cursor(0,*x,*y,ccolor,csize); paint_box(0,Black,buff,0,ScreenYs-35,ScreenXs,35); sprintf(string,"x=%3d y=%3d",*x,*y); plot_font_h(White,2,ScreenYs-33,string,2,Font); do { ans=getch(); if(ans=='-'&&*speed>1) *speed/=2; if(ans=='+'&&*speed=ScreenXs) *x=ScreenXs-1; if(*y<0) *y=0; if(*y>=ScreenYs) *y=ScreenYs-1; uncursor(0,xo,yo,csize,buffer); cval=getpt(0,*x,*y); if(((int)Hdr[Img].lut[cval].r*10+ (int)Hdr[Img].lut[cval].g*8+(int)Hdr[Img].lut[cval].b*2)>2048) ccolor=Black; else ccolor=White; tcursor(0,*x,*y,csize,buffer); cursor(0,*x,*y,ccolor,csize); paint_box(0,Black,buff,0,ScreenYs-35,ScreenXs,35); val=getpt(0,*x,*y); if(sample>0) { lx=ix=Xc*Sample+*x*sample; ly=iy=Yc*Sample+*y*sample; lx*=Sample_Rate; ly*=Sample_Rate; } else { lx=ix=Xc*Sample+*x/nsample; ly=iy=Yc*Sample+*y/nsample; lx*=Sample_Rate; ly*=Sample_Rate; } if(ChannelOn==1&&ix0) sprintf(string,"%5d %5d lat = %9.5lf lon = %10.5lf", ix,iy,clat((double)ix,(double)iy),clon((double)ix,(double)iy)); else sprintf(string,"%5d %5d",ix,iy); plot_font_h(White,2,ScreenYs-16,string,2,Font); xo=*x; yo=*y; } }while(ans!=27&&ans!=13); uncursor(0,xo,yo,csize,buffer); paint_box(0,Black,buff,0,ScreenYs-33,121,30); fclose(fpr); fclose(fpg); fclose(fpb); } /************************************************************************** ** ** ** ************************************************************************* */ double clat(x,y) double x,y; { double lat=Nav.B_Lat[0]; if(Nav.numlat>1) lat+=Nav.B_Lat[1]*y; if(Nav.numlat>2) lat+=Nav.B_Lat[2]*y*y; if(Nav.numlat>3) lat+=Nav.B_Lat[3]*x; if(Nav.numlat>4) lat+=Nav.B_Lat[4]*x*x; if(Nav.numlat>5) lat+=Nav.B_Lat[5]*y*x; return(lat); } /************************************************************************** ** ** ** ************************************************************************* */ double clon(x,y) double x,y; { double lon=Nav.B_Lon[0]; if(Nav.numlon>1) lon+=Nav.B_Lon[1]*x; if(Nav.numlon>2) lon+=Nav.B_Lon[2]*x*x; if(Nav.numlon>3) lon+=Nav.B_Lon[3]*y; if(Nav.numlon>4) lon+=Nav.B_Lon[4]*y*y; if(Nav.numlon>5) lon+=Nav.B_Lon[5]*y*x; return(lon); } /************************************************************************** ** ** ** ************************************************************************* */ double cy(lat,lon) double lat,lon; { double y=Nav.B_Y[0]; if(Nav.numy>1) y+=Nav.B_Y[1]*lat; if(Nav.numy>2) y+=Nav.B_Y[2]*lat*lat; if(Nav.numy>3) y+=Nav.B_Y[3]*lon; if(Nav.numy>4) y+=Nav.B_Y[4]*lon*lon; if(Nav.numy>5) y+=Nav.B_Y[5]*lat*lon; return(y); } /************************************************************************** ** ** ** ************************************************************************* */ double cx(lat,lon) double lat,lon; { double x=Nav.B_X[0]; if(Nav.numx>1) x+=Nav.B_X[1]*lon; if(Nav.numx>2) x+=Nav.B_X[2]*lon*lon; if(Nav.numx>3) x+=Nav.B_X[3]*lat; if(Nav.numx>4) x+=Nav.B_X[4]*lat*lat; if(Nav.numx>5) x+=Nav.B_X[5]*lat*lon; return(x); } /************************************************************************** ** ** ** ************************************************************************* */ int change_color() { int i,j,k; int num=0; int maxr=-1,maxg=-1,maxb=-1,minr=256,ming=256,minb=256; float flut[3],flutm[3],fdel[3],fmin[3],fv[3],fr[3]; float scale=1.0,dels=0.05,max,min,tint[3],brite=1.0; FILE *fplut; int val; char ans,ans2; /* put lut into lutc for safe keeping */ for(i=0;i<256;i++) { Hdr[Img].lutc[i].r=Hdr[Img].lut[i].r; Hdr[Img].lutc[i].g=Hdr[Img].lut[i].g; Hdr[Img].lutc[i].b=Hdr[Img].lut[i].b; } do { num=do_menu_buff(menu_c,MENU_C,MENUXC,25,num,D_Grey,L_Grey,White,Font); if(num==0) /* change saturation and tint and brightness*/ { for(k=0;k<3;k++) tint[k]=1.0; brite=scale=1.0; while((ans=getch())!=27&&ans!=13) { if(ans==0) { ans2=getch(); if(ans2==71)tint[0]+=dels; if(ans2==72)tint[1]+=dels; if(ans2==73)tint[2]+=dels; if(ans2==79)tint[0]-=dels; if(ans2==80)tint[1]-=dels; if(ans2==81)tint[2]-=dels; for(k=0;k<3;k++) { if(tint[k]<0.0)tint[k]=0.0; if(tint[k]>1.0)tint[k]=1.0; } } if(ans=='+') scale+=dels; if(ans=='-') scale-=dels; if(scale<0.0) scale=0.0; if(scale> 2.0) scale= 2.0; if(ans=='b') brite+=dels; if(ans=='d') brite-=dels; if(brite<0.0) brite=0.0; if(ans=='r') { for(i=0;i<256;i++) /* put original (c) into lut */ { Hdr[Img].lut[i].r=Hdr[Img].lutc[i].r; Hdr[Img].lut[i].g=Hdr[Img].lutc[i].g; Hdr[Img].lut[i].b=Hdr[Img].lutc[i].b; } scale=1.0; for(k=0;k<3;k++) tint[k]=1.0; } for(i=0;i<256;i++) { fv[0]=Hdr[Img].lut[i].r; fv[1]=Hdr[Img].lut[i].g; fv[2]=Hdr[Img].lut[i].b; max=0.0;min=256.0; for(k=0;k<3;k++) { if(fv[k]>max)max=fv[k]; if(fv[k]min) { for(k=0;k<3;k++) fr[k]=(fv[k]-min)/(max-min); if(scale>1.0) min*=2.0-scale; else min+=(max-min)*(1.0-scale); for(k=0;k<3;k++) { fv[k]=fr[k]*(max-min)+min+0.5; if(fv[k]<0.0)fv[k]=0.0; if(fv[k]>256.0)fv[k]=256.0; } } for(k=0;k<3;k++) { fv[k]*=brite*tint[k]; if(fv[k]>255.0) fv[k]=255.0; } Hdr[Img].lutm[i].r=fv[0]; Hdr[Img].lutm[i].g=fv[1]; Hdr[Img].lutm[i].b=fv[2]; } WritePalette(Hdr[Img].lutm); } for(i=0;i<256;i++) /* put changed palette (m) into lut */ { Hdr[Img].lut[i].r=Hdr[Img].lutm[i].r; Hdr[Img].lut[i].g=Hdr[Img].lutm[i].g; Hdr[Img].lut[i].b=Hdr[Img].lutm[i].b; } } if(num==1) /* stretch table */ { maxr=-1; maxg=-1; maxb=-1; minr=256; ming=256; minb=256; for(i=0;i<256;i++) { if((Hdr[Img].lut[i].r<255||Hdr[Img].lut[i].g<255|| Hdr[Img].lut[i].b<255)&& (Hdr[Img].lut[i].r>0||Hdr[Img].lut[i].g>0||Hdr[Img].lut[i].b>0)) { if((int)Hdr[Img].lut[i].r>maxr)maxr=Hdr[Img].lut[i].r; if((int)Hdr[Img].lut[i].rmaxg)maxg=Hdr[Img].lut[i].g; if((int)Hdr[Img].lut[i].gmaxb)maxb=Hdr[Img].lut[i].b; if((int)Hdr[Img].lut[i].b255.0) val=255.0; flutm[k]=val; } Hdr[Img].lut[i].r=flutm[0]; Hdr[Img].lut[i].g=flutm[1]; Hdr[Img].lut[i].b=flutm[2]; } WritePalette(Hdr[Img].lut); } if(num==2) /* reset */ { for(i=0;i<256;i++) /* put original (c) into lut */ { Hdr[Img].lut[i].r=Hdr[Img].lutc[i].r; Hdr[Img].lut[i].g=Hdr[Img].lutc[i].g; Hdr[Img].lut[i].b=Hdr[Img].lutc[i].b; } scale=1.0; for(k=0;k<3;k++) tint[k]=1.0; WritePalette(Hdr[Img].lut); } if(num==MENU_C-2&&VideoType!='V') { SetVideoMode(0,&B_Id); printf( "\n\nYou have requested that the Look Up Table be changed. If you proceed\n"); printf( "you will replace the current '.pal' file with a new one and the current\n"); printf( "file will be destroyed. You may wish to make a copy of it first.\n\n"); printf(" Do you wish to continue? (y or n)\n\n"); if(getch()=='y') { if(strlen(Hdr[Img].Lut)>0) { fplut=open_to_write_text(Hdr[Img].Lut); if(fplut) { for(i=0;i0) { offset=Hdr[filenum].header_bytes; fseek(fp,offset,SEEK_SET); } video_on(); set_lut('G'); do { Sample=sample+=1; Row=Hdr[filenum].row/sample; Col=Hdr[filenum].col/sample; offset=(sample-1); offset*=Hdr[filenum].col; }while(Col>ScreenXs||Row>ScreenYs); Hdr[filenum].sample=sample; if(Hdr[filenum].pal_type>0) set_lut(Hdr[filenum].pal_type); else { if(set_lut('P',Hdr[filenum].Lut)<0) set_lut('G'); } plot_full_image(fp,sample,filenum); if(sample>-17) { sample=ZoomSample; if(limit_area_fixed(&Xc,&Yc,&xs,&ys,&Speed,&sample)!=27) { ZoomSample=sample; plot_sub_image(fp,sample,filenum); } else { Xc=Yc=0; ZoomSample=Sample; return(0); } } fclose(fp); return(1); } /************************************************************************** ** ** ** ************************************************************************* */ int plot_sub_image(fp,sample,filenum) FILE *fp; int sample,filenum; { int i,j,k; long offset,offscale=1; int val,nsample=sample*-1+2,zscale=1; if(Hdr[filenum].sample_bits==16) offscale=2; ScreenZoom=sample; if(sample<1) zscale=nsample; rewind(fp); offset=Hdr[filenum].col*offscale; offset*=Yc*Sample; offset+=Xc*Sample*offscale; if(Hdr[filenum].header_bytes>0) offset+=Hdr[filenum].header_bytes; fseek(fp,offset,SEEK_SET); Row=ScreenYs; Col=ScreenXs; offset=Hdr[filenum].col*offscale; if(sample>0) { if((Yc*Sample+Row*sample)>Hdr[filenum].row) Row=(Hdr[filenum].row-Yc*Sample)/sample; if((Xc*Sample+Col*sample)>Hdr[filenum].col) Col=(Hdr[filenum].col-Xc*Sample)/sample; } else { if((Yc*Sample+Row/nsample)>Hdr[filenum].row) Row=(Hdr[filenum].row-Yc*Sample)*nsample; if((Xc*Sample+Col/nsample)>Hdr[filenum].col) Col=(Hdr[filenum].col-Xc*Sample)*nsample; offset=0; } offset*=(sample-1)*offscale; for(i=0;i0) { val=getch(); if(val==27) return(-2); } if(offset>0) fseek(fp,offset,SEEK_CUR); if(sample>1) for(j=0;j0;j--) Mbuff[j]=Mbuff[j/nsample]; if(VideoType=='V'||VideoType=='E') { if(ActiveLut=='P') { for(j=0;j0) plotrow(3,0,Col-1,i,Mbuff); else for(k=0;k0) { val=getch(); if(val==27) return(-2); } plotrow(0,0,col-1,i,Mbuff); } fclose(fpsub); } else { if(!fp) { SetVideoMode(0,&B_Id); printf("In plot_full_image() fp = (null)\n"); exit(0); } rewind(fp); offset=Hdr[filenum].header_bytes; if(offset>0) fseek(fp,offset,SEEK_SET); offset=(sample-1); offset*=Hdr[filenum].col; for(i=0;i0) { val=getch(); if(val==27) return(-2); } if(offset>0) { fseek(fp,offset,SEEK_CUR); if(Hdr[filenum].sample_bits==16) fseek(fp,offset,SEEK_CUR); } if(sample>1) for(j=0;j1) { fpsub=open_to_write_binary(string); if(fpsub) { fwrite((char *)&Row,sizeof(int),1,fpsub); fwrite((char *)&Col,sizeof(int),1,fpsub); for(i=0;i0) { xso=*xs=ScreenXs/Sample*(*sample); yso=*ys=ScreenYs/Sample*(*sample); } else { xso=*xs=ScreenXs/Sample/(*sample*-1+2); yso=*ys=ScreenYs/Sample/(*sample*-1+2); } if(*xs+*xc>=ScreenXs||*ys+*yc>=ScreenYs) { ok=0; if(*xc!=0||*yc!=0) { *xc=*yc=0; } else { *sample-=1; } } else ok=1; }while(ok==0); if(*sample>0) tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center); else tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Center,Center,Center); do { ans=getch(); unbox(3,*xc,*yc,*xs,*ys,Mbuff); if(ans==27) { return(27); } else if(ans=='-'&&*speed>1)*speed/=2; else if(ans=='+'&&*speed0) { *xs=ScreenXs/Sample*(*sample); *ys=ScreenYs/Sample*(*sample); } else { *xs=ScreenXs/Sample/(*sample*-1+2); *ys=ScreenYs/Sample/(*sample*-1+2); } if(ans==0) { ans=getch(); if(ans==71) { *xc-=*speed; *yc-=*speed; } else if(ans==73) { *xc+=*speed; *yc-=*speed; } else if(ans==79) { *xc-=*speed; *yc+=*speed; } else if(ans==81) { *xc+=*speed; *yc+=*speed; } else if(ans==72) *yc-=*speed; else if(ans==80) *yc+=*speed; else if(ans==75) *xc-=*speed; else if(ans==77) *xc+=*speed; } if(*xs>ScreenXs)*xs=ScreenXs; if(*ys>ScreenYs)*ys=ScreenYs; if(*xs<2)*xs=2; if(*ys<2)*ys=2; if((*xc+*xs)>=ScreenXs)*xc=ScreenXs-*xs; if((*yc+*ys)>=ScreenYs)*yc=ScreenYs-*ys; if(*xc<0)*xc=0; if(*yc<0)*yc=0; if(*sample>0) tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Black,White,Center); else tbox_val(3,*xc,*yc,*xs,*ys,Mbuff,Center,Center,Center); }while(ans!=83&&ans!='x'&&ans!=27&&ans!=13); unbox(3,*xc,*yc,*xs,*ys,Mbuff); return(ans); } /************************************************************************** ** ** ** ************************************************************************* */ int read_lbl(label,filenum) char *label; int filenum; { int i,j,k; char string1[100],string2[100],string3[100],string[100]; FILE *fp; int status=1,numread,n1,n2,n3,num; double lat0,lat1,lat2,lon0; fp=open_to_read_text(label); if(!fp) return(-1); Hdr[filenum].sample_bits=8; Hdr[filenum].record_bytes=0; Hdr[filenum].file_records=0; Hdr[filenum].pal_type=0; Hdr[filenum].row_col_header=0; ProjType=0; Hdr[filenum].infile[0]='\0'; Hdr[filenum].image[0]='\0'; Hdr[filenum].Lut[0]='\0'; Hdr[filenum].label[0]='\0'; for(i=0;i30) { printf("Invalid SAMPLE_RATE = %ld\n",Sample_Rate); exit(0); } } if(strcmpi(string1,"Projection")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } ProjType=string3[0]; if(ProjType=='A') { while(fgetc(fp)!=0xa); /* skip to end of line */ fgets(string1,100,fp); sscanf(string1,"%lf",&lat0); fgets(string1,100,fp); sscanf(string1,"%lf",&lat1); fgets(string1,100,fp); sscanf(string1,"%lf",&lat2); fgets(string1,100,fp); sscanf(string1,"%lf",&lon0); fgets(string1,100,fp); sscanf(string1,"%lf",&X0); fgets(string1,100,fp); sscanf(string1,"%lf",&Y0); fgets(string1,100,fp); sscanf(string1,"%lf",&PixelSize); fgets(string1,100,fp); sscanf(string1,"%d",&P); set_const(P,lat0,lat1,lat2,lon0); } } if(strcmpi(string1,"file_records")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].row); Hdr[filenum].file_records=Hdr[filenum].row; } if(strcmpi(string1,"line_samples")==0&&Hdr[filenum].record_bytes==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].col); } if(strcmpi(string1,"record_bytes")==0|| strcmpi(string1,"image_record_bytes")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].col); Hdr[filenum].record_bytes=Hdr[filenum].col; } if(strcmpi(string1,"header_bytes")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].header_bytes); } if(strcmpi(string1,"data_max")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].data_max); } if(strcmpi(string1,"data_min")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } sscanf(string3,"%d",&Hdr[filenum].data_min); } if(strcmpi(string1,"image_pointer")==0) { numread=fscanf(fp,"%s%s",string2,string3); if(strcmpi(string2,"end")==0||strcmpi(string3,"end")==0|| numread<2) { fclose(fp); return(status); } k=0; for(i=0;iMAX_LL||Nav.numlat<2) { printf("Invalid number of Latitude coefficients '%s'\n\n",string3); exit(0); } for(i=0;iMAX_LL||Nav.numy<2) { printf("Invalid number of Y coefficients '%s'\n\n",string3); exit(0); } for(i=0;iMAX_LL||Nav.numlon<2) { printf("Invalid number of longitude coefficients '%s'\n\n",string3); exit(0); } for(i=0;iMAX_LL||Nav.numx<2) { printf("Invalid number of X coefficients '%s'\n\n",string3); exit(0); } for(i=0;i=NUM_IMAGE) { printf("Invalid number of images in set.\n\n"); exit(0); } for(i=0;i=NUM_TYPE) { printf("Invalid number of vector sets.\n"); exit(0); } for(i=0;i=NUM_SIZE) { printf("Invalid number of vectors.\n"); exit(0); } for(j=0;j0) { x=(double)Xc*(double)Sample+x*(double)ZoomSample; y=(double)Yc*(double)Sample+y*(double)ZoomSample; } else { x=(double)Xc*(double)Sample+x/nsample; y=(double)Yc*(double)Sample+y/nsample; } x=x*PixelSize+X0; y=Y0-y*PixelSize; if(ProjType=='A') { axy_ll_e(x,y,lat,lon); return(1); } return(-1); } /*********************************************************************** ** ** x,y in screen coordinates ** ** ************************************************************************/ int ll_xy(x,y,lat,lon) double *x,*y,lat,lon; { double nsample=(double)ZoomSample*-1.0+2.0; if(ProjType=='A') { all_xy_e(x,y,lat,lon); *x=(*x-X0)/PixelSize; *y=(Y0-*y)/PixelSize; if(ZoomSample>0) { *x=(*x-(double)Xc*(double)Sample)/(double)ZoomSample; *y=(*y-(double)Yc*(double)Sample)/(double)ZoomSample; } else { *x=(*x-(double)Xc*(double)Sample)*nsample; *y=(*y-(double)Yc*(double)Sample)*nsample; } } } /*********************************************************************** ** ** ** ** ************************************************************************/ int copy_hdr(d,s) int d,s; /* (d)estination and (s)ource */ { int i,j,k; Hdr[d].row=Hdr[s].row; Hdr[d].col=Hdr[s].col; Hdr[d].sample=Hdr[s].sample; Hdr[d].record_bytes=Hdr[s].record_bytes; Hdr[d].file_records=Hdr[s].file_records; Hdr[d].record_col_header=Hdr[s].record_col_header; Hdr[d].row_col_header=Hdr[s].row_col_header; Hdr[d].header_bytes=Hdr[s].header_bytes; Hdr[d].imbedded_header=Hdr[s].imbedded_header; Hdr[d].sample_bits=Hdr[s].sample_bits; Hdr[d].pal_type=Hdr[s].pal_type; strcpy(Hdr[d].infile,Hdr[s].infile); strcpy(Hdr[d].image,Hdr[s].image); strcpy(Hdr[d].Lut,Hdr[s].Lut); strcpy(Hdr[d].label,Hdr[s].label); for(i=0;i<256;i++) { Hdr[d].vga_color[i]=Hdr[s].vga_color[i]; Hdr[d].lut[i].r=Hdr[s].lut[i].r; Hdr[d].lut[i].g=Hdr[s].lut[i].g; Hdr[d].lut[i].b=Hdr[s].lut[i].b; Hdr[d].lutm[i].r=Hdr[s].lutm[i].r; Hdr[d].lutm[i].g=Hdr[s].lutm[i].g; Hdr[d].lutm[i].b=Hdr[s].lutm[i].b; Hdr[d].lutc[i].r=Hdr[s].lutc[i].r; Hdr[d].lutc[i].g=Hdr[s].lutc[i].g; Hdr[d].lutc[i].b=Hdr[s].lutc[i].b; } } /******************************************************************** ** ** type g -- grey all lut[] files ** G -- grey only lut[] ** i -- initial header map ** r -- reset lut[] to lutc[] ** p -- positive (0-127) magenta, negative (128-255) green ** ********************************************************************* */ int set_lut(type,filename) char type,*filename; { int i,k,hue,brite,j; int r,g,b; float color[3]; double dbrite,dval; float val,minval,sat,inten; float fval,fk; FILE *fplut; int end=0,scale,sum; char string[100]; long del,mindel,l1,l2,l3,l4; scale=1; if(Num_Color==16) scale=17; for(k=0;klen)len=l; if(len==0)return(-1); wide=(len+1)*15/size+1; if((ScreenXs-1-wide)0)val-=1; else val=num-1; } if(ans2=='P') { if(val=0&&last_slashcolon-1) { string[len]='.'; dot=len; len+=1; string[len]='\0'; } if(colon>0) disk=string[0]; if(first_slash>=0) { for(i=first_slash;i<=last_slash;i++) path[i-first_slash]=string[i]; path[last_slash-first_slash+1]='\0'; } if(last_slash>0&&last_slash0) { for(i=last_slash+1;i0&&last_slash<0&&dot>0) /* d:test.img */ { for(i=colon+1;i0) /* test.img */ { for(i=0;i0&&dot3) type[3]='\0'; } return(disk); } /*********************************************************************** ** ** ** ** ************************************************************************/ FILE *open_to_write_text(name) char *name; { int i,j,k; FILE *fp; char string[STR_LEN]; for(j=0;j0&&len