Back to index

tetex-bin  3.0
Defines | Functions | Variables
regions.c File Reference
#include "types.h"
#include "objects.h"
#include "spaces.h"
#include "regions.h"
#include "paths.h"
#include "curves.h"
#include "lines.h"
#include "pictures.h"
#include "fonts.h"
#include "hints.h"
#include "strokes.h"

Go to the source code of this file.

Defines

#define ISOPTIMIZED(flag)   ((flag)&0x10)
#define MAXEDGE   1000
#define TOP(e)   ((e)->ymin) /* the top of an edge (for readability */
#define BOTTOM(e)   ((e)->ymax) /* the bottom of an edge (for readability */
#define INSWATH(p, y0, y1)   (p != NULL && p->ymin == y0 && p->ymax == y1)

Functions

static int Unwind ()
static int newfilledge ()
static int vertjoin ()
static discard ()
static int edgemin ()
static int edgemax ()
static struct edgelistsplitedge ()
static int touches ()
static int crosses ()
static int edgecheck ()
static struct edgelistNewEdge ()
void KillRegion (struct region *area)
struct regionCopyRegion (struct region *area)
static struct edgelistNewEdge (pel xmin, pel xmax, pel ymin, pel ymax, pel *xvalues, int isdown)
struct regionInterior (struct segment *p, int fillrule)
static int Unwind (struct edgelist *area)
void ChangeDirection (int type, struct region *R, fractpel x, fractpel y, fractpel dy)
static int newfilledge (struct region *R, fractpel xmin, fractpel xmax, fractpel ymin, fractpel ymax, int isdown)
struct edgelistSortSwath (struct edgelist *anchor, struct edgelist *edge, struct edgelist *(*swathfcn)())
static struct edgelistsplitedge (struct edgelist *list, pel y)
static int vertjoin (struct edgelist *top, struct edgelist *bottom)
struct edgelistswathxsort (struct edgelist *before0, struct edgelist *edge)
struct edgelistSwathUnion (struct edgelist *before0, struct edgelist *edge)
struct edgelistswathrightmost (struct edgelist *before, struct edgelist *edge)
static int touches (int h, pel *left, pel *right)
static int crosses (int h, pel *left, pel *right)
static void cedgemin (register int h, register pel *e1, register pel x)
static void cedgemax (register int h, register pel *e1, register pel x)
static void edgemin (register int h, register pel *e1, register pel *e2)
static void edgemax (register int h, register pel *e1, register pel *e2)
static discard (struct edgelist *left, struct edgelist *right)
void MoveEdges (struct region *R, fractpel dx, fractpel dy)
void UnJumble (struct region *region)
static OptimizeRegion (struct region *R)
void MoreWorkArea (struct region *R, fractpel x1, fractpel y1, fractpel x2, fractpel y2)
struct regionBoxClip (struct region *R, pel xmin, pel ymin, pel xmax, pel ymax)
struct segmentRegionBounds (struct region *R)
void DumpArea (struct region *area)
void DumpEdges (struct edgelist *edges)
static int edgecheck (struct edgelist *edge, int oldmin, int oldmax)

Variables

static struct region
struct regionINFINITY = &t1_infinity
static pel workedge [MAXEDGE]
static pelcurrentworkarea = workedge
static pel currentsize = MAXEDGE
static pel RegionDebugYMin = MINPEL
static pel RegionDebugYMax = MAXPEL

Define Documentation

#define BOTTOM (   e)    ((e)->ymax) /* the bottom of an edge (for readability */

Definition at line 811 of file regions.c.

#define INSWATH (   p,
  y0,
  y1 
)    (p != NULL && p->ymin == y0 && p->ymax == y1)

Definition at line 1685 of file regions.c.

#define ISOPTIMIZED (   flag)    ((flag)&0x10)

Definition at line 134 of file regions.c.

#define MAXEDGE   1000

Definition at line 647 of file regions.c.

#define TOP (   e)    ((e)->ymin) /* the top of an edge (for readability */

Definition at line 810 of file regions.c.


Function Documentation

struct region* BoxClip ( struct region R,
pel  xmin,
pel  ymin,
pel  xmax,
pel  ymax 
) [read]

Definition at line 1559 of file regions.c.

{
       struct edgelist anchor;  /* pretend edgelist to facilitate discards   */
       register struct edgelist *e,*laste;
 
       IfTrace1((OffPageDebug),"BoxClip of %x:\n", R);
 
       R = UniqueRegion(R);
 
       if (xmin > R->xmin) {
               IfTrace2((OffPageDebug),"BoxClip:  left clip old %d new %d\n",
                                            (LONG) R->xmin, (LONG) xmin);
               R->xmin = xmin;
       }
       if (xmax < R->xmax) {
               IfTrace2((OffPageDebug),"BoxClip:  right clip old %d new %d\n",
                                            (LONG) R->xmax, (LONG) xmax);
               R->xmax = xmax;
       }
 
       if (ymin > R->ymin) {
               IfTrace2((OffPageDebug),"BoxClip:  top clip old %d new %d\n",
                                            (LONG) R->ymin, (LONG) ymin);
               R->ymin = ymin;
       }
       if (ymax < R->ymax) {
               IfTrace2((OffPageDebug),"BoxClip:  bottom clip old %d new %d\n",
                                            (LONG) R->ymax, (LONG) ymax);
               R->ymax = ymax;
       }
 
 
       laste = &anchor;
       anchor.link = R->anchor;
 
       for (e = R->anchor; VALIDEDGE(e); e = e->link) {
               if (TOP(e) < ymin) {
                       e->xvalues += ymin - e->ymin;
                       e->ymin = ymin;
               }
               if (BOTTOM(e) > ymax)
                       e->ymax = ymax;
               if (TOP(e) >= BOTTOM(e)) {
                       discard(laste, e->link->link);
                       e = laste;
                       continue;
               }
               if (e->xmin < xmin) {
                       cedgemax(BOTTOM(e) - TOP(e), e->xvalues, xmin);
                       e->xmin = xmin;
                       e->xmax = MAX(e->xmax, xmin);
               }
               if (e->xmax > xmax) {
                       cedgemin(BOTTOM(e) - TOP(e), e->xvalues, xmax);
                       e->xmin = MIN(e->xmin, xmax);
                       e->xmax = xmax;
               }
               laste = e;
       }
 
       R->anchor = anchor.link;
 
       return(R);
}

Here is the call graph for this function:

static void cedgemax ( register int  h,
register pel e1,
register pel  x 
) [static]

Definition at line 1321 of file regions.c.

{
       for (; --h >= 0; e1++)
               if (*e1 < x)
                       *e1 = x;
}

Here is the caller graph for this function:

static void cedgemin ( register int  h,
register pel e1,
register pel  x 
) [static]

Definition at line 1311 of file regions.c.

{
       for (; --h >= 0; e1++)
               if (*e1 > x)
                       *e1 = x;
}

Here is the caller graph for this function:

void ChangeDirection ( int  type,
struct region R,
fractpel  x,
fractpel  y,
fractpel  dy 
)

Definition at line 663 of file regions.c.

{
       register fractpel ymin,ymax;  /* minimum and maximum Y since last call */
       register fractpel x_at_ymin,x_at_ymax;  /* their respective X's       */
       register pel iy;      /* nearest integer pel to 'y'                   */
       register pel idy;     /* nearest integer pel to 'dy'                  */
       register int ydiff;   /* allowed Y difference in 'currentworkarea'    */
 
       IfTrace4((RegionDebug>0),"Change Y direction (%d) from (%p,%p), dy=%p\n",
                                         (LONG) type, x, y, dy);
 
       if (type != CD_FIRST) {
 
               if (R->lastdy > 0) {
                       ymin = R->firsty;
                       x_at_ymin = R->firstx;
                       ymax = y;
                       x_at_ymax = x;
               }
               else {
                       ymin = y;
                       x_at_ymin = x;
                       ymax = R->firsty;
                       x_at_ymax = R->firstx;
               }
 
               if (ymax < ymin)
                       t1_abort("negative sized edge?");
 
 
              /* FIXME: there are not as much parameters as here. */
               (*R->newedgefcn)(R, R->edgexmin, R->edgexmax, ymin, ymax,
                                   R->lastdy > 0 /*, x_at_ymin, x_at_ymax */);
 
       }
 
       R->firsty = y;
       R->firstx = x;
       R->lastdy = dy;
 
       iy = NEARESTPEL(y);
       idy = NEARESTPEL(dy);
       if (currentworkarea != workedge && idy < MAXEDGE && idy > -MAXEDGE) {
               NonObjectFree(currentworkarea);
               currentworkarea = workedge;
               currentsize = MAXEDGE;
       }
       ydiff = currentsize - 1;
       if (dy > 0) {
               R->edge = &currentworkarea[-iy];
               R->edgeYstop = TOFRACTPEL(ydiff + iy) + FPHALF;
       }
       else {
               R->edge = &currentworkarea[ydiff - iy];
               R->edgeYstop = TOFRACTPEL(iy - ydiff) - FPHALF;
       }
       R->edgexmax = R->edgexmin = x;
/*
If this is the end of a subpath, we complete the subpath circular
chain:
*/
       if (type == CD_LAST && R->lastedge != NULL) {
               register struct edgelist *e = R->firstedge;
 
               while (e->subpath != NULL)
                       e = e->subpath;
               e->subpath = R->lastedge;
               R->lastedge = R->firstedge = NULL;
       }
}

Here is the call graph for this function:

struct region* CopyRegion ( struct region area) [read]

Definition at line 261 of file regions.c.

{
        register struct region *r;  /* output region built here              */
        register struct edgelist *last;  /* loop variable                    */
        register struct edgelist *p,*newp;  /* loop variables                */
 
        r = (struct region *)Allocate(sizeof(struct region), area, 0);
        r->anchor = NULL;
 
        for (p=area->anchor; VALIDEDGE(p); p=p->link) {
 
               newp = NewEdge(p->xmin, p->xmax, p->ymin, p->ymax, p->xvalues, ISDOWN(p->flag));
               if (r->anchor == NULL)
                       r->anchor = last = newp;
               else
                       last->link = newp;
 
               last = newp;
        }
        if (area->thresholded != NULL)
    /* replaced DupPicture with Dup() 3-26-91 PNM */
               r->thresholded = (struct picture *)Dup(area->thresholded);
        return(r);
}

Here is the call graph for this function:

static int crosses ( ) [static]
static int crosses ( int  h,
pel left,
pel right 
) [static]

Definition at line 1298 of file regions.c.

{
       for (; h > 0; h--)
               if (*left++ > *right++)
                       break;
       return(h);
}
static discard ( ) [static]
static discard ( struct edgelist left,
struct edgelist right 
) [static]

Definition at line 1366 of file regions.c.

{
       register struct edgelist *beg,*end,*p;
 
       IfTrace2((RegionDebug > 0),"discard:  l=%x, r=%x\n", left, right);
 
       beg = left->link;
       if (beg == right)
               return;
 
       for (p = beg; p != right; p = p->link) {
               if (p->link == NULL && right != NULL)
                       t1_abort("discard():  ran off end");
               IfTrace1((RegionDebug > 0),"discarding %x\n", p);
               p->ymin = p->ymax = 32767;
               end = p;
       }
       /*
       * now put the chain beg/end at the end of right, if it is not
       * already there:
       */
       if (right != NULL) {
               left->link = right;
               while (right->link != NULL)
                       right = right->link;
               right->link = beg;
       }
       end->link = NULL;
}

Here is the call graph for this function:

void DumpArea ( struct region area)

Definition at line 1674 of file regions.c.

{
       IfTrace1(TRUE,"Dumping area %x,", area);
       IfTrace4(TRUE," X %d:%d Y %d:%d;", (LONG) area->xmin,
                      (LONG) area->xmax, (LONG) area->ymin,(LONG) area->ymax);
       IfTrace4(TRUE," origin=(%p,%p), ending=(%p,%p)\n",
               area->origin.x, area->origin.y, area->ending.x, area->ending.y);
       DumpEdges(area->anchor);
}
void DumpEdges ( struct edgelist edges)

Definition at line 1693 of file regions.c.

{
       register struct edgelist *p,*p2;
       register pel ymin = MINPEL;
       register pel ymax = MINPEL;
       register int y;
 
       if (edges == NULL) {
               IfTrace0(TRUE,"    NULL area.\n");
               return;
       }
       if (RegionDebug <= 1) {
               for (p=edges; p != NULL; p = p->link) {
                       edgecheck(p, ymin, ymax);
                       ymin = p->ymin;  ymax = p->ymax;
                       IfTrace3(TRUE,". at %x type=%d flag=%x",
                                        p, (LONG) p->type,(LONG) p->flag);
                       IfTrace4(TRUE," bounding box HxW is %dx%d at (%d,%d)\n",
                               (LONG) ymax - ymin, (LONG) p->xmax - p->xmin,
                               (LONG) p->xmin, (LONG) ymin);
               }
       }
       else {
 
               for (p2=edges; p2 != NULL; ) {
 
                       edgecheck(p2, ymin, ymax);
                       ymin = p2->ymin;
                       ymax = p2->ymax;
 
                       if (RegionDebug > 3 || (ymax > RegionDebugYMin
                                   && ymin < RegionDebugYMax)) {
                               IfTrace2 (TRUE,". Swath from %d to %d:\n",
                                                              ymin, ymax);
                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link) {
                                       IfTrace4(TRUE,". . at %x[%x] range %d:%d, ",
                                                 p, (LONG) p->flag,
                                                 (LONG) p->xmin, (LONG)p->xmax);
                                       IfTrace1(TRUE, "subpath=%x,\n", p->subpath);
                               }
                       }
                       for (y=MAX(ymin,RegionDebugYMin); y < MIN(ymax, RegionDebugYMax); y++) {
                               IfTrace1(TRUE,". . . Y[%5d] ", (LONG) y);
                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link)
                                       IfTrace1(TRUE,"%5d ",
                                                (LONG) p->xvalues[y - ymin]);
                               IfTrace0(TRUE,"\n");
                       }
                       while (INSWATH(p2, ymin, ymax))
                               p2 = p2->link;
               }
       }
}

Here is the call graph for this function:

static int edgecheck ( ) [static]
static int edgecheck ( struct edgelist edge,
int  oldmin,
int  oldmax 
) [static]

Definition at line 1753 of file regions.c.

{
       if (edge->type != EDGETYPE)
               t1_abort("EDGE ERROR: non EDGETYPE in list");
/*
The following check is not valid if the region is jumbled so I took it
out:
*/
/*     if (edge->ymin < oldmax && edge->ymin != oldmin)
               t1_abort("EDGE ERROR: overlapping swaths"); */
}

Here is the call graph for this function:

static int edgemax ( ) [static]
static void edgemax ( register int  h,
register pel e1,
register pel e2 
) [static]

Definition at line 1341 of file regions.c.

{
       for (; --h >= 0; e1++,e2++)
               if (*e1 < *e2)
                       *e1 = *e2;
}
static int edgemin ( ) [static]
static void edgemin ( register int  h,
register pel e1,
register pel e2 
) [static]

Definition at line 1331 of file regions.c.

{
       for (; --h >= 0; e1++,e2++)
               if (*e1 > *e2)
                       *e1 = *e2;
}
struct region* Interior ( struct segment p,
int  fillrule 
) [read]

Definition at line 378 of file regions.c.

{
       register fractpel x,y;  /* keeps ending point of path segment         */
       fractpel lastx,lasty; /* previous x,y from path segment before        */
       register struct region *R;  /* region I will build                    */
       register struct segment *nextP; /* next segment of path */
       struct fractpoint hint; /* accumulated hint value */
       char tempflag;        /* flag; is path temporary?                     */
       char Cflag;           /* flag; should we apply continuity?            */
 
       IfTrace2((MustTraceCalls),".  INTERIOR(%x, %d)\n", p, (LONG) fillrule);
 
       if (p == NULL)
               return(NULL);
/*
Establish the 'Cflag' continuity flag based on user's fill rule and
our own 'Continuity' pragmatic (0: never do continuity, 1: do what
user asked, >1: do it regardless).
*/
       if (fillrule > 0) {
               Cflag = Continuity > 0;
               fillrule -= CONTINUITY;
       }
       else
               Cflag = Continuity > 1;
 
       ARGCHECK((fillrule != WINDINGRULE && fillrule != EVENODDRULE),
                       "Interior: bad fill rule", NULL, NULL, (1,p), struct region *);
 
       if (p->type == TEXTTYPE)
/*             if (fillrule != EVENODDRULE)
               else */
                       return((struct region *)UniquePath(p));
       if (p->type == STROKEPATHTYPE)
               if (fillrule == WINDINGRULE)
                       return((struct region *)DoStroke(p));
               else
                       p = CoercePath(p);
 
       R = (struct region *)Allocate(sizeof(struct region), &EmptyRegion, 0);
 
       ARGCHECK(!ISPATHANCHOR(p), "Interior:  bad path", p, R, (0), struct region *);
       ARGCHECK((p->type != MOVETYPE), "Interior:  path not closed", p, R, (0), struct region *);
 
 
/* changed definition from !ISPERMANENT to references <= 1 3-26-91 PNM */
       tempflag =  (p->references <= 1); /* only first segment in path is so marked */
       if (!ISPERMANENT(p->flag)) p->references -= 1;
 
       R->newedgefcn = newfilledge;
/*
Believe it or not, "R" is now completely initialized.  We are counting
on the copy of template to get other fields the way we want them,
namely
:ol.
:li.anchor = NULL
:li.xmin, ymin, xmax, ymax, to minimum and maximum values respectively.
:eol.
Anchor = NULL is very
important to ChangeDirection.
See :hdref refid=CD..
 
To minimize problems of "wrapping" in our pel arithmetic, we keep an
origin of the region which is the first move.  Hopefully, that keeps
numbers within plus or minus 32K pels.
*/
       R->origin.x = 0/*TOFRACTPEL(NEARESTPEL(p->dest.x))*/;
       R->origin.y = 0/*TOFRACTPEL(NEARESTPEL(p->dest.y))*/;
       lastx = - R->origin.x;
       lasty = - R->origin.y;
/*
ChangeDirection initializes other important fields in R, such as
lastdy, edge, edgeYstop, edgexmin, and edgexmax.  The first segment
is a MOVETYPE, so it will be called first.
*/
/*
The hints data structure must be initialized once for each path.
*/
 
       if (ProcessHints)
               InitHints(); /* initialize hint data structure */
 
       while (p != NULL)  {
 
               x = lastx + p->dest.x;
               y = lasty + p->dest.y;
 
               IfTrace2((HintDebug > 0),"Ending point = (%p,%p)\n", x, y);
 
               nextP = p->link;
 
/*
Here we start the hints processing by initializing the hint value to
zero.  If ProcessHints is FALSE, the value will remain zero.
Otherwise, hint accumulates the computed hint values.
*/
 
               hint.x = hint.y = 0;
 
/*
If we are processing hints, and this is a MOVE segment (other than
the first on the path), we need to close (reverse) any open hints.
*/
 
               if (ProcessHints)
                       if ((p->type == MOVETYPE) && (p->last == NULL)) {
                               CloseHints(&hint);
                               IfTrace2((HintDebug>0),"Closed point= (%p,%p)\n",
                                               x+hint.x, y+hint.y);
                       }
 
/*
Next we run through all the hint segments (if any) attached to this
segment.  If ProcessHints is TRUE, we will accumulate computed hint
values.  In either case, nextP will be advanced to the first non-HINT
segment (or NULL), and each hint segment will be freed if necessary.
*/
 
               while ((nextP != NULL) && (nextP->type == HINTTYPE))  {
                       if (ProcessHints)
                               ProcessHint(nextP, x + hint.x, y + hint.y, &hint);
 
                       {
                               register struct segment *saveP = nextP;
 
                               nextP = nextP->link;
                               if (tempflag)
                                       Free(saveP);
                       }
               }
 
/*
We now apply the full hint value to the ending point of the path segment.
*/
 
               x += hint.x;
               y += hint.y;
 
               IfTrace2((HintDebug>0),"Hinted ending point = (%p,%p)\n", x, y);
 
               switch(p->type) {
 
                   case LINETYPE:
                       StepLine(R, lastx, lasty, x, y);
                       break;
 
                   case CONICTYPE:
                   {
 
/*
For a conic curve, we apply half the hint value to the conic midpoint.
*/
 
                   }
                       break;
 
                   case BEZIERTYPE:
                   {
                       register struct beziersegment *bp = (struct beziersegment *) p;
 
/*
For a Bezier curve, we apply the full hint value to the Bezier C point.
*/
 
                       StepBezier(R, lastx, lasty,
                                 lastx + bp->B.x, lasty + bp->B.y,
                                 lastx + bp->C.x + hint.x,
                                 lasty + bp->C.y + hint.y,
                                 x, y);
                   }
                       break;
 
                   case MOVETYPE:
/*
At this point we have encountered a MOVE segment.  This breaks the
path, making it disjoint.
*/
                       if (p->last == NULL) /* i.e., not first in path */
                               ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0);
 
                       ChangeDirection(CD_FIRST, R, x, y, (fractpel) 0);
/*
We'll just double check for closure here.  We forgive an appended
MOVETYPE at the end of the path, if it isn't closed:
*/
                       if (!ISCLOSED(p->flag) && p->link != NULL)
                               return((struct region *)ArgErr("Fill: sub-path not closed", p, NULL));
                       break;
 
                   default:
                       t1_abort("Interior: path type error");
               }
/*
We're done with this segment.  Advance to the next path segment in
the list, freeing this one if necessary:
*/
               lastx = x;  lasty = y;
 
               if (tempflag)
                       Free(p);
               p = nextP;
       }
       ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0);
       R->ending.x = lastx;
       R->ending.y = lasty;
/*
Finally, clean up the region's based on the user's 'fillrule' request:
*/
       if (Cflag)
             ApplyContinuity(R);
       if (fillrule == WINDINGRULE)
             Unwind(R->anchor);
       return(R);
}

Here is the call graph for this function:

void KillRegion ( struct region area)

Definition at line 238 of file regions.c.

{
        register struct edgelist *p;  /* loop variable                       */
        register struct edgelist *next;  /* loop variable                    */
 
        if (area->references < 0)
               t1_abort("KillRegion:  negative reference count");
        if ( (--(area->references) > 1) ||
           ( (area->references == 1) && !ISPERMANENT(area->flag) ) )
            return;
 
        for (p=area->anchor; p != NULL; p=next) {
               next = p->link;
               Free(p);
        }
        if (area->thresholded != NULL)
                 KillPicture(area->thresholded);
        Free(area);
}

Here is the call graph for this function:

void MoreWorkArea ( struct region R,
fractpel  x1,
fractpel  y1,
fractpel  x2,
fractpel  y2 
)

Definition at line 1527 of file regions.c.

{
       register int idy;     /* integer dy of line                           */
 
       idy = NEARESTPEL(y1) - NEARESTPEL(y2);
       if (idy < 0)  idy = - idy;
 
       /*
       * we must add one to the delta for the number of run ends we
       * need to store:
       */
       if (++idy > currentsize) {
               IfTrace1((RegionDebug > 0),"Allocating edge of %d pels\n", idy);
               if (currentworkarea != workedge)
                       NonObjectFree(currentworkarea);
               currentworkarea = (pel *)Allocate(0, NULL, idy * sizeof(pel));
               currentsize = idy;
       }
       ChangeDirection(CD_CONTINUE, R, x1, y1, y2 - y1);
}
void MoveEdges ( struct region R,
fractpel  dx,
fractpel  dy 
)

Definition at line 1409 of file regions.c.

{
       register struct edgelist *edge;  /* for looping through edges         */
 
       R->origin.x += dx;
       R->origin.y += dy;
       R->ending.x += dx;
       R->ending.y += dy;
       if (R->thresholded != NULL) {
               R->thresholded->origin.x -= dx;
               R->thresholded->origin.y -= dy;
       }
/*
From now on we will deal with dx and dy as integer pel values:
*/
       dx = NEARESTPEL(dx);
       dy = NEARESTPEL(dy);
       if (dx == 0 && dy == 0)
               return;
 
       R->xmin += dx;
       R->xmax += dx;
       R->ymin += dy;
       R->ymax += dy;
 
       for (edge = R->anchor; VALIDEDGE(edge); edge = edge->link) {
               edge->ymin += dy;
               edge->ymax += dy;
               if (dx != 0) {
                       register int h;  /* loop index; height of edge        */
                       register pel *Xp;  /* loop pointer to X values        */
 
                       edge->xmin += dx;
                       edge->xmax += dx;
                       for (Xp = edge->xvalues, h = edge->ymax - edge->ymin;
                                     --h >= 0; )
                               *Xp++ += dx;
               }
       }
}
static struct edgelist* NewEdge ( ) [static, read]
static struct edgelist* NewEdge ( pel  xmin,
pel  xmax,
pel  ymin,
pel  ymax,
pel xvalues,
int  isdown 
) [static, read]

Definition at line 295 of file regions.c.

{
       static struct edgelist template = {
                 EDGETYPE, 0, 1, NULL, NULL,
                 0, 0, 0, 0, NULL };
 
       register struct edgelist *r;  /* returned structure                   */
       register int iy;      /* ymin adjusted for 'long' alignment purposes  */
 
       IfTrace2((RegionDebug),"....new edge: ymin=%d, ymax=%d ",
                                              (LONG)ymin, (LONG) ymax);
       if (ymin >= ymax)
               t1_abort("newedge: height not positive");
/*
We are going to copy the xvalues into a newly allocated area.  It
helps performance if the values are all "long" aligned.  We can test
if the xvalues are long aligned by ANDing the address with the
(sizeof(long) - 1)--if non zero, the xvalues are not aligned well.  We
set 'iy' to the ymin value that would give us good alignment:
*/
#if defined (__alpha)
       iy = ymin - (((long) xvalues) & (sizeof(LONG) - 1)) / sizeof(pel);
#else
       iy = ymin - (((int) xvalues) & (sizeof(LONG) - 1)) / sizeof(pel);
#endif 
       r = (struct edgelist *)Allocate(sizeof(struct edgelist), &template,
                             (ymax - iy) * sizeof(pel));
 
       if (isdown) r->flag = ISDOWN(ON);
       r->xmin = xmin;
       r->xmax = xmax;
       r->ymin = ymin;
       r->ymax = ymax;
 
       r->xvalues = (pel *) FOLLOWING(r);
       if (ymin != iy) {
               r->xvalues += ymin - iy;
               xvalues -= ymin - iy;
       }
 
/*
We must round up (ymax - iy) so we get the ceiling of the number of
longs.  The destination must be able to hold these extra bytes because
Allocate() makes everything it allocates be in multiples of longs.
*/
       LONGCOPY(&r[1], xvalues, (ymax - iy) * sizeof(pel) + sizeof(LONG) - 1);
 
       IfTrace1((RegionDebug),"result=%x\n", r);
       return(r);
}

Here is the call graph for this function:

static int newfilledge ( ) [static]
static int newfilledge ( struct region R,
fractpel  xmin,
fractpel  xmax,
fractpel  ymin,
fractpel  ymax,
int  isdown 
) [static]

Definition at line 754 of file regions.c.

{
       struct edgelist *swathxsort();  /* 'SortSwath' function               */
 
       register pel pelxmin,pelymin,pelxmax,pelymax;  /* pel versions of bounds */
       register struct edgelist *edge;  /* newly created edge                */
 
       pelymin = NEARESTPEL(ymin);
       pelymax = NEARESTPEL(ymax);
       if (pelymin == pelymax)
               return;
 
       pelxmin = NEARESTPEL(xmin);
       pelxmax = NEARESTPEL(xmax);
 
       if (pelxmin < R->xmin)  R->xmin = pelxmin;
       if (pelxmax > R->xmax)  R->xmax = pelxmax;
       if (pelymin < R->ymin)  R->ymin = pelymin;
       if (pelymax > R->ymax)  R->ymax = pelymax;
 
       edge = NewEdge(pelxmin, pelxmax, pelymin, pelymax, &R->edge[pelymin], isdown);
       edge->subpath = R->lastedge;
       R->lastedge = edge;
       if (R->firstedge == NULL)
               R->firstedge = edge;
 
       R->anchor = SortSwath(R->anchor, edge, swathxsort);
 
}

Here is the call graph for this function:

static OptimizeRegion ( struct region R) [static]

Definition at line 1485 of file regions.c.

{
       register pel *xP;     /* pel pointer for inner loop                   */
       register int x;       /* holds X value                                */
       register int xmin,xmax;  /* holds X range                             */
       register int h;       /* loop counter                                 */
       register struct edgelist *e;  /* edgelist pointer for loop            */
 
       R->flag |= ISRECTANGULAR(ON);
 
       for (e = R->anchor; VALIDEDGE(e); e=e->link) {
               xmin = MAXPEL;
               xmax = MINPEL;
               for (h = e->ymax - e->ymin, xP = e->xvalues; --h >= 0;) {
                         x = *xP++;
                         if (x < xmin)  xmin = x;
                         if (x > xmax)  xmax = x;
               }
               if (xmin != xmax || (xmin != R->xmin && xmax != R->xmax))
                       R->flag &= ~ISRECTANGULAR(ON);
               if (xmin < e->xmin || xmax > e->xmax)
                       t1_abort("Tighten: existing edge bound was bad");
               if (xmin < R->xmin || xmax > R->xmax)
                       t1_abort("Tighten: existing region bound was bad");
               e->xmin = xmin;
               e->xmax = xmax;
       }
       R->flag |= ISOPTIMIZED(ON);
}

Here is the call graph for this function:

struct segment* RegionBounds ( struct region R) [read]

Definition at line 1655 of file regions.c.

{
       extern struct XYspace *IDENTITY;
 
       register struct segment *path;  /* returned path                      */
 
       path = BoxPath(IDENTITY, R->ymax - R->ymin, R->xmax - R->xmin);
       path = Join(PathSegment(MOVETYPE, R->origin.x + TOFRACTPEL(R->xmin),
                                         R->origin.y + TOFRACTPEL(R->ymin) ),
                   path);
       return(path);
}
struct edgelist* SortSwath ( struct edgelist anchor,
struct edgelist edge,
struct edgelist *(*)()  swathfcn 
) [read]

Definition at line 813 of file regions.c.

{
       register struct edgelist *before,*after;
       struct edgelist base;
 
       if (RegionDebug > 0) {
               if (RegionDebug > 2)  {
                       IfTrace3(TRUE,"SortSwath(anchor=%x, edge=%x, fcn=%x)\n",
                            anchor, edge, swathfcn);
               }
               else  {
                       IfTrace3(TRUE,"SortSwath(anchor=%x, edge=%x, fcn=%x)\n",
                            anchor, edge, swathfcn);
               }
       }
       if (anchor == NULL)
               return(edge);
 
       before = &base;
       before->ymin = before->ymax = MINPEL;
       before->link = after = anchor;
 
/*
If the incoming edge is above the current list, we connect the current
list to the bottom of the incoming edge.  One slight complication is
if the incoming edge overlaps into the current list.  Then, we
first split the incoming edge in two at the point of overlap and recursively
call ourselves to sort the bottom of the split into the current list:
*/
       if (TOP(edge) < TOP(after)) {
               if (BOTTOM(edge) > TOP(after)) {
 
                       after = SortSwath(after, splitedge(edge, TOP(after)), swathfcn);
               }
               vertjoin(edge, after);
               return(edge);
       }
/*
At this point the top of edge is not higher than the top of the list,
which we keep in 'after'.  We move the 'after' point down the list,
until the top of the edge occurs in the swath beginning with 'after'.
 
If the bottom of 'after' is below the bottom of the edge, we have to
split the 'after' swath into two parts, at the bottom of the edge.
If the bottom of 'after' is above the bottom of the swath,
*/
 
       while (VALIDEDGE(after)) {
 
               if (TOP(after) == TOP(edge)) {
                       if (BOTTOM(after) > BOTTOM(edge))
                               vertjoin(after, splitedge(after, BOTTOM(edge)));
                       else if (BOTTOM(after) < BOTTOM(edge)) {
                               after = SortSwath(after,
                                     splitedge(edge, BOTTOM(after)), swathfcn);
                       }
                       break;
               }
               else if (TOP(after) > TOP(edge)) {
                       IfTrace0((BOTTOM(edge) < TOP(after) && RegionDebug > 0),
                                                "SortSwath:  disjoint edges\n");
                       if (BOTTOM(edge) > TOP(after)) {
                               after = SortSwath(after,
                                         splitedge(edge, TOP(after)), swathfcn);
                       }
                       break;
               }
               else if (BOTTOM(after) > TOP(edge))
                       vertjoin(after, splitedge(after, TOP(edge)));
 
               before = after;
               after = after->link;
       }
 
/*
At this point 'edge' exactly corresponds in height to the current
swath pointed to by 'after'.
*/
       if (after != NULL && TOP(after) == TOP(edge)) {
               before = (*swathfcn)(before, edge);
               after = before->link;
       }
/*
At this point 'after' contains all the edges after 'edge', and 'before'
contains all the edges before.  Whew!  A simple matter now of adding
'edge' to the linked list in its rightful place:
*/
       before->link = edge;
       if (RegionDebug > 1) {
               IfTrace3(TRUE,"SortSwath:  in between %x and %x are %x",
                                                before, after, edge);
               while (edge->link != NULL) {
                       edge = edge->link;
                       IfTrace1(TRUE," and %x", edge);
               }
               IfTrace0(TRUE,"\n");
       }
       else
               for (; edge->link != NULL; edge = edge->link) { ; }
 
       edge->link = after;
       return(base.link);
}

Here is the call graph for this function:

static struct edgelist* splitedge ( ) [static, read]
static struct edgelist* splitedge ( struct edgelist list,
pel  y 
) [static, read]

Definition at line 928 of file regions.c.

{
       register struct edgelist *new;  /* anchor for newly built list        */
       register struct edgelist *last;  /* end of newly built list           */
       register struct edgelist *r;  /* temp pointer to new structure        */
       register struct edgelist *lastlist;  /* temp pointer to last 'list' value */
 
       IfTrace2((RegionDebug > 1),"splitedge of %x at %d ", list, (LONG) y);
 
       lastlist = new = NULL;
 
       while (list != NULL) {
               if (y < list->ymin)
                       break;
               if (y >= list->ymax)
                       t1_abort("splitedge: above top of list");
               if (y == list->ymin)
                       t1_abort("splitedge: would be null");
 
               r = (struct edgelist *)Allocate(sizeof(struct edgelist), list, 0);
/*
At this point 'r' points to a copy of the single structure at 'list'.
We will make 'r' be the new split 'edgelist'--the lower half.
We don't bother to correct 'xmin' and 'xmax', we'll take the
the pessimistic answer that results from using the old values.
*/
               r->ymin = y;
               r->xvalues = list->xvalues + (y - list->ymin);
/*
Note that we do not need to allocate new memory for the X values,
they can remain with the old "edgelist" structure.  We do have to
update that old structure so it is not as high:
*/
               list->ymax = y;
/*
Insert 'r' in the subpath chain:
*/
               r->subpath = list->subpath;
               list->subpath = r;
/*
Now attach 'r' to the list we are building at 'new', and advance
'list' to point to the next element in the old list:
*/
               if (new == NULL)
                       new = r;
               else
                       last->link = r;
               last = r;
               lastlist = list;
               list = list->link;
       }
/*
At this point we have a new list built at 'new'.  We break the old
list at 'lastlist', and add the broken off part to the end of 'new'.
Then, we return the caller a pointer to 'new':
*/
       if (new == NULL)
               t1_abort("null splitedge");
       lastlist->link = NULL;
       last->link = list;
       IfTrace1((RegionDebug > 1),"yields %x\n", new);
       return(new);
}

Here is the call graph for this function:

struct edgelist* swathrightmost ( struct edgelist before,
struct edgelist edge 
) [read]

Definition at line 1260 of file regions.c.

{
       register struct edgelist *after;
 
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
               before = after;
               after = after->link;
       }
 
       return(before);
 
}
struct edgelist* SwathUnion ( struct edgelist before0,
struct edgelist edge 
) [read]

Definition at line 1103 of file regions.c.

{
       register int h;       /* saves height of edge                         */
       register struct edgelist *rightedge;  /* saves right edge of 'edge'   */
       register struct edgelist *before,*after;  /* edge before and after    */
       int h0;               /* saves initial height                         */
 
       IfTrace2((RegionDebug > 1),"SwathUnion entered, before=%x, edge=%x\n",
                      before0, edge);
 
       h0 = h = edge->ymax - edge->ymin;
       if (h <= 0)
               t1_abort("SwathUnion:  0 height swath?");
 
       before = before0;
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
               register struct edgelist *right;
 
               right = after->link;
               if (right->xvalues[0] >= edge->xvalues[0])
                       break;
               before = right;
               after = before->link;
       }
/*
This is the picture at this point.  'L' indicates a left hand edge,
'R' indicates the right hand edge.
'<--->' indicates the degree of uncertainty as to its placement
relative to other edges:
:xmp atomic.
   before           after
     R            <---L---->  R             L   R    L   R
              <---L--->  <------R-------------------------->
                 edge
:exmp.
In case the left of 'edge' touches 'before', we need to reduce
the height by that amount.
*/
       if (TOP(before) == TOP(edge))
               h -= touches(h, before->xvalues, edge->xvalues);
 
       rightedge = edge->link;
 
       if (after == NULL || TOP(after) != TOP(edge) ||
                   after->xvalues[0] > rightedge->xvalues[0]) {
              IfTrace2((RegionDebug > 1),
                       "SwathUnion starts disjoint: before=%x after=%x\n",
                                     before, after);
/*
On this side of the the above 'if', the new edge is disjoint from the
existing edges in the swath.  This is the picture:
:xmp atomic.
   before           after
     R                L    R     L   R    L   R
              L    R
             edge
:exmp.
We will verify it remains disjoint for the entire height.  If the
situation changes somewhere down the edge, we split the edge at that
point and recursively call ourselves (through 'SortSwath') to figure
out the new situation:
*/
               if (after != NULL && TOP(after) == TOP(edge))
                       h -= touches(h, rightedge->xvalues, after->xvalues);
               if (h < h0)
                       SortSwath(before0->link, splitedge(edge, edge->ymin + h), t1_SwathUnion);
               /* go to "return" this edge pair; it is totally disjoint */
       }
       else {
/*
At this point, at the 'else', we know that the
new edge overlaps one or more pairs in the existing swath.  Here is
a picture of our knowledge and uncertainties:
:xmp atomic.
   before       after
     R            L        R     L   R    L   R
            <---L--->   <---R------------------->
               edge
:exmp.
We need to move 'after' along until it is to the right of the
right of 'edge'.  ('After' should always point to a left edge of a pair:)
*/
               register struct edgelist *left;  /* variable to keep left edge in */
 
               do {
                        left = after;
                        after = (after->link)->link;
 
               } while  (after != NULL && TOP(after) == TOP(edge)
                               && after->xvalues[0] <= rightedge->xvalues[0]);
/*
At this point this is the picture:
:xmp atomic.
   before                 left        after
     R            L    R   L      R     L   R
            <---L--->        <---R--->
               edge
:exmp.
We need to verify that the situation stays like this all the way
down the edge.  Again, if the
situation changes somewhere down the edge, we split the edge at that
point and recursively call ourselves (through 'SortSwath') to figure
out the new situation:
*/
 
               h -= crosses(h, left->xvalues, rightedge->xvalues);
               h -= crosses(h, edge->xvalues, ((before->link)->link)->xvalues);
 
               if (after != NULL && TOP(after) == TOP(edge))
 
                       h -= touches(h, rightedge->xvalues, after->xvalues);
 
               IfTrace3((RegionDebug > 1),
                      "SwathUnion is overlapped until %d: before=%x after=%x\n",
                                          (LONG) TOP(edge) + h, before, after);
/*
OK, if we touched either of our neighbors we need to split at that point
and recursively sort the split edge onto the list.  One tricky part
is that when we recursively sort, 'after' will change if it was not
in our current swath:
*/
               if (h < h0) {
                       SortSwath(before0->link,
                                 splitedge(edge, edge->ymin + h),
                                 t1_SwathUnion);
 
                       if (after == NULL || TOP(after) != TOP(edge))
                                 for (after = before0->link;
                                      TOP(after) == TOP(edge);
                                      after = after->link) { ; }
               }
/*
Now we need to augment 'edge' by the left and right of the overlapped
swath, and to discard all edges between before and after, because they
were overlapped and have been combined with the new incoming 'edge':
*/
               edge->xmin = MIN(edge->xmin, (before->link)->xmin);
               edge->xmax = MIN(edge->xmax, (before->link)->xmax);
               edgemin(h, edge->xvalues, (before->link)->xvalues);
               rightedge->xmin = MAX(rightedge->xmin, (left->link)->xmin);
               rightedge->xmax = MAX(rightedge->xmax, (left->link)->xmax);
               edgemax(h, rightedge->xvalues, (left->link)->xvalues);
               discard(before, after);
       }
       return(before);
}

Here is the call graph for this function:

struct edgelist* swathxsort ( struct edgelist before0,
struct edgelist edge 
) [read]

Definition at line 1027 of file regions.c.

{
       register struct edgelist *before;
       register struct edgelist *after;
       register pel y;
 
       before = before0;
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
 
               register pel *x1,*x2;
 
               y = TOP(edge);
               x1 = after->xvalues;
               x2 = edge->xvalues;
 
               while (y < BOTTOM(edge) && *x1 == *x2) {
                       x1++; x2++; y++;
               }
               if (y >= BOTTOM(edge)) {
                       edge->flag |= ISAMBIGUOUS(ON);
                       after->flag |= ISAMBIGUOUS(ON);
                       break;
               }
 
               if (*x1 >= *x2)
                       break;
 
               before = after;
               after = after->link;
       }
 
/*
At this point, 'edge' is between 'before' and 'after'.  If 'edge' didn't
cross either of those other edges, we would be done.  We check for
crossing.  If it does cross, we split the problem up by calling SortSwath
recursively with the part of the edge that is below the crossing point:
*/
{
       register int h0,h;    /* height of edge--number of scans              */
 
       h0 = h = BOTTOM(edge) - y;
       y -= TOP(edge);
 
       if (h0 <= 0) {
               IfTrace0((RegionDebug>0),"swathxsort: exactly equal edges\n");
               return(before);
       }
 
       if (TOP(before) == TOP(edge))
               h -= crosses(h, &before->xvalues[y], &edge->xvalues[y]);
       if (after != NULL && TOP(after) == TOP(edge))
               h -= crosses(h, &edge->xvalues[y], &after->xvalues[y]);
 
       if (h < h0) {
               SortSwath(before0->link,
                         splitedge(edge, TOP(edge) + y + h),
                         swathxsort);
 
       }
}
 
       return(before);
}

Here is the call graph for this function:

static int touches ( ) [static]
static int touches ( int  h,
pel left,
pel right 
) [static]

Definition at line 1283 of file regions.c.

{
       for (; h > 0; h--)
               if (*left++ >= *right++)
                       break;
       return(h);
}
void UnJumble ( struct region region)

Definition at line 1458 of file regions.c.

{
       register struct edgelist *anchor;  /* new lists built here            */
       register struct edgelist *edge;  /* edge pointer for loop             */
       register struct edgelist *next;  /* ditto                             */
 
       anchor = NULL;
 
       for (edge=region->anchor; VALIDEDGE(edge); edge=next) {
               if (edge->link == NULL)
                       t1_abort("UnJumble:  unpaired edge?");
               next = edge->link->link;
               edge->link->link = NULL;
               anchor = SortSwath(anchor, edge, t1_SwathUnion);
       }
 
       if (edge != NULL)
               vertjoin(anchor, edge);
 
       region->anchor = anchor;
       region->flag &= ~ISJUMBLED(ON);
}

Here is the call graph for this function:

static int Unwind ( ) [static]
static int Unwind ( struct edgelist area) [static]

Definition at line 603 of file regions.c.

{
       register struct edgelist *last,*next;  /* struct before and after current one */
       register int y;       /* ymin of current swath                        */
       register int count,newcount;  /* winding count registers              */
 
       IfTrace1((RegionDebug>0),"...Unwind(%x)\n", area);
 
       while (VALIDEDGE(area)) {
 
               count = 0;
               y = area->ymin;
 
               do {
                       next = area->link;
 
                       if (ISDOWN(area->flag))
                               newcount = count + 1;
                       else
                               newcount = count - 1;
 
                       if (count == 0 || newcount == 0)
                               last = area;
                       else
                               discard(last, next);
 
                       count = newcount;
                       area = next;
 
               } while (area != NULL && area->ymin == y);
 
               if (count != 0)
                       t1_abort("Unwind:  uneven edges");
       }
}

Here is the call graph for this function:

static int vertjoin ( ) [static]
static int vertjoin ( struct edgelist top,
struct edgelist bottom 
) [static]

Definition at line 1003 of file regions.c.

{
       if (BOTTOM(top) > TOP(bottom))
               t1_abort("vertjoin not disjoint");
 
       for (; top->link != NULL; top=top->link) { ; }
 
       top->link = bottom;
       return;
}

Here is the call graph for this function:


Variable Documentation

pel currentsize = MAXEDGE [static]

Definition at line 652 of file regions.c.

Definition at line 651 of file regions.c.

struct region* INFINITY = &t1_infinity

Definition at line 157 of file regions.c.

struct region [static]
Initial value:
 { REGIONTYPE,
                           ISCOMPLEMENT(ON)+ISINFINITE(ON)+ISPERMANENT(ON)+ISIMMORTAL(ON), 2,
                           0, 0, 0, 0,
                           0, 0, 0, 0,
                           NULL, NULL,
                           0, 0, 0, 0, 0, NULL, NULL,
                           NULL, 0, NULL, NULL }

Definition at line 150 of file regions.c.

Definition at line 1691 of file regions.c.

Definition at line 1690 of file regions.c.

pel workedge[MAXEDGE] [static]

Definition at line 650 of file regions.c.