Beispiel #1
0
/*!
 * \brief   popFillseg()
 *
 * \param[in]    stack
 * \param[out]   pxleft left x
 * \param[out]   pxright right x
 * \param[out]   py y coordinate
 * \param[out]   pdy delta y
 * \return  void
 *
 * <pre>
 * Notes:
 *      (1) This removes a line segment from the stack, and returns its size.
 *      (2) The surplussed fillseg is placed on the auxiliary stack
 *          for future use.
 * </pre>
 */
static void
popFillseg(L_STACK  *stack,
           l_int32  *pxleft,
           l_int32  *pxright,
           l_int32  *py,
           l_int32  *pdy)
{
    FILLSEG  *fseg;
    L_STACK  *auxstack;

    PROCNAME("popFillseg");

    if (!stack) {
        L_ERROR("stack not defined\n", procName);
        return;
    }
    if ((auxstack = stack->auxstack) == NULL) {
        L_ERROR("auxstack not defined\n", procName);
        return;
    }

    if ((fseg = (FILLSEG *)lstackRemove(stack)) == NULL)
        return;

    *pxleft = fseg->xleft;
    *pxright = fseg->xright;
    *py = fseg->y + fseg->dy;  /* this now points to the new line */
    *pdy = fseg->dy;

    /* Save it for re-use */
    lstackAdd(auxstack, fseg);
    return;
}
Beispiel #2
0
/*
 *  popWSPixel()
 *
 *      Input:  lh  (priority queue)
 *              stack  (of reusable WSPixels)
 *              &val  (<return> pixel value)
 *              &x, &y  (<return> pixel coordinates)
 *              &index  (<return> label for set to which pixel belongs)
 *      Return: void
 *
 *   Notes:
 *       (1) This is a wrapper for removing a WSPixel from a heap,
 *           which returns the WSPixel data and saves the WSPixel
 *           on the storage stack.
 */
static void
popWSPixel(L_HEAP *lh,
           L_STACK *stack,
           l_int32 *pval,
           l_int32 *px,
           l_int32 *py,
           l_int32 *pindex) {
    L_WSPIXEL *wsp;

    PROCNAME("popWSPixel");

    if (!lh) {
        L_ERROR("lheap not defined\n", procName);
        return;
    }
    if (!stack) {
        L_ERROR("stack not defined\n", procName);
        return;
    }
    if (!pval || !px || !py || !pindex) {
        L_ERROR("data can't be returned\n", procName);
        return;
    }

    if ((wsp = (L_WSPIXEL *) lheapRemove(lh)) == NULL)
        return;
    *pval = (l_int32) wsp->val;
    *px = wsp->x;
    *py = wsp->y;
    *pindex = wsp->index;
    lstackAdd(stack, wsp);  /* save for re-use */
    return;
}
Beispiel #3
0
/*!
 * \brief   pushFillsegBB()
 *
 * \param[in]    stack
 * \param[in]    xleft, xright
 * \param[in]    y
 * \param[in]    dy
 * \param[in]    ymax
 * \param[out]   pminx minimum x
 * \param[out]   pmaxx maximum x
 * \param[out]   pminy minimum y
 * \param[out]   pmaxy maximum y
 * \return  void
 *
 * <pre>
 * Notes:
 *      (1) This adds a line segment to the stack, and returns its size.
 *      (2) The auxiliary stack is used as a storage area to recycle
 *          fillsegs that are no longer in use.  We only calloc new
 *          fillsegs if the auxiliary stack is empty.
 * </pre>
 */
static void
pushFillsegBB(L_STACK  *stack,
              l_int32   xleft,
              l_int32   xright,
              l_int32   y,
              l_int32   dy,
              l_int32   ymax,
              l_int32  *pminx,
              l_int32  *pmaxx,
              l_int32  *pminy,
              l_int32  *pmaxy)
{
    FILLSEG  *fseg;
    L_STACK  *auxstack;

    PROCNAME("pushFillsegBB");

    if (!stack) {
        L_ERROR("stack not defined\n", procName);
        return;
    }

    *pminx = L_MIN(*pminx, xleft);
    *pmaxx = L_MAX(*pmaxx, xright);
    *pminy = L_MIN(*pminy, y);
    *pmaxy = L_MAX(*pmaxy, y);

    if (y + dy >= 0 && y + dy <= ymax) {
        if ((auxstack = stack->auxstack) == NULL) {
            L_ERROR("auxstack not defined\n", procName);
            return;
        }

        /* Get a fillseg to use */
        if (lstackGetCount(auxstack) > 0) {
            fseg = (FILLSEG *)lstackRemove(auxstack);
        } else {
            if ((fseg = (FILLSEG *)LEPT_CALLOC(1, sizeof(FILLSEG))) == NULL) {
                L_ERROR("fillseg not made\n", procName);
                return;
            }
        }

        fseg->xleft = xleft;
        fseg->xright = xright;
        fseg->y = y;
        fseg->dy = dy;
        lstackAdd(stack, fseg);
    }
    return;
}
Beispiel #4
0
/*!
 *  pushFillseg()
 *
 *      Input:  lstack
 *              xleft, xright
 *              y
 *              dy
 *              ymax
 *      Return: void
 *
 *  Notes:
 *      (1) This adds a line segment to the stack.
 *      (2) The auxiliary stack is used as a storage area to recycle
 *          fillsegs that are no longer in use.  We only calloc new
 *          fillsegs if the auxiliary stack is empty.
 */
static void
pushFillseg(L_STACK  *lstack,
            l_int32   xleft,
            l_int32   xright,
            l_int32   y,
            l_int32   dy,
            l_int32   ymax)
{
FILLSEG  *fseg;
L_STACK  *auxstack;

    PROCNAME("pushFillseg");

    if (!lstack) {
        L_ERROR(procName, "lstack not defined");
        return;
    }

    if (y + dy >= 0 && y + dy <= ymax) {
        if ((auxstack = lstack->auxstack) == NULL) {
            L_ERROR("auxstack not defined", procName);
            return;
        }

            /* Get a fillseg to use */
        if (lstackGetCount(auxstack) > 0)
            fseg = (FILLSEG *)lstackRemove(auxstack);
        else {
            if ((fseg = (FILLSEG *)CALLOC(1, sizeof(FILLSEG))) == NULL) {
                L_ERROR("fillseg not made", procName);
                return;
            }
        }

        fseg->xleft = xleft;
        fseg->xright = xright;
        fseg->y = y;
        fseg->dy = dy;
        lstackAdd(lstack, fseg);
    }
    return;
}
Beispiel #5
0
/*
 *  popNewPixel()
 *
 *      Input:  lqueue
 *              &x, &y   (<return> pixel coordinates)
 *      Return: void
 *
 *   Notes:
 *       (1) This is a wrapper for removing a NewPixel from a queue,
 *           which returns the pixel coordinates and saves the NewPixel
 *           on the storage stack.
 */
static void
popNewPixel(L_QUEUE *lq,
            l_int32 *px,
            l_int32 *py) {
    L_NEWPIXEL *np;

    PROCNAME("popNewPixel");

    if (!lq) {
        L_ERROR("lqueue not defined\n", procName);
        return;
    }

    if ((np = (L_NEWPIXEL *) lqueueRemove(lq)) == NULL)
        return;
    *px = np->x;
    *py = np->y;
    lstackAdd(lq->stack, np);  /* save for re-use */
    return;
}