home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcRslvC.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  3KB  |  81 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /* $Header: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcRslvC.c,v 9.1 88/10/24 04:01:18 paul Exp $ */
  25. /* $Source: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcRslvC.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Header: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcRslvC.c,v 9.1 88/10/24 04:01:18 paul Exp $";
  29. #endif
  30.  
  31. /* Generic Color Resolution Scheme
  32.  * P. Shupak 12/31/87
  33.  */
  34.  
  35. #include "X.h"
  36. #include "screenint.h"
  37. #include "scrnintstr.h"
  38. #include "OScompiler.h"
  39.  
  40. void
  41. ppcResolveColor( pRed, pGreen, pBlue, pVisual )
  42. register unsigned short * const pRed ;
  43. register unsigned short * const pGreen ;
  44. register unsigned short * const pBlue ;
  45. register VisualPtr const pVisual ;
  46. register unsigned long int tmp ;
  47. register unsigned long int round ;
  48. register unsigned short int mask ;
  49.  
  50. tmp = pVisual->bitsPerRGBValue ;
  51. round = 0x8000 >> tmp ;
  52. mask = ( 0xFFFF << ( 16 - tmp ) ) & 0xFFFF ;
  53.  
  54. switch ( pVisual->class ) {
  55.     case PseudoColor:
  56.     *pRed   = ( ( tmp =   *pRed + round ) > mask ) ? mask : ( tmp & mask ) ;
  57.     *pGreen = ( ( tmp = *pGreen + round ) > mask ) ? mask : ( tmp & mask ) ;
  58.     *pBlue  = ( ( tmp =  *pBlue + round ) > mask ) ? mask : ( tmp & mask ) ;
  59.     break ;
  60.  
  61.     case GrayScale:
  62.     /* Convert To Resonable Approx. Of Gray */
  63.     tmp = ( ( 30 * *pRed ) + ( 59 * *pGreen ) + ( 11 * *pBlue ) ) / 100 ;
  64.     if ( ( tmp += round ) > mask )
  65.         tmp = mask ;
  66.     else
  67.         tmp &= mask ;
  68.     *pRed   =
  69.     *pGreen =
  70.     *pBlue = tmp ;
  71.     break ;
  72.  
  73.     default:
  74.     Error( "can't resolve color for this visual" ) ;
  75.     break ;
  76. }
  77.  
  78. return ;
  79. }
  80.