home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / clrsetup.c < prev    next >
C/C++ Source or Header  |  1990-06-03  |  7KB  |  203 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:     clrsetup.c (Color Setup)
  6.  * Purpose:    Set parameters for the current color mode
  7.  * Subroutine:    init_overlay_color()        returns: void
  8.  * Subroutine:    init_cell_color()        returns: void
  9.  * Subroutine:    init_halftone_color()        returns: void
  10.  * Xlib calls:    XStoreColors()
  11.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  12.  *        You may do anything you like with this file except remove
  13.  *        this copyright.  The Smithsonian Astrophysical Observatory
  14.  *        makes no representations about the suitability of this
  15.  *        software for any purpose.  It is provided "as is" without
  16.  *        express or implied warranty.
  17.  * Modified:    {0} Michael VanHilst    initial version           9 May 1989
  18.  *        {1} MVH initialize flags in init_cellstore        15 Oct 1989
  19.  *        {n} <who> -- <does what> -- <when>
  20.  */
  21.  
  22. #include <stdio.h>            /* stderr, NULL, etc. */
  23. #include <X11/Xlib.h>            /* X window stuff */
  24. #include <X11/Xutil.h>            /* X window manager stuff */
  25. #include "hfiles/color.h"        /* color structs */
  26.  
  27. /*
  28.  * Subroutine:    init_overlay_color
  29.  * Purpose:    Set up color parameters unique to overlay type usage
  30.  * Xlib calls:    XStoreColors()
  31.  */
  32. void init_overlay_color ( color )
  33.      struct colorRec *color;
  34. {
  35.   int ncolors;
  36.   void make_cellstore_from_tables();
  37.   static void set_cursor_overlay_color(), copy_xcolor_rgb(), init_cellstore();
  38.  
  39.   init_cellstore(color->cellstore, color->pixvalmap, color->ncolors);
  40.   /* color in the cursor range of the color map */
  41.   set_cursor_overlay_color(color, &color->cellstore[color->ncolors]);
  42.   /* set aside two pixel values for region maps */
  43.   color->ncolors -= 2;
  44.   ncolors = color->ncolors;
  45.   color->cur.color_one.pixel = color->pixvalmap[ncolors]; 
  46.   color->cur.color_two.pixel = color->pixvalmap[ncolors + 1];
  47.   color->image_plane_mask = ~color->overlay_mask;
  48.   copy_xcolor_rgb(&(color->cur.color_one), &color->cellstore[ncolors]);
  49.   copy_xcolor_rgb(&(color->cur.color_two), &color->cellstore[ncolors+1]);
  50.   /* set up the cursor drawing parameters */
  51.   color->gcset.draw.foreground = color->overlay_mask;
  52.   color->gcset.draw.mask = color->overlay_mask;
  53.   color->gcset.track.foreground = color->overlay_mask;
  54.   color->gcset.track.mask = color->overlay_mask;
  55.   color->gcset.track.func = GXcopy;
  56.   color->gcset.undraw.foreground = 0;
  57.   color->gcset.undraw.func = GXcopy;
  58.   color->gcset.undraw.mask = color->overlay_mask;
  59.   color->gcset.incl.foreground = color->cur.color_one.pixel;
  60.   color->gcset.excl.foreground = color->cur.color_two.pixel;
  61.   color->gcset.incl.background = color->pixvalmap[0];
  62.   color->gcset.excl.background = color->gcset.incl.background;
  63.   /* make or remake the color table */
  64.   color->ctable.red.map_sz = ncolors;
  65.   color->ctable.green.map_sz = ncolors;
  66.   color->ctable.blue.map_sz = ncolors;
  67.   make_cellstore_from_tables(color);
  68.   /* store all the colors at the same time */
  69.   XStoreColors(color->display, color->colormap,
  70.            color->cellstore, 2 * (ncolors + 2));
  71. }
  72.  
  73. /*
  74.  * Subroutine:    init_cell_color
  75.  * Purpose:    Set up color parameters unique to cell usage without overlay
  76.  * Xlib calls:    XStoreColors()
  77.  */
  78. void init_cell_color ( color )
  79.      struct colorRec *color;
  80. {
  81.   void make_cellstore_from_tables();
  82.   int alloc_cursor_cell_color();
  83.   static void init_cellstore();
  84.  
  85.   init_cellstore(color->cellstore, color->pixvalmap, color->ncolors);
  86.   /* Not cursor plane */
  87.   color->image_plane_mask = AllPlanes;
  88.   /* Set up the cursor drawing parameters */
  89.   color->gcset.draw.foreground =
  90.     alloc_cursor_cell_color(color, color->colormap);
  91.   color->gcset.draw.mask = AllPlanes;
  92.   color->gcset.track.foreground = AllPlanes;
  93.   color->gcset.track.func = GXxor;
  94.   color->gcset.track.mask = AllPlanes;
  95.   color->gcset.undraw.foreground = AllPlanes;
  96.   color->gcset.undraw.func = GXxor;
  97.   color->gcset.undraw.mask = AllPlanes;
  98.   color->gcset.incl.foreground = color->cur.disp_one;
  99.   color->gcset.excl.foreground = color->cur.disp_two;
  100.   color->gcset.incl.background = color->hard.true_black;
  101.   color->gcset.excl.background = color->hard.true_black;
  102.   /* Make or remake the color table */
  103.   color->ctable.red.map_sz = color->ncolors;
  104.   color->ctable.green.map_sz = color->ncolors;
  105.   color->ctable.blue.map_sz = color->ncolors;
  106.   make_cellstore_from_tables(color);
  107.   /* Store all the colors at the same time */
  108.   XStoreColors(color->display, color->colormap,
  109.            color->cellstore, color->ncolors);
  110. }
  111.  
  112. /*
  113.  * Subroutine:    init_halftone_color
  114.  * Purpose:    Initialize color parameters for halftone mode
  115.  */
  116. void init_halftone_color ( color )
  117.      struct colorRec *color;
  118. {
  119.   color->ncolors = 1;
  120.   color->cursor_overlay = 0;
  121.   color->gcset.disp.foreground = color->hard.std_black;
  122.   color->gcset.disp.background = color->hard.std_white;
  123.   color->gcset.draw.foreground = color->hard.std_black;
  124.   color->gcset.draw.mask = AllPlanes;
  125.   color->gcset.track.foreground = 1;
  126.   color->gcset.track.func = GXxor;
  127.   color->gcset.track.mask = 1;
  128.   color->gcset.undraw.foreground = 1;
  129.   color->gcset.undraw.func = GXxor;
  130.   color->gcset.undraw.mask = 1;
  131.   color->gcset.incl.foreground = 0;
  132.   color->gcset.excl.foreground = 1;
  133.   color->gcset.incl.background = 1;
  134.   color->gcset.excl.background = 0;
  135.   color->cur.disp_one = 0;
  136.   color->cur.disp_two = 1;
  137.   {
  138.     /* set up a remapping table in the pixvalmap space (not used much yet) */
  139.     register int i;
  140.     register unsigned long *pixels;
  141.  
  142.     pixels = color->pixvalmap;
  143.     for( i=0; i<256; i++ ) {
  144.       *pixels = i;
  145.       ++pixels;
  146.     }
  147.   }
  148. }
  149.  
  150. /*
  151.  * Subroutine:    init_cellstore
  152.  * Purpose:    Set the pixel values in the color cellstore
  153.  */
  154. static void init_cellstore ( cellstore, pixvalmap, ncolors )
  155.      XColor *cellstore;
  156.      unsigned long *pixvalmap;
  157.      int ncolors;
  158. {
  159.   int i;
  160.  
  161.   for( i=0; i<ncolors; i++ ) {
  162.     cellstore[i].pixel = pixvalmap[i];
  163.     cellstore[i].flags = DoRed | DoBlue | DoGreen;
  164.   }
  165. }
  166.  
  167. /*
  168.  * Subroutine:    copy_xcolor_rgb
  169.  * Purpose:    Copy the red, green, and blue valuesto another XColor
  170.  */
  171. static void copy_xcolor_rgb ( orig, dup )
  172.      XColor *orig, *dup;
  173. {
  174.   dup->red = orig->red;
  175.   dup->green = orig->green;
  176.   dup->blue = orig->blue;
  177. }
  178.  
  179. /*
  180.  * Subroutine:    set_cursor_overlay_color
  181.  * Purpose:    Set the cellstore entries for an overlay cursor
  182.  */
  183. static void set_cursor_overlay_color ( color, cellstore )
  184.      struct colorRec *color;
  185.      XColor *cellstore;
  186. {
  187.   unsigned long *pixvalmap, overlay_bit;
  188.   unsigned short red, green, blue;
  189.   int i;
  190.  
  191.   pixvalmap = color->pixvalmap;
  192.   red = color->cur.color_cur.red;
  193.   green = color->cur.color_cur.green;
  194.   blue = color->cur.color_cur.blue;
  195.   overlay_bit = (int)color->overlay_mask;
  196.   for( i=0; i<color->ncolors; i++ ) {
  197.     cellstore[i].pixel = pixvalmap[i] + overlay_bit;
  198.     cellstore[i].red = red;
  199.     cellstore[i].green = green;
  200.     cellstore[i].blue = blue;
  201.   }
  202. }
  203.