src/pixabasic.c
PIXA *
pixaCreateFromBoxa(PIX      *pixs,
                   BOXA     *boxa,
                   l_int32  *pcropwarn)
{
l_int32  i, n, w, h, wbox, hbox, cropwarn;
BOX     *box, *boxc;
PIX     *pixd;
PIXA    *pixad;

    PROCNAME("pixaCreateFromBoxa");

    if (!pixs)
        return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!boxa)
        return (PIXA *)ERROR_PTR("boxa not defined", procName, NULL);

    n = boxaGetCount(boxa);
    if ((pixad = pixaCreate(n)) == NULL)
        return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);

    boxaGetExtent(boxa, &wbox, &hbox, NULL);
    pixGetDimensions(pixs, &w, &h, NULL);
    cropwarn = FALSE;
    if (wbox > w || hbox > h)
        cropwarn = TRUE;
    if (pcropwarn)
        *pcropwarn = cropwarn;

    for (i = 0; i < n; i++) {
        box = boxaGetBox(boxa, i, L_COPY);
        if (cropwarn) {  /* if box is outside pixs, pixd is NULL */
            pixd = pixClipRectangle(pixs, box, &boxc);  /* may be NULL */
            if (pixd) {
                pixaAddPix(pixad, pixd, L_INSERT);
                pixaAddBox(pixad, boxc, L_INSERT);
            }
            boxDestroy(&box);
        }
        else {
            pixd = pixClipRectangle(pixs, box, NULL);
            pixaAddPix(pixad, pixd, L_INSERT);
            pixaAddBox(pixad, box, L_INSERT);
        }
    }

    return pixad;
}
/*!
 *  pixaCreateFromBoxa()
 *
 *      Input:  pixs
 *              boxa
 *              &cropwarn (<optional return> TRUE if the boxa extent
 *                         is larger than pixs.
 *      Return: pixad, or null on error
 *
 *  Notes:
 *      (1) This simply extracts from pixs the region corresponding to each
 *          box in the boxa.
 *      (2) The 3rd arg is optional.  If the extent of the boxa exceeds the
 *          size of the pixa, so that some boxes are either clipped
 *          or entirely outside the pix, a warning is returned as TRUE.
 *      (3) pixad will have only the properly clipped elements, and
 *          the internal boxa will be correct.
 */
pixaCreateFromBoxa()
Input:  pixs
boxa
&cropwarn ( TRUE if the boxa extent
is larger than pixs.
Return: pixad, or null on error

(1) This simply extracts from pixs the region corresponding to each
box in the boxa.
(2) The 3rd arg is optional.  If the extent of the boxa exceeds the
size of the pixa, so that some boxes are either clipped
or entirely outside the pix, a warning is returned as TRUE.
(3) pixad will have only the properly clipped elements, and
the internal boxa will be correct.
pixaCreateFromBoxa () Input : pixs boxa &cropwarn ( TRUE if the boxa extent is larger than pixs . Return : pixad or null on error ( 1 ) This simply extracts from pixs the region corresponding to each box in the boxa . ( 2 ) The 3rd arg is optional . If the extent of the boxa exceeds the size of the pixa so that some boxes are either clipped or entirely outside the pix a warning is returned as TRUE . ( 3 ) pixad will have only the properly clipped elements and the internal boxa will be correct .
PIXA *
pixaCreateFromBoxa(PIX      *pixs,
                   BOXA     *boxa,
                   l_int32  *pcropwarn)
{
l_int32  i, n, w, h, wbox, hbox, cropwarn;
BOX     *box, *boxc;
PIX     *pixd;
PIXA    *pixad;
    PROCNAME("pixaCreateFromBoxa");
    if (!pixs)
        return (PIXA *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!boxa)
        return (PIXA *)ERROR_PTR("boxa not defined", procName, NULL);
    n = boxaGetCount(boxa);
    if ((pixad = pixaCreate(n)) == NULL)
        return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
    boxaGetExtent(boxa, &wbox, &hbox, NULL);
    pixGetDimensions(pixs, &w, &h, NULL);
    cropwarn = FALSE;
    if (wbox > w || hbox > h)
        cropwarn = TRUE;
    if (pcropwarn)
        *pcropwarn = cropwarn;
    for (i = 0; i < n; i++) {
        box = boxaGetBox(boxa, i, L_COPY);
        if (cropwarn) {  
            pixd = pixClipRectangle(pixs, box, &boxc);  
            if (pixd) {
                pixaAddPix(pixad, pixd, L_INSERT);
                pixaAddBox(pixad, boxc, L_INSERT);
            }
            boxDestroy(&box);
        }
        else {
            pixd = pixClipRectangle(pixs, box, NULL);
            pixaAddPix(pixad, pixd, L_INSERT);
            pixaAddBox(pixad, box, L_INSERT);
        }
    }
    return pixad;
}
PIXA * pixaCreateFromBoxa ( PIX * pixs , BOXA * boxa , l_int32 * pcropwarn ) { l_int32 i , n , w , h , wbox , hbox , cropwarn ; BOX * box , * boxc ; PIX * pixd ; PIXA * pixad ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ! boxa ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; n = boxaGetCount ( boxa ) ; if ( ( pixad = pixaCreate ( n ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; boxaGetExtent ( boxa , & wbox , & hbox , NULL ) ; pixGetDimensions ( pixs , & w , & h , NULL ) ; cropwarn = FALSE ; if ( wbox > w || hbox > h ) cropwarn = TRUE ; if ( pcropwarn ) * pcropwarn = cropwarn ; for ( i = 0 ; i < n ; i ++ ) { box = boxaGetBox ( boxa , i , L_COPY ) ; if ( cropwarn ) { pixd = pixClipRectangle ( pixs , box , & boxc ) ; if ( pixd ) { pixaAddPix ( pixad , pixd , L_INSERT ) ; pixaAddBox ( pixad , boxc , L_INSERT ) ; } boxDestroy ( & box ) ; } else { pixd = pixClipRectangle ( pixs , box , NULL ) ; pixaAddPix ( pixad , pixd , L_INSERT ) ; pixaAddBox ( pixad , box , L_INSERT ) ; } } return pixad ; }
pixaCreateFromBoxa()
      Input:  pixs
              boxa
              &cropwarn (<optional return> TRUE if the boxa extent
                         is larger than pixs.
pixaCreateFromBoxa () Input : pixs boxa &cropwarn ( <optional return > TRUE if the boxa extent is larger than pixs .
/* if box is outside pixs, pixd is NULL */ /* may be NULL */