home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbfillarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-06  |  7.3 KB  |  326 lines

  1. /************************************************************
  2. Copyright 1989 by The Massachusetts Institute of Technology
  3.  
  4. Permission to use, copy, modify, and distribute this
  5. software and its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting
  9. documentation, and that the name of MIT not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific prior written permission.
  12. M.I.T. makes no representation about the suitability of
  13. this software for any purpose. It is provided "as is"
  14. without any express or implied warranty.
  15.  
  16. ********************************************************/
  17.  
  18. /* $XConsortium: mfbfillarc.c,v 5.7 90/10/06 13:58:08 rws Exp $ */
  19.  
  20. #include "X.h"
  21. #include "Xprotostr.h"
  22. #include "miscstruct.h"
  23. #include "gcstruct.h"
  24. #include "pixmapstr.h"
  25. #include "scrnintstr.h"
  26. #include "mfb.h"
  27. #include "maskbits.h"
  28. #include "mifillarc.h"
  29.  
  30. extern void miPolyFillArc();
  31.  
  32. static void
  33. mfbFillEllipseSolid(pDraw, arc, rop)
  34.     DrawablePtr pDraw;
  35.     xArc *arc;
  36.     register int rop;
  37. {
  38.     int x, y, e;
  39.     int yk, xk, ym, xm, dx, dy, xorg, yorg;
  40.     register int slw;
  41.     miFillArcRec info;
  42.     int *addrlt, *addrlb;
  43.     register int *addrl;
  44.     register int n;
  45.     int nlwidth;
  46.     register int xpos;
  47.     int startmask, endmask, nlmiddle;
  48.  
  49.     if (pDraw->type == DRAWABLE_WINDOW)
  50.     {
  51.     addrlt = (int *)
  52.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  53.     nlwidth = (int)
  54.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  55.     }
  56.     else
  57.     {
  58.     addrlt = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  59.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  60.     }
  61.     miFillArcSetup(arc, &info);
  62.     MIFILLARCSETUP();
  63.     xorg += pDraw->x;
  64.     yorg += pDraw->y;
  65.     addrlb = addrlt;
  66.     addrlt += nlwidth * (yorg - y);
  67.     addrlb += nlwidth * (yorg + y + dy);
  68.     while (y)
  69.     {
  70.     addrlt += nlwidth;
  71.     addrlb -= nlwidth;
  72.     MIFILLARCSTEP(slw);
  73.     if (!slw)
  74.         continue;
  75.     xpos = xorg - x;
  76.     addrl = addrlt + (xpos >> 5);
  77.     if (((xpos & 0x1f) + slw) < 32)
  78.     {
  79.         maskpartialbits(xpos, slw, startmask);
  80.         if (rop == RROP_BLACK)
  81.         *addrl &= ~startmask;
  82.         else if (rop == RROP_WHITE)
  83.         *addrl |= startmask;
  84.         else
  85.         *addrl ^= startmask;
  86.         if (miFillArcLower(slw))
  87.         {
  88.         addrl = addrlb + (xpos >> 5);
  89.         if (rop == RROP_BLACK)
  90.             *addrl &= ~startmask;
  91.         else if (rop == RROP_WHITE)
  92.             *addrl |= startmask;
  93.         else
  94.             *addrl ^= startmask;
  95.         }
  96.         continue;
  97.     }
  98.     maskbits(xpos, slw, startmask, endmask, nlmiddle);
  99.     if (startmask)
  100.     {
  101.         if (rop == RROP_BLACK)
  102.         *addrl++ &= ~startmask;
  103.         else if (rop == RROP_WHITE)
  104.         *addrl++ |= startmask;
  105.         else
  106.         *addrl++ ^= startmask;
  107.     }
  108.     n = nlmiddle;
  109.     if (rop == RROP_BLACK)
  110.         while (n--)
  111.         *addrl++ = 0;
  112.     else if (rop == RROP_WHITE)
  113.         while (n--)
  114.         *addrl++ = ~0;
  115.     else
  116.         while (n--)
  117.         *addrl++ ^= ~0;
  118.     if (endmask)
  119.     {
  120.         if (rop == RROP_BLACK)
  121.         *addrl &= ~endmask;
  122.         else if (rop == RROP_WHITE)
  123.         *addrl |= endmask;
  124.         else
  125.         *addrl ^= endmask;
  126.     }
  127.     if (!miFillArcLower(slw))
  128.         continue;
  129.     addrl = addrlb + (xpos >> 5);
  130.     if (startmask)
  131.     {
  132.         if (rop == RROP_BLACK)
  133.         *addrl++ &= ~startmask;
  134.         else if (rop == RROP_WHITE)
  135.         *addrl++ |= startmask;
  136.         else
  137.         *addrl++ ^= startmask;
  138.     }
  139.     n = nlmiddle;
  140.     if (rop == RROP_BLACK)
  141.         while (n--)
  142.         *addrl++ = 0;
  143.     else if (rop == RROP_WHITE)
  144.         while (n--)
  145.         *addrl++ = ~0;
  146.     else
  147.         while (n--)
  148.         *addrl++ ^= ~0;
  149.     if (endmask)
  150.     {
  151.         if (rop == RROP_BLACK)
  152.         *addrl &= ~endmask;
  153.         else if (rop == RROP_WHITE)
  154.         *addrl |= endmask;
  155.         else
  156.         *addrl ^= endmask;
  157.     }
  158.     }
  159. }
  160.  
  161. #define FILLSPAN(xl,xr,addr) \
  162.     if (xr >= xl) \
  163.     { \
  164.     width = xr - xl + 1; \
  165.     addrl = addr + (xl >> 5); \
  166.     if (((xl & 0x1f) + width) < 32) \
  167.     { \
  168.         maskpartialbits(xl, width, startmask); \
  169.         if (rop == RROP_BLACK) \
  170.         *addrl &= ~startmask; \
  171.         else if (rop == RROP_WHITE) \
  172.         *addrl |= startmask; \
  173.         else \
  174.         *addrl ^= startmask; \
  175.     } \
  176.     else \
  177.     { \
  178.         maskbits(xl, width, startmask, endmask, nlmiddle); \
  179.         if (startmask) \
  180.         { \
  181.         if (rop == RROP_BLACK) \
  182.             *addrl++ &= ~startmask; \
  183.         else if (rop == RROP_WHITE) \
  184.             *addrl++ |= startmask; \
  185.         else \
  186.             *addrl++ ^= startmask; \
  187.         } \
  188.         n = nlmiddle; \
  189.         if (rop == RROP_BLACK) \
  190.         while (n--) \
  191.             *addrl++ = 0; \
  192.         else if (rop == RROP_WHITE) \
  193.         while (n--) \
  194.             *addrl++ = ~0; \
  195.         else \
  196.         while (n--) \
  197.             *addrl++ ^= ~0; \
  198.         if (endmask) \
  199.         { \
  200.         if (rop == RROP_BLACK) \
  201.             *addrl &= ~endmask; \
  202.         else if (rop == RROP_WHITE) \
  203.             *addrl |= endmask; \
  204.         else \
  205.             *addrl ^= endmask; \
  206.         } \
  207.     } \
  208.     }
  209.  
  210. #define FILLSLICESPANS(flip,addr) \
  211.     if (!flip) \
  212.     { \
  213.     FILLSPAN(xl, xr, addr); \
  214.     } \
  215.     else \
  216.     { \
  217.     xc = xorg - x; \
  218.     FILLSPAN(xc, xr, addr); \
  219.     xc += slw - 1; \
  220.     FILLSPAN(xl, xc, addr); \
  221.     }
  222.  
  223. static void
  224. mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop)
  225.     DrawablePtr pDraw;
  226.     GCPtr pGC;
  227.     xArc *arc;
  228.     register int rop;
  229. {
  230.     register int *addrl;
  231.     register int n;
  232.     int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
  233.     register int x, y, e;
  234.     miFillArcRec info;
  235.     miArcSliceRec slice;
  236.     int xl, xr, xc;
  237.     int *addrlt, *addrlb;
  238.     int nlwidth;
  239.     int width;
  240.     int startmask, endmask, nlmiddle;
  241.  
  242.     if (pDraw->type == DRAWABLE_WINDOW)
  243.     {
  244.     addrlt = (int *)
  245.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  246.     nlwidth = (int)
  247.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  248.     }
  249.     else
  250.     {
  251.     addrlt = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  252.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  253.     }
  254.     miFillArcSetup(arc, &info);
  255.     miFillArcSliceSetup(arc, &slice, pGC);
  256.     MIFILLARCSETUP();
  257.     xorg += pDraw->x;
  258.     yorg += pDraw->y;
  259.     addrlb = addrlt;
  260.     addrlt += nlwidth * (yorg - y);
  261.     addrlb += nlwidth * (yorg + y + dy);
  262.     slice.edge1.x += pDraw->x;
  263.     slice.edge2.x += pDraw->x;
  264.     while (y > 0)
  265.     {
  266.     addrlt += nlwidth;
  267.     addrlb -= nlwidth;
  268.     MIFILLARCSTEP(slw);
  269.     MIARCSLICESTEP(slice.edge1);
  270.     MIARCSLICESTEP(slice.edge2);
  271.     if (miFillSliceUpper(slice))
  272.     {
  273.         MIARCSLICEUPPER(xl, xr, slice, slw);
  274.         FILLSLICESPANS(slice.flip_top, addrlt);
  275.     }
  276.     if (miFillSliceLower(slice))
  277.     {
  278.         MIARCSLICELOWER(xl, xr, slice, slw);
  279.         FILLSLICESPANS(slice.flip_bot, addrlb);
  280.     }
  281.     }
  282. }
  283.  
  284. void
  285. mfbPolyFillArcSolid(pDraw, pGC, narcs, parcs)
  286.     register DrawablePtr pDraw;
  287.     GCPtr    pGC;
  288.     int        narcs;
  289.     xArc    *parcs;
  290. {
  291.     mfbPrivGC *priv;
  292.     register xArc *arc;
  293.     register int i;
  294.     BoxRec box;
  295.     RegionPtr cclip;
  296.     int rop;
  297.  
  298.     priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  299.     rop = priv->rop;
  300.     if ((rop == RROP_NOP) || !(pGC->planemask & 1))
  301.     return;
  302.     cclip = priv->pCompositeClip;
  303.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  304.     {
  305.     if (miFillArcEmpty(arc))
  306.         continue;
  307.     if (miCanFillArc(arc))
  308.     {
  309.         box.x1 = arc->x + pDraw->x;
  310.         box.y1 = arc->y + pDraw->y;
  311.         box.x2 = box.x1 + (int)arc->width + 1;
  312.         box.y2 = box.y1 + (int)arc->height + 1;
  313.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  314.         {
  315.         if ((arc->angle2 >= FULLCIRCLE) ||
  316.             (arc->angle2 <= -FULLCIRCLE))
  317.             mfbFillEllipseSolid(pDraw, arc, rop);
  318.         else
  319.             mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop);
  320.         continue;
  321.         }
  322.     }
  323.     miPolyFillArc(pDraw, pGC, 1, arc);
  324.     }
  325. }
  326.