home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbzerarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-24  |  6.3 KB  |  235 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: mfbzerarc.c,v 5.10 89/09/20 18:55:33 rws Exp $ */
  19.  
  20. /* Derived from:
  21.  * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
  22.  * by M. L. V. Pitteway
  23.  * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
  24.  */
  25.  
  26. #include "X.h"
  27. #include "Xprotostr.h"
  28. #include "miscstruct.h"
  29. #include "gcstruct.h"
  30. #include "pixmapstr.h"
  31. #include "scrnintstr.h"
  32. #include "mfb.h"
  33. #include "maskbits.h"
  34. #include "mizerarc.h"
  35.  
  36. extern void miPolyArc(), miZeroPolyArc();
  37.  
  38. #if (BITMAP_BIT_ORDER == MSBFirst)
  39. #define LEFTMOST    ((unsigned int) 0x80000000)
  40. #else
  41. #define LEFTMOST    ((unsigned int) 1)
  42. #endif
  43.  
  44. #define PixelateWhite(addr,off) \
  45.     (addr)[(off)>>5] |= SCRRIGHT (LEFTMOST, ((off) & 0x1f))
  46. #define PixelateBlack(addr,off) \
  47.     (addr)[(off)>>5] &= ~(SCRRIGHT (LEFTMOST, ((off) & 0x1f)))
  48.  
  49. #define Pixelate(base,off) \
  50. { \
  51.     paddr = base + ((off)>>5); \
  52.     pmask = SCRRIGHT(LEFTMOST, (off) & 0x1f); \
  53.     *paddr = (*paddr & ~pmask) | (pixel & pmask); \
  54. }
  55.  
  56. #define DoPix(bit,base,off) if (mask & bit) Pixelate(base,off);
  57.  
  58. static void
  59. mfbZeroArcSS(pDraw, pGC, arc)
  60.     DrawablePtr pDraw;
  61.     GCPtr pGC;
  62.     xArc *arc;
  63. {
  64.     miZeroArcRec info;
  65.     Bool do360;
  66.     register int x, y, a, b, d, mask;
  67.     register int k1, k3, dx, dy;
  68.     int *addrl;
  69.     int *yorgl, *yorgol;
  70.     unsigned long pixel;
  71.     int nlwidth, yoffset, dyoffset;
  72.     int pmask;
  73.     register int *paddr;
  74.  
  75.     if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop ==
  76.     RROP_BLACK)
  77.     pixel = 0;
  78.     else
  79.     pixel = ~0L;
  80.  
  81.     if (pDraw->type == DRAWABLE_WINDOW)
  82.     {
  83.     addrl = (int *)
  84.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  85.     nlwidth = (int)
  86.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  87.     }
  88.     else
  89.     {
  90.     addrl = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  91.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  92.     }
  93.     do360 = miZeroArcSetup(arc, &info, TRUE);
  94.     yorgl = addrl + ((info.yorg + pDraw->y) * nlwidth);
  95.     yorgol = addrl + ((info.yorgo + pDraw->y) * nlwidth);
  96.     info.xorg += pDraw->x;
  97.     info.xorgo += pDraw->x;
  98.     MIARCSETUP();
  99.     yoffset = y ? nlwidth : 0;
  100.     dyoffset = 0;
  101.     mask = info.initialMask;
  102.     if (!(arc->width & 1))
  103.     {
  104.     DoPix(2, yorgl, info.xorgo);
  105.     DoPix(8, yorgol, info.xorgo);
  106.     }
  107.     if (!info.end.x || !info.end.y)
  108.     {
  109.     mask = info.end.mask;
  110.     info.end = info.altend;
  111.     }
  112.     if (do360 && (arc->width == arc->height) && !(arc->width & 1))
  113.     {
  114.     int xoffset = nlwidth;
  115.     int *yorghl = yorgl + (info.h * nlwidth);
  116.     int xorghp = info.xorg + info.h;
  117.     int xorghn = info.xorg - info.h;
  118.  
  119.     if (pixel)
  120.     {
  121.         while (1)
  122.         {
  123.         PixelateWhite(yorgl + yoffset, info.xorg + x);
  124.         PixelateWhite(yorgl + yoffset, info.xorg - x);
  125.         PixelateWhite(yorgol- yoffset, info.xorg - x);
  126.         PixelateWhite(yorgol - yoffset, info.xorg + x);
  127.         if (a < 0)
  128.             break;
  129.         PixelateWhite(yorghl - xoffset, xorghp - y);
  130.         PixelateWhite(yorghl - xoffset, xorghn + y);
  131.         PixelateWhite(yorghl + xoffset, xorghn + y);
  132.         PixelateWhite(yorghl + xoffset, xorghp - y);
  133.         xoffset += nlwidth;
  134.         MIARCCIRCLESTEP(yoffset += nlwidth;);
  135.         }
  136.     }
  137.     else
  138.     {
  139.         while (1)
  140.         {
  141.         PixelateBlack(yorgl + yoffset, info.xorg + x);
  142.         PixelateBlack(yorgl + yoffset, info.xorg - x);
  143.         PixelateBlack(yorgol- yoffset, info.xorg - x);
  144.         PixelateBlack(yorgol - yoffset, info.xorg + x);
  145.         if (a < 0)
  146.             break;
  147.         PixelateBlack(yorghl - xoffset, xorghp - y);
  148.         PixelateBlack(yorghl - xoffset, xorghn + y);
  149.         PixelateBlack(yorghl + xoffset, xorghn + y);
  150.         PixelateBlack(yorghl + xoffset, xorghp - y);
  151.         xoffset += nlwidth;
  152.         MIARCCIRCLESTEP(yoffset += nlwidth;);
  153.         }
  154.     }
  155.     x = info.w;
  156.     yoffset = info.h * nlwidth;
  157.     }
  158.     else if (do360)
  159.     {
  160.     while (y < info.h || x < info.w)
  161.     {
  162.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  163.         Pixelate(yorgl + yoffset, info.xorg + x);
  164.         Pixelate(yorgl + yoffset, info.xorgo - x);
  165.         Pixelate(yorgol - yoffset, info.xorgo - x);
  166.         Pixelate(yorgol - yoffset, info.xorg + x);
  167.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  168.     }
  169.     }
  170.     else
  171.     {
  172.     while (y < info.h || x < info.w)
  173.     {
  174.         MIARCOCTANTSHIFT(dyoffset = nlwidth;);
  175.         if ((x == info.start.x) || (y == info.start.y))
  176.         {
  177.         mask = info.start.mask;
  178.         info.start = info.altstart;
  179.         }
  180.         DoPix(1, yorgl + yoffset, info.xorg + x);
  181.         DoPix(2, yorgl + yoffset, info.xorgo - x);
  182.         DoPix(4, yorgol - yoffset, info.xorgo - x);
  183.         DoPix(8, yorgol - yoffset, info.xorg + x);
  184.         if ((x == info.end.x) || (y == info.end.y))
  185.         {
  186.         mask = info.end.mask;
  187.         info.end = info.altend;
  188.         }
  189.         MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
  190.     }
  191.     }
  192.     if ((x == info.start.x) || (y == info.start.y))
  193.     mask = info.start.mask;
  194.     DoPix(1, yorgl + yoffset, info.xorg + x);
  195.     DoPix(4, yorgol - yoffset, info.xorgo - x);
  196.     if (arc->height & 1)
  197.     {
  198.     DoPix(2, yorgl + yoffset, info.xorgo - x);
  199.     DoPix(8, yorgol - yoffset, info.xorg + x);
  200.     }
  201. }
  202.  
  203. void
  204. mfbZeroPolyArcSS(pDraw, pGC, narcs, parcs)
  205.     DrawablePtr    pDraw;
  206.     GCPtr    pGC;
  207.     int        narcs;
  208.     xArc    *parcs;
  209. {
  210.     register xArc *arc;
  211.     register int i;
  212.     BoxRec box;
  213.     RegionPtr cclip;
  214.  
  215.     if (!pGC->planemask & 1)
  216.     return;
  217.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  218.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  219.     {
  220.     if (miCanZeroArc(arc))
  221.     {
  222.         box.x1 = arc->x + pDraw->x;
  223.         box.y1 = arc->y + pDraw->y;
  224.         box.x2 = box.x1 + (int)arc->width + 1;
  225.         box.y2 = box.y1 + (int)arc->height + 1;
  226.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  227.         mfbZeroArcSS(pDraw, pGC, arc);
  228.         else
  229.         miZeroPolyArc(pDraw, pGC, 1, arc);
  230.     }
  231.     else
  232.         miPolyArc(pDraw, pGC, 1, arc);
  233.     }
  234. }
  235.