home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbmskbits.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-04  |  5.8 KB  |  216 lines

  1. /************************************************************
  2. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  3.  
  4.                     All Rights Reserved
  5.  
  6. Permission  to  use,  copy,  modify,  and  distribute   this
  7. software  and  its documentation for any purpose and without
  8. fee is hereby granted, provided that the above copyright no-
  9. tice  appear  in all copies and that both that copyright no-
  10. tice and this permission notice appear in  supporting  docu-
  11. mentation,  and  that the names of Sun or MIT not be used in
  12. advertising or publicity pertaining to distribution  of  the
  13. software  without specific prior written permission. Sun and
  14. M.I.T. make no representations about the suitability of this
  15. software for any purpose. It is provided "as is" without any
  16. express or implied warranty.
  17.  
  18. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  19. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  20. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  21. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  23. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  24. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  25. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  
  27. ********************************************************/
  28.  
  29. /* $XConsortium: cfbmskbits.c,v 4.6 91/07/05 10:52:59 rws Exp $ */
  30.  
  31. /*
  32.  * ==========================================================================
  33.  * Converted to Color Frame Buffer by smarks@sun, April-May 1987.  The "bit 
  34.  * numbering" in the doc below really means "byte numbering" now.
  35.  * ==========================================================================
  36.  */
  37.  
  38. /*
  39.    these tables are used by several macros in the cfb code.
  40.  
  41.    the vax numbers everything left to right, so bit indices on the
  42. screen match bit indices in longwords.  the pc-rt and Sun number
  43. bits on the screen the way they would be written on paper,
  44. (i.e. msb to the left), and so a bit index n on the screen is
  45. bit index 32-n in a longword
  46.  
  47.    see also cfbmskbits.h
  48. */
  49. #include    <X.h>
  50. #include    <Xmd.h>
  51. #include    <servermd.h>
  52.  
  53. #if    (BITMAP_BIT_ORDER == MSBFirst)
  54. /* NOTE:
  55. the first element in starttab could be 0xffffffff.  making it 0
  56. lets us deal with a full first word in the middle loop, rather
  57. than having to do the multiple reads and masks that we'd
  58. have to do if we thought it was partial.
  59. */
  60. unsigned int cfbstarttab[] =
  61.     {
  62.     0x00000000,
  63.     0x00FFFFFF,
  64.     0x0000FFFF,
  65.     0x000000FF
  66.     };
  67.  
  68. unsigned int cfbendtab[] =
  69.     {
  70.     0x00000000,
  71.     0xFF000000,
  72.     0xFFFF0000,
  73.     0xFFFFFF00
  74.     };
  75.  
  76. /* a hack, for now, since the entries for 0 need to be all
  77.    1 bits, not all zeros.
  78.    this means the code DOES NOT WORK for segments of length
  79.    0 (which is only a problem in the horizontal line code.)
  80. */
  81. unsigned int cfbstartpartial[] =
  82.     {
  83.     0xFFFFFFFF,
  84.     0x00FFFFFF,
  85.     0x0000FFFF,
  86.     0x000000FF
  87.     };
  88.  
  89. unsigned int cfbendpartial[] =
  90.     {
  91.     0xFFFFFFFF,
  92.     0xFF000000,
  93.     0xFFFF0000,
  94.     0xFFFFFF00
  95.     };
  96. #else        /* (BITMAP_BIT_ORDER == LSBFirst) */
  97. /* NOTE:
  98. the first element in starttab could be 0xffffffff.  making it 0
  99. lets us deal with a full first word in the middle loop, rather
  100. than having to do the multiple reads and masks that we'd
  101. have to do if we thought it was partial.
  102. */
  103. unsigned int cfbstarttab[] = 
  104.     {
  105.     0x00000000,
  106.     0xFFFFFF00,
  107.     0xFFFF0000,
  108.     0xFF000000
  109.     };
  110.  
  111. unsigned int cfbendtab[] = 
  112.     {
  113.     0x00000000,
  114.     0x000000FF,
  115.     0x0000FFFF,
  116.     0x00FFFFFF
  117.     };
  118.  
  119. /* a hack, for now, since the entries for 0 need to be all
  120.    1 bits, not all zeros.
  121.    this means the code DOES NOT WORK for segments of length
  122.    0 (which is only a problem in the horizontal line code.)
  123. */
  124. unsigned int cfbstartpartial[] = 
  125.     {
  126.     0xFFFFFFFF,
  127.     0xFFFFFF00,
  128.     0xFFFF0000,
  129.     0xFF000000
  130.     };
  131.  
  132. unsigned int cfbendpartial[] = 
  133.     {
  134.     0xFFFFFFFF,
  135.     0x000000FF,
  136.     0x0000FFFF,
  137.     0x00FFFFFF
  138.     };
  139. #endif    /* (BITMAP_BIT_ORDER == MSBFirst) */
  140.  
  141.  
  142. /* used for masking bits in bresenham lines
  143.    mask[n] is used to mask out all but bit n in a longword (n is a
  144. screen position).
  145.    rmask[n] is used to mask out the single bit at position n (n
  146. is a screen posiotion.)
  147. */
  148.  
  149. #if    (BITMAP_BIT_ORDER == MSBFirst)
  150. unsigned int cfbmask[] =
  151.     {
  152.     0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
  153.     }; 
  154. unsigned int cfbrmask[] = 
  155.     {
  156.     0x00FFFFFF, 0xFF00FFFF, 0xFFFF00FF, 0xFFFFFF00
  157.     };
  158. #else    /* (BITMAP_BIT_ORDER == LSBFirst) */
  159. unsigned int cfbmask[] =
  160.     {
  161.     0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
  162.     }; 
  163. unsigned int cfbrmask[] = 
  164.     {
  165.     0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, 0x00FFFFFF
  166.     };
  167. #endif    /* (BITMAP_BIT_ORDER == MSBFirst) */
  168.  
  169. /*
  170.  * QuartetBitsTable contains four masks whose binary values are masks in the
  171.  * low order quartet that contain the number of bits specified in the
  172.  * index.  This table is used by getstipplepixels.
  173.  */
  174. unsigned int QuartetBitsTable[5] = {
  175. #if (BITMAP_BIT_ORDER == MSBFirst)
  176.     0x00000000,                         /* 0 - 0000 */
  177.     0x00000008,                         /* 1 - 1000 */
  178.     0x0000000C,                         /* 2 - 1100 */
  179.     0x0000000E,                         /* 3 - 1110 */
  180.     0x0000000F                          /* 4 - 1111 */
  181. #else /* (BITMAP_BIT_ORDER == LSBFirst */
  182.     0x00000000,                         /* 0 - 0000 */
  183.     0x00000001,                         /* 1 - 0001 */
  184.     0x00000003,                         /* 2 - 0011 */
  185.     0x00000007,                         /* 3 - 0111 */
  186.     0x0000000F                          /* 4 - 1111 */
  187. #endif /* (BITMAP_BIT_ORDER == MSBFirst) */
  188. };
  189.  
  190. /*
  191.  * QuartetPixelMaskTable is used by getstipplepixels to get a pixel mask
  192.  * corresponding to a quartet of bits.
  193.  */
  194. unsigned int QuartetPixelMaskTable[16] = {
  195.     0x00000000,
  196.     0x000000FF,
  197.     0x0000FF00,
  198.     0x0000FFFF,
  199.     0x00FF0000,
  200.     0x00FF00FF,
  201.     0x00FFFF00,
  202.     0x00FFFFFF,
  203.     0xFF000000,
  204.     0xFF0000FF,
  205.     0xFF00FF00,
  206.     0xFF00FFFF,
  207.     0xFFFF0000,
  208.     0xFFFF00FF,
  209.     0xFFFFFF00,
  210.     0xFFFFFFFF
  211. };
  212.  
  213. #ifdef    vax
  214. #undef    VAXBYTEORDER
  215. #endif
  216.