[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

3429.0. "Pseudo Color on PXG " by CCIIS1::KRZEWINA () Thu Oct 04 1990 06:36

       X Visual problem on the DS5000/PXG
       ==================================

	* My problemd is to run an application in PseudoColor on 8 planes as
	 any other DECW station and run a superset of this application
         if the workstation is a 24 planes TRUECOLOR (PXG WS)

	* The sample below X1.c can show what are the problems
	 we have in this way .It seems that it's not possible to
	 create and Install an PseudoColor colormap on a PXG booted in
	 TRUECOLOR without destroying the ROOT colors ...Screen becomes
	 BLACK ...

	Q : Why an colormap is necessary in TRUECOLOR mode ?
	Q : Why the Window Manager allocate the full default colormap entries ?
	
	  How to solve that ???


/*
	Sample test X1  :

		Purpose : Create an X_window with a visual
			  of 8 planes and PseudoColormap on
			  a PXG booted in TRUECOLOR .

			  Allocate 32 colors

			  And Draw lines in color .

		Problem : If the PXG is booted in TRUECOLOR
			 (Default mode) , Screen become black at the
			 Window mapping time .


*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

Display *dpy;
Window  w ;
GC      gc;
Screen *screen;
Visual *visual;
XSetWindowAttributes attr ;
XVisualInfo vinfo ;

#define COL  128 
#define LGN   20
#define EPS    5

long int dxw = 512 ;
long int dyw = 512 ;
long int xw  = 256 ;
long int yw  = 256 ;
long int border = 1 ;
long int depth = 8 ;		/* Depth of the VISUAL */
long int ncolors = 32 ;

long int nplanes = 0 ;
long int cells ;
unsigned long int pixels[256] ;
unsigned long int planes[256] ;

/***************** doInitialize **************************/
static void do5000( )

{ long int n , l , c ;
  long int dx , dy ;
  XSegment segment[ COL ] ;

  dx = dxw / COL ;
  dy = 15 ; 


  printf("\007") ;

  for ( n = 0 ; n < 32 ; n ++ ) {
    XSetForeground( dpy , gc , pixels[n] ) ;
    for ( l = 0 ; l < LGN ; l++ ) {
      for ( c = 0 ; c < COL ; c++ ) {
         segment[c].x1 = segment[c].x2 = c * dx + c ;
         segment[c].y1 = l * ( dy + EPS ) ;
         segment[c].y2 = segment[c].y1 + dy ;
      }
      XDrawSegments( dpy , w , gc , segment , c ) ;
    }
    XClearWindow( dpy , w ) ;
  }  

  printf("\007") ;

}
/***************** doInitialize **************************/
static void doInitialize( )
{ long int mask ;       
XColor color ;
int i ;
int status ;

    dpy = XOpenDisplay(0);	
    if (!dpy){
        printf("Display not opened!\n");
        exit(-1);
    }

    XSynchronize( dpy , 1 ) ; 

    screen = XDefaultScreenOfDisplay ( dpy ) ;
    cells  = DisplayCells ( dpy , DefaultScreen( dpy ) ) ;
    if( !XMatchVisualInfo( dpy , DefaultScreen( dpy ) , depth , 
				PseudoColor , &vinfo ) ) {
		printf(" Bad Visual\n") ;
		exit (2) ;
    }
    visual = vinfo.visual ;

    mask = CWBackPixel | CWBorderPixel ;
    attr.background_pixel = WhitePixel( dpy , DefaultScreen( dpy ) ) ;   
    mask |= CWBorderPixel ;
    attr.border_pixel = BlackPixel( dpy , DefaultScreen( dpy ) ) ;   
    mask |= CWColormap ;

/* Create application colormap */
    attr.colormap = XCreateColormap( dpy , RootWindowOfScreen( screen )
					 , visual , AllocNone ) ;

/* Can't work because Default Colormap has not the same VISUAL
    attr.colormap = DefaultColormapOfScreen( screen ) ;
*/


    w      = XCreateWindow( dpy , RootWindowOfScreen( screen )
                                      , xw  , yw
				      , dxw , dyw
				      , border , depth
				      , InputOutput
				      , visual
				      , mask , &attr ) ;
				
    XMapWindow( dpy , w ) ;

/* At this time Screen become BLACK if you select the banner of the window
	with the mouse */

/* Allocate 32 colors */
    status = XAllocColorCells( dpy , attr.colormap , True  ,
						planes , nplanes 
						 , pixels , ncolors ) ;
   if( !status ) {
	printf(" Bad Colormap\n") ;
        exit (3) ;
    }

    XInstallColormap( dpy , attr.colormap ) ;
/* At this time screen become black */  
    gc     = XCreateGC( dpy , w , 0 , NULL ) ;
    XFlush( dpy ) ;
    for( i=0 ; i<ncolors ; i++ ) {
        color.red = 0xFFFF * i / ncolors ;
        color.green = 0x7FFF * i / ncolors ;
        color.blue = 0x3FFF * i / ncolors ;
	color.pixel = pixels[i] ;           
        color.flags = DoRed | DoGreen | DoBlue ;
	XStoreColor( dpy , attr.colormap , &color ) ;
        XFlush( dpy ) ;
    }
    XSync( dpy , 0 ) ;
}

/********************** The main program *******************************/

int main()
{          
char c;

    doInitialize( );
    do5000( );
    scanf("%c",&c) ;
}                                        
T.RTitleUserPersonal
Name
DateLines
3429.1DECWIN::FISHERI like my species the way it is&quot; &quot;A narrow view...Wed Oct 10 1990 18:2715
I don't know about the particular hardware you are dealing with, but I will
guess that if it has both a TrueColor and a PseudoColor visual, that in fact
the hardware is implemented as DirectColor.  In that case, TrueColor gets
simulated by loading up the DirectColor hardware colormap with a gigantic color
cube.  When you want a PseudoColor visual, that gets done by duplicating the
8-bit index across all 24 bits and using the hardware colormap again.

The point being that *most* hardware devices have only one native visual and
one native colormap.  (The VAX 35x0 is an exception to the 1 colormap rule).
Thus, in your case, when you install the pseudocolor map, you are, in fact,
displacing the map which is simulating TrueColor.

Does that explain it?

Burns