⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmovie.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* XMOVIE: $Revision: 1.21 $ ; $Date: 2006/03/06 16:07:59 $	*/#include "par.h"#include "Xtcwp/Xtcwp.h"#include "Xtcwp/Axes.h"#include <X11/keysym.h>#include <X11/Shell.h>/*********************** self documentation **********************/char *sdoc[] = {" 									"," XMOVIE - image one or more frames of a uniformly sampled function f(x1,x2)"," 									"," xmovie n1= n2= [optional parameters] <fileoffloats			"," 									"," X Functionality:							"," Button 1	Zoom with rubberband box				"," Button 2 	reverse the direction of the movie.			"," Button 3 	stop and start the movie.				"," q or Q key	Quit 							"," s or S key	stop display and switch to Step mode                    "," b or B key	set frame direction to Backward                         "," f or F key	set frame direction to Forward                          "," n or N key	same as 'f'                                             "," c or C key	set display mode to Continuous mode                     "," 									"," Required Parameters:							"," n1=                    number of samples in 1st (fast) dimension	"," n2=                    number of samples in 2nd (slow) dimension	"," 									"," Optional Parameters:							"," d1=1.0                 sampling interval in 1st dimension		"," f1=0.0                 first sample in 1st dimension			"," d2=1.0                 sampling interval in 2nd dimension		"," f2=0.0                 first sample in 2nd dimension			"," perc=100.0             percentile used to determine clip		"," clip=(perc percentile) clip used to determine bclip and wclip		"," bperc=perc             percentile for determining black clip value	"," wperc=100.0-perc       percentile for determining white clip value	"," bclip=clip             data values outside of [bclip,wclip] are clipped"," wclip=-clip            data values outside of [bclip,wclip] are clipped"," x1beg=x1min            value at which axis 1 begins			"," x1end=x1max            value at which axis 1 ends			"," x2beg=x2min            value at which axis 2 begins			"," x2end=x2max            value at which axis 2 ends			"," fframe=1               value corresponding to first frame		"," dframe=1               frame sampling interval			"," loop=0                 =1 to loop over frames after last frame is input","                        =2 to run movie back and forth                 "," interp=1               =0 for a non-interpolated, blocky image        "," verbose=1              =1 for info printed on stderr (0 for no info)	"," idm=0                  =1 to set initial display mode to stepmode"," 									"," Optional resource parameters (defaults taken from resource database):	"," windowtitle=      	 title on window and icon			"," width=                 width in pixels of window			"," height=                height in pixels of window			"," nTic1=                 number of tics per numbered tic on axis 1	"," grid1=                 grid lines on axis 1 - none, dot, dash, or solid"," label1=                label on axis 1				"," nTic2=                 number of tics per numbered tic on axis 2	"," grid2=                 grid lines on axis 2 - none, dot, dash, or solid"," label2=                label on axis 2				"," labelFont=             font name for axes labels			"," title=                 title of plot					"," titleFont=             font name for title				"," titleColor=            color for title				"," axesColor=             color for axes					"," gridColor=             color for grid lines				"," style=                 normal (axis 1 horizontal, axis 2 vertical) or	","                        seismic (axis 1 vertical, axis 2 horizontal)	"," sleep=                 delay between frames in microseconds           "," 									"," Color options:                                                        "," cmap=gray     gray, hue, saturation, or default colormaps may be specified"," bhue=0        hue mapped to bclip (hue and saturation maps)		"," whue=240      hue mapped to wclip (hue and saturation maps)		"," sat=1         saturation (hue map only)				"," bright=1      brightness (hue and saturation maps)			"," white=(bclip+wclip)/2  data value mapped to white (saturation map only)","									"," Notes:								"," Colors are specified using the HSV color wheel model:			","   Hue:  0=360=red, 60=yellow, 120=green, 180=cyan, 240=blue, 300=magenta","   Saturation:  0=white, 1=pure color					","   Value (brightness):  0=black, 1=maximum intensity			"," For the saturation mapping (cmap=sat), data values between white and bclip","   are mapped to bhue, with saturation varying from white to the pure color.","   Values between wclip and white are similarly mapped to whue.	"," For the hue mapping (cmap=hue), data values between wclip and bclip are","   mapped to hues between whue and bhue.  Intermediate hues are found by","   moving counterclockwise around the circle from bhue to whue.  To reverse","   the polarity of the image, exchange bhue and whue.  Equivalently,	","   exchange bclip and wclip (setting perc=0 is an easy way to do this).","   Hues in excess of 360 degrees can be specified in order to reach the","   opposite side of the color circle, or to wrap around the circle more","   than once.								","									"," The title string may contain a C printf format string containing a	","   conversion character for the frame number.  The frame number is	","   computed from dframe and fframe.  E.g., try setting title=\"Frame %g\"."," 									",NULL};/**************** end self doc ********************************//* * AUTHOR:  Dave Hale, Colorado School of Mines, 06/01/91 * MODIFIED:  Craig Artley, Colorado School of Mines, 06/03/93 *	      Optionally place a frame number in the plot title, *	      add facility to pause movie using Button3 (courtesy *	      of Dave Hale, Advance Geophysical). * MODIFIED:  Craig Artley, Colorado School of Mines, 11/23/93 *	      Made hues used by hue map user-specifiable, added *            user-specifiable saturation map. * MODIFIED:  Jack Cohen, Colorado School of Mines, 07/19/95 *            Added quit on q or Q keypress. * MODIFIED:  Craig Artley, Fairfield Industries, 08/31/98 *            Added Button 2 to reverse movie, and loop=2 switch to *            automatically bounce movie off ends of frame loop. *            Added interp=0 option for non-interpolated (blocky) images. * MODIFIED:  Sang-yong Suh, KIGAM, 06/20/2002 *            Added keypress functions to enable step mode display. */#define DM_CONT	0#define DM_STEP 1static int displayMode;/* data structure for one frame in film loop */typedef struct FrameStruct {	unsigned char *abytes;		/* bytes in one frame of loop */	int nxa;			/* bytes per scanline in frame */	int nya;			/* number of scanlines in frame */	struct FrameStruct *next;	/* pointer to next frame in loop */	struct FrameStruct *prev;	/* pointer to previous frame in loop */} Frame;/* client data structures for callbacks */typedef struct ClientDataStruct {	int n1;			/* number of float samples in 1st dimension */	float d1;		/* sampling interval in 1st dimension */	float f1;		/* first sample in 1st dimension */	int n2;			/* number of float samples in 2nd dimension */	float d2;		/* sampling interval in 2nd dimension */	float f2;		/* first sample in 2nd dimension */	float *floats;		/* one entire frame f(x1,x2) */	float fmin;		/* float value corresponding to bmin */	float fmax;		/* float value corresponding to bmax */	unsigned char bmin;	/* minimum byte value in pixels */	unsigned char bmax;	/* maximum byte value in pixels */	float x1bega;		/* axis 1 beginning value in entire frame */	float x1enda;		/* axis 1 ending value in entire frame */	float x2bega;		/* axis 2 beginning value in entire frame */	float x2enda;		/* axis 2 ending value in entire frame */	int nxa;		/* bytes per scanline in entire frame */	int nya;		/* number of scanlines in entire frame */	unsigned char *abytes;	/* bytes in entire frame */	int nxb;		/* bytes per scanline in zoomed frame */	int nyb;		/* number of scanlines in zoomed frame */	int ixb;		/* index of first byte in zoomed frame */	int iyb;		/* index of first scanline in zoomed frame */	unsigned char *bbytes;	/* bytes in zoomed frame */	XImage *image;		/* pixels interpolated from bbytes */	int exposed;		/* non-zero if frame has been exposed */	int noframes;		/* non-zero until first frame processed */	int looping;		/* non-zero if looping over frames */	Frame *frame;		/* current frame in film loop */	Widget axes;		/* axes widget inside which pixels are drawn */	char *format;		/* title format string */	char title[256];	/* title string */	float fframe;		/* first frame sample */	float dframe;		/* frame sample interval */	int iframe;		/* index of current frame */	int interp;		/* ==1 for smooth interpolated image */	int forward;		/* direction of movie */        int sleep;              /* microsecond sleep to slow movie */	XtWorkProcId wpid;	/* work proc id */	XtAppContext ac;	/* application context */} ClientData;/* Bill Wingle's typedefs */typedef struct {    int  x1, y1, x2, y2;    int  (*func) ();    GC   gc;    } GBUFFER;typedef struct {    int          start_x, start_y, last_x, last_y;    GC           xorgc;    GC           gc;    int          (*current_func)();    int          foreground, background;    int          id;    GBUFFER      buffer[10];    int          next_pos;    } graphics_data;graphics_data key_data;/* work procedures */Boolean readFrame (ClientData *cd);/* callback functions */void resizeCB (Widget w, 	ClientData *clientdata,	XtcwpAxesCallbackStruct *calldata);void exposeCB (Widget w, 	ClientData *clientdata,	XtcwpAxesCallbackStruct *calldata);void inputCB (Widget w, 	ClientData *clientdata,	XtcwpAxesCallbackStruct *calldata);/* functions defined and used internally */static void adjustAxesValues (int n1, float d1, float f1,	int n2, float d2, float f2,	float *x1beg, float *x1end, float *x2beg, float *x2end);static unsigned char *makeABytes (int style,	float x1beg, float x1end, float x2beg, float x2end,	float fmin, float fmax, unsigned char bmin, unsigned char bmax,	int n1, float d1, float f1, int n2, float d2, float f2, float *floats,	int *nxa, int *nya);static unsigned char *makeBBytes (int nxa, int nya, unsigned char *abytes,	int nxb, int nyb, int ixb, int iyb);static XImage *makeImage (Display *dpy, int width, int height,	int nx, int ny, int interp, unsigned char *bytes);void key_pressed (Widget w, ClientData *data, XKeyEvent *event);void intn2b (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);intmain (int argc, char **argv){	int n1,n2,nz,iz,verbose,looping,nTic1,nTic2,width,height,interp;	float d1,f1,d2,f2,*z,		clip,bclip,wclip,white,wfrac,		perc,bperc,wperc,*temp,		bhue,whue,sat,bright,		x1beg,x2beg,x1end,x2end,		x1min,x1max,x2min,x2max,		fframe,dframe;	char *label1="",*label2="",*format="",*windowtitle="",		*labelFont="",*titleFont="",		*axesColor="",*gridColor="",*titleColor="",		*style="normal",*grid1="none",*grid2="none",		*cmap;	ClientData cd;	XrmValue from,to;	Widget toplevel,axes;	XtAppContext ac;	Display *dpy;	Window win;	Arg args[98];	int nargs;	int scr;	unsigned int depth;	/* initialize getpar */	initargs(argc,argv);	requestdoc(1);	/* get parameters describing colormaps */	cmap = "gray";  getparstring("cmap",&cmap);	if (STREQ("saturation",cmap)) cmap = "sat";	bhue = 0;  getparfloat("bhue",&bhue);  bhue /= 360.0;	whue = 240;  getparfloat("whue",&whue); whue /= 360.0;	sat = 1.0; getparfloat("sat",&sat);	if (sat<0.0 || sat>1.0) err("sat must be in range [0,1]!\n");	bright = 1.0; getparfloat("bright",&bright);	if (bright<0.0 || bright>1.0) err("bright must be in range [0,1]!\n");	/* get parameters describing 1st dimension sampling */	if (!getparint("n1",&n1))		err("Must specify number of samples in 1st dimension!\n");	if (!getparfloat("d1",&d1)) d1 = 1.0;	if (!getparfloat("f1",&f1)) f1 = 0.0;	x1min = (d1>0.0)?f1:f1+(n1-1)*d1;	x1max = (d1<0.0)?f1:f1+(n1-1)*d1;	if (!getparfloat("x1beg",&x1beg)) x1beg = x1min;	if (!getparfloat("x1end",&x1end)) x1end = x1max;	/* get parameters describing 2nd dimension sampling */	if (!getparint("n2",&n2))		err("Must specify number of samples in 2nd dimension!\n");	if (!getparfloat("d2",&d2)) d2 = 1.0;	if (!getparfloat("f2",&f2)) f2 = 0.0;	x2min = (d2>0.0)?f2:f2+(n2-1)*d2;	x2max = (d2<0.0)?f2:f2+(n2-1)*d2;	if (!getparfloat("x2beg",&x2beg)) x2beg = x2min;	if (!getparfloat("x2end",&x2end)) x2end = x2max;	/* read first frame of float data */	nz = n1*n2;	z = ealloc1float(nz);	if (fread(z,sizeof(float),nz,stdin)!=nz)		err("error reading input file");	/* if necessary, determine clips from percentiles */	if (getparfloat("clip",&clip)) {		bclip = clip;		wclip = -clip;	}	if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&		!getparfloat("clip",&clip)) {		perc = 100.0;  getparfloat("perc",&perc);		temp = ealloc1float(nz);		for (iz=0; iz<nz; iz++)			temp[iz] = z[iz];		if (!getparfloat("bclip",&bclip)) {			bperc = perc;	getparfloat("bperc",&bperc);			iz = (nz*bperc/100.0);			if (iz<0) iz = 0;			if (iz>nz-1) iz = nz-1;			qkfind(iz,nz,temp);			bclip = temp[iz];		}		if (!getparfloat("wclip",&wclip)) {			wperc = 100.0-perc;  getparfloat("wperc",&wperc);			iz = (nz*wperc/100.0);			if (iz<0) iz = 0;			if (iz>nz-1) iz = nz-1;			qkfind(iz,nz,temp);			wclip = temp[iz];		}		free1float(temp);	}	if (!getparfloat("white",&white)) white = (bclip+wclip)/2.0;	if (!getparint("verbose",&verbose)) verbose = 1;	if (!getparint("sleep",&cd.sleep)) cd.sleep = 0;	if (!getparint("loop",&looping)) looping = 0;	if (verbose)		if(STREQ(cmap,"sat") || STREQ(cmap,"customsat"))			warn("bclip=%g wclip=%g white=%g",bclip,wclip,white);		else			warn("bclip=%g wclip=%g",bclip,wclip);	wfrac = (bclip!=wclip) ? (bclip-white)/(bclip-wclip) : 1.0;	/* initialize toolkit and set toplevel parameters */ 	toplevel = XtAppInitialize(&ac,"XMovie",NULL,0,&argc,argv,NULL,NULL,0);	dpy = XtDisplay(toplevel);	nargs = 0;	if (getparstring("windowtitle",&windowtitle))		{XtSetArg(args[nargs],XtNtitle,windowtitle); nargs++;}	if (getparstring("windowtitle",&windowtitle))		{XtSetArg(args[nargs],XtNiconName,windowtitle); nargs++;}	if (getparint("width",&width))		{XtSetArg(args[nargs],XtNwidth,width); nargs++;}	if (getparint("height",&height))		{XtSetArg(args[nargs],XtNheight,height); nargs++;}	XtSetArg(args[nargs],XtNinput,TRUE);nargs++; 	XtSetValues(toplevel,args,nargs);	/* if necessary, make private colormap */	win = XRootWindowOfScreen(XtScreen(toplevel));	nargs = 0;	scr=DefaultScreen(dpy);	depth=(unsigned int)DefaultDepth(dpy,scr);	if (depth<=8) {	  if (STREQ(cmap,"gray")) {	    Colormap cm=XtcwpCreateGrayColormap(dpy,win);	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;	  } else if (STREQ(cmap,"hue")) {	    Colormap cm=XtcwpCreateHueColormap(dpy,win,					       bhue,whue,sat,bright);	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;	  } else if (STREQ(cmap,"sat")) {	    Colormap cm=XtcwpCreateSatColormap(dpy,win,					       bhue,whue,wfrac,bright);	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;	  }	  XtSetValues(toplevel,args,nargs);	}	/* create axes and set axes parameters */	axes = XtCreateManagedWidget("axes",xtcwpAxesWidgetClass, 		toplevel,NULL,0);			nargs = 0;	if (getparstring("grid1",&grid1)) {		from.addr = (char *)grid1;		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);		if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr));		nargs++;	}	if (getparstring("grid2",&grid2)) {		from.addr = (char *)grid2;		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);		if (to.addr) XtSetArg(args[nargs],XtNgrid2,*((int*)to.addr));		nargs++;	}	if (getparint("nTic1",&nTic1))		{XtSetArg(args[nargs],XtNnTic1,nTic1); nargs++;}	if (getparint("nTic2",&nTic2))		{XtSetArg(args[nargs],XtNnTic2,nTic2); nargs++;}	if (getparstring("label1",&label1))		{XtSetArg(args[nargs],XtNlabel1,label1); nargs++;}	if (getparstring("label2",&label2))		{XtSetArg(args[nargs],XtNlabel2,label2); nargs++;}	if (getparstring("title",&format))		{XtSetArg(args[nargs],XtNtitle,format); nargs++;}	if (getparstring("style",&style)) {		from.size = (unsigned int) strlen(style);  from.addr = (char *)style;		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesStyle,&to);		if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr));		nargs++;	}	if (getparstring("axesColor",&axesColor)) {		from.addr = (char *)axesColor;		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNaxesColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("gridColor",&gridColor)) {		from.addr = (char *)gridColor;		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNgridColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("titleColor",&titleColor)) {		from.addr = (char *)titleColor;		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNtitleColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("labelFont",&labelFont)) {		from.addr = (char *)labelFont;		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);		if (to.addr) XtSetArg(args[nargs],XtNlabelFont,			*((Font*)to.addr));		nargs++;	}	if (getparstring("titleFont",&titleFont)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -