home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / x386 / vga / vgaCmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-26  |  4.2 KB  |  161 lines

  1. /*
  2.  * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided that
  6.  * the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Thomas Roell not be used in
  9.  * advertising or publicity pertaining to distribution of the software without
  10.  * specific, written prior permission.  Thomas Roell makes no representations
  11.  * about the suitability of this software for any purpose.  It is provided
  12.  * "as is" without express or implied warranty.
  13.  *
  14.  * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * $Header: /proj/X11/mit/server/ddx/x386/vga/RCS/vgaCmap.c,v 1.2 1991/06/27 00:03:01 root Exp $
  23.  */
  24.  
  25. #include "X.h"
  26. #include "Xproto.h"
  27. #include "scrnintstr.h"
  28. #include "colormapst.h"
  29. #include "windowstr.h"
  30. #include "compiler.h"
  31.  
  32. #include "vga.h"
  33.  
  34. #define NOMAPYET        (ColormapPtr) 0
  35.  
  36. static ColormapPtr InstalledMaps[MAXSCREENS];
  37.                 /* current colormap for each screen */
  38.  
  39. int
  40. vgaListInstalledColormaps(pScreen, pmaps)
  41.      ScreenPtr    pScreen;
  42.      Colormap    *pmaps;
  43. {
  44.   /* By the time we are processing requests, we can guarantee that there
  45.    * is always a colormap installed */
  46.   
  47.   *pmaps = InstalledMaps[pScreen->myNum]->mid;
  48.   return(1);
  49. }
  50.  
  51.  
  52. void
  53. vgaStoreColors(pmap, ndef, pdefs)
  54.      ColormapPtr    pmap;
  55.      int        ndef;
  56.      xColorItem            *pdefs;
  57. {
  58.   int        i;
  59.   unsigned char *cmap;
  60.   xColorItem    directDefs[256];
  61.  
  62.   if (pmap != InstalledMaps[pmap->pScreen->myNum])
  63.     return;
  64.  
  65.   if ((pmap->pVisual->class | DynamicClass) == DirectColor)
  66.     {
  67.       ndef = cfbExpandDirectColors (pmap, ndef, pdefs, directDefs);
  68.       pdefs = directDefs;
  69.     }
  70.  
  71.   for(i = 0; i < ndef; i++)
  72.     {
  73.       cmap = &((vgaHWPtr)vgaNewVideoState)->DAC[pdefs[i].pixel*3];
  74.       cmap[0] = pdefs[i].red   >> 10;
  75.       cmap[1] = pdefs[i].green >> 10;
  76.       cmap[2] = pdefs[i].blue  >> 10;
  77.       
  78.       if (x386VTSema)
  79.     {
  80.       outb(0x3C8, pdefs[i].pixel);
  81.       outb(0x3C9, cmap[0]);
  82.       outb(0x3C9, cmap[1]);
  83.       outb(0x3C9, cmap[2]);
  84.     }
  85.     }    
  86. }
  87.  
  88.  
  89. void
  90. vgaInstallColormap(pmap)
  91.      ColormapPtr    pmap;
  92. {
  93.   ColormapPtr oldmap = InstalledMaps[pmap->pScreen->myNum];
  94.   int         entries;
  95.   Pixel *     ppix;
  96.   xrgb *      prgb;
  97.   xColorItem *defs;
  98.   int         i;
  99.  
  100.  
  101.   if (pmap == oldmap)
  102.     return;
  103.  
  104.   if ((pmap->pVisual->class | DynamicClass) == DirectColor)
  105.     entries = (pmap->pVisual->redMask |
  106.            pmap->pVisual->greenMask |
  107.            pmap->pVisual->blueMask) + 1;
  108.   else
  109.     entries = pmap->pVisual->ColormapEntries;
  110.  
  111.   ppix = (Pixel *)ALLOCATE_LOCAL( entries * sizeof(Pixel));
  112.   prgb = (xrgb *)ALLOCATE_LOCAL( entries * sizeof(xrgb));
  113.   defs = (xColorItem *)ALLOCATE_LOCAL(entries * sizeof(xColorItem));
  114.  
  115.   if ( oldmap != NOMAPYET)
  116.     WalkTree( pmap->pScreen, TellLostMap, &oldmap->mid);
  117.  
  118.   InstalledMaps[pmap->pScreen->myNum] = pmap;
  119.  
  120.   for ( i=0; i<entries; i++) ppix[i] = i;
  121.  
  122.   QueryColors( pmap, entries, ppix, prgb);
  123.  
  124.   for ( i=0; i<entries; i++) /* convert xrgbs to xColorItems */
  125.     {
  126.       defs[i].pixel = ppix[i];
  127.       defs[i].red = prgb[i].red;
  128.       defs[i].green = prgb[i].green;
  129.       defs[i].blue = prgb[i].blue;
  130.       defs[i].flags =  DoRed|DoGreen|DoBlue;
  131.     }
  132.  
  133.   vgaStoreColors( pmap, entries, defs);
  134.  
  135.   WalkTree(pmap->pScreen, TellGainedMap, &pmap->mid);
  136.   
  137.   DEALLOCATE_LOCAL(ppix);
  138.   DEALLOCATE_LOCAL(prgb);
  139.   DEALLOCATE_LOCAL(defs);
  140. }
  141.  
  142.  
  143. void
  144. vgaUninstallColormap(pmap)
  145.      ColormapPtr pmap;
  146. {
  147.   ColormapPtr defColormap;
  148.   
  149.   if ( pmap != InstalledMaps[pmap->pScreen->myNum] )
  150.     return;
  151.  
  152.   defColormap = (ColormapPtr) LookupIDByType( pmap->pScreen->defColormap,
  153.                           RT_COLORMAP);
  154.  
  155.   if (defColormap == InstalledMaps[pmap->pScreen->myNum])
  156.     return;
  157.  
  158.   (*pmap->pScreen->InstallColormap) (defColormap);
  159. }
  160.  
  161.