home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / skyway / skyCmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  4.7 KB  |  180 lines

  1. /*
  2.  * $XConsortium: skyCmap.c,v 1.2 91/07/16 13:13:47 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. /*
  28.  * skyCmap.c - colormap routines
  29.  *             copied from ibm/pgc/pgcCmap.c
  30.  *             revised to be just for skyway
  31.  */
  32.  
  33. #define NEED_EVENTS
  34.  
  35. #include "X.h"
  36. #include "Xproto.h"
  37. #include "resource.h"
  38. #include "misc.h"
  39. #include "scrnintstr.h"
  40. #include "screenint.h"
  41. #include "colormapst.h"
  42. #include "colormap.h"
  43. #include "pixmapstr.h"
  44.  
  45. #include "OScompiler.h"
  46. #include "ibmTrace.h"
  47.  
  48. /* remember the ONE installed colormap here */
  49. static ColormapPtr  InstalledColormap = NULL;
  50.  
  51. void
  52. skyStoreColors( pmap, ndef, pdefs )
  53. register ColormapPtr pmap ;
  54. register int ndef ;
  55. register xColorItem *pdefs ;
  56. {
  57.    register int i ;
  58.    int index ;
  59.  
  60.    TRACE(("skyStoreColors(pmap=x%x)\n", pmap)) ;
  61.    if ( pmap != InstalledColormap )
  62.     return;
  63.  
  64.    index = pmap->pScreen->myNum ;
  65.  
  66.    while ( ndef-- ) {
  67.     i = pdefs->pixel;
  68.     skySetColor(i, pdefs->red, pdefs->green, pdefs->blue, index);
  69.     pdefs++;
  70.     }
  71. }
  72.  
  73. int
  74. skyListInstalledColormaps( pScreen, pCmapList )
  75. register ScreenPtr pScreen ;
  76. register Colormap *pCmapList ;
  77. {
  78.    int index ;
  79.  
  80.    TRACE(("skyListInstalledColormaps(InstalledColormap=x%x)\n", InstalledColormap)) ;
  81.    index = pScreen->myNum ;
  82.  
  83.    if ( InstalledColormap ) {
  84.             *pCmapList = InstalledColormap->mid ;
  85.             return 1 ;
  86.     }
  87.     else {
  88.             *pCmapList = 0 ;
  89.             return 0 ;
  90.     }
  91. }
  92.  
  93. void
  94. skyInstallColormap( pColormap )
  95. register ColormapPtr pColormap ;
  96. {
  97.     register int i ;
  98.     register Entry *pent;
  99.     register VisualPtr pVisual = pColormap->pVisual;
  100.     int index ;
  101.     ScreenPtr pScreen = pColormap->pScreen ;
  102.     unsigned int red, green, blue;
  103.  
  104.    TRACE(("skyInstallColormap(pColormap=x%x)\n", pColormap)) ;
  105.  
  106.    index = pScreen->myNum ;
  107.  
  108.    if ( !pColormap ) /* Re-Install of NULL map ?? */
  109.     return ;
  110.  
  111.     if ((pVisual->class | DynamicClass) == DirectColor) {
  112.     for (i = 0; i < 256; i++) {
  113.         pent = &pColormap->red[(i & pVisual->redMask) >>
  114.                           pVisual->offsetRed];
  115.         red = pent->co.local.red;
  116.         pent = &pColormap->green[(i & pVisual->greenMask) >>
  117.                             pVisual->offsetGreen];
  118.         green = pent->co.local.green;
  119.         pent = &pColormap->blue[(i & pVisual->blueMask) >>
  120.                            pVisual->offsetBlue];
  121.         blue = pent->co.local.blue;
  122.         skySetColor( i, red, green, blue, index );
  123.     }
  124.     } else {
  125.     for (i = 0, pent = pColormap->red;
  126.          i < pVisual->ColormapEntries;
  127.          i++, pent++) {
  128.         if (pent->fShared) {
  129.             red = pent->co.shco.red->color;
  130.             green = pent->co.shco.green->color;
  131.             blue = pent->co.shco.blue->color;
  132.         }
  133.         else {
  134.             red = pent->co.local.red;
  135.             green = pent->co.local.green;
  136.             blue = pent->co.local.blue;
  137.         }
  138.         skySetColor( i, red, green, blue, index );
  139.     }
  140.     }
  141.  
  142.    if ( InstalledColormap != pColormap ) {
  143.     if (InstalledColormap ) /* Remember it may not exist */
  144.         WalkTree( pScreen, TellLostMap,
  145.                   &(InstalledColormap->mid) ) ;
  146.     InstalledColormap = pColormap ;
  147.     WalkTree( pScreen, TellGainedMap, &(pColormap->mid) ) ;
  148.     /* should really recolor cursor here for new color map ??? */
  149.     }
  150.  
  151.    return ;
  152. }
  153.  
  154. void
  155. skyUninstallColormap( pColormap )
  156. register ColormapPtr pColormap ;
  157. {
  158.    register ColormapPtr pCmap ;
  159.  
  160.    TRACE(("skyUninstallColormap(pColormap=x%x)\n", pColormap)) ;
  161.    if (pColormap != InstalledColormap)
  162.     return;
  163.  
  164.    pCmap = (ColormapPtr) LookupIDByType( pColormap->pScreen->defColormap,
  165.                                RT_COLORMAP ) ;
  166.    if ( pCmap != pColormap ) /* never uninstall the default map */
  167.     (* pColormap->pScreen->InstallColormap)( pCmap ) ;
  168.  
  169.    return ;
  170. }
  171.  
  172.  
  173. void
  174. skyRefreshColormaps(pScreen)
  175. ScreenPtr pScreen ;
  176. {
  177.    TRACE(("skyRefreshColormaps(pColormap=x%x)\n", InstalledColormap)) ;
  178.    skyInstallColormap(InstalledColormap);
  179. }
  180.