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

📄 viz2d-f77.c

📁 xy时域有限差分的fortran数值模拟 xy时域有限差分的fortran数值模拟
💻 C
📖 第 1 页 / 共 2 页
字号:
	if( ncolors > 256 ) ncolors = 256;
	pixels = (unsigned long *)calloc(sizeof(unsigned long),ncolors+1);
		/* I'm not sure what these plane_masks do, I don't use them */
	nplanes = 0;
	plane_masks = (unsigned long *)calloc(sizeof(unsigned long),nplanes+1);
	if( XAllocColorCells( theDisplay, theDefaultColormap, True,
				plane_masks, nplanes, pixels, ncolors ) ){
			/* Figure out how many colors we can actually use */
		colors_created = *request_colors;
		colormapsize = theDefaultVisual->map_entries;
		mapstart = (int)pixels[0];
		colorcell_defs =
			(XColor *)calloc( sizeof(XColor),colors_created+1 );
		colors_to_store = colors_created;
		aColormap = theDefaultColormap;
		aVisual = theDefaultVisual;
		defstart = 0;
	}else{
		/* Couldn't allocate enough default colormap entries so, */
			/* make our own colormap */
            vinfo_mask = VisualClassMask;
            vinfo_template.class = PseudoColor;
            vlist = XGetVisualInfo( theDisplay,
                        vinfo_mask, &vinfo_template, &nitems );
	    if( !vlist ){
		fprintf(stderr,"\nERROR: No PseudoColor visuals found.\n");
		return 0;
	    }
	    aVisual = vlist->visual;
	    aColormap = XCreateColormap(theDisplay, aWindow, aVisual, AllocAll);
	    colormap_created = TRUE;
		/* Copy the first entries of the server's default colormap */
	    colormapsize = aVisual->map_entries;
	    colors_to_copy = MAX_COLORS_TO_COPY;
	    if( colormapsize < colors_to_copy ) colors_to_copy = colormapsize;
            theDefColorDefs = (XColor *)calloc(sizeof(XColor),colors_to_copy);
            for( iii=0; iii<colors_to_copy; iii++ ){
                theDefColorDefs[iii].pixel = iii;
            }
            XQueryColors(theDisplay, theDefaultColormap,
					theDefColorDefs, colors_to_copy);
		/* Now copy in the first N default colormap entries */
            colorcell_defs = (XColor *)calloc(sizeof(XColor),colormapsize+1);
		/* Initialize my colorcell definition array */
            for( iii=0; iii<colormapsize; iii++ ){
                colorcell_defs[iii].pixel = iii;
		colorcell_defs[iii].red = 0;
		colorcell_defs[iii].green = 0;
		colorcell_defs[iii].blue = 0;
		colorcell_defs[iii].flags = 0;
            }
	    for( iii=0; iii<colors_to_copy; iii++ ){
		colorcell_defs[iii].pixel = iii;
		colorcell_defs[iii].red = theDefColorDefs[iii].red;
		colorcell_defs[iii].green = theDefColorDefs[iii].green;
		colorcell_defs[iii].blue = theDefColorDefs[iii].blue;
		colorcell_defs[iii].flags = theDefColorDefs[iii].flags;
	    }
		/* Figure out how many colors we can actually use */
	    colors_created = *request_colors;
	    if( colors_created > 256 ) colors_created = 256;
	    if( colors_created > colormapsize ) colors_created = colormapsize;
	    mapstart = colormapsize - colors_created;
	    colors_to_store = colormapsize;
	    defstart = mapstart;
	}
		/* Now calculate the colormaps depending on request */
		/* HERE a programmer may want to customize or add colormaps */
	if( *colormap_type == 2 ){
			/* Create the Blue to Red colormap */
		delta = (int)(MAX_INTENSITY/(colors_created-1));
		an8bitFlag = DoRed | DoGreen | DoBlue;
		for( iii=0; iii<colors_created; iii++ ){
			colorcell_defs[iii+defstart].pixel = iii + mapstart;
			colorcell_defs[iii+defstart].red = iii * delta;
			colorcell_defs[iii+defstart].green = 0;
			colorcell_defs[iii+defstart].blue =
					MAX_INTENSITY - (iii * delta);
			colorcell_defs[iii+defstart].flags = an8bitFlag;
		}
	}else if( *colormap_type == 3 ){
			/* Create the Blue to Green to Red colormap */
		delta = (int)(2*(MAX_INTENSITY/(colors_created-1)));
		an8bitFlag = DoRed | DoGreen | DoBlue;
		midmap = colors_created/2;
		for( iii=0; iii<midmap; iii++ ){
			colorcell_defs[iii+defstart].pixel = iii + mapstart;
			colorcell_defs[iii+defstart].red = 0;
			colorcell_defs[iii+defstart].green = iii * delta;
			colorcell_defs[iii+defstart].blue =
					MAX_INTENSITY - (iii * delta);
			colorcell_defs[iii+defstart].flags = an8bitFlag;
		}
		for( iii=midmap; iii<colors_created; iii++ ){
			colorcell_defs[iii+defstart].pixel = iii + mapstart;
			colorcell_defs[iii+defstart].red = (iii-midmap)*delta;
			colorcell_defs[iii+defstart].green =
					MAX_INTENSITY - ((iii-midmap)*delta);
			colorcell_defs[iii+defstart].blue = 0;
			colorcell_defs[iii+defstart].flags = an8bitFlag;
		}
	}else{
			/* Create the grayscale colormap */
		delta = (int)(MAX_INTENSITY/(colors_created-1));
		an8bitFlag = DoRed | DoGreen | DoBlue;
		for( iii=0; iii<colors_created; iii++ ){
			colorcell_defs[iii+defstart].pixel = iii + mapstart;
			colorcell_defs[iii+defstart].red = iii * delta;
			colorcell_defs[iii+defstart].green = iii * delta;
			colorcell_defs[iii+defstart].blue = iii * delta;
			colorcell_defs[iii+defstart].flags = an8bitFlag;
		}
	}
        XStoreColors( theDisplay, aColormap, colorcell_defs, colors_to_store );
        XInstallColormap( theDisplay, aColormap );
        XSetWindowColormap( theDisplay, aWindow, aColormap );
	XFlush( theDisplay );
		/* Create and display the key buffer (the bottom color ramp) */
	if( *display_key ){
		for( iii=0; iii<KEY_HEIGHT; iii++ ){
		    for( jjj=0; jjj<width; jjj++ ){
			key_buffer[iii*width+jjj] = mapstart +
			    (int)((jjj*colors_created)/width);
		    }
		}
		keyImage = XCreateImage( theDisplay, aVisual, theDepth,
			ZPixmap, 0, key_buffer, width, KEY_HEIGHT, 8, 0 );
		XPutImage( theDisplay, aWindow, theGC, keyImage,
			0,0,0,height+3, width,KEY_HEIGHT );
	}
	XFlush( theDisplay );
	viz2d_was_initialized = 1;
	return 1;
}

/*
 *	quit_viz2d()
 *
 *      This subroutine is called when the program is finished
 *      with the viz2d window.  It removes the window and frees
 *      the memory that was allocated by viz2d only if init_viz2d()
 *	successfully created things.
 */

quit_viz2d_()
{
	if( viz2d_was_initialized ){
		cfree( trans_buffer );
		cfree( key_buffer );
		cfree( colorcell_defs );
		XDestroyImage( keyImage );
		if( colormap_created ) XFreeColormap( theDisplay, aColormap );
		XCloseDisplay( theDisplay );
	}
}

/*
 *	initX()
 *
 *	This function is not used by the user.  It is used by the init_viz2d()
 *	function to initialize X windows.
 */

int initX()
{
	theDisplay = XOpenDisplay( NULL );
	if( theDisplay == NULL ){
		fprintf(stderr,"ERROR: Can't open connection to %s\n",
			XDisplayName( NULL ) );
		return 0;
	}
	theScreen = DefaultScreen( theDisplay );
	theDepth = DefaultDepth( theDisplay, theScreen );
	theBlackPixel = BlackPixel( theDisplay, theScreen );
	theWhitePixel = WhitePixel( theDisplay, theScreen );
	return 1;
}

/*
 *	openWindow()
 *
 *	This function is not used by the user.  It is used by the init_viz2d()
 *	function to create an X window.
 */

Window openWindow( x, y, width, height, flag, theNewGC )
int	x, y, width, height, flag;
GC	*theNewGC;
{
XSetWindowAttributes	theWindowAttributes;
XSizeHints	theSizeHints;
unsigned long	theWindowMask;
Window	theNewWindow;
Pixmap	theIconPixmap;
XWMHints	theWMHints;
	theWindowAttributes.border_pixel = theWhitePixel;
	theWindowAttributes.background_pixel = theBlackPixel;
	theWindowAttributes.override_redirect = False;
	theWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;

	theNewWindow = XCreateWindow( theDisplay,
		RootWindow( theDisplay, theScreen ),
		x, y, width, height,
		BORDER_WIDTH, theDepth, InputOutput,
		CopyFromParent,
		theWindowMask,
		&theWindowAttributes );

	theIconPixmap = XCreateBitmapFromData( theDisplay, theNewWindow,
		icon_viz50x50_bits,
		icon_viz50x50_width,
		icon_viz50x50_height );

	theWMHints.icon_pixmap = theIconPixmap;
	theWMHints.initial_state = NormalState;
	theWMHints.flags = IconPixmapHint | StateHint;

	XSetWMHints( theDisplay, theNewWindow, &theWMHints );

	theSizeHints.flags = PPosition | PSize;
	theSizeHints.x = x;
	theSizeHints.y = y;
	theSizeHints.width = width;
	theSizeHints.height = height;

	XSetNormalHints( theDisplay, theNewWindow, &theSizeHints );

	if( createGC(theNewWindow, theNewGC ) == 0 ){
		XDestroyWindow( theDisplay, theNewWindow );
		return( (Window) 0 );
	}

	XMapWindow( theDisplay, theNewWindow );

	XFlush( theDisplay );
	return( theNewWindow );
}

/*
 *	createGC()
 *
 *	This function is not used by the user.  It is used by the openWindow()
 *	function to create a graphics context to be associated with the
 *	new window.
 */

createGC( theNewWindow, theNewGC )
Window theNewWindow;
GC	*theNewGC;
{
XGCValues	theGCValues;
	*theNewGC = XCreateGC( theDisplay, theNewWindow,
		(unsigned long) 0, &theGCValues );
	if( *theNewGC == 0 ){
		return 0;
	}else{
		XSetForeground( theDisplay, *theNewGC, theWhitePixel );
		XSetBackground( theDisplay, *theNewGC, theBlackPixel );
		return( 1 );
	}
}



⌨️ 快捷键说明

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