/* vklein.c vkln.bat = cl /AL vklein.c vimage2 graphlib */ #include #include #include #include "font.h" #define MAX_BUFF 32768 #define MENU 12 #define MENU_C 7 #define MENU_X 3 #define MENUXC 550 #define DEG_RAD 0.01745329251 /* converts degrees to radians */ #define INT1 64 #define INT2 255 #define HUE1 200 #define HUE2 0 #define SAT1 255 #define SAT2 255 #define CYAN 0+Num_Color/2 #define YELLOW 3+Num_Color/2 #define RED 2+Num_Color/2 #define ORANGE 1+Num_Color/2 #define GREEN 4+Num_Color/2 #define BLUE 5+Num_Color/2 #define D_BLUE 6+Num_Color/2 #define BROWN 7+Num_Color/2 #define MAX_PIC 170 #define MAX_TEXT 5 #define S_SIZE 40 struct board { int row,col,color; }B_Id; int Max_X,Min_X,Max_Y,Min_Y; int Picture=0; struct file_id { char name[S_SIZE]; long size; unsigned date,time; }; extern struct file_id GF_File[8]; int Num_Vector=-1; int Record_Bytes,File_Records; int Row,Col; int Row_Col_Header=0; int Imbedded_Header=0; int Sample_Bits=0; char Image[100],Lut[100],Pal_Type,Label[100],Color_Image; char FileName[8][60]; struct picture { float lat,lon; char text[MAX_TEXT][60]; char filename[60]; int num_line; }Pic[MAX_PIC]; float MaxLat,MinLat,MaxLon,MinLon; int Bands=1; long Dir[3][2]={INT1,INT2,HUE1,HUE2,SAT1,SAT2}; struct color { char *name; int r,g,b; }Color[8]= { { "cyan", 0,255,255}, {"yellow",200,200, 0}, { "red",255, 0, 0}, {"orange",255,128, 0}, { "green", 0,255, 0}, { "blue", 0, 0,255}, {"d_blue", 0, 20, 60}, { "brown", 96, 28, 14} }; char *menu_v[8]; char *menu[MENU]= {"zoom","graticule","reverse grey","fix track lines", "color","histogram","text plot","location", "vector plot","pictures of bottom", "Lable vectors", "exit"}; char *menu_c[MENU_C]= {"intensity","hue","saturation","bands of color","flip all", "reset","exit color"}; char *menu_x[MENU_X]= {"new cross section","add cross section","exit"}; int Map=0,Zoom=0; char Proj; double LatB[2],LonB[2]; char InFile[100]; char VideoType='X',ImageSuffix[10],ImageScale=0,GreyScale=1,Scale; int Num_Color=256; int Sample,I_Sample; int ScreenXs=640,ScreenYs=480,Reverse=0; int SplitXc=0,SplitXs=320,SplitYc=0,SplitYs=480; int PicXc=320,PicXs=320,PicYc=480,PicYs=480; int ImageRow,ImageCol; int Black=0,White=255,L_Grey=191,D_Grey=46,Center=127; long Hist[256]; char Text[5][200]; int Color_Lines=0; struct Color { unsigned char r, g, b; }lut[256],lutm[256],lutc[256],luts[256]; unsigned char Vga_Color[256]; unsigned char Mbuff[MAX_BUFF],Buffer[4096],Ibuff[MAX_BUFF]; unsigned char Inbuff[BUFSIZ],Inbuff2[BUFSIZ],Outbuff[BUFSIZ]; 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 }; FILE *FpErr; unsigned char getpt(); int set_lut(); char get_pad_color(long [2],int *); main(argc,argv) int argc; char *argv[]; { int i,j,k,n; char string[100],imgfile[100],ans,ans2; int numfile,num=0,xnum=0,xc=0,yc=0,xs,ys,sample=1,scale=1,speed=16; int bxc=ScreenXs-257,byc=ScreenYs-129,bxs=256,bys=128; int wxc=0,wyc=0,wxs=380,wys=ScreenYs; int ix,iy,isize=20,ixo,iyo,num_text,picnum,hit; FILE *fp,*fpmap; int txc=ScreenXs/2,tyc=ScreenYs/2,txs=64,tys=ScreenYs/2,tspeed=16; double alpha=0.0,dxc0,dyc0,x,y,lat,lon; int numpic,color_on,val; FpErr=fopen("vklein.err","wt"); if(argc>1) { for(i=0;i=0) { for(k=0;kSample) Sample=sample; plot_full_image(1); if(limit_area_fixed(&xc,&yc,&xs,&ys,&speed,&scale,0,Sample,1)!=27) { expand(imgfile,Mbuff,scale,xc,yc,0); Zoom=1; set_max_min(xc,xc+ScreenXs*scale,yc,yc+ScreenYs*scale); } else Zoom=0; } if(num==1&&Map==1) /* graticule */ { if(Zoom==0) { Sample=(ImageCol+ScreenXs-1)/ScreenXs; sample=(ImageRow+ScreenYs-1)/ScreenYs; if(sample>Sample) Sample=sample; grat(0,0,Sample); } else { grat(xc,yc,scale); } } if(num==2) /* reverse grey scale */ { if(Reverse==0) Reverse=1; else Reverse=0; set_lut('g'); } if(num==3) fix_tip(&txc,&tyc,&txs,&tys,&tspeed,&alpha); if(num==4) /* color */ { color_table(ScreenXs-155,ScreenYs-20,150,15); } if(num==5) /* Histogram */ { 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,1); 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 { sprintf(string, "Limit area to process for Histogram ('Del' to Process 'Esc' to exit)"); xc=yc=0; 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); ans=limit_area_all(&wxc,&wyc,&wxs,&wys,&speed,ScreenXs,ScreenYs, 1,Buffer,Black,White,Center,1); recall_sub_mem(xc,yc,xs,ys); if(ans!=27) { 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); } }while(ans!=27); paint_box(0,Black,Buffer,bxc,byc,bxs,bys); } if(num==6) /* plot text */ { if(Zoom==0) { Sample=(ImageCol+ScreenXs-1)/ScreenXs; sample=(ImageRow+ScreenYs-1)/ScreenYs; if(sample>Sample) Sample=sample; xc=yc=0; scale=Sample; hit=plot_text(0,0,Sample); } else { hit=plot_text(xc,yc,scale); } if(hit>0) { ixo=ix=ScreenXs/2; iyo=iy=ScreenYs/2; speed=16; tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1,(Num_Color*3)/4); do { ans2=getpad(&isize,&ix,&iy,&speed); if(ans2==13) { num_text=find_text(xc,yc,scale,&ix,&iy,Text); paint_box(0,0,Buffer,0,ScreenYs-num_text*20, ScreenXs,num_text*20); for(k=0;kSample) Sample=sample; if(Zoom==0) { xc=yc=0; scale=Sample; } ixo=ix=ScreenXs/2; iyo=iy=ScreenYs/2; dxc0=xc*Sample; dyc0=yc*Sample; speed=16; tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1,(Num_Color*3)/4); ixo=ix; iyo=iy; x=dxc0+ix*scale; y=dyc0+iy*scale; o_xy_ll(x,y,&lat,&lon); paint_box(0,0,Buffer,0,ScreenYs-20, ScreenXs,20); sprintf(Text[0],"Latitude = %lf Longitude = %lf dn = %d", lat,lon,val); plot_font_h(Num_Color-1,5,ScreenYs-20,Text[0],2,Font); do { ans2=getpad(&isize,&ix,&iy,&speed); uncursor(0,ixo,iyo,isize,Buffer); val=getpt(0,ix,iy); tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1, (Num_Color*3)/4); ixo=ix; iyo=iy; x=dxc0+ix*scale; y=dyc0+iy*scale; o_xy_ll(x,y,&lat,&lon); paint_box(0,0,Buffer,0,ScreenYs-20, ScreenXs,20); sprintf(Text[0],"Latitude = %lf Longitude = %lf dn = %d", lat,lon,val); plot_font_h(Num_Color-1,5,ScreenYs-20,Text[0],2,Font); }while(ans2!='x'&&ans2!=27); uncursor(0,ixo,iyo,isize,Buffer); paint_box(0,0,Buffer,0,ScreenYs-20, ScreenXs,20); } if(num==8) { Sample=(ImageCol+ScreenXs-1)/ScreenXs; sample=(ImageRow+ScreenYs-1)/ScreenYs; if(sample>Sample) Sample=sample; if(Zoom==0) { xc=yc=0; scale=Sample; } Max_X=ScreenXs; val=get_vector(string,xc,yc,scale); if(Picture==1) Max_X*=2; } if(num==9) /* Pictures of bottom */ { Picture=1; scale=1; SetVideoMode(0); numpic=load_pic(); set_video_on(); set_lut('g'); paint_box(3,D_Grey,Mbuff,0,0,ScreenXs,ScreenYs); ScreenXs/=2; xs=ScreenXs; ys=ScreenYs; strcpy(imgfile,InFile); strcat(imgfile,".kln"); Sample=(ImageCol+ScreenXs-1)/ScreenXs; sample=(ImageRow+ScreenYs-1)/ScreenYs; if(sample>Sample) Sample=sample; plot_full_image(2); plot_pic_loc(0,0,Sample,numpic); if(limit_area_fixed(&xc,&yc,&xs,&ys,&speed,&scale,0,Sample,1)!=27) { expand(imgfile,Mbuff,scale,xc,yc,0); Zoom=1; set_max_min(xc,xc+ScreenXs*scale,yc,yc+ScreenYs*scale); } else { xc=yc=0; scale=Sample; Zoom=0; } hit=plot_pic_loc(xc,yc,scale,numpic); if(hit>0) { ixo=ix=ScreenXs/2; iyo=iy=ScreenYs/2; speed=16; tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1,(Num_Color*3)/4); do { ans2=getpad(&isize,&ix,&iy,&speed); if(ans2==13) { n=find_pic(xc,yc,scale,&ix,&iy,numpic); uncursor(0,ixo,iyo,isize,Buffer); tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1, (Num_Color*3)/4); ixo=ix; iyo=iy; ScreenXs*=2; paint_box(0,0,Buffer,ScreenXs,0,ScreenXs/2,ScreenYs); ScreenXs/=2; plot_picture(Pic[n].filename); ScreenXs*=2; paint_box(0,0,Buffer,ScreenXs/2, ScreenYs-Pic[n].num_line*20,ScreenXs/2, Pic[n].num_line*20); for(k=0;kSample) Sample=sample; if(Zoom==0) { xc=yc=0; scale=Sample; } Max_X=ScreenXs; val=label_vector(string,xc,yc,scale); if(Picture==1) Max_X*=2; } }while(numSample) Sample=sample; if(Zoom==0) { xc=yc=0; scale=Sample; } ixo=ix=ScreenXs/2; iyo=iy=ScreenYs/2; speed=16; tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1,(Num_Color*3)/4); ixo=ix; iyo=iy; do { ans=getpad(&isize,&ix,&iy,&speed); uncursor(0,ixo,iyo,isize,Buffer); tcursor_val(0,ix,iy,isize,Buffer,0,Num_Color-1, (Num_Color*3)/4); ixo=ix; iyo=iy; if(ans=='s') if(txt_size<4) txt_size+=1; if(ans=='l') if(txt_size>1) txt_size-=1; py=19/txt_size; py/=2; if(ans==13) { rewind(fpbin); rewind(fpatr); x=dxc0+ix*scale; y=dyc0+iy*scale; o_xy_ll(x,y,&lat,&lon); lonscale=1.0/cos(lat*DEG_RAD); lat0=lat;lon0=lon; fread((char *)&numseg,sizeof(int),1,fpbin); mindist=100000000.0; for(i=0;iSample) Sample=sample; if(Zoom==0) { xc=yc=0; scale=Sample; } if(Color_Lines==0) { for(i=0;i0) { load_image(Image); } } /************************************************************************** ** ** ** ************************************************************************* */ int load_image(filename) char *filename; { int i,j,k; int row=Row,col=Col,sample=0; int xc=0,yc=0,xs,ys,speed=16; FILE *fp; long offset=0; char string[100]; int sxs=ScreenXs,sys=ScreenYs; ScreenXs*=2; if(Sample_Bits==0) Sample_Bits=8; if((row==0||col==0)&&Row_Col_Header==0) return(-1); fcloseall(); fp=fopen(filename,"rb"); if(!fp) return(-1); do { I_Sample=sample+=1; row=Row/sample; col=Col/sample; offset=sample-1; offset*=Col; }while(col>ScreenXs/2||row>ScreenYs); if(set_lut('P',Lut)<0) set_lut('g'); for(i=0;i1) for(j=0;j1) { sample=1; if(limit_area_fixed(&xc,&yc,&xs,&ys, &speed,&sample,ScreenXs/2,I_Sample,2)!=27) { rewind(fp); paint_box(3,0,Mbuff,ScreenXs/2,0,ScreenXs/2,ScreenYs); offset=Col; offset*=yc*I_Sample; offset+=xc*I_Sample; if(Row_Col_Header>0) offset+=4; fseek(fp,offset,SEEK_SET); row=ScreenYs; col=ScreenXs/2; if((yc*I_Sample+row*sample)>Row) row=(Row-yc*I_Sample)/sample; if((xc*I_Sample+col*sample)>Col) col=(Col-xc*I_Sample)/sample; offset=Col; offset*=(sample-1); for(i=0;i1) for(j=0;j=0&&ix=0&&iy=0&&ix=0&&iyMaxLon||mnlt>MaxLat||mxln0) plotln(3,ix,iy,ixo,iyo,val); ixo=ix;iyo=iy; xo=ix;yo=iy; } } } } fclose(fp); fclose(fphdr); return(numplot); } /************************************************************************** ** ** ** ************************************************************************* */ int set_max_min(ix1,ix2,iy1,iy2) int ix1,ix2,iy1,iy2; { int i,j,k; double x,y,lat,lon; x=ix2; y=iy1; o_xy_ll(x,y,&lat,&lon); MaxLat=lat; MaxLon=lon; x=ix1; y=iy2; o_xy_ll(x,y,&lat,&lon); MinLat=lat; MinLon=lon; } /*********************************************************************** ** ** ** ***********************************************************************/ int convert_bin_val(xc,yc,scale,region,low,high,center) int xc,yc,scale; char *region; int low,high,center; { int i,j,k; double x,y,xo,yo; int ix,iy,ixo=-1,iyo=-1; double dx,dy,dist; int secnum,numpt,numsec; FILE *fp,*fphdr; float latlon[2],mll[4],mnln,mxln,mnlt,mxlt; char string[40]; int doit,numplot=0; int first_seg=-1,last_seg=-1; long offset; double dxc0=xc*Sample,dyc0=yc*Sample,dsample=Sample,dscale=scale; int val; strcpy(string,region); strcat(string,".bin"); fp=fopen(string,"rb"); if(!fp)return(-1); setbuf(fp,Inbuff); strcpy(string,region); strcat(string,".hdr"); fphdr=fopen(string,"rb"); if(!fphdr) return(-1); setbuf(fphdr,Inbuff2); fread((char *)&numsec,sizeof(int),1,fphdr); fread((char *)&numsec,sizeof(int),1,fp); for(j=0;jMaxLon||mnlt>MaxLat||mxln0) { dx-=ixo; dy-=iyo; dist=dx*dx+dy*dy; if(dist<40000.0) { plotln_val(3,ix,iy,ixo,iyo,Black,White,L_Grey,1); ixo=ix;iyo=iy; xo=ix;yo=iy; } } } } } } fclose(fp); fclose(fphdr); return(numplot); } /************************************************************************** ** ** ** ************************************************************************* */ int find_text(xc,yc,scale,xx,yy,text) int xc,yc,scale,*xx,*yy; char text[5][200]; { int i,j,k; FILE *fp; double dxc0=xc*Sample,dyc0=yc*Sample,dsample=Sample,dscale=scale; int num_line,eof=0; double lat,lon,x,y,min=500000000000000000000.0,dx=*xx,dy=*yy,dist; int ix,iy; char string[5][100]; strcpy(string[0],InFile); strcat(string[0],".txt"); fp=fopen(string[0],"rb"); if(!fp) return(-1); k=0; while((string[0][k++]=fgetc(fp))!=0xa); sscanf(string[0],"%d",&num_line); do { k=0; while((string[0][k]=fgetc(fp))!=0xa&&string[0][k]!=EOF) { k+=1; } if(k<2) eof=1; else { sscanf(string[0],"%lf%lf",&lat,&lon); for(i=0;i=0&&ix=0&&iy=0&&ix=0&&iymax) max=Hist[k]; for(k=0;k=0&&num<=2) { do { ans=get_pad_color(Dir[num],&speed); set_color(MaxHues,Dir); WritePalette(lutc); }while(ans!=83&&ans!=13); } if(num==3) /* Bands */ { do { ans=getch(); if(ans=='-'&&Bands>1)Bands/=2; if(ans=='+'&&Bands<128)Bands*=2; set_color(MaxHues,Dir); WritePalette(lutc); }while(ans!=83&&ans!=13); } if(num==5) /* initialize */ { Bands=1; Dir[0][0]=INT1; Dir[0][1]=INT2; Dir[1][0]=HUE1; Dir[1][1]=HUE2; Dir[2][0]=SAT1; Dir[2][1]=SAT2; set_color(MaxHues,Dir); WritePalette(lutc); } }while(num255)val-=256; j=val; for(k=0;k<3;k++)color[i][k]=maxhues[j][k]; } /* set saturation */ range=dir[2][1]-dir[2][0]; for(i=0;i255)val-=256; for(k=0;k<3;k++) { val2=color[i][k]; val2=(255-val2)*(255-val); val2/=255; val2+=color[i][k]; color[i][k]=val2; } } /* set intensity */ range=dir[0][1]-dir[0][0]; for(i=0;i255)val-=256; for(k=0;k<3;k++) { val2=color[i][k]; val2*=val; val2/=255; color[i][k]=val2; } lutc[i].r=color[i][0]; lutc[i].g=color[i][1]; lutc[i].b=color[i][2]; } /* set Bands */ if(Bands>1) { for(i=1;i2) *speed/=2; else if(ans=='+'&&*speed<128) *speed*=2; return(ans); } /************************************************************************** ** ** ** ************************************************************************* */ int o_ll_xy(x,y,lat,lon) double *x,*y,lat,lon; { *y=(lat-LatB[0])/LatB[1]; *x=(lon-LonB[0])/LonB[1]; } /************************************************************************** ** ** ** ************************************************************************* */ int o_xy_ll(x,y,lat,lon) double x,y,*lat,*lon; { *lat=LatB[0]+LatB[1]*y; *lon=LonB[0]+LonB[1]*x; } /************************************************************************** ** ** ** ************************************************************************* */ int fix_tip(txc,tyc,txs,tys,tspeed,alpha) int *txc,*tyc,*txs,*tys,*tspeed; double *alpha; { int i,j,k; double cos_a,sin_a,di,dj,dxc,dyc,dtyc,dtxc,dxs,dys,rx,ry; int xc,yc,xs,ys; int val; float fval1,fval2,fxs,fys,fn; limit_tip(txc,tyc,txs,tys,tspeed,alpha); cos_a=cos(*alpha*DEG_RAD); sin_a=sin(*alpha*DEG_RAD); dys=ys=*tys+1; dxs=xs=*txs+1; dxc=xc=*txc-*txs/2; dyc=yc=*tyc-*tys/2; dtxc=*txc; dtyc=*tyc; fxs=xs; for(di=0;di360.0) a-=360.0; if(a<0.0)a+=360.0; if(ans==72) yc-=speed; if(ans==75) xc-=speed; if(ans==77) xc+=speed; if(ans==80) yc+=speed; } else if(ans=='+') { if(speed<512) speed*=2; aspd*=2.0; } else if(ans=='-') { if(speed>1) speed/=2; aspd/=2.0; } else if(ans=='h') ys+=speed; else if(ans=='s') ys-=speed; else if(ans=='n') xs-=speed; else if(ans=='w') xs+=speed; if(ys<2) ys=2; if(xs<2) xs=2; plot_box_tip(3,xc,yc,xs,ys,a,Mbuff); }while(ans!=27&&ans!=83&&ans!=82&&ans!='x'&&ans!=13); *alpha=a; *txc=xc; *tyc=yc; *txs=xs*2; *tys=ys*2; *tspeed=speed; unplot_box_tip(3,xc,yc,xs,ys,a,Mbuff); return(ans); } /************************************************************************** ** ** ** ************************************************************************* */ int plot_box_tip(hue,xc,yc,xs,ys,alpha,buffer) int hue,xc,yc,xs,ys,buffer; double alpha; { int i,j,k; double x[4],y[4]; int xp[4],yp[4],num; double cos_a=cos(alpha*DEG_RAD),sin_a=sin(alpha*DEG_RAD); x[0]=x[1]=xs; x[2]=x[3]=-xs; y[0]=y[3]=ys; y[1]=y[2]=-ys; for(k=0;k<4;k++) { xp[k]=x[k]*cos_a-y[k]*sin_a; yp[k]=x[k]*sin_a+y[k]*cos_a; } for(k=0;k<4;k++) { if(k<3) i=k+1; else i=0; if(Reverse==0) num=tplot_ln(hue,xc+xp[k],yc-yp[k],xc+xp[i],yc-yp[i], buffer,ScreenXs,Black,White,Center); else num=tplot_ln(hue,xc+xp[k],yc-yp[k],xc+xp[i],yc-yp[i], buffer,ScreenXs,White,Black,Center); buffer+=num; } } /* ****************************************************************** ** ** draw a line on the image and save data destroyed in buffer ** ** returns the number of points ploted ** ********************************************************************* */ int tplot_ln(hue,x1,y1,x2,y2,buffer,low_color,high_color,center) int hue; /* image plane */ int x1,y1; /* coordinates of 1st point */ int x2,y2; /* coordinates of 2nd point */ int low_color,high_color,center; unsigned char *buffer; { int numpts=0,val; int i, j, k, numx, numy; float x, y, dy, dx; if(hue<0 || hue>3) return; numx = ( x2 > x1 ) ? x2-x1 : x1-x2; numy = ( y2 > y1 ) ? y2-y1 : y1-y2; if(numx==0 && numy==0) return; if( numx>numy ) { dy = (float)(y2-y1)/(float)(x2-x1); dx = (x2>x1) ? 1.0 : -1.0; i = x = x1; j = y = y1; for(k=2;k<=(numx);k++) { if(i>=0&&i=0&&jy1) ? 1.0 : -1.0; i = x = x1; j = y = y1; for(k=2;k<=(numy);k++) { if(i>=0&&i=0&&j3) return; numx = ( x2 > x1 ) ? x2-x1 : x1-x2; numy = ( y2 > y1 ) ? y2-y1 : y1-y2; if(numx==0 && numy==0) return; if( numx>numy ) { dy = (float)(y2-y1)/(float)(x2-x1); dx = (x2>x1) ? 1.0 : -1.0; i = x = x1; j = y = y1; for(k=2;k<=(numx);k++) { if(i>=0&&i=0&&jy1) ? 1.0 : -1.0; i = x = x1; j = y = y1; for(k=2;k<=(numy);k++) { if(i>=0&&i=0&&j1)*speed/=2; else if(ans=='+'&&*speed1) *sample-=1; *xs=ScreenXs/screen/l_sample*(*sample); *ys=ScreenYs/l_sample*(*sample); 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/screen)*xs=ScreenXs/screen; if(*ys>ScreenYs)*ys=ScreenYs; if(*xs<2)*xs=2; if(*ys<2)*ys=2; if((*xc+*xs)>=ScreenXs/screen)*xc=ScreenXs/screen-*xs; if((*yc+*ys)>=ScreenYs)*yc=ScreenYs-*ys; if(*xc<0)*xc=0; if(*yc<0)*yc=0; if(Reverse==0) tbox_val(3,*xc+x_zero,*yc,*xs,*ys,Mbuff,Black,White,Center); else tbox_val(3,*xc+x_zero,*yc,*xs,*ys,Mbuff,White,Black,Center); }while(ans!=82&&ans!=83&&ans!='x'&&ans!=27&&ans!=13); unbox(3,*xc+x_zero,*yc,*xs,*ys,Mbuff); return(ans); } /************************************************************************** ** ** ** ************************************************************************* */ int expand(filename,buffer,scale,xc,yc,iop) char *filename; unsigned char *buffer; int xc,yc,iop; { int i,j,k; int row=ImageRow,col=ImageCol,pcol,prow,val; long offset,lcol=ImageCol,lxc=xc,lyc=yc,lsample=Sample,offset0,lscale=scale; char label[100],string[100]; FILE *fpin; offset=lcol*(lscale-1); offset0=lcol*lsample*lyc+lxc*lsample; fpin=fopen(filename,"rb"); if(!fpin) return(-1); row=ImageRow; col=ImageCol; pcol=col/scale; prow=row/scale; if(pcol>ScreenXs)pcol=ScreenXs; if(prow>ScreenYs)prow=ScreenYs; fseek(fpin,offset0,SEEK_SET); for(i=0;i0) { val=getch(); if(val==27) return(-2); } fseek(fpin,offset,SEEK_CUR); if(GreyScale!=1) { for(j=0;jImageScale) ImageScale=scale; strcpy(string,InFile); strcat(string,ImageSuffix); fpin=fopen(string,"rb"); if(!fpin) { strcpy(string,InFile); strcat(string,".kln"); fpin=fopen(string,"rb"); strcpy(string,InFile); strcat(string,ImageSuffix); fpout=fopen(string,"wb"); offset=ImageCol; offset*=ImageScale-1; for(i=0;i1) { fseek(fpin,offset,SEEK_CUR); for(j=0;jlen)len=l; if(len==0)return(-1); wide=(len+1)*15/size+1; if((639-wide)MAX_BUFF) { SetVideoMode(0); printf("Menu exceeded maximum buffer size\n"); exit(0); } if((xc+(len+1)*15/size+1)<640) { save_sub_mem(xc,yc,(len+1)*15/size+1,30/size*num+1); paint_box(0,dgrey,Mbuff,xc,yc,(len+1)*15/size+1,30/size*num+1); for(k=0;k0)val-=1; else val=num-1; } if(ans2=='P') { if(val