home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcLine.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  26KB  |  986 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /***********************************************************
  25. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  26. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  27.  
  28.             All Rights Reserved
  29.  
  30. Permission to use, copy, modify, and distribute this software and its
  31. documentation for any purpose and without fee is hereby granted,
  32. provided that the above copyright notice appear in all copies and that
  33. both that copyright notice and this permission notice appear in
  34. supporting documentation, and that the names of Digital or MIT not be
  35. used in advertising or publicity pertaining to distribution of the
  36. software without specific, written prior permission.
  37.  
  38. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. SOFTWARE.
  45.  
  46. ******************************************************************/
  47.  
  48. /* $Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcLine.c,v 30.2 89/05/07 15:26:53 paul Exp $ */
  49. /* $Source: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcLine.c,v $ */
  50.  
  51. #ifndef lint
  52. static char *rcsid = "$Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcLine.c,v 30.2 89/05/07 15:26:53 paul Exp $" ;
  53. #endif
  54.  
  55. #include "X.h"
  56.  
  57. #include "misc.h"
  58. #include "gcstruct.h"
  59. #include "gc.h"
  60. #include "pixmap.h"
  61. #include "window.h"
  62. #include "windowstr.h"
  63. #include "pixmapstr.h"
  64. #include "regionstr.h"
  65. #include "scrnintstr.h"
  66. #include "mistruct.h"
  67.  
  68. #include "mfb.h"
  69. #include "ppc.h"
  70.  
  71. #include "OScompiler.h"
  72. extern int mfbGCPrivateIndex;
  73.  
  74. /* ppc Line-
  75.  *
  76.  * This routine is basically the mfb line, except it calls functions it
  77.  * finds in the ScreenPriv field defined as the ppcScreenPriv field.
  78.  *
  79.  * THE KEY IS YOU CANNOT USE THIS UNTIL YOU WRITE YOUR OWN ROUTINES FOR
  80.  * LINE, HLINE, and VLINE.
  81.  *
  82.  * Until you do, most ppc users should use milines.  When you do, put
  83.  * the function pointers into the ScreenPriv and then you can use ppcLine.
  84.  * As long as your line routine is mi, you can NoopDDA the aforementioned
  85.  * three line routines.
  86.  *
  87.  *
  88.  * PLEASE READ COMMENT ON CODE AT TOP OF MFBLINE
  89.  *
  90.  * T. Paquin   9/87
  91.  *
  92.  */
  93.  
  94. /* NOTE
  95.    maybe OUTCODES should take box (the one that includes all
  96. edges) instead of pbox (the standard no-right-or-lower-edge one)?
  97. */
  98. #define OUTCODES(result, x, y, pbox) \
  99.     if (x < pbox->x1) \
  100.     result |= OUT_LEFT ; \
  101.     else if (x >= pbox->x2) \
  102.     result |= OUT_RIGHT ; \
  103.     if (y < pbox->y1) \
  104.     result |= OUT_ABOVE ; \
  105.     else if (y >= pbox->y2) \
  106.     result |= OUT_BELOW ;
  107.  
  108. /* This Function is ONLY used when the linestyle in the GC is LineSolid.
  109.  * This is assumed below !!
  110.  */
  111.  
  112. void
  113. ppcScrnZeroLine(pDrawable, pGC, mode, npt, pptInit)
  114.     DrawablePtr pDrawable ;
  115.     GCPtr pGC ;
  116.     int mode ;        /* Origin or Previous */
  117.     int npt ;        /* number of points */
  118.     DDXPointPtr pptInit ;
  119. {
  120.     int nboxInit ;
  121.     register int nbox ;
  122.     BoxPtr pboxInit ;
  123.     BoxRec box ;
  124.     register BoxPtr pbox ;
  125.     int nptTmp ;
  126.     DDXPointPtr ppt ;        /* pointer to list of translated points */
  127.  
  128.     DDXPointRec pt1 ;
  129.     DDXPointRec pt2 ;
  130.  
  131.     unsigned int oc1 ;        /* outcode of point 1 */
  132.     unsigned int oc2 ;        /* outcode of point 2 */
  133.  
  134.     int xorg, yorg ;        /* origin of window */
  135.  
  136.     int adx ;        /* abs values of dx and dy */
  137.     int ady ;
  138.     int signdx ;        /* sign of dx and dy */
  139.     int signdy ;
  140.     int e, e1, e2 ;        /* bresenham error and increments */
  141.     int len ;            /* length of segment */
  142.  
  143.     int clipDone ;        /* flag for clipping loop */
  144.     DDXPointRec pt1Orig ;    /* unclipped start point */
  145.     DDXPointRec pt2Orig ;    /* unclipped end point */
  146.     int err ;            /* modified bresenham error term */
  147.     int clip1, clip2 ;        /* clippedness of the endpoints */
  148.  
  149.     int alu ;            /* Screen Raster-Op value */
  150.     long fg ;            /* foreground Pixel value */
  151.     long pm ;            /* plane mask */
  152.     register int tmp ;
  153.     int x1, x2, y1, y2 ;        /* a bunch of temporaries */
  154.     ppcPrivGC *gcPriv ;
  155.     ppcScrnPriv *scrnPriv ;
  156.     void (* scrnFunc)() ;
  157.  
  158.     if ( pDrawable->type != DRAWABLE_WINDOW ) {
  159.     ErrorF("ppcScrnZeroLine: not a window\n") ;
  160.     return ;
  161.     }
  162.  
  163.     gcPriv = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;
  164.     switch ( gcPriv->colorRrop.fillStyle ) {
  165.     case FillStippled :
  166.     case FillSolid : /* Can Use Optimized Color Raster-Op */
  167.         alu = gcPriv->colorRrop.alu ;
  168.         pm = gcPriv->colorRrop.planemask ;
  169.         fg = gcPriv->colorRrop.fgPixel ;
  170.         break ;
  171.     case FillOpaqueStippled :
  172.     case FillTiled : /* Can't Use Optimized Color Raster-Op */
  173.         alu = pGC->alu ;
  174.         pm = pGC->planemask ;
  175.         fg = pGC->fgPixel ;
  176.         break ;
  177.     }
  178.     if ( alu == GXnoop )
  179.     return ;
  180.  
  181.     pboxInit = REGION_RECTS(gcPriv->pCompositeClip) ;
  182.     nboxInit = REGION_NUM_RECTS(gcPriv->pCompositeClip) ;
  183.  
  184.     xorg = pDrawable->x ;
  185.     yorg = pDrawable->y ;
  186.  
  187.     /* translate the point list */
  188.     ppt = pptInit ;
  189.     nptTmp = npt ;
  190.     if (mode == CoordModeOrigin) {
  191.     while ( nptTmp-- ) {
  192.         ppt->x += xorg ;
  193.         ppt->y += yorg ;
  194.         ppt++ ;
  195.     }
  196.     }
  197.     else {
  198.     ppt->x += xorg ;
  199.     ppt->y += yorg ;
  200.     nptTmp-- ;
  201.     while ( nptTmp-- ) {
  202.         ppt++ ;
  203.         ppt->x += (ppt-1)->x ;
  204.         ppt->y += (ppt-1)->y ;
  205.     }
  206.     }
  207.  
  208.     scrnPriv = (ppcScrnPriv *) ( pDrawable->pScreen->devPrivate ) ;
  209.     ppt = pptInit ;
  210.     while ( --npt ) {
  211.     nbox = nboxInit ;
  212.     pbox = pboxInit ;
  213.  
  214.     pt1 = *ppt++ ;
  215.     pt2 = *ppt ;
  216.  
  217.     if ( !( adx = ( pt2.x - pt1.x ) ) ) {
  218.         /* make the line go top to bottom of screen, keeping
  219.            endpoint semantics
  220.         */
  221.         if ( pt1.y > pt2.y ) {
  222.         tmp = pt2.y ;
  223.         pt2.y = pt1.y + 1 ;
  224.         pt1.y = tmp + 1 ;
  225.         }
  226.  
  227.         /* get to first band that might contain part of line */
  228.         while ((nbox) && (pbox->y2 <= pt1.y)) {
  229.         pbox++ ;
  230.         nbox-- ;
  231.         }
  232.  
  233.         if ( nbox ) {
  234.         scrnFunc = scrnPriv->lineVert ;
  235.         /* stop when lower edge of box is beyond end of line */
  236.         while ( ( nbox ) && ( pt2.y >= pbox->y1 ) ) {
  237.             if ( ( pt1.x >= pbox->x1 ) && ( pt1.x < pbox->x2 ) ) {
  238.             /* this box has part of the line in it */
  239.             if ( ( y1 = MAX( pt1.y, pbox->y1 ) )
  240.               != ( y2 = MIN( pt2.y, pbox->y2 ) ) ) {
  241.                 (* scrnFunc)( fg, alu, pm, pt1.x, y1, y2 - y1 ) ;
  242.             }
  243.             }
  244.             nbox-- ;
  245.             pbox++ ;
  246.         }
  247.         }
  248.  
  249.     }
  250.     else if ( !( ady = ( pt2.y - pt1.y ) ) ) {
  251.         /* force line from left to right, keeping
  252.            endpoint semantics
  253.         */
  254.         if (pt1.x > pt2.x) {
  255.         tmp = pt2.x ;
  256.         pt2.x = pt1.x + 1 ;
  257.         pt1.x = tmp + 1 ;
  258.         }
  259.  
  260.         /* find the correct band */
  261.         while ( nbox && (pbox->y2 <= pt1.y)) {
  262.         pbox++ ;
  263.         nbox-- ;
  264.         }
  265.  
  266.         /* try to draw the line, if we haven't gone beyond it */
  267.         if ( nbox && ( pbox->y1 <= pt1.y ) ) {
  268.         /* when we leave this band, we're done */
  269.         tmp = pbox->y1 ;
  270.         scrnFunc = scrnPriv->lineHorz ;
  271.         while ( nbox && ( pbox->y1 == tmp ) ) {
  272.             if ( pbox->x2 <= pt1.x ) {
  273.             /* skip boxes until one might contain start point */
  274.             nbox-- ;
  275.             pbox++ ;
  276.             continue ;
  277.             }
  278.  
  279.             /* stop if left of box is beyond right of line */
  280.             if (pbox->x1 >= pt2.x)
  281.             {
  282.             nbox = 0 ;
  283.             continue ;
  284.             }
  285.             if ( ( x1 = MAX( pt1.x, pbox->x1 ) )
  286.               != ( x2 = MIN( pt2.x, pbox->x2 ) ) ) {
  287.                 (* scrnFunc)( fg, alu, pm, x1, pt1.y, x2 - x1 ) ;
  288.             }
  289.             nbox-- ;
  290.             pbox++ ;
  291.         }
  292.         }
  293.     }
  294.     else    /* sloped line */
  295.     {
  296.         signdx = sign(adx) ;
  297.         signdy = sign(ady) ;
  298.         adx = ABS(adx) ;
  299.         ady = ABS(ady) ;
  300.  
  301.         if ( adx > ady ) {
  302.         e1 = ady << 1 ;
  303.         e = e1 - adx ;
  304.         e2 = e - adx ;
  305.  
  306.         }
  307.         else {
  308.         e1 = adx << 1 ;
  309.         e = e1 - ady ;
  310.         e2 = e - ady ;
  311.         }
  312.  
  313.         /* we have bresenham parameters and two points.
  314.            all we have to do now is clip and draw.
  315.         */
  316.  
  317.         pt1Orig = pt1 ;
  318.         pt2Orig = pt2 ;
  319.  
  320.         while ( nbox-- )
  321.         {
  322.  
  323.         pt1 = pt1Orig ;
  324.         pt2 = pt2Orig ;
  325.         clipDone = 0 ;
  326.         box.x1 = pbox->x1 ;
  327.         box.y1 = pbox->y1 ;
  328.         box.x2 = pbox->x2-1 ;
  329.         box.y2 = pbox->y2-1 ;
  330.         clip1 = 0 ;
  331.         clip2 = 0 ;
  332.  
  333.         oc1 = 0 ;
  334.         oc2 = 0 ;
  335.         OUTCODES(oc1, pt1.x, pt1.y, pbox) ;
  336.         OUTCODES(oc2, pt2.x, pt2.y, pbox) ;
  337.  
  338.         if (oc1 & oc2)
  339.             clipDone = -1 ;
  340.         else if ((oc1 | oc2) == 0)
  341.             clipDone = 1 ;
  342.         else /* have to clip */
  343.             clipDone = mfbClipLine(pbox, box,
  344.                        &pt1Orig, &pt1, &pt2,
  345.                        adx, ady, signdx, signdy,
  346.                        ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  347.                        &clip1, &clip2) ;
  348.  
  349.         if (clipDone == -1)
  350.             pbox++ ;
  351.         else {
  352.             scrnFunc = scrnPriv->lineBres ;
  353.  
  354.             if ( adx > ady )
  355.             len = ABS(pt2.x - pt1.x) ;
  356.             else
  357.             len = ABS(pt2.y - pt1.y) ;
  358.  
  359.             len += (clip2 != 0) ;
  360.             if (len) {
  361.             /* unwind bresenham error term to first point */
  362.             if (clip1)
  363.             {
  364.                 if ( adx > ady )
  365.                 err = e
  366.                     + ( ABS( pt1.y - pt1Orig.y ) * ( e2 - e1 ) )
  367.                     + ( ABS( pt1.x - pt1Orig.x ) * e1 ) ;
  368.                 else
  369.                 err = e
  370.                     + ( ABS( pt1.x - pt1Orig.x ) * ( e2 - e1 ) )
  371.                     + ( ABS( pt1.y - pt1Orig.y ) * e1 ) ;
  372.             }
  373.             else
  374.                 err = e ;
  375.             (* scrnFunc)( fg, alu, pm,
  376.                       signdx, signdy,
  377.                       ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  378.                       pt1.x, pt1.y, err, e1, e2, len ) ;
  379.             }
  380.             /* if segment is unclipped, skip remaining rectangles */
  381.             if (!(clip1 || clip2))
  382.             break ;
  383.             else
  384.             pbox++ ;
  385.         }
  386.         } /* while (nbox--) */
  387.     } /* sloped line */
  388.     } /* while (nline--) */
  389.  
  390.     /* paint the last point if the end style isn't CapNotLast.
  391.        (Assume that a projecting, butt, or round cap that is one
  392.     pixel wide is the same as the single pixel of the endpoint.)
  393.     */
  394.  
  395.     if ( ( pGC->capStyle != CapNotLast )
  396.       && ( ( ppt->x != pptInit->x ) || ( ppt->y != pptInit->y )
  397.         || ( ppt == pptInit + 1 ) )
  398.       && ( (* pDrawable->pScreen->PointInRegion)(
  399.         gcPriv->pCompositeClip,
  400.         ppt->x, ppt->y, &box ) ) )
  401.     (* scrnPriv->solidFill)( fg, alu, pm, ppt->x, ppt->y, 1, 1 ) ;
  402.  
  403.     return ;
  404. }
  405.  
  406. void
  407. ppcScrnZeroDash(pDrawable, pGC, mode, npt, pptInit)
  408.     DrawablePtr pDrawable ;
  409.     GCPtr pGC ;
  410.     int mode ;        /* Origin or Previous */
  411.     int npt ;        /* number of points */
  412.     DDXPointPtr pptInit ;
  413. {
  414.     int nseg ;            /* number of dashed segments */
  415.     miDashPtr pdash ;        /* list of dashes */
  416.     miDashPtr pdashInit ;
  417.     int alu ;
  418.     unsigned long int color ;
  419.     unsigned long int fg, bg, pm ;
  420.  
  421.     int nboxInit ;
  422.     int nbox ;
  423.     BoxPtr pboxInit ;
  424.     BoxPtr pbox ;
  425.     int nptTmp ;
  426.     DDXPointPtr ppt ;        /* pointer to list of translated points */
  427.  
  428.     DDXPointRec pt1 ;
  429.     DDXPointRec pt2 ;
  430.  
  431.     unsigned int oc1 ;        /* outcode of point 1 */
  432.     unsigned int oc2 ;        /* outcode of point 2 */
  433.  
  434.     int xorg, yorg ;        /* origin of window */
  435.  
  436.                 /* these are all per original line */
  437.     int adx ;            /* abs values of dx and dy */
  438.     int ady ;
  439.     int signdx ;            /* sign of dx and dy */
  440.     int signdy ;
  441.     int e ;            /* error term for first point of
  442.                    original line */
  443.     int e1, e2 ;            /* unwinding terms */
  444.                 /* these are all per dash */
  445.     int err ;            /* bres error term for first drawn point */
  446.     int len ;            /* length of segment */
  447.  
  448.     int clipDone ;        /* flag for clipping loop */
  449.     DDXPointRec pt1Orig ;    /* unclipped start point */
  450.     int clip1, clip2 ;        /* clippedness of the endpoints */
  451.  
  452.     void (* scrnFunc)() ;
  453.     register int tmp1 ;
  454.     register int tmp2 ;
  455.  
  456.     if (pDrawable->type != DRAWABLE_WINDOW) {
  457.     ErrorF( "ppcScrnZeroDash: not a window\n" ) ;
  458.     return ;
  459.     }
  460.  
  461.     if ( !( nboxInit = REGION_NUM_RECTS(((ppcPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip)))
  462.     return ; /* No Work To Do !! */
  463.  
  464.     pboxInit = REGION_RECTS(((ppcPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip) ;
  465.  
  466.     /* Get The Function, Planemask and Colors */
  467.  
  468.     if ( pGC->lineStyle == LineOnOffDash ) {
  469.     switch ( ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fillStyle ) {
  470.         case FillStippled :
  471.         case FillSolid : /* Can Use Optimized Color Raster-Op */
  472.         alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ;
  473.         pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  474.         color = fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fgPixel ;
  475.         break ;
  476.         case FillOpaqueStippled :
  477.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  478.         alu = pGC->alu ;
  479.         pm = pGC->planemask ;
  480.         color = fg = pGC->fgPixel ;
  481.         break ;
  482.     }
  483.     }
  484.     else {
  485.     switch ( ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fillStyle ) {
  486.         case FillStippled :
  487.         case FillSolid :
  488.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  489.         alu = pGC->alu ;
  490.         pm = pGC->planemask ;
  491.         fg = pGC->fgPixel ;
  492.         bg = pGC->bgPixel ;
  493.         break ;
  494.         case FillOpaqueStippled : /* Can Use Optimized Color Raster-Op */
  495.         alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ;
  496.         pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  497.         fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fgPixel ;
  498.         bg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.bgPixel ;
  499.         break ;
  500.     }
  501.     }
  502.     if ( alu == GXnoop )
  503.     return ;
  504.  
  505.     xorg = pDrawable->x ;
  506.     yorg = pDrawable->y ;
  507.  
  508.     /* translate the point list */
  509.     ppt = pptInit ;
  510.     nptTmp = npt ;
  511.     if (mode == CoordModeOrigin) {
  512.     while ( nptTmp-- ) {
  513.         ppt->x += xorg ;
  514.         ppt->y += yorg ;
  515.         ppt++ ;
  516.     }
  517.     }
  518.     else {
  519.     ppt->x += xorg ;
  520.     ppt->y += yorg ;
  521.     while ( --nptTmp ) {
  522.         ppt++ ;
  523.         ppt->x += (ppt-1)->x ;
  524.         ppt->y += (ppt-1)->y ;
  525.     }
  526.     }
  527.  
  528.     pdashInit = pdash = miDashLine( npt, pptInit, pGC->numInDashList,
  529.                     pGC->dash, pGC->dashOffset, &nseg ) ;
  530.  
  531.     for ( ; nseg-- ; pdash++ ) {
  532.     if (pGC->lineStyle == LineOnOffDash) {
  533.         for ( ; nseg && (pdash->which == ODD_DASH) ; nseg--, pdash++ ) {
  534.         if (pdash->newLine) {
  535.             pt1Orig = pt1 = *pptInit++ ;
  536.             pt2 = *pptInit ;
  537.             if ( ( adx = pt2.x - pt1.x )
  538.               && ( ady = pt2.y - pt1.y ) ) {
  539.             signdx = sign(adx) ;
  540.             signdy = sign(ady) ;
  541.             adx = ABS(adx) ;
  542.             ady = ABS(ady) ;
  543.             e = pdash->e ;
  544.             e1 = pdash->e1 ;
  545.             e2 = pdash->e2 ;
  546.             }
  547.         }
  548.         }
  549.         /* ??? is this right ??? */
  550.         if (!nseg)
  551.         break ;
  552.     }
  553.     else if (pGC->lineStyle == LineDoubleDash) {
  554.         /* use a different color for odd dashes */
  555.         color = (pdash->which == EVEN_DASH) ? fg : bg ;
  556.     }
  557.  
  558.     if (pdash->newLine) {
  559.         pt1Orig = pt1 = *pptInit++ ;
  560.         pt2 = *pptInit ;
  561.         if ( ( adx = pt2.x - pt1.x )
  562.           && ( ady = pt2.y - pt1.y ) ) {
  563.         signdx = sign(adx) ;
  564.         signdy = sign(ady) ;
  565.         adx = ABS(adx) ;
  566.         ady = ABS(ady) ;
  567.         e = pdash->e ;
  568.         e1 = pdash->e1 ;
  569.         e2 = pdash->e2 ;
  570.         }
  571.     }
  572.  
  573.     nbox = nboxInit ;
  574.     pbox = pboxInit ;
  575.  
  576. /* ************************************************************************** */
  577.     if ( !adx ) {
  578.         pt1 = pdash->pt ;
  579.         pt2 = (pdash+1)->pt ;
  580.         /* make the line go top to bottom of screen, keeping
  581.            endpoint semantics
  582.         */
  583.         if ( pt1.y > pt2.y ) {
  584.         tmp1 = pt2.y + 1 ;
  585.         tmp2 = pt1.y + 1 ;
  586.         }
  587.         else {
  588.         tmp1 = pt1.y ;
  589.         tmp2 = pt2.y ;
  590.         }
  591.  
  592.         /* get to first band that might contain part of line */
  593.         for ( ; nbox && ( pbox->y2 <= tmp1 ) ; pbox++, nbox-- ) ;
  594.  
  595.         if ( nbox ) {
  596.         scrnFunc =
  597.          ( (ppcScrnPriv *)(pDrawable->pScreen->devPrivate))->lineVert ;
  598.         /* stop when lower edge of box is beyond end of line */
  599.         for ( ; nbox && ( pbox->y1 < tmp2 ) ; nbox--, pbox++ ) {
  600.             if ( ( pt1.x >= pbox->x1 ) && ( pt1.x < pbox->x2 ) ) {
  601.             register int y1, y2 ;
  602.             /* this box has part of the line in it */
  603.             if ( ( y1 = MAX( tmp1, pbox->y1 ) )
  604.               != ( y2 = MIN( tmp2, pbox->y2 ) ) ) {
  605.                 (* scrnFunc)( color, alu, pm, pt1.x, y1, y2 - y1 ) ;
  606.             }
  607.             }
  608.         }
  609.         }
  610.     }
  611.     else if ( !ady ) {
  612.         pt1 = pdash->pt ;
  613.         pt2 = (pdash+1)->pt ;
  614.         /* force line from left to right, keeping
  615.            endpoint semantics
  616.         */
  617.         if (pt1.x > pt2.x) {
  618.         tmp1 = pt2.x + 1 ;
  619.         tmp2 = pt1.x + 1 ;
  620.         }
  621.         else {
  622.         tmp1 = pt1.x ;
  623.         tmp2 = pt2.x ;
  624.         }
  625.  
  626.         /* find the correct band */
  627.         for ( ; nbox && (pbox->y2 <= pt1.y ) ; pbox++, nbox-- ) ;
  628.  
  629.         /* try to draw the line, if we haven't gone beyond it */
  630.         if ( nbox && ( pbox->y1 <= pt1.y ) ) {
  631.         /* when we leave this band, we're done */
  632.         int tmp3 = pbox->y1 ;
  633.         scrnFunc =
  634.          ( (ppcScrnPriv *)(pDrawable->pScreen->devPrivate))->lineHorz ;
  635.         for ( ; nbox && ( pbox->y1 == tmp3 ) ; nbox--, pbox++ )
  636.             if ( pbox->x2 <= tmp1 )
  637.             /* skip boxes until one might contain start point */
  638.             continue ;
  639.             /* stop if left of box is beyond right of line */
  640.             else if (pbox->x1 >= tmp2 )
  641.             break ;
  642.             else {
  643.             register int x1, x2 ;
  644.             if ( ( x1 = MAX( tmp1, pbox->x1 ) )
  645.               != ( x2 = MIN( tmp2, pbox->x2 ) ) )
  646.                 (* scrnFunc)( color, alu, pm, x1, pt1.y, x2 - x1 ) ;
  647.             }
  648.         }
  649.     }
  650.     else {    /* sloped line */
  651.         /* we have bresenham parameters and two points.
  652.            all we have to do now is clip and draw.
  653.         */
  654.         scrnFunc =
  655.         ( (ppcScrnPriv *)(pDrawable->pScreen->devPrivate))->lineBres ;
  656.  
  657.         for ( ; nbox-- ; pbox++ ) {
  658.         BoxRec box ;
  659.  
  660.         clipDone = 0 ;
  661.         box.x1 = pbox->x1 ;
  662.         box.y1 = pbox->y1 ;
  663.         box.x2 = pbox->x2-1 ;
  664.         box.y2 = pbox->y2-1 ;
  665.         clip1 = 0 ;
  666.         clip2 = 0 ;
  667.         pt1 = pdash->pt ;
  668.         pt2 = (pdash+1)->pt ;
  669.  
  670.         oc1 = 0 ;
  671.         oc2 = 0 ;
  672.         OUTCODES(oc1, pt1.x, pt1.y, pbox) ;
  673.         OUTCODES(oc2, pt2.x, pt2.y, pbox) ;
  674.  
  675.         if (oc1 & oc2)
  676.             clipDone = -1 ;
  677.         else if ((oc1 | oc2) == 0)
  678.             clipDone = 1 ;
  679.         else /* have to clip */
  680.             clipDone = mfbClipLine(pbox, box,
  681.                        &pt1Orig, &pt1, &pt2,
  682.                        adx, ady, signdx, signdy,
  683.                        ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  684.                        &clip1, &clip2) ;
  685.  
  686.         if ( clipDone != -1 ) {
  687.             if ( adx > ady )
  688.             len = ABS(pt2.x - pt1.x) ;
  689.             else
  690.             len = ABS(pt2.y - pt1.y) ;
  691.  
  692.             len += (clip2 != 0) ;
  693.             if (len) {
  694.             if (clip1) {
  695.                 /* unwind bres error term to first visible point */
  696.                 if ( adx > ady )
  697.                 err = e
  698.                     + ( ABS( pt1.y - pt1Orig.y ) * ( e2 - e1 ) )
  699.                     + ( ABS( pt1.x - pt1Orig.x ) * e1 ) ;
  700.                 else
  701.                 err = e
  702.                     + ( ABS( pt1.x - pt1Orig.x ) * ( e2 - e1 ) )
  703.                     + ( ABS( pt1.y - pt1Orig.y ) * e1 ) ;
  704.             }
  705.             else {
  706.                 /* use error term calculated with the dash */
  707.                 err = pdash->e ;
  708.             }
  709.             (* scrnFunc)( color, alu, pm, signdx, signdy,
  710.                       ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  711.                       pt1.x, pt1.y, err, e1, e2, len ) ;
  712.             }
  713.             /* if segment is unclipped, skip remaining rectangles */
  714.             if (!(clip1 || clip2))
  715.                 break ;
  716.         }
  717.         } /* while (nbox--) */
  718.     } /* sloped line */
  719. /* ************************************************************************** */
  720.     } /* for ( ; --nseg ; pdash++ ) */
  721.  
  722.     Xfree( pdashInit ) ;
  723.     return ;
  724. }
  725.  
  726. /* This Function is ONLY used when the linestyle in the GC is LineSolid.
  727.  * This is assumed below !!
  728.  */
  729.  
  730. void
  731. ppcScrnZeroSegs( pDrawable, pGC, nseg, psgInit )
  732. DrawablePtr    pDrawable ;
  733. GCPtr        pGC ;
  734. int        nseg ;
  735. xSegment    *psgInit ;
  736. {
  737. register int    nbox ;
  738. register BoxPtr pbox ;
  739. register int    tmp ;
  740.  
  741. BoxPtr        pboxInit ;
  742. BoxRec        box ;
  743. DDXPointRec    pt1, pt2,
  744.         pt1Orig, pt2Orig ;    /* unclipped points */
  745. xSegment    *psg ;
  746.  
  747. unsigned int    oc1, oc2 ;        /* outcodes */
  748.  
  749. int        xorg, yorg,        /* origin of window */
  750.         adx, ady,         /* abs values of dx and dy */
  751.         signdx, signdy,        /* sign of dx and dy */
  752.         e, e1, e2,        /* bresenham error and increments */
  753.         len,            /* length of segment */
  754.         clipDone,        /* flag for clipping loop */
  755.         err,            /* modified bresenham error term */
  756.         clip1, clip2,        /* clippedness of the endpoints */
  757.         alu ,            /* Screen Raster-Op value */
  758.         x1, x2, y1, y2,        /* a bunch of temporaries */
  759.         nboxInit, nsgTmp ;
  760.  
  761. unsigned long int fg ;             /* foreground Pixel value */
  762. unsigned long int pm ;            /* plane mask */
  763. ppcPrivGC     *gcPriv ;
  764. ppcScrnPriv     *scrnPriv ;
  765. void         (* scrnFunc)() ;    /* function that will do the draw */
  766.  
  767. if ( pDrawable->type != DRAWABLE_WINDOW ) {
  768.     ErrorF( "ppcScrnZeroSegs: not a window\n" ) ;
  769.     return ;
  770. }
  771.  
  772. gcPriv = (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr ;
  773. switch ( gcPriv->colorRrop.fillStyle ) {
  774.     case FillStippled :
  775.     case FillSolid : /* Can Use Optimized Color Raster-Op */
  776.         alu = gcPriv->colorRrop.alu ;
  777.         pm = gcPriv->colorRrop.planemask ;
  778.         fg = gcPriv->colorRrop.fgPixel ;
  779.         break ;
  780.     case FillOpaqueStippled :
  781.     case FillTiled : /* Can't Use Optimized Color Raster-Op */
  782.         alu = pGC->alu ;
  783.         pm = pGC->planemask ;
  784.         fg = pGC->fgPixel ;
  785.         break ;
  786. }
  787. if ( alu == GXnoop )
  788.     return ;
  789.  
  790. pboxInit = REGION_RECTS(gcPriv->pCompositeClip);
  791. nboxInit = REGION_NUM_RECTS(gcPriv->pCompositeClip) ;
  792.  
  793. xorg = pDrawable->x ;
  794. yorg = pDrawable->y ;
  795.  
  796. /* translate the point list */
  797. for ( psg = psgInit, nsgTmp = nseg ; nsgTmp-- ; psg++) {
  798.     psg->x1 += xorg ;
  799.     psg->y1 += yorg ;
  800.     psg->x2 += xorg ;
  801.     psg->y2 += yorg ;
  802. }
  803.  
  804. scrnPriv = (ppcScrnPriv *) ( pDrawable->pScreen->devPrivate ) ;
  805. psg = psgInit ;
  806. while ( nseg-- ) {
  807.     nbox = nboxInit ;
  808.     pbox = pboxInit ;
  809.  
  810.     pt1.x = psg->x1 ;
  811.     pt1.y = psg->y1 ;
  812.     pt2.x = psg->x2 ;
  813.     pt2.y = psg->y2 ;
  814.     psg++ ;
  815.  
  816.     if ( !( adx = ( pt2.x - pt1.x ) ) ) {
  817.         /* WE'RE GOING TO DO A VERTICAL LINE */
  818.         /* make the line go top to bottom of screen, keeping
  819.            endpoint semantics
  820.         */
  821.         if ( pt1.y > pt2.y ) {
  822.             tmp = pt2.y ;
  823.             pt2.y = pt1.y + 1 ;
  824.             pt1.y = tmp + 1 ;
  825.         }
  826.         /* get to first band that might contain part of line */
  827.         while ((nbox) && (pbox->y2 <= pt1.y)) {
  828.             pbox++ ;
  829.             nbox-- ;
  830.         }
  831.         if ( nbox ) {
  832.             scrnFunc = scrnPriv->lineVert ;
  833.             /* stop when lower edge of box is beyond end of line */
  834.             while ( ( nbox ) && ( pt2.y >= pbox->y1 ) ) {
  835.                 if ( ( pt1.x >= pbox->x1 )
  836.                   && ( pt1.x < pbox->x2 ) )
  837.                     /* box has part of the line in it */
  838.                     if ( ( y1 = MAX( pt1.y, pbox->y1 ) )
  839.                       != ( y2 = MIN( pt2.y, pbox->y2 ) ) )
  840.                         (* scrnFunc)( fg, alu, pm,
  841.                                   pt1.x, y1,
  842.                                   y2 - y1 ) ;
  843.                 nbox-- ;
  844.                 pbox++ ;
  845.             }
  846.         }
  847.     }/* END OF VERTICAL LINE SECTION */
  848.     else if ( !( ady = ( pt2.y - pt1.y ) ) ) {
  849.         /* WE'RE GOING TO DO A HORIZONTAL LINE */
  850.         /* force line from left to right, keeping
  851.            endpoint semantics
  852.         */
  853.         if (pt1.x > pt2.x) {
  854.             tmp = pt2.x ;
  855.             pt2.x = pt1.x + 1 ;
  856.             pt1.x = tmp + 1 ;
  857.         }
  858.  
  859.         /* find the correct band */
  860.         while ( nbox && ( pbox->y2 <= pt1.y ) ) {
  861.             pbox++ ;
  862.             nbox-- ;
  863.         }
  864.         /* try to draw the line, if we haven't gone beyond it */
  865.         if ( nbox && ( pbox->y1 <= pt1.y ) ) {
  866.             /* when we leave this band, we're done */
  867.             tmp = pbox->y1 ;
  868.             scrnFunc = scrnPriv->lineHorz ;
  869.             while ( nbox && ( pbox->y1 == tmp ) ) {
  870.                 /* skip boxes until one may hold start point */
  871.                 if ( pbox->x2 <= pt1.x ) {
  872.                     nbox-- ;
  873.                     pbox++ ;
  874.                     continue ;
  875.                 }
  876.                 /* stop if left of box is past right of line */
  877.                 if ( pbox->x1 >= pt2.x ) {
  878.                     nbox = 0 ;
  879.                     continue ;
  880.                 }
  881.                 if ( ( x1 = MAX( pt1.x, pbox->x1 ) )
  882.                   != ( x2 = MIN( pt2.x, pbox->x2 ) ) ) {
  883.                     (* scrnFunc)( fg, alu, pm, x1,
  884.                               pt1.y, x2 - x1 ) ;
  885.                 }
  886.                 nbox-- ;
  887.                 pbox++ ;
  888.             }
  889.         }
  890.     }/* END OF HORIZONTAL LINE SECTION */
  891.     else {    /* sloped line -- BRESENHAM TIME!! */
  892.         signdx = sign(adx) ;
  893.         adx = ABS(adx) ;
  894.         signdy = sign(ady) ;
  895.         ady = ABS(ady) ;
  896.  
  897.         if (adx > ady) {
  898.             e1 = ady << 1 ;
  899.             e = e1 - adx ;
  900.             e2 = e - adx ;
  901.         }
  902.         else {
  903.             e1 = adx << 1 ;
  904.             e = e1 - ady ;
  905.             e2 = e - ady ;
  906.         }
  907.         /* we have bresenham parameters and two points.
  908.          * all we have to do now is clip and draw.
  909.          */
  910.         pt1Orig = pt1 ;
  911.         pt2Orig = pt2 ;
  912.         scrnFunc = scrnPriv->lineBres ;
  913.         while ( nbox-- ) {
  914.             pt1 = pt1Orig ;
  915.             pt2 = pt2Orig ;
  916.             clipDone = 0 ;
  917.             box.x1 = pbox->x1 ;
  918.             box.y1 = pbox->y1 ;
  919.             box.x2 = pbox->x2-1 ;
  920.             box.y2 = pbox->y2-1 ;
  921.             clip1 = 0 ;
  922.             clip2 = 0 ;
  923.  
  924.             oc1 = 0 ;
  925.             oc2 = 0 ;
  926.             OUTCODES(oc1, pt1.x, pt1.y, pbox) ;
  927.             OUTCODES(oc2, pt2.x, pt2.y, pbox) ;
  928.  
  929.             if ( oc1 & oc2 )
  930.                 clipDone = -1 ;
  931.             else if ( !( oc1 | oc2 ) )
  932.                 clipDone = 1 ;
  933.             else /* have to clip */
  934.                 clipDone = mfbClipLine( pbox, box,
  935.                             &pt1Orig, &pt1, &pt2,
  936.                             adx, ady,
  937.                                 signdx, signdy,
  938.                     ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  939.                             &clip1, &clip2 ) ;
  940.             if (clipDone == -1)
  941.                 pbox++ ;
  942.             else {
  943.                 if ( adx > ady )
  944.                     len = ABS(pt2.x - pt1.x) ;
  945.                 else
  946.                     len = ABS(pt2.y - pt1.y) ;
  947.  
  948.                 len += (clip2 != 0) ;
  949.                 if (len) {
  950.                 /* unwind bresenham error term to first point */
  951.                     if (clip1) {
  952.                         if ( adx > ady )
  953.                             err = e
  954.                         + ( ABS( pt1.y - pt1Orig.y )
  955.                          * ( e2 - e1 ) )
  956.                         + ( ABS( pt1.x - pt1Orig.x )
  957.                          * e1 ) ;
  958.                         else
  959.                             err = e
  960.                         + ( ABS( pt1.x - pt1Orig.x )
  961.                          * ( e2 - e1 ) )
  962.                         + ( ABS( pt1.y - pt1Orig.y )
  963.                          * e1 ) ;
  964.                     }
  965.                     else
  966.                         err = e ;
  967.                     (* scrnFunc)( fg, alu, pm,
  968.                               signdx, signdy,
  969.                       ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  970.                               pt1.x, pt1.y,
  971.                               err, e1, e2, len ) ;
  972.                 }
  973.                 /* if segment is unclipped,
  974.                    skip remaining rectangles */
  975.                 if ( !( clip1 || clip2 ) )
  976.                     break ;
  977.                 else
  978.                     pbox++ ;
  979.             }
  980.         } /* while (nbox--) */
  981.     } /* sloped line */
  982. } /* while (nline--) */
  983.  
  984. return ;
  985. }
  986.