home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xlibpr3.zip / basicwin / color / colorplanes.fr < prev    next >
Text File  |  1989-11-25  |  1KB  |  54 lines

  1.     #define PIXELS 256
  2.     Display *display;
  3.     int screen;
  4.     int contig = False;        /* non-contiguous planes */
  5.     unsigned long pixels[PIXELS];    /* return of pixel values */
  6.  
  7.     /* number of independent pixel values allocate */
  8.     unsigned int ncolors = PIXELS;    
  9.  
  10.     XColor defs[2048];    /* PIXELS * 2^maxplanes where maxplanes
  11.          * is the largest of nred, ngreen, and nblue */
  12.  
  13.     /* number of planes to allocate for each primary */
  14.     unsigned int nreds = 3, ngreens = 3, nblues = 2;    
  15.  
  16.     /* returned masks, which bits of pixel value for each primary */
  17.     unsigned long red_mask, green_mask, blue_mask;    
  18.  
  19.     Colormap colormap;
  20.     Status status;
  21.  
  22.     /* open display, etc. */
  23.     /* get or create large DirectColor colormap */
  24.  
  25.     while (status = XAllocColorPlanes(display, colormap, 
  26.             contig, pixels, ncolors, nreds, ngreens, nblues, 
  27.             &red_mask, &green_mask, &blue_mask) == 0) {
  28.         {
  29.         /* Make contig False if it was True,
  30.          * reduce value of ncolors,
  31.          * reduce value of nreds, ngreens and/or nblues,
  32.          * or try allocating new map,
  33.          * break when you give up */
  34.         break;
  35.         }
  36.     if (status == 0)
  37.         {
  38.         fprintf(stderr, "%s: couldn't allocate requested colorcells", 
  39.                 argv[0]);
  40.         exit(-1);
  41.         }
  42.  
  43.     /* define desired colors in defs */
  44.  
  45.     while (status = XStoreColors(display, colormap, defs, 
  46.             ncolors) == 0)
  47.         {
  48.         fprintf(stderr, "%s: can't store colors", argv[0]);
  49.         /* try to fix problem here, exit or break */
  50.         exit(-1);
  51.         }
  52.         
  53.     /* draw your shaded stuff! */
  54.