Ejemplo n.º 1
0
int
main (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_XAPP_DEF",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)) {
		from.addr = (char *)titleFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleFont,
			*((Font*)to.addr));
		nargs++;
	}
	XtSetValues(axes,args,nargs);
	x1beg = x1min; getparfloat("x1beg",&x1beg);
	x1end = x1max; getparfloat("x1end",&x1end);
	x2beg = x2min; getparfloat("x2beg",&x2beg);
	x2end = x2max; getparfloat("x2end",&x2end);
	adjustAxesValues(n1,d1,f1,n2,d2,f2,&x1beg,&x1end,&x2beg,&x2end);
	XtcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end);

	/* frame sampling */
	if (!getparfloat("fframe",&fframe)) fframe = 1.0;
	if (!getparfloat("dframe",&dframe)) dframe = 1.0;

	/* interpolation */
	if (!getparint("interp",&interp)) interp = 1;

	/* initial display mode: cont or step */
	if (!getparint("idm", &displayMode)) displayMode = DM_CONT;

	checkpars();

	/* initialize client data */
	cd.n1 = n1;  cd.d1 = d1;  cd.f1 = f1;
	cd.n2 = n2;  cd.d2 = d2;  cd.f2 = f2;
	cd.floats = z;
	cd.fmin = bclip;
	cd.fmax = wclip;
	cd.bmin = (unsigned char) (XtcwpGetFirstPixel(dpy));
	cd.bmax = (unsigned char) (XtcwpGetLastPixel(dpy));
	if(cd.bmax==0)cd.bmax=255;
	warn("bmin=%d bmax=%d",cd.bmin,cd.bmax);
	cd.x1bega = x1beg;
	cd.x1enda = x1end;
	cd.x2bega = x2beg;
	cd.x2enda = x2end;
	cd.abytes = NULL;
	cd.bbytes = NULL;
	cd.image = NULL;
	cd.exposed = 0;
	cd.noframes = 1;
	cd.axes = axes;
	cd.looping = looping;
	cd.frame = NULL;
	cd.format = format;
	cd.iframe = 0;
	cd.fframe = fframe;
	cd.dframe = dframe;
	cd.interp = interp;
	cd.forward = 1;
	cd.ac = ac;

	/* adjust axes title if formatted */
	if (strchr(cd.format,'%') && !strstr(cd.format,"%%")) {
		sprintf(cd.title,cd.format,cd.fframe+cd.iframe*cd.dframe);
		XtVaSetValues(cd.axes,XtNtitle,cd.title,NULL);
	}

	/* add work procedure */
	cd.wpid = XtAppAddWorkProc(ac,(XtWorkProc) readFrame,&cd);

	/* add callbacks to axes widget */
	XtAddCallback(axes,XtNresizeCallback,(XtCallbackProc) resizeCB,&cd);
	XtAddCallback(axes,XtNexposeCallback,(XtCallbackProc) exposeCB,&cd);
	XtAddCallback(axes,XtNinputCallback,(XtCallbackProc) inputCB,&cd);

	/* add Button2 translation for reversing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn2Up>: input()"));

	/* add Button3 translation for pausing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn3Up>: input()"));

	/* set up keypress */
	XtAddEventHandler(axes, KeyPress, FALSE,
			  (XtEventHandler) key_pressed, &cd);

	/* realize everything */
	XtRealizeWidget(toplevel);

	/* go */
	XtAppMainLoop(ac);

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
static void drawimage (Display *dpy, Drawable dbl, Region region,
					   FGC fgc, Model *m, float fmin, float fmax, int style)
{
  int scr=-1;
  int x,y,width,height;
  int i,j,k,line,iline,jline,widthpad;
  unsigned long pmin,pmax,p;

  float fx,fy,s,base,scale;
  Tri *t=NULL;
  TriAttributes *ta;
  XRectangle rect;
  XImage *image=NULL;
  int bitmap_pad=0;
  int nbpr=0;


	 

#if 0 /* OLD VERSION . See JG fix below */ 
  unsigned char *data=NULL;

  scr=DefaultScreen(dpy);

  /* Kludge to fix problem with XCreateImage introduced in */
  /* Xorg 7.0 update for security */
 
  if (BitmapPad(dpy)>16) {
	bitmap_pad = 16;
  } else if (BitmapPad(dpy) < 16) {
	bitmap_pad = 8;
  }


  /* determine smallest box enclosing region */
  XClipBox(region,&rect);
  x = rect.x;  y = rect.y;  width = rect.width;  height = rect.height;
  if (width==0 || height==0) return;

  /* allocate memory for image data */
  widthpad = (1+(width-1)/bitmap_pad)*bitmap_pad;
  nbpr = widthpad-1;

  data = alloc1(widthpad*height,sizeof(unsigned char));
  if (data==NULL) err("width,widthpad,height = %d %d %d",
					  width,widthpad,height);

  warn("nbpr = %d  widthpad = %d height = %d bitmap_pad = %d ",
	   nbpr,widthpad,height,bitmap_pad);
  /* determine min and max pixels from standard colormap */
  pmin = XtcwpGetFirstPixel(dpy);  
  pmax = XtcwpGetLastPixel(dpy);

  /* determine base and scale factor */
  scale = (fmax!=fmin) ? ((float) (pmax-pmin))/(fmax-fmin) : 0.0;
  base = ((float) pmin)-fmin*scale;
	
  /* loop over scan lines */
  for (line=0; line<height; line++) {
	iline = line*width;
	jline = line*widthpad;
		
	/* loop over pixels in scan line */
	for (i=iline,j=jline,k=0; k<width; ++i,++j,++k) {
		
	  /* determine float x and y coordinates */
	  if (style==XtcwpNORMAL) {
		fx = MapX(fgc,x+k);
		fy = MapY(fgc,y+line);
	  } else {
		fx = MapY(fgc,y+line);
		fy = MapX(fgc,x+k);
	  }
			
	  /* determine sloth */
	  t = insideTriInModel(m,t,fx,fy);
	  ta = (TriAttributes*)t->fa;
	  s = ta->s00+fy*ta->dsdx+fx*ta->dsdz;
			
	  /* convert to pixel and put in image */
	  p = (unsigned long) (base+s*scale);
	  if (p<pmin) p = pmin;
	  if (p>pmax) p = pmax;
	  data[j] = (unsigned char) p;
	}
	for (j=jline+width,k=width; k<widthpad; ++j,++k)
	  data[j] = data[jline+width-1];
  }
  
	
  /* create, put, and destroy image */
  image = XCreateImage(	(Display *) dpy,
						(Visual *) DefaultVisual(dpy,scr),
						(unsigned int) DefaultDepth(dpy,scr),
						(int)ZPixmap,
						(int) 0,
						(char*)data,
						(unsigned int) widthpad,
						(unsigned int) height,
						(int) bitmap_pad, 
						(int) nbpr);

#else
  char *data=NULL;
  char noCmap;

  scr=DefaultScreen(dpy);

  /* JG: get bitmap_pad from X */ 
  bitmap_pad = BitmapPad(dpy);
	
  /* determine smallest box enclosing region */
  XClipBox(region,&rect);
  x = rect.x;  y = rect.y;  width = rect.width;  height = rect.height;
  if (width==0 || height==0) return;

  /* allocate memory for image data */
  widthpad = (1+(width-1)/bitmap_pad)*bitmap_pad;
  nbpr = widthpad-1;

  /* create image & determine alloc size from X */
  image = XCreateImage(	(Display *) dpy,
						(Visual *) DefaultVisual(dpy,scr),
						(unsigned int) DefaultDepth(dpy,scr),
						(int)ZPixmap,
						(int) 0,
						NULL ,
						(unsigned int) widthpad,
						(unsigned int) height,
						(int) bitmap_pad, 
						0);
  /* JG XCreateImage(....,0)  gets X to compute the size it needs. Then we alloc. */
  image->data = (char *)calloc(image->bytes_per_line, image->height);
  if (image->data==NULL) err("width,widthpad,height = %d %d %d",
					  width,widthpad,height);

  /* warn("nbpr = %d  widthpad = %d height = %d bitmap_pad = %d ", nbpr,widthpad,height,bitmap_pad); */
  /* determine min and max pixels from standard colormap */
  pmin = XtcwpGetFirstPixel(dpy);  
  pmax = XtcwpGetLastPixel(dpy);
  /* JGHACK ... When colormap fails, we get pmax=pmin=0 */
  noCmap = (pmax==0 && pmin==0) ? 1:0;
  if (noCmap) 
	{
	  pmax = 255; 
	  warn("No colormap found....");
	}
  /* ...JGHACK */

  /* determine base and scale factor */
  scale = (fmax!=fmin) ? ((float) (pmax-pmin))/(fmax-fmin) : 0.0;
  base = ((float) pmin)-fmin*scale;
	

  data = (char *)image->data ;
  /* loop over scan lines */
  for (line=0; line<height; line++) {
	iline = line*width;
	jline = line*widthpad;
		
	/* loop over pixels in scan line */
	for (i=iline,j=jline,k=0; k<width; ++i,++j,++k) {
		
	  /* determine float x and y coordinates */
	  if (style==XtcwpNORMAL) {
		fx = MapX(fgc,x+k);
		fy = MapY(fgc,y+line);
	  } else {
		fx = MapY(fgc,y+line);
		fy = MapX(fgc,x+k);
	  }
			
	  /* determine sloth */
	  t = insideTriInModel(m,t,fx,fy);
	  ta = (TriAttributes*)t->fa;
	  s = ta->s00+fy*ta->dsdx+fx*ta->dsdz;
			
	  /* convert to pixel and put in image */
	  p = (unsigned long) (base+s*scale);
	  if (p<pmin) p = pmin;
	  if (p>pmax) p = pmax;

	  if (noCmap) 
		{
		  /* JG. Can't get colormap. Might as well write RGB pixels as grayscale */
		  XPutPixel(image,k,line, p | (p<<8)| (p<<16));
		}
	  else 
		{
		  /* original */
		  /* data[j] = (unsigned char) p; */
		  XPutPixel(image,k,line,p);
		}
	}
	/* original. Not sure this is needed JG */
	/*
	  for (j=jline+width,k=width; k<widthpad; ++j,++k) data[j] = data[jline+width-1]; 
	*/
  }
	

#endif

  XPutImage(dpy,dbl,fgc->gc,image,0,0,x,y,image->width,image->height);

  /* free(data); */
  XDestroyImage(image);
}
Ejemplo n.º 3
0
main()
{
	Display *dpy;
	Window root,win;
	Colormap cmap;
	XStandardColormap scmap;
	XColor color,junk;
	XImage *image;
	XEvent event;
	GC gc;
	int scr,i;
	unsigned long black,white,pmin,pmax;
	char *data;
	
	/* connect to X server */
	dpy = XOpenDisplay(NULL);
	if ((dpy=XOpenDisplay(NULL))==NULL) {
		fprintf(stderr,"Cannot open display!\n");
		exit(-1);
	}
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy,scr);
	black = BlackPixel(dpy,scr);
	white = WhitePixel(dpy,scr);
	
	/* create and map window */
	win = XCreateSimpleWindow(dpy,root,X,Y,WIDTH,HEIGHT,4,black,white);
	cmap = XtcwpCreateGrayColormap(dpy,win);
	XSetWindowColormap(dpy,win,cmap);
	XMapWindow(dpy,win);
	
	/* determine range of contiguous pixels from standard colormap */
	if (!XtcwpCreateRGBDefaultMap(dpy,&scmap)) {
		fprintf(stderr,"Cannot create standard colormap!\n");
		exit(-1);
	}
	pmin = XtcwpGetFirstPixel(dpy);
	pmax = XtcwpGetLastPixel(dpy);
	
	/* create image */
	data = (char*)malloc(WIDTH*HEIGHT);
	for (i=0; i<WIDTH*HEIGHT; ++i)
		data[i] = pmin+(pmax-pmin)*(i%WIDTH)/WIDTH;
	image = XCreateImage(dpy,DefaultVisual(dpy,scr),
		DefaultDepth(dpy,scr),ZPixmap,
		0,data,WIDTH,HEIGHT,BitmapPad(dpy),WIDTH);
	gc = XCreateGC(dpy,win,0,NULL);
	XAllocNamedColor(dpy,cmap,"red",&color,&junk);
	XSetForeground(dpy,gc,color.pixel);
	
	/* set event mask */
	XSelectInput(dpy,win,ExposureMask);

	/* loop forever */
	XPutImage(dpy,win,gc,image,0,0,0,0,WIDTH,HEIGHT);
	while(True) {
		XNextEvent(dpy,&event);
		while (XCheckTypedEvent(dpy,Expose,&event));
		XPutImage(dpy,win,gc,image,0,0,0,0,WIDTH,HEIGHT);
		XDrawLine(dpy,win,gc,0,0,WIDTH,HEIGHT);
	}

	/* close display */
	XCloseDisplay(dpy);
}
Ejemplo n.º 4
0
Colormap XtcwpCreateSatColormap (Display *dpy, Window win,
	float fhue, float lhue, float wfrac, float bright)
/*****************************************************************************
create a colormap with varying saturations in contiguous cells
******************************************************************************
Input:
dpy		display
win		window
fhue		first hue in colormap (saturation=1)
lhue		last hue in colormap (saturation=1)
wfrac		fractional position of white within the colormap (saturation=0)
bright		brightness
******************************************************************************
Notes:
The returned colormap is only created; the window's colormap attribute
is not changed, and the colormap is not installed by this function.
The returned colormap is a copy of the window's current colormap, but 
with varying hues (blue to red) allocated in the range of contiguous
cells determined by XA_RGB_DEFAULT_MAP.  If it does not already exist,
XA_RGB_DEFAULT_MAP will be created.
******************************************************************************
Author:  Craig Artley, Colorado School of Mines, 11/22/93
*****************************************************************************/
{
	Screen *scr=XDefaultScreenOfDisplay(dpy);
	Colormap cmap,wcmap;
	XColor color;
	XWindowAttributes wa;
	unsigned long i,j,ncells,npixels,nfpixels,nlpixels;
	unsigned long bpixel,epixel,pixel[4096];
	long  ltemp;
	float red=0,green=0,blue=0;

	/* determine beginning and ending pixels in contiguous range */
	bpixel = XtcwpGetFirstPixel(dpy);
	epixel = XtcwpGetLastPixel(dpy);
	if (epixel<=bpixel) return None;

	/* determine window's current colormap */
	XGetWindowAttributes(dpy,win,&wa);
	wcmap = wa.colormap;

	/* create new colormap and allocate all cells read/write */
	cmap = XCreateColormap(dpy,win,DefaultVisualOfScreen(scr),AllocNone);
	ncells = CellsOfScreen(scr);
	XAllocColorCells(dpy,cmap,True,NULL,0,pixel,(unsigned int) ncells);

	/* copy color cells from window's colormap to new colormap */
	for (i=0; i<ncells; ++i) {
		if (i<bpixel || i>epixel) {
			color.pixel = i;
			XQueryColor(dpy,wcmap,&color);
			XFreeColors(dpy,cmap,&i,1,0);
			XAllocColor(dpy,cmap,&color);
		}
	}

	/* devide colormap into 3 regions: fhues, white, and lhues */
	npixels = epixel-bpixel+1;
	ltemp = (long) (wfrac*((float) npixels));
	nfpixels = (ltemp<0) ? 0: ltemp;
	if (nfpixels>npixels-1) nfpixels = npixels-1;
	nlpixels = npixels-nfpixels-1;

	/* pixels from fhue to just under white */
	for (i=0; i<nfpixels; ++i) {
		color.pixel = bpixel+i;
		hsvrgb(fhue,((float)(nfpixels-i))/((float) nfpixels),bright,
			&red,&green,&blue);
		color.red = 65535*red;
		color.green = 65535*green;
		color.blue = 65535*blue;
		color.flags = DoRed|DoGreen|DoBlue;
		XStoreColor(dpy,cmap,&color);
	}

	/* white pixel */
	color.pixel = bpixel+i;
	hsvrgb(fhue,0.0,bright,&red,&green,&blue);
	color.red = 65535*red;
	color.green = 65535*green;
	color.blue = 65535*blue;
	color.flags = DoRed|DoGreen|DoBlue;
	XStoreColor(dpy,cmap,&color);
	++i;

	/* pixels from just under white to lhue */
	for (j=0; j<nlpixels; ++i,++j) {
		color.pixel = bpixel+i;
		hsvrgb(lhue,((float)(j+1))/((float) nlpixels),bright,&red,&green,&blue);
		color.red = 65535*red;
		color.green = 65535*green;
		color.blue = 65535*blue;
		color.flags = DoRed|DoGreen|DoBlue;
		XStoreColor(dpy,cmap,&color);
	}

	/* return colormap */
	return cmap;
}
Ejemplo n.º 5
0
Colormap XtcwpCreateHueColormap (Display *dpy, Window win,
	float fhue, float lhue, float sat, float bright)
/*****************************************************************************
create a colormap with varying hues (user-specified) in contiguous cells
******************************************************************************
Input:
dpy		display
win		window
fhue		first hue in colormap
lhue		last hue in colormap
sat		saturation
bright		brightness
******************************************************************************
Notes:
The returned colormap is only created; the window's colormap attribute
is not changed, and the colormap is not installed by this function.
The returned colormap is a copy of the window's current colormap, but 
with varying hues (blue to red) allocated in the range of contiguous
cells determined by XA_RGB_DEFAULT_MAP.  If it does not already exist,
XA_RGB_DEFAULT_MAP will be created.
******************************************************************************
Author:  Dave Hale, Colorado School of Mines, 09/29/90
Modified:  Craig Artley, Colorado School of Mines, 11/22/93
	   Saturation, brightness, and range of hues now user-specified.
*****************************************************************************/
{
	Screen *scr=XDefaultScreenOfDisplay(dpy);
	Colormap cmap,wcmap;
	XColor color;
	XWindowAttributes wa;
	unsigned long i,ncells,npixels;
	unsigned long bpixel,epixel,pixel[4096];
	float red=0,green=0,blue=0;

	/* determine beginning and ending pixels in contiguous range */
	bpixel = XtcwpGetFirstPixel(dpy);
	epixel = XtcwpGetLastPixel(dpy);
	if (epixel<=bpixel) return None;

	/* determine window's current colormap */
	XGetWindowAttributes(dpy,win,&wa);
	wcmap = wa.colormap;

	/* create new colormap and allocate all cells read/write */
	cmap = XCreateColormap(dpy,win,DefaultVisualOfScreen(scr),AllocNone);
	ncells = CellsOfScreen(scr);
	XAllocColorCells(dpy,cmap,True,NULL,0,pixel,(unsigned int) ncells);

	/* copy color cells from window's colormap to new colormap */
	for (i=0; i<ncells; ++i) {
		if (i<bpixel || i>epixel) {
			color.pixel = i;
			XQueryColor(dpy,wcmap,&color);
			XFreeColors(dpy,cmap,&i,1,0);
			XAllocColor(dpy,cmap,&color);
		}
	}

	/* build hues in contiguous cells in new colormap */
	npixels = epixel-bpixel+1;
	for (i=0; i<npixels; ++i) {
		color.pixel = bpixel+i;
		hsvrgb(fhue+(lhue-fhue)*((float)i)/((float)(npixels-1)),sat,bright,
			&red,&green,&blue);
		color.red = 65535*red;
		color.green = 65535*green;
		color.blue = 65535*blue;
		color.flags = DoRed|DoGreen|DoBlue;
		XStoreColor(dpy,cmap,&color);
	}

	/* return colormap */
	return cmap;
}
Ejemplo n.º 6
0
Colormap XtcwpCreateGrayColormap (Display *dpy, Window win)
/*****************************************************************************
create a colormap with a gray scale in contiguous cells
******************************************************************************
Input:
dpy		display
win		window
******************************************************************************
Notes:
The returned colormap is only created; the window's colormap attribute
is not changed, and the colormap is not installed by this function.
The returned colormap is a copy of the window's current colormap, but 
with a gray scale (black to white) allocated in the range of contiguous
cells determined by XA_RGB_DEFAULT_MAP.  If it does not already exist,
XA_RGB_DEFAULT_MAP will be created.
******************************************************************************
Author:  Dave Hale, Colorado School of Mines, 09/29/90
*****************************************************************************/
{
	Screen *scr=XDefaultScreenOfDisplay(dpy);
	Colormap cmap,wcmap;
	XColor color;
	XWindowAttributes wa;
	unsigned long i,ncells,npixels;
	unsigned long bpixel,epixel,pixel[4096];
	
	/* determine beginning and ending pixels in contiguous range */
	bpixel = XtcwpGetFirstPixel(dpy);
	epixel = XtcwpGetLastPixel(dpy);
	if (epixel<=bpixel) return None;
	
	/* determine window's current colormap */
	XGetWindowAttributes(dpy,win,&wa);
	wcmap = wa.colormap;
	
	/* create new colormap and allocate all cells read/write */
	cmap = XCreateColormap(dpy,win,DefaultVisualOfScreen(scr),AllocNone);
	ncells = CellsOfScreen(scr);
	XAllocColorCells(dpy,cmap,True,NULL,0,pixel,(unsigned int)ncells);
	
	/* copy color cells from window's colormap to new colormap */
	for (i=0; i<ncells; ++i) {
		if (i<bpixel || i>epixel) {
			color.pixel = i;
			XQueryColor(dpy,wcmap,&color);
			XFreeColors(dpy,cmap,&i,1,0);
			XAllocColor(dpy,cmap,&color);
		}
	}
	
	/* build gray scale in contiguous cells in new colormap */
	npixels = epixel-bpixel+1;
	for (i=0; i<npixels; ++i) {
		color.pixel = bpixel+i;
		color.red = (unsigned short) (65535*i/(npixels-1));
		color.green = color.red;
		color.blue = color.red;
		color.flags = DoRed|DoGreen|DoBlue;
		XStoreColor(dpy,cmap,&color);
	}
	
	/* return colormap */
	return cmap;
}
Ejemplo n.º 7
0
Colormap XtcwpCreateRGBColormap (Display *dpy, Window win)
/*****************************************************************************
create a colormap with an RGB color scale in contiguous cells
******************************************************************************
Input:
dpy		display
win		window
******************************************************************************
Notes:
The returned colormap is only created; the window's colormap attribute
is not changed, and the colormap is not installed by this function.
The returned colormap is a copy of the window's current colormap, but 
with an RGB color scale allocated in the range of contiguous cells
determined by XA_RGB_DEFAULT_MAP.  If it does not already exist,
XA_RGB_DEFAULT_MAP will be created.
******************************************************************************
Author:  Dave Hale, Colorado School of Mines, 09/29/90
*****************************************************************************/
{
	Screen *scr=XDefaultScreenOfDisplay(dpy);
	Window root=XRootWindowOfScreen(scr);
	Colormap cmap,wcmap;
	XStandardColormap scmap;
	XColor color;
	XWindowAttributes wa;
	unsigned long i,ncells,npixels;
	unsigned long bpixel,epixel,pixel[4096];
	
	/* determine beginning and ending pixels in contiguous range */
	bpixel = XtcwpGetFirstPixel(dpy);
	epixel = XtcwpGetLastPixel(dpy);
	if (epixel<=bpixel) return None;
	
	/* get standard colormap XA_RGB_DEFAULT_MAP */
	if (!XGetStandardColormap(dpy,root,&scmap,XA_RGB_DEFAULT_MAP))
		if (!XtcwpCreateRGBDefaultMap(dpy,&scmap))
			return None;
	
	/* determine window's current colormap */
	XGetWindowAttributes(dpy,win,&wa);
	wcmap = wa.colormap;
	
	/* create new colormap and allocate all cells read/write */
	cmap = XCreateColormap(dpy,win,DefaultVisualOfScreen(scr),AllocNone);
	ncells = CellsOfScreen(scr);
	XAllocColorCells(dpy,cmap,True,NULL,0,pixel,(unsigned int)ncells);
	
	/* copy color cells from window's colormap to new colormap */
	for (i=0; i<ncells; ++i) {
		if (i<bpixel || i>epixel) {
			color.pixel = i;
			XQueryColor(dpy,wcmap,&color);
			XFreeColors(dpy,cmap,&i,1,0);
			XAllocColor(dpy,cmap,&color);
		}
	}
	
	/* copy RGB color scale from XA_RGB_DEFAULT_MAP to new colormap */
	npixels = epixel-bpixel+1;
	for (i=0; i<npixels; ++i) {
		color.pixel = bpixel+i;
		XQueryColor(dpy,scmap.colormap,&color);
		XStoreColor(dpy,cmap,&color);
	}
	
	/* return colormap */
	return cmap;
}