home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfb8bit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-27  |  5.4 KB  |  226 lines

  1. /*
  2.  * cfb8bit.c
  3.  *
  4.  * 8 bit color frame buffer utility routines
  5.  */
  6.  
  7. /* $XConsortium: cfb8bit.c,v 1.5 91/01/27 13:02:56 keith Exp $ */
  8.  
  9. #include    "X.h"
  10. #include    "Xmd.h"
  11. #include    "Xproto.h"
  12. #include    "gcstruct.h"
  13. #include    "windowstr.h"
  14. #include    "scrnintstr.h"
  15. #include    "pixmapstr.h"
  16. #include    "regionstr.h"
  17. #include    "cfb.h"
  18. #include    "cfbmskbits.h"
  19. #include    "cfb8bit.h"
  20.  
  21. #if (PPW == 4)
  22.  
  23. unsigned long cfb8StippleMasks[16] = {
  24.     0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  25.     0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  26.     0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  27.     0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff,
  28. };
  29.  
  30. int    cfb8StippleMode, cfb8StippleAlu, cfb8StippleRRop;
  31. unsigned long    cfb8StippleFg, cfb8StippleBg, cfb8StipplePm;
  32. unsigned long    cfb8StippleAnd[16], cfb8StippleXor[16];
  33.  
  34. int
  35. cfb8SetStipple (alu, fg, planemask)
  36. int        alu;
  37. unsigned long    fg, planemask;
  38. {
  39.     unsigned long   and, xor, rrop;
  40.     int    s;
  41.     unsigned long   c;
  42.  
  43.     cfb8StippleMode = FillStippled;
  44.     cfb8StippleAlu = alu;
  45.     cfb8StippleFg = fg & PMSK;
  46.     rrop = cfbReduceRasterOp (alu, fg, planemask, &and, &xor);
  47.     cfb8StippleRRop = rrop;
  48.     /*
  49.      * create the appropriate pixel-fill bits for current
  50.      * foreground
  51.      */
  52.     for (s = 0; s < 16; s++)
  53.     {
  54.     c = cfb8StippleMasks[s];
  55.     cfb8StippleAnd[s] = and | ~c;
  56.     cfb8StippleXor[s] = xor & c;
  57.     }
  58. }
  59.  
  60. int
  61. cfb8SetOpaqueStipple (alu, fg, bg, planemask)
  62. int        alu;
  63. unsigned long    fg, bg, planemask;
  64. {
  65.     unsigned long   andfg, xorfg, andbg, xorbg, rropfg, rropbg;
  66.     int    s;
  67.     unsigned long   c;
  68.  
  69.     cfb8StippleMode = FillOpaqueStippled;
  70.     cfb8StippleAlu = alu;
  71.     cfb8StippleFg = fg & PMSK;
  72.     cfb8StippleBg = bg & PMSK;
  73.     cfb8StipplePm = planemask & PMSK;
  74.     rropfg = cfbReduceRasterOp (alu, cfb8StippleFg, cfb8StipplePm, &andfg, &xorfg);
  75.     rropbg = cfbReduceRasterOp (alu, cfb8StippleBg, cfb8StipplePm, &andbg, &xorbg);
  76.     if (rropfg == rropbg)
  77.     cfb8StippleRRop = rropfg;
  78.     else
  79.     cfb8StippleRRop = GXset;
  80.     /*
  81.      * create the appropriate pixel-fill bits for current
  82.      * foreground
  83.      */
  84.     for (s = 0; s < 16; s++)
  85.     {
  86.     c = cfb8StippleMasks[s];
  87.     cfb8StippleAnd[s] = (andfg | ~c) & (andbg | c);
  88.     cfb8StippleXor[s] = (xorfg & c) | (xorbg & ~c);
  89.     }
  90. }
  91.  
  92. /*
  93.  * a grungy little routine.  This computes clip masks
  94.  * for partial character blts.  Returns rgnOUT if the
  95.  * entire character is clipped; returns rgnIN if the entire
  96.  * character is unclipped; returns rgnPART if a portion of
  97.  * the character is visible.  Computes clip masks for each
  98.  * longword of the character -- and those with the
  99.  * contents of the glyph to compute the visible bits.
  100.  */
  101.  
  102. #if (BITMAP_BIT_ORDER == MSBFirst)
  103. unsigned long    cfb8BitLenMasks[32] = {
  104.     0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff,
  105.     0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff,
  106.     0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff,
  107.     0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff,
  108.     0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff,
  109.     0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
  110.     0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f,
  111.     0x0000000f, 0x00000007, 0x00000003, 0x00000001,
  112. };
  113. #else
  114. unsigned long cfb8BitLenMasks[32] = {
  115.     0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
  116.     0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
  117.     0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
  118.     0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
  119.     0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
  120.     0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
  121.     0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
  122.     0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
  123. };
  124. #endif
  125.  
  126. int
  127. cfb8ComputeClipMasks32 (pBox, numRects, x, y, w, h, clips)
  128.     BoxPtr    pBox;
  129.     int        numRects;
  130.     int        x, y, w, h;
  131.     unsigned long   *clips;
  132. {
  133.     int        yBand, yBandBot;
  134.     int        ch;
  135.     unsigned long        clip;
  136.     int        partIN = FALSE, partOUT = FALSE;
  137.     int        result;
  138.  
  139.     if (numRects == 0)
  140.     return rgnOUT;
  141.     while (numRects && pBox->y2 <= y)
  142.     {
  143.     --numRects;
  144.     ++pBox;
  145.     }
  146.     if (!numRects || pBox->y1 >= y + h)
  147.     return rgnOUT;
  148.     yBand = pBox->y1;
  149.     while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
  150.     {
  151.     --numRects;
  152.     ++pBox;
  153.     }
  154.     if (!numRects || pBox->y1 >= y + h)
  155.     return rgnOUT;
  156.     if (numRects &&
  157.     x >= pBox->x1 &&
  158.     x + w <= pBox->x2 &&
  159.     y >= pBox->y1 &&
  160.     y + h <= pBox->y2)
  161.     {
  162.     return rgnIN;
  163.     }
  164.     ch = 0;
  165.     while (ch < h && y + ch < pBox->y1)
  166.     {
  167.     partOUT = TRUE;
  168.     clips[ch++] = 0;
  169.     }
  170.     while (numRects && pBox->y1 < y + h)
  171.     {
  172.     yBand = pBox->y1;
  173.     yBandBot = pBox->y2;
  174.         while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
  175.         {
  176.         --numRects;
  177.         ++pBox;
  178.         }
  179.         if (!numRects)
  180.         break;
  181.     clip = 0;
  182.         while (numRects && pBox->y1 == yBand && pBox->x1 < x + w)
  183.         {
  184.         if (x < pBox->x1)
  185.         if (pBox->x2 < x + w)
  186.             clip |= cfb8BitLenMasks[pBox->x1 - x] & ~cfb8BitLenMasks[pBox->x2 - x];
  187.         else
  188.             clip |= cfb8BitLenMasks[pBox->x1 - x];
  189.          else
  190.         if (pBox->x2 < x + w)
  191.             clip |= ~cfb8BitLenMasks[pBox->x2 - x];
  192.         else
  193.             clip = ~0;
  194.         --numRects;
  195.         ++pBox;
  196.         }
  197.     if (clip != 0)
  198.         partIN = TRUE;
  199.     if (clip != ~0)
  200.         partOUT = TRUE;
  201.     while (ch < h && y + ch < yBandBot)
  202.         clips[ch++] = clip;
  203.     while (numRects && pBox->y1 == yBand)
  204.     {
  205.         --numRects;
  206.         ++pBox;
  207.     }
  208.     }
  209.     while (ch < h)
  210.     {
  211.     partOUT = TRUE;
  212.     clips[ch++] = 0;
  213.     }
  214.     result = rgnOUT;
  215.     if (partIN)
  216.     {
  217.     if (partOUT)
  218.         result = rgnPART;
  219.     else
  220.         result = rgnIN;
  221.     }
  222.     return result;
  223. }
  224.  
  225. #endif /* PPW == 4 */
  226.