📄 ximage.c
字号:
nxb,ixb,x1begb,x1endb, nyb,iyb,x2endb,x2begb, &nxb,&ixb,&x1begb,&x1endb, &nyb,&iyb,&x2endb,&x2begb); } else { zoomBox(x,y,width,height, xb,yb,wb,hb, nxb,ixb,x2begb,x2endb, nyb,iyb,x1begb,x1endb, &nxb,&ixb,&x2begb,&x2endb, &nyb,&iyb,&x1begb,&x1endb); } /* make new bytes in zoombox */ if (czb!=cz) free1(czb); czb = ealloc1(nxb*nyb, sizeof(signed char)); for (i=0,czbp=czb; i<nyb; i++) { czp = cz+(iyb+i)*nx+ixb; for (j=0; j<nxb; j++) *czbp++ = *czp++; } } /* clear area and force an expose event */ XClearArea(dpy,win,0,0,0,0,True); /* note that image is out of date */ imageOutOfDate = 1; /* else if 2nd button down: display mouse coords */ } else if (event.xbutton.button==Button2) { showloc = 1; xMouseLoc(dpy,win,event,style,showloc, x,y,width,height,x1begb,x1endb, x2begb,x2endb,z,f1,d1,n1,f2,d2, n2,verbose); } else if (event.xbutton.button==Button3) { /* ZM: Mouse-Button-3 shows the amplitude constantly */ showloc = 1; xMouseLoc(dpy,win,event,style,showloc, x,y,width,height,x1begb,x1endb, x2begb,x2endb,z,f1,d1,n1,f2,d2, n2,verbose); } else { continue; } /* else if pointer has moved */ } else if (event.type==MotionNotify) { /* if button2 down, show mouse location */ if (showloc) xMouseLoc(dpy,win,event,style,True, x,y,width,height,x1begb,x1endb, x2begb,x2endb,z,f1,d1,n1,f2,d2, n2,verbose); /* else if button2 released, stop tracking */ } else if (event.type==ButtonRelease && event.xbutton.button==Button2) { showloc = 0; } } /* end of event loop */ /* close connection to X server */ XCloseDisplay(dpy); if (curve) { free1int(npair); for (i=0; i<curve; i++) { free1float(x1curve[i]); free1float(x2curve[i]); } free((void**)x1curve); free((void**)x2curve); free((void**)curvefile); free((void**)curvecolor); } free1float(z); return EXIT_SUCCESS;}/* update parameters associated with zoom box */static void zoomBox (int x, int y, int w, int h, int xb, int yb, int wb, int hb, int nx, int ix, float x1, float x2, int ny, int iy, float y1, float y2, int *nxb, int *ixb, float *x1b, float *x2b, int *nyb, int *iyb, float *y1b, float *y2b){ /* if width and/or height of box are zero, just copy values */ if (wb==0 || hb==0) { *nxb = nx; *ixb = ix; *x1b = x1; *x2b = x2; *nyb = ny; *iyb = iy; *y1b = y1; *y2b = y2; return; } /* clip box */ if (xb<x) { wb -= x-xb; xb = x; } if (yb<y) { hb -= y-yb; yb = y; } if (xb+wb>x+w) wb = x-xb+w; if (yb+hb>y+h) hb = y-yb+h; /* determine number of samples in rubber box (at least 2) */ *nxb = MAX(nx*wb/w,2); *nyb = MAX(ny*hb/h,2); /* determine indices of first samples in box */ *ixb = ix+(xb-x)*(nx-1)/w; *ixb = MIN(*ixb,ix+nx-*nxb); *iyb = iy+(yb-y)*(ny-1)/h; *iyb = MIN(*iyb,iy+ny-*nyb); /* determine box limits to nearest samples */ *x1b = x1+(*ixb-ix)*(x2-x1)/(nx-1); *x2b = x1+(*ixb+*nxb-1-ix)*(x2-x1)/(nx-1); *y1b = y1+(*iyb-iy)*(y2-y1)/(ny-1); *y2b = y1+(*iyb+*nyb-1-iy)*(y2-y1)/(ny-1);}/* return pointer to new interpolated array of bytes */static unsigned char *newInterpBytes (int n1in, int n2in, unsigned char *bin, int n1out, int n2out, int useBlockInterp) /* JG */{ unsigned char *bout; float d1in,d2in,d1out,d2out,f1in,f2in,f1out,f2out; f1in = f2in = f1out = f2out = 0.0; d1in = d2in = 1.0; d1out = d1in*(float)(n1in-1)/(float)(n1out-1); d2out = d2in*(float)(n2in-1)/(float)(n2out-1); bout = ealloc1(n1out*n2out,sizeof(unsigned char)); /* JG .... */ if (!useBlockInterp) { intl2b(n1in,d1in,f1in,n2in,d2in,f2in,bin, n1out,d1out,f1out,n2out,d2out,f2out,bout); } else { intl2b_block(n1in,d1in,f1in,n2in,d2in,f2in,bin, n1out,d1out,f1out,n2out,d2out,f2out,bout); } /* .... JG */ return bout;}/*********************** self documentation **********************//*****************************************************************************INTL2B_block - blocky interpolation of a 2-D array of bytesintl2b_block blocky interpolation of a 2-D array of bytes******************************************************************************Function Prototype:void intl2b_block(int nxin, float dxin, float fxin, int nyin, float dyin, float fyin, unsigned char *zin, int nxout, float dxout, float fxout, int nyout, float dyout, float fyout, unsigned char *zout);******************************************************************************Input:nxin number of x samples input (fast dimension of zin)dxin x sampling interval inputfxin first x sample inputnyin number of y samples input (slow dimension of zin)dyin y sampling interval inputfyin first y sample inputzin array[nyin][nxin] of input samples (see notes)nxout number of x samples output (fast dimension of zout)dxout x sampling interval outputfxout first x sample outputnyout number of y samples output (slow dimension of zout)dyout y sampling interval outputfyout first y sample outputOutput:zout array[nyout][nxout] of output samples (see notes)******************************************************************************Notes:The arrays zin and zout must passed as pointers to the first element ofa two-dimensional contiguous array of unsigned char values.Constant extrapolation of zin is used to compute zout foroutput x and y outside the range of input x and y.******************************************************************************Author: James Gunning, CSIRO Petroleum 1999. Hacked fromintl2b() by Dave Hale, Colorado School of Mines, c. 1989-1991*****************************************************************************//**************** end self doc ********************************/void intl2b_block(int nxin, float dxin, float fxin, int nyin, float dyin, float fyin, unsigned char *zin, int nxout, float dxout, float fxout, int nyout, float dyout, float fyout, unsigned char *zout)/*****************************************************************************blocky interpolation of a 2-D array of bytes: gridblock effect******************************************************************************Input:nxin number of x samples input (fast dimension of zin)dxin x sampling interval inputfxin first x sample inputnyin number of y samples input (slow dimension of zin)dyin y sampling interval inputfyin first y sample inputzin array[nyin][nxin] of input samples (see notes)nxout number of x samples output (fast dimension of zout)dxout x sampling interval outputfxout first x sample outputnyout number of y samples output (slow dimension of zout)dyout y sampling interval outputfyout first y sample outputOutput:zout array[nyout][nxout] of output samples (see notes)******************************************************************************Notes:The arrays zin and zout must passed as pointers to the first element ofa two-dimensional contiguous array of unsigned char values.Constant extrapolation of zin is used to compute zout foroutput x and y outside the range of input x and y. Mapping of bytes between arrays is done to preserve appearance of `gridblocks':no smooth interpolation is performed.*****************************************************************************/{ int ixout,iyout,iin,jin; float xoff,yoff; xoff=fxout+0.5*dxin-fxin; yoff=fyout+0.5*dyin-fyin; for (iyout=0;iyout<nyout;iyout++) { jin=(int)((iyout*dyout+yoff)/dyin); jin=MIN(nyin-1,MAX(jin,0)); for (ixout=0;ixout<nxout;ixout++) { iin=(int)((ixout*dxout+xoff)/dxin); iin=MIN(nxin-1,MAX(iin,0)); zout[nxout*iyout+ixout]=zin[nxin*jin+iin]; } }} void xMouseLoc(Display *dpy, Window win, XEvent event, int style, Bool show, int x, int y, int width, int height, float x1begb, float x1endb, float x2begb, float x2endb, float *z, float f1, float d1, int n1,float f2, float d2, int n2, int verbose){ static XFontStruct *fs=NULL; static XCharStruct overall; static GC gc; int dummy,xoffset=5,yoffset=5; float x1,x2,amp; char string[256]; /* if first time, get font attributes and make gc */ if (fs==NULL) { fs = XLoadQueryFont(dpy,"fixed"); gc = XCreateGC(dpy,win,0,NULL); /* make sure foreground/background are black/white */ XSetForeground(dpy,gc,BlackPixel(dpy,DefaultScreen(dpy))); XSetBackground(dpy,gc,WhitePixel(dpy,DefaultScreen(dpy))); XSetFont(dpy,gc,fs->fid); overall.width = 1; overall.ascent = 1; overall.descent = 1; } /* erase previous string */ XClearArea(dpy,win,xoffset,yoffset, overall.width,overall.ascent+overall.descent,False); /* if not showing, then return */ if (!show) return; /* convert mouse location to (x1,x2) coordinates */ if (style==NORMAL) { x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width; x2 = x2endb+(x2begb-x2endb)*(event.xmotion.y-y)/height; } else { x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height; x2 = x2begb+(x2endb-x2begb)*(event.xmotion.x-x)/width; } /* draw string indicating mouse location */ /* ZM: computing amplitude at the poked point from dataset */ amp = getamp(z,f1,d1,n1,f2,d2,n2,x1,x2,verbose); sprintf(string,"(%0.6g,%0.6g,%0.6g)",x2,x1,amp); /* ZM */ XTextExtents(fs,string,(int)strlen(string),&dummy,&dummy,&dummy,&overall); XDrawString(dpy,win,gc,xoffset,yoffset+overall.ascent, string,(int) strlen(string));}void xMousePrint(XEvent event, int style, FILE *mpicksfp, int x, int y, int width, int height, float x1begb, float x1endb, float x2begb, float x2endb){ float x1,x2; /* convert mouse location to (x1,x2) coordinates */ if (style==NORMAL) { x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width; x2 = x2endb+(x2begb-x2endb)*(event.xmotion.y-y)/height; } else { x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height; x2 = x2begb+(x2endb-x2begb)*(event.xmotion.x-x)/width; } /* write string indicating mouse location */ fprintf(mpicksfp, "%0.6g %0.6g\n", x1, x2);}float getamp(float *zz,float f1,float d1,int n1, float f2,float d2,int n2,float x1,float x2,int verbose)/*****************************************************************************return the amplitude value at x1,x2******************************************************************************Input:zz zz(n1*nz) is the dataf1 coordinate in first xd1 x coordinate incrementn1 number samples in xf2 coordinate in first yd2 y coordinate incrementn2 number samples in yx1 x1 coordinate of the probed pointx2 x2 coordinate of the probed point******************************************************************************Author: Zhaobo Meng, ConocoPhillips, Feb. 03,2004*****************************************************************************/{ float x1last,x2last,x1i,x2i,xfrac,zfrac,xfrac0,zfrac0,temp; int ix1,ix2,i00; if (d1==0.0) err("d1 can not be 0.0"); if (d2==0.0) err("d2 can not be 0.0"); x1last = f1 + (n1-1)*d1; if (x1<f1 || x1>x1last) return -999.0; x2last = f2 + (n2-1)*d2; if (x2<f2 || x2>x2last) return -999.0; x1i = (x1-f1)/d1; ix1 = MIN(x1i,n1-1); xfrac = x1i-ix1; xfrac0 = 1.0-xfrac; x2i = (x2-f2)/d2; ix2 = MIN(x2i,n2-1); zfrac = x2i-ix2; zfrac0 = 1.0-zfrac; i00 = ix1 + n1*ix2; temp = zfrac *( xfrac*zz[i00+1+n1] + xfrac0*zz[i00+n1]) + zfrac0*( xfrac*zz[i00+1 ] + xfrac0*zz[i00 ]); /* if (verbose) warn("x1=%g x2=%g,value=%g,ix1=%d,ix2=%d f1=%g d1=%g n1=%d f2=%g d2=%g n2=%d", x1,x2,temp,ix1,ix2,f1,d1,n1,f2,d2,n2); */ return(temp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -