home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mi / mipushpxl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-26  |  4.6 KB  |  175 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: mipushpxl.c,v 5.1 89/07/26 12:18:19 rws Exp $ */
  25. #include "X.h"
  26. #include "gcstruct.h"
  27. #include "scrnintstr.h"
  28. #include "pixmapstr.h"
  29. #include "miscstruct.h"
  30. #include "../mfb/maskbits.h"
  31.  
  32. #define NPT 128
  33.  
  34. /* miPushPixels -- squeegees the fill style of pGC through pBitMap
  35.  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
  36.  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
  37.  * is set in the bitmap, the fill style is put onto the drawable using
  38.  * the GC's logical function. The drawable is not changed where the bitmap
  39.  * has a zero bit or outside the area covered by the stencil.
  40.  
  41. WARNING:
  42.     this code works if the 1-bit deep pixmap format returned by GetSpans
  43. is the same as the format defined by the mfb code (i.e. 32-bit padding
  44. per scanline, scanline unit = 32 bits; later, this might mean
  45. bitsizeof(int) padding and sacnline unit == bitsizeof(int).)
  46.  
  47.  */
  48. void
  49. miPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  50.     GCPtr    pGC;
  51.     PixmapPtr    pBitMap;
  52.     DrawablePtr pDrawable;
  53.     int        dx, dy, xOrg, yOrg;
  54. {
  55.     int        h, dxDiv32, ibEnd;
  56.     unsigned long *pwLineStart;
  57.     register unsigned long    *pw, *pwEnd;
  58.     register unsigned long msk;
  59.     register int ib, w;
  60.     register int ipt;        /* index into above arrays */
  61.     Bool     fInBox;
  62.     DDXPointRec    pt[NPT], ptThisLine;
  63.     int        width[NPT];
  64.  
  65.     pwLineStart = (unsigned long *)xalloc(PixmapBytePad(dx, 1));
  66.     if (!pwLineStart)
  67.     return;
  68.     ipt = 0;
  69.     dxDiv32 = dx/32;
  70.  
  71.     for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0; 
  72.     h < dy; 
  73.     h++, ptThisLine.y++)
  74.     {
  75.  
  76.     (*pBitMap->drawable.pScreen->GetSpans)(pBitMap, dx, &ptThisLine, &dx,
  77.                            1, pwLineStart);
  78.  
  79.     pw = pwLineStart;
  80.     /* Process all words which are fully in the pixmap */
  81.     
  82.     fInBox = FALSE;
  83.     pwEnd = pwLineStart + dxDiv32;
  84.     while(pw  < pwEnd)
  85.     {
  86.         w = *pw;
  87.         msk = endtab[1];
  88.         for(ib = 0; ib < 32; ib++)
  89.         {
  90.         if(w & msk)
  91.         {
  92.             if(!fInBox)
  93.             {
  94.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  95.             pt[ipt].y = h + yOrg;
  96.             /* start new box */
  97.             fInBox = TRUE;
  98.             }
  99.         }
  100.         else
  101.         {
  102.             if(fInBox)
  103.             {
  104.             width[ipt] = ((pw - pwLineStart) << 5) + 
  105.                      ib + xOrg - pt[ipt].x;
  106.             if (++ipt >= NPT)
  107.             {
  108.                 (*pGC->ops->FillSpans)(pDrawable, pGC, 
  109.                           NPT, pt, width, TRUE);
  110.                 ipt = 0;
  111.             }
  112.             /* end box */
  113.             fInBox = FALSE;
  114.             }
  115.         }
  116.         msk = SCRRIGHT(msk, 1);
  117.         }
  118.         pw++;
  119.     }
  120.     ibEnd = dx & 0x1F;
  121.     if(ibEnd)
  122.     {
  123.         /* Process final partial word on line */
  124.         w = *pw;
  125.         msk = endtab[1];
  126.         for(ib = 0; ib < ibEnd; ib++)
  127.         {
  128.         if(w & msk)
  129.         {
  130.             if(!fInBox)
  131.             {
  132.             /* start new box */
  133.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  134.             pt[ipt].y = h + yOrg;
  135.             fInBox = TRUE;
  136.             }
  137.         }
  138.         else
  139.         {
  140.             if(fInBox)
  141.             {
  142.             /* end box */
  143.             width[ipt] = ((pw - pwLineStart) << 5) + 
  144.                      ib + xOrg - pt[ipt].x;
  145.             if (++ipt >= NPT)
  146.             {
  147.                 (*pGC->ops->FillSpans)(pDrawable, 
  148.                           pGC, NPT, pt, width, TRUE);
  149.                 ipt = 0;
  150.             }
  151.             fInBox = FALSE;
  152.             }
  153.         }
  154.         msk = SCRRIGHT(msk, 1);
  155.         }
  156.     }
  157.     /* If scanline ended with last bit set, end the box */
  158.     if(fInBox)
  159.     {
  160.         width[ipt] = dx + xOrg - pt[ipt].x;
  161.         if (++ipt >= NPT)
  162.         {
  163.         (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
  164.         ipt = 0;
  165.         }
  166.     }
  167.     }
  168.     xfree(pwLineStart);
  169.     /* Flush any remaining spans */
  170.     if (ipt)
  171.     {
  172.     (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
  173.     }
  174. }
  175.