home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbbresd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-08  |  4.8 KB  |  180 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: mfbbresd.c,v 1.3 89/11/08 17:12:27 keith Exp $ */
  25. #include "X.h"
  26. #include "misc.h"
  27. #include "mfb.h"
  28. #include "maskbits.h"
  29.  
  30. /* Dashed bresenham line */
  31.  
  32. #define StepDash\
  33.     if (!--dashRemaining) { \
  34.     if (++ dashIndex == numInDashList) \
  35.         dashIndex = 0; \
  36.     dashRemaining = pDash[dashIndex]; \
  37.     rop = fgrop; \
  38.     if (dashIndex & 1) \
  39.         rop = bgrop; \
  40.     }
  41.  
  42. mfbBresD(fgrop, bgrop,
  43.      pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
  44.      addrl, nlwidth,
  45.      signdx, signdy, axis, x1, y1, e, e1, e2, len)
  46. int fgrop, bgrop;
  47. int *pdashIndex;    /* current dash */
  48. unsigned char *pDash;    /* dash list */
  49. int numInDashList;    /* total length of dash list */
  50. int *pdashOffset;    /* offset into current dash */
  51. int isDoubleDash;
  52. int *addrl;        /* pointer to base of bitmap */
  53. int nlwidth;        /* width in longwords of bitmap */
  54. int signdx, signdy;    /* signs of directions */
  55. int axis;        /* major axis (Y_AXIS or X_AXIS) */
  56. int x1, y1;        /* initial point */
  57. register int e;        /* error accumulator */
  58. register int e1;    /* bresenham increments */
  59. int e2;
  60. int len;        /* length of line */
  61. {
  62.     register int yinc;    /* increment to next scanline, in bytes */
  63.     register unsigned char *addrb;
  64.     register int e3 = e2-e1;
  65.     register unsigned long bit;
  66.     unsigned int leftbit = mask[0]; /* leftmost bit to process in new word */
  67.     unsigned int rightbit = mask[31]; /* rightmost bit to process in new word */
  68.     int dashIndex;
  69.     int dashOffset;
  70.     int dashRemaining;
  71.     int    rop;
  72.  
  73.     dashOffset = *pdashOffset;
  74.     dashIndex = *pdashIndex;
  75.     dashRemaining = pDash[dashIndex] - dashOffset;
  76.     rop = fgrop;
  77.     if (!isDoubleDash)
  78.     bgrop = -1;
  79.     if (dashIndex & 1)
  80.     rop = bgrop;
  81.  
  82.     /* point to longword containing first point */
  83.     addrb = (unsigned char *)(addrl + (y1 * nlwidth) + (x1 >> 5));
  84.     yinc = signdy * nlwidth * 4;                /* 4 == sizeof(int) */
  85.     e = e-e1;            /* to make looping easier */
  86.     bit = mask[x1 & 31];
  87.     if (axis == X_AXIS)
  88.     {
  89.     if (signdx > 0)
  90.     {
  91.         while(len--)
  92.         { 
  93.         if (rop == RROP_BLACK)
  94.             *(unsigned long *)addrb &= ~bit;
  95.         else if (rop == RROP_WHITE)
  96.             *(unsigned long *)addrb |= bit;
  97.         else if (rop == RROP_INVERT)
  98.             *(unsigned long *)addrb ^= bit;
  99.         e += e1;
  100.         if (e >= 0)
  101.         {
  102.             addrb += yinc;
  103.             e += e3;
  104.         }
  105.         bit = SCRRIGHT(bit,1);
  106.         if (!bit) { bit = leftbit;addrb += 4; }
  107.         StepDash
  108.         }
  109.     }
  110.     else
  111.     {
  112.         while(len--)
  113.         { 
  114.         if (rop == RROP_BLACK)
  115.             *(unsigned long *)addrb &= ~bit;
  116.         else if (rop == RROP_WHITE)
  117.             *(unsigned long *)addrb |= bit;
  118.         else if (rop == RROP_INVERT)
  119.             *(unsigned long *)addrb ^= bit;
  120.         e += e1;
  121.         if (e >= 0)
  122.         {
  123.             addrb += yinc;
  124.             e += e3;
  125.         }
  126.         bit = SCRLEFT(bit,1);
  127.         if (!bit) { bit = rightbit;addrb -= 4; }
  128.         StepDash
  129.         }
  130.     }
  131.     } /* if X_AXIS */
  132.     else
  133.     {
  134.     if (signdx > 0)
  135.     {
  136.         while(len--)
  137.         {
  138.         if (rop == RROP_BLACK)
  139.             *(unsigned long *)addrb &= ~bit;
  140.         else if (rop == RROP_WHITE)
  141.             *(unsigned long *)addrb |= bit;
  142.         else if (rop == RROP_INVERT)
  143.             *(unsigned long *)addrb ^= bit;
  144.         e += e1;
  145.         if (e >= 0)
  146.         {
  147.             bit = SCRRIGHT(bit,1);
  148.             if (!bit) { bit = leftbit;addrb += 4; }
  149.             e += e3;
  150.         }
  151.         addrb += yinc;
  152.         StepDash
  153.         }
  154.     }
  155.     else
  156.     {
  157.         while(len--)
  158.         {
  159.         if (rop == RROP_BLACK)
  160.             *(unsigned long *)addrb &= ~bit;
  161.         else if (rop == RROP_WHITE)
  162.             *(unsigned long *)addrb |= bit;
  163.         else if (rop == RROP_INVERT)
  164.             *(unsigned long *)addrb ^= bit;
  165.         e += e1;
  166.         if (e >= 0)
  167.         {
  168.             bit = SCRLEFT(bit,1);
  169.             if (!bit) { bit = rightbit;addrb -= 4; }
  170.             e += e3;
  171.         }
  172.         addrb += yinc;
  173.         StepDash
  174.         }
  175.     }
  176.     } /* else Y_AXIS */
  177.     *pdashIndex = dashIndex;
  178.     *pdashOffset = pDash[dashIndex] - dashRemaining;
  179.