home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfb8cppl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-22  |  5.5 KB  |  219 lines

  1. /*
  2.  * $XConsortium: cfb8cppl.c,v 1.5 91/08/22 15:41:05 keith Exp $
  3.  *
  4.  * Copyright 1990 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. /* 
  27.  * this is actually an mfb-specific function, except that
  28.  * it knows how to read from 8-bit cfb pixmaps.  Alas, this
  29.  * means that it doesn't know PPW so it is always compiled
  30.  */
  31.  
  32. #include "X.h"
  33. #include "Xmd.h"
  34. #include "gcstruct.h"
  35. #include "window.h"
  36. #include "pixmapstr.h"
  37. #include "scrnintstr.h"
  38. #include "windowstr.h"
  39. #include "cfb.h"
  40. #include "maskbits.h"
  41.  
  42. #include "mergerop.h"
  43.  
  44. #if BITMAP_BIT_ORDER == MSBFirst
  45. #define LeftMost    31
  46. #define StepBit(bit, inc)  ((bit) -= (inc))
  47. #else
  48. #define LeftMost    0
  49. #define StepBit(bit, inc)  ((bit) += (inc))
  50. #endif
  51.  
  52. #define GetBits(psrc, nBits, curBit, bitPos, bits) {\
  53.     bits = 0; \
  54.     while (nBits--) \
  55.     { \
  56.     bits |= ((*psrc++ >> bitPos) & 1) << curBit; \
  57.     StepBit (curBit, 1); \
  58.     } \
  59. }
  60.  
  61. cfbCopyImagePlane (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask)
  62.     DrawablePtr pSrcDrawable;
  63.     DrawablePtr pDstDrawable;
  64.     int    rop;
  65.     unsigned long planemask;
  66.     RegionPtr prgnDst;
  67.     DDXPointPtr pptSrc;
  68. {
  69.     cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc,
  70.               (unsigned long) ~0L, planemask);
  71. }
  72.  
  73. cfbCopyPlane8to1 (pSrcDrawable, pDstDrawable, rop, prgnDst, pptSrc, planemask, bitPlane)
  74.     DrawablePtr pSrcDrawable;
  75.     DrawablePtr pDstDrawable;
  76.     int    rop;
  77.     RegionPtr prgnDst;
  78.     DDXPointPtr pptSrc;
  79.     unsigned long planemask;
  80.     unsigned long   bitPlane;
  81. {
  82.     int                srcx, srcy, dstx, dsty, width, height;
  83.     unsigned char        *psrcBase;
  84.     unsigned long        *pdstBase;
  85.     int                widthSrc, widthDst;
  86.     unsigned char        *psrcLine;
  87.     unsigned long        *pdstLine;
  88.     register unsigned char  *psrc;
  89.     register int        i;
  90.     register int        curBit;
  91.     register int        bitPos;
  92.     register unsigned long  bits;
  93.     register unsigned long  *pdst;
  94.     unsigned long        startmask, endmask;
  95.     int                niStart, niEnd;
  96.     int                bitStart, bitEnd;
  97.     int                nl, nlMiddle;
  98.     int                nbox;
  99.     BoxPtr            pbox;
  100.     MROP_DECLARE()
  101.  
  102.     if (!(planemask & 1))
  103.     return;
  104.  
  105.     if (rop != GXcopy)
  106.     MROP_INITIALIZE (rop, planemask);
  107.  
  108.     cfbGetByteWidthAndPointer (pSrcDrawable, widthSrc, psrcBase)
  109.  
  110.     mfbGetLongWidthAndPointer (pDstDrawable, widthDst, pdstBase)
  111.  
  112.     bitPos = ffs (bitPlane) - 1;
  113.  
  114.     nbox = REGION_NUM_RECTS(prgnDst);
  115.     pbox = REGION_RECTS(prgnDst);
  116.     while (nbox--)
  117.     {
  118.     dstx = pbox->x1;
  119.     dsty = pbox->y1;
  120.     srcx = pptSrc->x;
  121.     srcy = pptSrc->y;
  122.     width = pbox->x2 - pbox->x1;
  123.     height = pbox->y2 - pbox->y1;
  124.     pbox++;
  125.     pptSrc++;
  126.     psrcLine = psrcBase + srcy * widthSrc + srcx;
  127.     pdstLine = pdstBase + dsty * widthDst + (dstx >> 5);
  128.     dstx &= 0x1f;
  129.     if (dstx + width <= 32)
  130.     {
  131.         maskpartialbits(dstx, width, startmask);
  132.         nlMiddle = 0;
  133.         endmask = 0;
  134.     }
  135.     else
  136.     {
  137.         maskbits (dstx, width, startmask, endmask, nlMiddle);
  138.     }
  139.     if (startmask)
  140.     {
  141.         niStart = 32 - dstx;
  142.         bitStart = LeftMost;
  143.         StepBit (bitStart, dstx);
  144.     }
  145.     if (endmask)
  146.     {
  147.         niEnd = (dstx + width) & 0x1f;
  148.         bitEnd = LeftMost;
  149.     }
  150.     if (rop == GXcopy)
  151.     {
  152.         while (height--)
  153.         {
  154.             psrc = psrcLine;
  155.             pdst = pdstLine;
  156.             psrcLine += widthSrc;
  157.             pdstLine += widthDst;
  158.             if (startmask)
  159.             {
  160.             i = niStart;
  161.             curBit = bitStart;
  162.             GetBits (psrc, i, curBit, bitPos, bits);
  163.             *pdst = *pdst & ~startmask | bits;
  164.             pdst++;
  165.             }
  166.             nl = nlMiddle;
  167.             while (nl--)
  168.             {
  169.             i = 32;
  170.             curBit = LeftMost;
  171.             GetBits (psrc, i, curBit, bitPos, bits);
  172.             *pdst++ = bits;
  173.             }
  174.             if (endmask)
  175.             {
  176.             i = niEnd;
  177.             curBit = bitEnd;
  178.             GetBits (psrc, i, curBit, bitPos, bits);
  179.             *pdst = *pdst & ~endmask | bits;
  180.             }
  181.         }
  182.     }
  183.     else
  184.     {
  185.         while (height--)
  186.         {
  187.             psrc = psrcLine;
  188.             pdst = pdstLine;
  189.             psrcLine += widthSrc;
  190.             pdstLine += widthDst;
  191.             if (startmask)
  192.             {
  193.             i = niStart;
  194.             curBit = bitStart;
  195.             GetBits (psrc, i, curBit, bitPos, bits);
  196.             *pdst = MROP_MASK(bits, *pdst, startmask);
  197.             pdst++;
  198.             }
  199.             nl = nlMiddle;
  200.             while (nl--)
  201.             {
  202.             i = 32;
  203.             curBit = LeftMost;
  204.             GetBits (psrc, i, curBit, bitPos, bits);
  205.             *pdst = MROP_SOLID(bits, *pdst);
  206.             pdst++;
  207.             }
  208.             if (endmask)
  209.             {
  210.             i = niEnd;
  211.             curBit = bitEnd;
  212.             GetBits (psrc, i, curBit, bitPos, bits);
  213.             *pdst = MROP_MASK (bits, *pdst, endmask);
  214.             }
  215.         }
  216.     }
  217.     }
  218. }
  219.