home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbpushpxl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-14  |  7.0 KB  |  255 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: mfbpushpxl.c,v 5.2 89/09/14 16:26:57 rws Exp $ */
  25.  
  26. #include "X.h"
  27. #include "gcstruct.h"
  28. #include "scrnintstr.h"
  29. #include "pixmapstr.h"
  30. #include "miscstruct.h"
  31. #include "maskbits.h"
  32. #include "regionstr.h"
  33. #include "mfb.h"
  34.  
  35. /*  mfbSolidPP is courtesy of xhacks@csri.toronto.edu
  36.  
  37.     For fillStyle==FillSolid, a monochrome PushPixels can be reduced to
  38.     a ROP in the following way:  (Note that the ROP is the same as the
  39.     result of ROP(src=0x3,dst=0x5))
  40.  
  41.             src=0011 0000 0011
  42.             dst=0101 0101 0101
  43.             rop      fg=0 fg=1
  44.     GXclear         0x0 0000 0100 0100 0
  45.     GXand           0x1 0001 0100 0101  s&d
  46.     GXandReverse    0x2 0010 0100 0110 s&~d
  47.     GXcopy          0x3 0011 0100 0111 s
  48.     GXandInverted   0x4 0100 0101 0100 ~s&d
  49.     GXnoop          0x5 0101 0101 0101 d
  50.     GXxor           0x6 0110 0101 0110 s^d
  51.     GXor            0x7 0111 0101 0111 s|d
  52.     GXnor           0x8 1000 0110 0100 ~s&~d
  53.     GXequiv         0x9 1001 0110 0101 ~s^d
  54.     GXinvert        0xa 1010 0110 0110 ~d
  55.     GXorReverse     0xb 1011 0110 0111 s|~d
  56.     GXcopyInverted  0xc 1100 0111 0100 ~s
  57.     GXorInverted    0xd 1101 0111 0101 ~s|d
  58.     GXnand          0xe 1110 0111 0110 ~s|~d
  59.     GXset           0xf 1111 0111 0111 1
  60.  
  61. For src=0: newRop = 0x4|(rop>>2)
  62. For src=1: newRop = 0x4|(rop&3)
  63. */
  64.  
  65. /* mfbSolidPP -- squeegees the forground color of pGC through pBitMap
  66.  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
  67.  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
  68.  * is set in the bitmap, the fill style is put onto the drawable using
  69.  * the GC's logical function. The drawable is not changed where the bitmap
  70.  * has a zero bit or outside the area covered by the stencil.
  71.  */
  72. void
  73. mfbSolidPP(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  74.     GCPtr    pGC;
  75.     PixmapPtr    pBitMap;
  76.     DrawablePtr pDrawable;
  77.     int        dx, dy, xOrg, yOrg;
  78. {
  79.     unsigned char alu;
  80.     RegionRec rgnDst;
  81.     DDXPointPtr pptSrc;
  82.     BoxRec srcBox;
  83.     register DDXPointPtr ppt;
  84.     register BoxPtr pbox;
  85.     int i;
  86.  
  87.     if (!pGC->planemask & 1) return;
  88.  
  89.     /* compute the reduced rop function */
  90.     alu = pGC->alu;
  91.     if (!(pGC->fgPixel&1)) alu >>= 2;
  92.     alu = (alu & 0x3) | 0x4;
  93.     if (alu == GXnoop) return;
  94.  
  95.     srcBox.x1 = xOrg;
  96.     srcBox.y1 = yOrg;
  97.     srcBox.x2 = xOrg + dx;
  98.     srcBox.y2 = yOrg + dy;
  99.     (*pGC->pScreen->RegionInit)(&rgnDst, &srcBox, 1);
  100.  
  101.     /* clip the shape of the dst to the destination composite clip */
  102.     (*pGC->pScreen->Intersect)(&rgnDst, &rgnDst,
  103.                    ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  104.  
  105.     if (!REGION_NIL(&rgnDst))
  106.     {
  107.     i = REGION_NUM_RECTS(&rgnDst);
  108.     pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
  109.         if(pptSrc)
  110.         {
  111.         for (pbox = REGION_RECTS(&rgnDst), ppt = pptSrc;
  112.          --i >= 0;
  113.          pbox++, ppt++)
  114.         {
  115.         ppt->x = pbox->x1 - xOrg;
  116.         ppt->y = pbox->y1 - yOrg;
  117.         }
  118.         mfbDoBitblt((DrawablePtr)pBitMap, pDrawable, alu, &rgnDst, pptSrc);
  119.         DEALLOCATE_LOCAL(pptSrc);
  120.     }
  121.     }
  122.     (*pGC->pScreen->RegionUninit)(&rgnDst);
  123. }
  124.  
  125. #define NPT 128
  126.  
  127. /* mfbPushPixels -- squeegees the forground color of pGC through pBitMap
  128.  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
  129.  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
  130.  * is set in the bitmap, the fill style is put onto the drawable using
  131.  * the GC's logical function. The drawable is not changed where the bitmap
  132.  * has a zero bit or outside the area covered by the stencil.
  133.  */
  134. void
  135. mfbPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  136.     GCPtr    pGC;
  137.     PixmapPtr    pBitMap;
  138.     DrawablePtr pDrawable;
  139.     int        dx, dy, xOrg, yOrg;
  140. {
  141.     int        h, dxDiv32, ibEnd;
  142.     unsigned int *pwLineStart;
  143.     register unsigned int    *pw, *pwEnd;
  144.     register unsigned int mask;
  145.     register int ib, w;
  146.     register int ipt;        /* index into above arrays */
  147.     Bool     fInBox;
  148.     DDXPointRec    pt[NPT];
  149.     int        width[NPT];
  150.  
  151.     /* Now scan convert the pixmap and use the result to call fillspans in
  152.      * in the drawable with the original GC */
  153.     ipt = 0;
  154.     dxDiv32 = dx/32;
  155.     for(h = 0; h < dy; h++)
  156.     {
  157.  
  158.     pw = (unsigned int *)
  159.          (((char *)(pBitMap->devPrivate.ptr))+(h * pBitMap->devKind));
  160.     pwLineStart = pw;
  161.     /* Process all words which are fully in the pixmap */
  162.     
  163.     fInBox = FALSE;
  164.     pwEnd = pwLineStart + dxDiv32;
  165.     while(pw  < pwEnd)
  166.     {
  167.         w = *pw;
  168.         mask = endtab[1];
  169.         for(ib = 0; ib < 32; ib++)
  170.         {
  171.         if(w & mask)
  172.         {
  173.             if(!fInBox)
  174.             {
  175.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  176.             pt[ipt].y = h + yOrg;
  177.             /* start new box */
  178.             fInBox = TRUE;
  179.             }
  180.         }
  181.         else
  182.         {
  183.             if(fInBox)
  184.             {
  185.             width[ipt] = ((pw - pwLineStart) << 5) + 
  186.                      ib + xOrg - pt[ipt].x;
  187.             if (++ipt >= NPT)
  188.             {
  189.                 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
  190.                                   width, TRUE);
  191.                 ipt = 0;
  192.             }
  193.             /* end box */
  194.             fInBox = FALSE;
  195.             }
  196.         }
  197.         mask = SCRRIGHT(mask, 1);
  198.         }
  199.         pw++;
  200.     }
  201.     ibEnd = dx & 0x1F;
  202.     if(ibEnd)
  203.     {
  204.         /* Process final partial word on line */
  205.         w = *pw;
  206.         mask = endtab[1];
  207.         for(ib = 0; ib < ibEnd; ib++)
  208.         {
  209.         if(w & mask)
  210.         {
  211.             if(!fInBox)
  212.             {
  213.             /* start new box */
  214.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  215.             pt[ipt].y = h + yOrg;
  216.             fInBox = TRUE;
  217.             }
  218.         }
  219.         else
  220.         {
  221.             if(fInBox)
  222.             {
  223.             /* end box */
  224.             width[ipt] = ((pw - pwLineStart) << 5) + 
  225.                      ib + xOrg - pt[ipt].x;
  226.             if (++ipt >= NPT)
  227.             {
  228.                 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
  229.                                   width, TRUE);
  230.                 ipt = 0;
  231.             }
  232.             fInBox = FALSE;
  233.             }
  234.         }
  235.         mask = SCRRIGHT(mask, 1);
  236.         }
  237.     }
  238.     /* If scanline ended with last bit set, end the box */
  239.     if(fInBox)
  240.     {
  241.         width[ipt] = dx + xOrg - pt[ipt].x;
  242.         if (++ipt >= NPT)
  243.         {
  244.         (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
  245.         ipt = 0;
  246.         }
  247.     }
  248.     }
  249.     /* Flush any remaining spans */
  250.     if (ipt)
  251.     {
  252.     (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
  253.     }
  254. }
  255.