Leptonica  1.73
Image processing and image analysis suite
Functions | Variables
boxbasic.c File Reference
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

BOXboxCreate (l_int32 x, l_int32 y, l_int32 w, l_int32 h)
 
BOXboxCreateValid (l_int32 x, l_int32 y, l_int32 w, l_int32 h)
 
BOXboxCopy (BOX *box)
 
BOXboxClone (BOX *box)
 
void boxDestroy (BOX **pbox)
 
l_int32 boxGetGeometry (BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
 
l_int32 boxSetGeometry (BOX *box, l_int32 x, l_int32 y, l_int32 w, l_int32 h)
 
l_int32 boxGetSideLocations (BOX *box, l_int32 *pl, l_int32 *pr, l_int32 *pt, l_int32 *pb)
 
l_int32 boxSetSideLocations (BOX *box, l_int32 l, l_int32 r, l_int32 t, l_int32 b)
 
l_int32 boxGetRefcount (BOX *box)
 
l_int32 boxChangeRefcount (BOX *box, l_int32 delta)
 
l_int32 boxIsValid (BOX *box, l_int32 *pvalid)
 
BOXAboxaCreate (l_int32 n)
 
BOXAboxaCopy (BOXA *boxa, l_int32 copyflag)
 
void boxaDestroy (BOXA **pboxa)
 
l_int32 boxaAddBox (BOXA *boxa, BOX *box, l_int32 copyflag)
 
l_int32 boxaExtendArray (BOXA *boxa)
 
l_int32 boxaExtendArrayToSize (BOXA *boxa, l_int32 size)
 
l_int32 boxaGetCount (BOXA *boxa)
 
l_int32 boxaGetValidCount (BOXA *boxa)
 
BOXboxaGetBox (BOXA *boxa, l_int32 index, l_int32 accessflag)
 
BOXboxaGetValidBox (BOXA *boxa, l_int32 index, l_int32 accessflag)
 
NUMAboxaFindInvalidBoxes (BOXA *boxa)
 
l_int32 boxaGetBoxGeometry (BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
 
l_int32 boxaIsFull (BOXA *boxa, l_int32 *pfull)
 
l_int32 boxaReplaceBox (BOXA *boxa, l_int32 index, BOX *box)
 
l_int32 boxaInsertBox (BOXA *boxa, l_int32 index, BOX *box)
 
l_int32 boxaRemoveBox (BOXA *boxa, l_int32 index)
 
l_int32 boxaRemoveBoxAndSave (BOXA *boxa, l_int32 index, BOX **pbox)
 
BOXAboxaSaveValid (BOXA *boxas, l_int32 copyflag)
 
l_int32 boxaInitFull (BOXA *boxa, BOX *box)
 
l_int32 boxaClear (BOXA *boxa)
 
BOXAAboxaaCreate (l_int32 n)
 
BOXAAboxaaCopy (BOXAA *baas, l_int32 copyflag)
 
void boxaaDestroy (BOXAA **pbaa)
 
l_int32 boxaaAddBoxa (BOXAA *baa, BOXA *ba, l_int32 copyflag)
 
l_int32 boxaaExtendArray (BOXAA *baa)
 
l_int32 boxaaExtendArrayToSize (BOXAA *baa, l_int32 size)
 
l_int32 boxaaGetCount (BOXAA *baa)
 
l_int32 boxaaGetBoxCount (BOXAA *baa)
 
BOXAboxaaGetBoxa (BOXAA *baa, l_int32 index, l_int32 accessflag)
 
BOXboxaaGetBox (BOXAA *baa, l_int32 iboxa, l_int32 ibox, l_int32 accessflag)
 
l_int32 boxaaInitFull (BOXAA *baa, BOXA *boxa)
 
l_int32 boxaaExtendWithInit (BOXAA *baa, l_int32 maxindex, BOXA *boxa)
 
l_int32 boxaaReplaceBoxa (BOXAA *baa, l_int32 index, BOXA *boxa)
 
l_int32 boxaaInsertBoxa (BOXAA *baa, l_int32 index, BOXA *boxa)
 
l_int32 boxaaRemoveBoxa (BOXAA *baa, l_int32 index)
 
l_int32 boxaaAddBox (BOXAA *baa, l_int32 index, BOX *box, l_int32 accessflag)
 
BOXAAboxaaReadFromFiles (const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
 
BOXAAboxaaRead (const char *filename)
 
BOXAAboxaaReadStream (FILE *fp)
 
BOXAAboxaaReadMem (const l_uint8 *data, size_t size)
 
l_int32 boxaaWrite (const char *filename, BOXAA *baa)
 
l_int32 boxaaWriteStream (FILE *fp, BOXAA *baa)
 
l_int32 boxaaWriteMem (l_uint8 **pdata, size_t *psize, BOXAA *baa)
 
BOXAboxaRead (const char *filename)
 
BOXAboxaReadStream (FILE *fp)
 
BOXAboxaReadMem (const l_uint8 *data, size_t size)
 
l_int32 boxaWrite (const char *filename, BOXA *boxa)
 
l_int32 boxaWriteStream (FILE *fp, BOXA *boxa)
 
l_int32 boxaWriteMem (l_uint8 **pdata, size_t *psize, BOXA *boxa)
 
l_int32 boxPrintStreamInfo (FILE *fp, BOX *box)
 

Variables

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20
 

Detailed Description

  Basic 'class' functions for box, boxa and boxaa,
  including accessors and serialization.
     Box creation, copy, clone, destruction
          BOX      *boxCreate()
          BOX      *boxCreateValid()
          BOX      *boxCopy()
          BOX      *boxClone()
          void      boxDestroy()
     Box accessors
          l_int32   boxGetGeometry()
          l_int32   boxSetGeometry()
          l_int32   boxGetSideLocations()
          l_int32   boxSetSideLocations()
          l_int32   boxGetRefcount()
          l_int32   boxChangeRefcount()
          l_int32   boxIsValid()
     Boxa creation, copy, destruction
          BOXA     *boxaCreate()
          BOXA     *boxaCopy()
          void      boxaDestroy()
     Boxa array extension
          l_int32   boxaAddBox()
          l_int32   boxaExtendArray()
          l_int32   boxaExtendArrayToSize()
     Boxa accessors
          l_int32   boxaGetCount()
          l_int32   boxaGetValidCount()
          BOX      *boxaGetBox()
          BOX      *boxaGetValidBox()
          NUMA     *boxaFindInvalidBoxes()
          l_int32   boxaGetBoxGeometry()
          l_int32   boxaIsFull()
     Boxa array modifiers
          l_int32   boxaReplaceBox()
          l_int32   boxaInsertBox()
          l_int32   boxaRemoveBox()
          l_int32   boxaRemoveBoxAndSave()
          BOXA     *boxaSaveValid()
          l_int32   boxaInitFull()
          l_int32   boxaClear()
     Boxaa creation, copy, destruction
          BOXAA    *boxaaCreate()
          BOXAA    *boxaaCopy()
          void      boxaaDestroy()
     Boxaa array extension
          l_int32   boxaaAddBoxa()
          l_int32   boxaaExtendArray()
          l_int32   boxaaExtendArrayToSize()
     Boxaa accessors
          l_int32   boxaaGetCount()
          l_int32   boxaaGetBoxCount()
          BOXA     *boxaaGetBoxa()
          BOX      *boxaaGetBox()
     Boxaa array modifiers
          l_int32   boxaaInitFull()
          l_int32   boxaaExtendWithInit()
          l_int32   boxaaReplaceBoxa()
          l_int32   boxaaInsertBoxa()
          l_int32   boxaaRemoveBoxa()
          l_int32   boxaaAddBox()
     Boxaa serialized I/O
          BOXAA    *boxaaReadFromFiles()
          BOXAA    *boxaaRead()
          BOXAA    *boxaaReadStream()
          BOXAA    *boxaaReadMem()
          l_int32   boxaaWrite()
          l_int32   boxaaWriteStream()
          l_int32   boxaaWriteMem()
     Boxa serialized I/O
          BOXA     *boxaRead()
          BOXA     *boxaReadStream()
          BOXA     *boxaReadMem()
          l_int32   boxaWrite()
          l_int32   boxaWriteStream()
          l_int32   boxaWriteMem()
     Box print (for debug)
          l_int32   boxPrintStreamInfo()
  Most functions use only valid boxes, which are boxes that have both
  width and height > 0.  However, a few functions, such as
  boxaGetMedian() do not assume that all boxes are valid.  For any
  function that can use a boxa with invalid boxes, it is convenient
  to use these accessors:
      boxaGetValidCount()   :  count of valid boxes
      boxaGetValidBox()     :  returns NULL for invalid boxes

Definition in file boxbasic.c.

Function Documentation

◆ boxaaAddBox()

l_int32 boxaaAddBox ( BOXAA baa,
l_int32  index,
BOX box,
l_int32  accessflag 
)

boxaaAddBox()

Parameters
[in]baa
[in]indexof boxa with boxaa
[in]boxto be added
[in]accessflagL_INSERT, L_COPY or L_CLONE
Returns
0 if OK, 1 on error
Notes:
     (1) Adds to an existing boxa only.

Definition at line 1775 of file boxbasic.c.

References boxaAddBox(), boxaaGetBoxa(), boxaaGetCount(), boxaDestroy(), L_CLONE, L_COPY, and L_INSERT.

Referenced by boxaSort2d().

◆ boxaaAddBoxa()

l_int32 boxaaAddBoxa ( BOXAA baa,
BOXA ba,
l_int32  copyflag 
)

◆ boxaaCopy()

BOXAA* boxaaCopy ( BOXAA baas,
l_int32  copyflag 
)

boxaaCopy()

Parameters
[in]baasinput boxaa to be copied
[in]copyflagL_COPY, L_CLONE
Returns
baad new boxaa, composed of copies or clones of the boxa in baas, or NULL on error
Notes:
     (1) L_COPY makes a copy of each boxa in baas.
         L_CLONE makes a clone of each boxa in baas.

Definition at line 1272 of file boxbasic.c.

References boxaaAddBoxa(), boxaaCreate(), boxaaGetBoxa(), boxaaGetCount(), L_CLONE, L_COPY, and L_INSERT.

◆ boxaaCreate()

BOXAA* boxaaCreate ( l_int32  n)

◆ boxaAddBox()

l_int32 boxaAddBox ( BOXA boxa,
BOX box,
l_int32  copyflag 
)

◆ boxaaDestroy()

void boxaaDestroy ( BOXAA **  pbaa)

boxaaDestroy()

Parameters
[in,out]pbaawill be set to null before returning

Definition at line 1303 of file boxbasic.c.

References Boxaa::boxa, boxaDestroy(), and Boxaa::n.

Referenced by boxaaCreate(), boxaaReadStream(), boxaSort2d(), pixGetWordBoxesInTextlines(), pixGetWordsInTextlines(), and recogExtractNumbers().

◆ boxaaExtendArray()

l_int32 boxaaExtendArray ( BOXAA baa)

boxaaExtendArray()

Parameters
[in]baa
Returns
0 if OK, 1 on error

Definition at line 1378 of file boxbasic.c.

References Boxaa::boxa, Boxaa::nalloc, and reallocNew().

Referenced by boxaaAddBoxa(), and boxaaInsertBoxa().

◆ boxaaExtendArrayToSize()

l_int32 boxaaExtendArrayToSize ( BOXAA baa,
l_int32  size 
)

boxaaExtendArrayToSize()

Parameters
[in]baa
[in]sizenew size of boxa array
Returns
0 if OK; 1 on error
Notes:
     (1) If necessary, reallocs the boxa ptr array to size.

Definition at line 1409 of file boxbasic.c.

References Boxaa::boxa, Boxaa::nalloc, and reallocNew().

Referenced by boxaaExtendWithInit().

◆ boxaaExtendWithInit()

l_int32 boxaaExtendWithInit ( BOXAA baa,
l_int32  maxindex,
BOXA boxa 
)

boxaaExtendWithInit()

Parameters
[in]baa
[in]maxindex
[in]boxato be replicated into the extended ptr array
Returns
0 if OK, 1 on error
Notes:
     (1) This should be used on an existing boxaa that has been
         fully loaded with boxa.  It then extends the boxaa,
         loading all the additional ptrs with copies of boxa.
         Typically, boxa will be empty.

Definition at line 1607 of file boxbasic.c.

References boxaaAddBoxa(), boxaaExtendArrayToSize(), boxaaGetCount(), and L_COPY.

Referenced by convertSegmentedFilesToPdf().

◆ boxaaGetBox()

BOX* boxaaGetBox ( BOXAA baa,
l_int32  iboxa,
l_int32  ibox,
l_int32  accessflag 
)

boxaaGetBox()

Parameters
[in]baa
[in]iboxaindex into the boxa array in the boxaa
[in]iboxindex into the box array in the boxa
[in]accessflagL_COPY or L_CLONE
Returns
box, or NULL on error

Definition at line 1515 of file boxbasic.c.

References boxaaGetBoxa(), boxaDestroy(), boxaGetBox(), and L_CLONE.

Referenced by boxaaTranspose().

◆ boxaaGetBoxa()

BOXA* boxaaGetBoxa ( BOXAA baa,
l_int32  index,
l_int32  accessflag 
)

◆ boxaaGetBoxCount()

l_int32 boxaaGetBoxCount ( BOXAA baa)

boxaaGetBoxCount()

Parameters
[in]baa
Returns
count number of boxes, or 0 if no boxes or on error

Definition at line 1455 of file boxbasic.c.

References boxaaGetBoxa(), boxaaGetCount(), boxaDestroy(), boxaGetCount(), and L_CLONE.

◆ boxaaGetCount()

l_int32 boxaaGetCount ( BOXAA baa)

◆ boxaaInitFull()

l_int32 boxaaInitFull ( BOXAA baa,
BOXA boxa 
)

boxaaInitFull()

Parameters
[in]baatypically empty
[in]boxato be replicated into the entire ptr array
Returns
0 if OK, 1 on error
Notes:
     (1) This initializes a boxaa by filling up the entire boxa ptr array
         with copies of boxa.  Any existing boxa are destroyed.
         After this operation, the number of boxa is equal to
         the number of allocated ptrs.
     (2) Note that we use boxaaReplaceBox() instead of boxaInsertBox().
         They both have the same effect when inserting into a NULL ptr
         in the boxa ptr array
     (3) Example usage.  This function is useful to prepare for a
         random insertion (or replacement) of boxa into a boxaa.
         To randomly insert boxa into a boxaa, up to some index "max":
            Boxaa *baa = boxaaCreate(max);
              // initialize the boxa
            Boxa *boxa = boxaCreate(...);
            ...  [optionally fix with boxes]
            boxaaInitFull(baa, boxa);
         A typical use is to initialize the array with empty boxa,
         and to replace only a subset that must be aligned with
         something else, such as a pixa.

Definition at line 1567 of file boxbasic.c.

References boxaaReplaceBoxa(), boxaCopy(), L_COPY, Boxaa::n, and Boxaa::nalloc.

Referenced by convertNumberedMasksToBoxaa().

◆ boxaaInsertBoxa()

l_int32 boxaaInsertBoxa ( BOXAA baa,
l_int32  index,
BOXA boxa 
)

boxaaInsertBoxa()

Parameters
[in]baa
[in]indexlocation in boxaa to insert new boxa
[in]boxanew boxa to be inserted
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts boxa[i] –> boxa[i + 1] for all i >= index,
         and then inserts boxa as boxa[index].
     (2) To insert at the beginning of the array, set index = 0.
     (3) To append to the array, it's easier to use boxaaAddBoxa().
     (4) This should not be used repeatedly to insert into large arrays,
         because the function is O(n).

Definition at line 1689 of file boxbasic.c.

References Boxaa::boxa, boxaaExtendArray(), boxaaGetCount(), Boxaa::n, and Boxaa::nalloc.

◆ boxaaRead()

BOXAA* boxaaRead ( const char *  filename)

boxaaRead()

Parameters
[in]filename
Returns
boxaa, or NULL on error

Definition at line 1867 of file boxbasic.c.

References boxaaReadStream(), and fopenReadStream().

◆ boxaaReadFromFiles()

BOXAA* boxaaReadFromFiles ( const char *  dirname,
const char *  substr,
l_int32  first,
l_int32  nfiles 
)

boxaaReadFromFiles()

Parameters
[in]dirnamedirectory
[in]substr[optional] substring filter on filenames; can be NULL
[in]first0-based
[in]nfilesuse 0 for everything from first to the end
Returns
baa, or NULL on error or if no boxa files are found.
Notes:
     (1) The files must be serialized boxa files (e.g., *.ba).
         If some files cannot be read, warnings are issued.
     (2) Use substr to filter filenames in the directory.  If
         substr == NULL, this takes all files.
     (3) After filtering, use first and nfiles to select
         a contiguous set of files, that have been lexically
         sorted in increasing order.

Definition at line 1823 of file boxbasic.c.

References boxaaAddBoxa(), boxaaCreate(), boxaRead(), getSortedPathnamesInDirectory(), L_INSERT, L_NOCOPY, sarrayDestroy(), sarrayGetCount(), and sarrayGetString().

◆ boxaaReadMem()

BOXAA* boxaaReadMem ( const l_uint8 *  data,
size_t  size 
)

boxaaReadMem()

Parameters
[in]dataserialization of boxaa; in ascii
[in]sizeof data in bytes; can use strlen to get it
Returns
baa, or NULL on error

Definition at line 1939 of file boxbasic.c.

References boxaaReadStream(), and fopenReadFromMemory().

◆ boxaaReadStream()

BOXAA* boxaaReadStream ( FILE *  fp)

boxaaReadStream()

Parameters
[in]fpfile stream
Returns
boxaa, or NULL on error

Definition at line 1894 of file boxbasic.c.

References BOXAA_VERSION_NUMBER, boxaaAddBoxa(), boxaaCreate(), boxaaDestroy(), boxaReadStream(), and L_INSERT.

Referenced by boxaaRead(), and boxaaReadMem().

◆ boxaaRemoveBoxa()

l_int32 boxaaRemoveBoxa ( BOXAA baa,
l_int32  index 
)

boxaaRemoveBoxa()

Parameters
[in]baa
[in]indexof the boxa to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This removes boxa[index] and then shifts
         boxa[i] –> boxa[i - 1] for all i > index.
     (2) The removed boxaa is destroyed.
     (2) This should not be used repeatedly on large arrays,
         because the function is O(n).

Definition at line 1735 of file boxbasic.c.

References Boxaa::boxa, boxaaGetCount(), boxaDestroy(), and Boxaa::n.

◆ boxaaReplaceBoxa()

l_int32 boxaaReplaceBoxa ( BOXAA baa,
l_int32  index,
BOXA boxa 
)

boxaaReplaceBoxa()

Parameters
[in]baa
[in]indexto the index-th boxa
[in]boxainsert and replace any existing one
Returns
0 if OK, 1 on error
Notes:
     (1) Any existing boxa is destroyed, and the input one
         is inserted in its place.
     (2) If the index is invalid, return 1 (error)

Definition at line 1648 of file boxbasic.c.

References Boxaa::boxa, boxaaGetCount(), and boxaDestroy().

Referenced by boxaaInitFull(), boxaSort2d(), and convertNumberedMasksToBoxaa().

◆ boxaaWrite()

l_int32 boxaaWrite ( const char *  filename,
BOXAA baa 
)

boxaaWrite()

Parameters
[in]filename
[in]baa
Returns
0 if OK, 1 on error

Definition at line 1967 of file boxbasic.c.

References boxaaWriteStream(), and fopenWriteStream().

◆ boxaaWriteMem()

l_int32 boxaaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
BOXAA baa 
)

boxaaWriteMem()

Parameters
[out]pdatadata of serialized boxaa; ascii
[out]psizesize of returned data
[in]baa
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a boxaa in memory and puts the result in a buffer.

Definition at line 2045 of file boxbasic.c.

References boxaaWriteStream(), fopenWriteWinTempfile(), and l_binaryReadStream().

◆ boxaaWriteStream()

l_int32 boxaaWriteStream ( FILE *  fp,
BOXAA baa 
)

boxaaWriteStream()

Parameters
[in]fpfile stream
[in]baa
Returns
0 if OK, 1 on error

Definition at line 1998 of file boxbasic.c.

References BOXAA_VERSION_NUMBER, boxaaGetBoxa(), boxaaGetCount(), boxaDestroy(), boxaGetExtent(), boxaWriteStream(), boxDestroy(), boxGetGeometry(), and L_CLONE.

Referenced by boxaaWrite(), and boxaaWriteMem().

◆ boxaClear()

l_int32 boxaClear ( BOXA boxa)

boxaClear()

Parameters
[in]boxa
Returns
0 if OK, 1 on error
Notes:
     (1) This destroys all boxes in the boxa, setting the ptrs
         to null.  The number of allocated boxes, n, is set to 0.

Definition at line 1210 of file boxbasic.c.

References Boxa::box, boxaGetCount(), boxDestroy(), and Boxa::n.

Referenced by pixaClear().

◆ boxaCopy()

BOXA* boxaCopy ( BOXA boxa,
l_int32  copyflag 
)

◆ boxaCreate()

BOXA* boxaCreate ( l_int32  n)

◆ boxaDestroy()

void boxaDestroy ( BOXA **  pboxa)

boxaDestroy()

Parameters
[in,out]pboxawill be set to null before returning
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the boxa.
     (2) Always nulls the input ptr.

Definition at line 577 of file boxbasic.c.

References Boxa::box, boxDestroy(), Boxa::n, and Boxa::refcount.

Referenced by boxaaAddBox(), boxaaAlignBox(), boxaaDestroy(), boxaaFlattenAligned(), boxaaFlattenToBoxa(), boxaaGetBox(), boxaaGetBoxCount(), boxaaGetExtent(), boxaaRemoveBoxa(), boxaaReplaceBoxa(), boxaaSizeRange(), boxaaTranspose(), boxaaWriteStream(), boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaCompareRegions(), boxaCreate(), boxaDisplayTiled(), boxaFillSequence(), boxaHandleOverlaps(), boxaLinearFit(), boxaPlotSides(), boxaPlotSizes(), boxaReadStream(), boxaReconcileEvenOddHeight(), boxaReconcilePairWidth(), boxaRotateOrth(), boxaSelectLargeULBox(), boxaSmoothSequenceLS(), boxaSmoothSequenceMedian(), boxaSort2d(), boxaTransform(), boxaTransformOrdered(), boxaWindowedMedian(), ccbDestroy(), convertNumberedMasksToBoxaa(), convertSegmentedFilesToPdf(), generatePtaGrid(), partelDestroy(), pixaAddBorderGeneral(), pixaaDestroy(), pixaaDisplay(), pixaaReadStream(), pixacompDestroy(), pixacompJoin(), pixacompReadStream(), pixaCreateFromPixacomp(), pixaDestroy(), pixaDisplay(), pixaDisplayBoxaa(), pixaDisplayOnColor(), pixaDisplayRandomCmap(), pixaEqual(), pixaIsFull(), pixaJoin(), pixaReadStream(), pixaSetBoxa(), pixGetWordBoxesInTextlines(), pixGetWordsInTextlines(), pixMorphSequenceByComponent(), pixSelectByAreaFraction(), pixSelectByPerimSizeRatio(), pixSelectByPerimToAreaRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), pixSelectLargeULComp(), recogDestroyDid(), and showExtractNumbers().

◆ boxaExtendArray()

l_int32 boxaExtendArray ( BOXA boxa)

boxaExtendArray()

Parameters
[in]boxa
Returns
0 if OK; 1 on error
Notes:
     (1) Reallocs with doubled size of ptr array.

Definition at line 662 of file boxbasic.c.

References boxaExtendArrayToSize(), and Boxa::nalloc.

Referenced by boxaAddBox(), boxaInsertBox(), pixacompExtendArray(), and pixaInsertPix().

◆ boxaExtendArrayToSize()

l_int32 boxaExtendArrayToSize ( BOXA boxa,
l_int32  size 
)

boxaExtendArrayToSize()

Parameters
[in]boxa
[in]sizenew size of boxa array
Returns
0 if OK; 1 on error
Notes:
     (1) If necessary, reallocs new boxa ptr array to size.

Definition at line 686 of file boxbasic.c.

References Boxa::box, Boxa::nalloc, and reallocNew().

Referenced by boxaExtendArray(), and pixaExtendArrayToSize().

◆ boxaFindInvalidBoxes()

NUMA* boxaFindInvalidBoxes ( BOXA boxa)

boxaFindInvalidBoxes()

Parameters
[in]boxa
Returns
na numa of invalid boxes; NULL if there are none or on error

Definition at line 827 of file boxbasic.c.

References boxaGetBoxGeometry(), boxaGetCount(), boxaGetValidCount(), numaMakeConstant(), and numaSetValue().

◆ boxaGetBox()

BOX* boxaGetBox ( BOXA boxa,
l_int32  index,
l_int32  accessflag 
)

◆ boxaGetBoxGeometry()

l_int32 boxaGetBoxGeometry ( BOXA boxa,
l_int32  index,
l_int32 *  px,
l_int32 *  py,
l_int32 *  pw,
l_int32 *  ph 
)

◆ boxaGetCount()

l_int32 boxaGetCount ( BOXA boxa)

boxaGetCount()

Parameters
[in]boxa
Returns
count of all boxes; 0 if no boxes or on error

Definition at line 715 of file boxbasic.c.

References Boxa::n.

Referenced by boxaaAlignBox(), boxaAddBox(), boxaAdjustHeightToTarget(), boxaAdjustSides(), boxaAdjustWidthToTarget(), boxaaFlattenAligned(), boxaaFlattenToBoxa(), boxaaGetBoxCount(), boxaaTranspose(), boxaBinSort(), boxaClear(), boxaClipToBox(), boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaCompareRegions(), boxaConstrainSize(), boxaContainedInBox(), boxaContainedInBoxa(), boxaContainedInBoxCount(), boxaConvertToPta(), boxaDisplayTiled(), boxaEncapsulateAligned(), boxaEqual(), boxaExtractAsNuma(), boxaExtractAsPta(), boxaExtractSortedPattern(), boxaFillAll(), boxaFillSequence(), boxaFindInvalidBoxes(), boxaFindNearestBoxes(), boxaGetArea(), boxaGetAverageSize(), boxaGetCoverage(), boxaGetExtent(), boxaGetNearestByDirection(), boxaGetNearestToLine(), boxaGetNearestToPt(), boxaGetValidCount(), boxaHandleOverlaps(), boxaInsertBox(), boxaIntersectsBox(), boxaIntersectsBoxCount(), boxaIsFull(), boxaJoin(), boxaLinearFit(), boxaLocationRange(), boxaMakeAreaIndicator(), boxaMakeSizeIndicator(), boxaMakeWHRatioIndicator(), boxaMergeEvenOdd(), boxaModifyWithBoxa(), boxaPermutePseudorandom(), boxaPermuteRandom(), boxaPlotSides(), boxaPlotSizes(), boxaPruneSortedOnOverlap(), boxaReconcilePairWidth(), boxaRemoveBox(), boxaRemoveBoxAndSave(), boxaRotateOrth(), boxaSaveValid(), boxaSelectByArea(), boxaSelectBySize(), boxaSelectByWHRatio(), boxaSelectLargeULBox(), boxaSelectPivotBox(), boxaSelectRange(), boxaSetSide(), boxaSimilar(), boxaSizeRange(), boxaSmoothSequenceLS(), boxaSmoothSequenceMedian(), boxaSort(), boxaSort2d(), boxaSort2dByIndex(), boxaSortByIndex(), boxaSplitEvenOdd(), boxaSwapBoxes(), boxaTestEvenOddHeight(), boxaTransform(), boxaTransformOrdered(), boxaWindowedMedian(), boxaWriteStream(), boxCheckIfOverlapIsBig(), convertSegmentedFilesToPdf(), generatePtaaBoxa(), generatePtaaHashBoxa(), generatePtaBoxa(), generatePtaHashBoxa(), pixaaDisplay(), pixaBinSort(), pixacompGetBoxaCount(), pixaCreateFromBoxa(), pixaDisplayBoxaa(), pixaGetBoxaCount(), pixaRemovePix(), pixaRemovePixAndSave(), pixaSort(), pixBlendBoxaRandom(), pixClipRectangles(), pixDrawBoxa(), pixDrawBoxaRandom(), pixPaintBoxa(), pixPaintBoxaRandom(), pixSelectLargeULComp(), and pixSetBlackOrWhiteBoxa().

◆ boxaGetValidBox()

BOX* boxaGetValidBox ( BOXA boxa,
l_int32  index,
l_int32  accessflag 
)

boxaGetValidBox()

Parameters
[in]boxa
[in]indexto the index-th box
[in]accessflagL_COPY or L_CLONE
Returns
box, or NULL if box is not valid or on error
Notes:
     (1) This returns NULL for an invalid box in a boxa.
         For a box to be valid, both the width and height must be > 0.
     (2) We allow invalid boxes, with w = 0 or h = 0, as placeholders
         in boxa for which the index of the box in the boxa is important.
         This is an atypical situation; usually you want to put only
         valid boxes in a boxa.

Definition at line 799 of file boxbasic.c.

References boxaGetBox(), boxDestroy(), and boxGetGeometry().

Referenced by boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaConstrainSize(), boxaFillAll(), boxaGetSizes(), boxaLinearFit(), boxaModifyWithBoxa(), and boxaSaveValid().

◆ boxaGetValidCount()

l_int32 boxaGetValidCount ( BOXA boxa)

boxaGetValidCount()

Parameters
[in]boxa
Returns
count of valid boxes; 0 if no valid boxes or on error

Definition at line 732 of file boxbasic.c.

References boxaGetBoxGeometry(), and boxaGetCount().

Referenced by boxaConstrainSize(), boxaExtractAsNuma(), boxaExtractAsPta(), boxaFillAll(), boxaFillSequence(), boxaFindInvalidBoxes(), boxaGetMedianVals(), boxaGetRankVals(), boxaGetSizes(), and boxaReconcileEvenOddHeight().

◆ boxaInitFull()

l_int32 boxaInitFull ( BOXA boxa,
BOX box 
)

boxaInitFull()

Parameters
[in]boxatypically empty
[in]box[optional] to be replicated into the entire ptr array
Returns
0 if OK, 1 on error
Notes:
     (1) This initializes a boxa by filling up the entire box ptr array
         with copies of box.  If box == NULL, use a placeholder box
         of zero size.  Any existing boxes are destroyed.
         After this opepration, the number of boxes is equal to
         the number of allocated ptrs.
     (2) Note that we use boxaReplaceBox() instead of boxaInsertBox().
         They both have the same effect when inserting into a NULL ptr
         in the boxa ptr array:
     (3) Example usage.  This function is useful to prepare for a
         random insertion (or replacement) of boxes into a boxa.
         To randomly insert boxes into a boxa, up to some index "max":
            Boxa *boxa = boxaCreate(max);
            boxaInitFull(boxa, NULL);
         If you want placeholder boxes of non-zero size:
            Boxa *boxa = boxaCreate(max);
            Box *box = boxCreate(...);
            boxaInitFull(boxa, box);
            boxDestroy(&box);
         If we have an existing boxa with a smaller ptr array, it can
         be reused for up to max boxes:
            boxaExtendArrayToSize(boxa, max);
            boxaInitFull(boxa, NULL);
         The initialization allows the boxa to always be properly
         filled, even if all the boxes are not later replaced.
         If you want to know which boxes have been replaced,
         and you initialized with invalid zero-sized boxes,
         use boxaGetValidBox() to return NULL for the invalid boxes.

Definition at line 1173 of file boxbasic.c.

References boxaReplaceBox(), boxCopy(), boxCreate(), Boxa::n, and Boxa::nalloc.

Referenced by pixaInitFull().

◆ boxaInsertBox()

l_int32 boxaInsertBox ( BOXA boxa,
l_int32  index,
BOX box 
)

boxaInsertBox()

Parameters
[in]boxa
[in]indexlocation in boxa to insert new value
[in]boxnew box to be inserted
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts box[i] –> box[i + 1] for all i >= index,
         and then inserts box as box[index].
     (2) To insert at the beginning of the array, set index = 0.
     (3) To append to the array, it's easier to use boxaAddBox().
     (4) This should not be used repeatedly to insert into large arrays,
         because the function is O(n).

Definition at line 980 of file boxbasic.c.

References Boxa::box, boxaExtendArray(), boxaGetCount(), Boxa::n, and Boxa::nalloc.

Referenced by pixaInsertPix().

◆ boxaIsFull()

l_int32 boxaIsFull ( BOXA boxa,
l_int32 *  pfull 
)

boxaIsFull()

Parameters
[in]boxa
[out]pfull1 if boxa is full
Returns
0 if OK, 1 on error

Definition at line 896 of file boxbasic.c.

References boxaGetBox(), boxaGetCount(), boxDestroy(), and L_CLONE.

Referenced by pixaIsFull().

◆ boxaRead()

BOXA* boxaRead ( const char *  filename)

boxaRead()

Parameters
[in]filename
Returns
boxa, or NULL on error

Definition at line 2095 of file boxbasic.c.

References boxaReadStream(), and fopenReadStream().

Referenced by boxaaReadFromFiles().

◆ boxaReadMem()

BOXA* boxaReadMem ( const l_uint8 *  data,
size_t  size 
)

boxaReadMem()

Parameters
[in]dataserialization of boxa; in ascii
[in]sizeof data in bytes; can use strlen to get it
Returns
boxa, or NULL on error

Definition at line 2165 of file boxbasic.c.

References boxaReadStream(), and fopenReadFromMemory().

◆ boxaReadStream()

BOXA* boxaReadStream ( FILE *  fp)

boxaReadStream()

Parameters
[in]fpfile stream
Returns
boxa, or NULL on error

Definition at line 2122 of file boxbasic.c.

References BOXA_VERSION_NUMBER, boxaAddBox(), boxaCreate(), boxaDestroy(), boxCreate(), and L_INSERT.

Referenced by boxaaReadStream(), boxaRead(), boxaReadMem(), pixaaReadStream(), pixacompReadStream(), and pixaReadStream().

◆ boxaRemoveBox()

l_int32 boxaRemoveBox ( BOXA boxa,
l_int32  index 
)

boxaRemoveBox()

Parameters
[in]boxa
[in]indexof box to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This removes box[index] and then shifts
         box[i] –> box[i - 1] for all i > index.
     (2) It should not be used repeatedly to remove boxes from
         large arrays, because the function is O(n).

Definition at line 1025 of file boxbasic.c.

References Boxa::box, boxaGetCount(), boxDestroy(), and Boxa::n.

Referenced by pixaRemovePix().

◆ boxaRemoveBoxAndSave()

l_int32 boxaRemoveBoxAndSave ( BOXA boxa,
l_int32  index,
BOX **  pbox 
)

boxaRemoveBoxAndSave()

Parameters
[in]boxa
[in]indexof box to be removed
[out]pbox[optional] removed box
Returns
0 if OK, 1 on error
Notes:
     (1) This removes box[index] and then shifts
         box[i] –> box[i - 1] for all i > index.
     (2) It should not be used repeatedly to remove boxes from
         large arrays, because the function is O(n).

Definition at line 1067 of file boxbasic.c.

References Boxa::box, boxaGetBox(), boxaGetCount(), boxDestroy(), L_CLONE, and Boxa::n.

Referenced by pixaRemovePixAndSave().

◆ boxaReplaceBox()

l_int32 boxaReplaceBox ( BOXA boxa,
l_int32  index,
BOX box 
)

boxaReplaceBox()

Parameters
[in]boxa
[in]indexto the index-th box
[in]boxinsert to replace existing one
Returns
0 if OK, 1 on error
Notes:
     (1) In-place replacement of one box.
     (2) The previous box at that location, if any, is destroyed.

Definition at line 942 of file boxbasic.c.

References Boxa::box, boxDestroy(), and Boxa::n.

Referenced by boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaFillAll(), boxaHandleOverlaps(), boxaInitFull(), pixaAddBorderGeneral(), and pixaReplacePix().

◆ boxaSaveValid()

BOXA* boxaSaveValid ( BOXA boxas,
l_int32  copyflag 
)

boxaSaveValid()

Parameters
[in]boxas
[in]copyflagL_COPY or L_CLONE
Returns
boxad if OK, NULL on error
Notes:
     (1) This makes a copy/clone of each valid box.

Definition at line 1109 of file boxbasic.c.

References boxaAddBox(), boxaCreate(), boxaGetCount(), boxaGetValidBox(), L_CLONE, L_COPY, and L_INSERT.

Referenced by boxaCombineOverlaps(), boxaCombineOverlapsInPair(), and boxaDisplayTiled().

◆ boxaWrite()

l_int32 boxaWrite ( const char *  filename,
BOXA boxa 
)

boxaWrite()

Parameters
[in]filename
[in]boxa
Returns
0 if OK, 1 on error

Definition at line 2193 of file boxbasic.c.

References boxaWriteStream(), and fopenWriteStream().

Referenced by boxaLinearFit(), boxaSmoothSequenceLS(), and boxaSmoothSequenceMedian().

◆ boxaWriteMem()

l_int32 boxaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
BOXA boxa 
)

boxaWriteMem()

Parameters
[out]pdatadata of serialized boxa; ascii
[out]psizesize of returned data
[in]boxa
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a boxa in memory and puts the result in a buffer.

Definition at line 2266 of file boxbasic.c.

References boxaWriteStream(), fopenWriteWinTempfile(), and l_binaryReadStream().

◆ boxaWriteStream()

l_int32 boxaWriteStream ( FILE *  fp,
BOXA boxa 
)

boxaWriteStream()

Parameters
[in]fpfile stream
[in]boxa
Returns
0 if OK, 1 on error

Definition at line 2225 of file boxbasic.c.

References BOXA_VERSION_NUMBER, boxaGetBox(), boxaGetCount(), boxDestroy(), Box::h, L_CLONE, Box::w, Box::x, and Box::y.

Referenced by boxaaWriteStream(), boxaWrite(), boxaWriteMem(), pixaaWriteStream(), pixacompWriteStream(), and pixaWriteStream().

◆ boxChangeRefcount()

l_int32 boxChangeRefcount ( BOX box,
l_int32  delta 
)

Adjust the current references count of box by delta.

Parameters
[in]boxptr to box
[in]deltaadjustment, usually -1 or 1
Returns
0 if OK, 1 on error

Definition at line 448 of file boxbasic.c.

References Box::refcount.

Referenced by boxClone(), and boxDestroy().

◆ boxClone()

BOX* boxClone ( BOX box)

boxClone()

Parameters
[in]box
Returns
ptr to same box, or NULL on error

Definition at line 251 of file boxbasic.c.

References boxChangeRefcount().

Referenced by boxaAddBox(), boxaGetBox(), pixacompGetBox(), and pixaGetBox().

◆ boxCopy()

BOX* boxCopy ( BOX box)

◆ boxCreate()

BOX* boxCreate ( l_int32  x,
l_int32  y,
l_int32  w,
l_int32  h 
)

boxCreate()

Parameters
[in]x,y,w,h
Returns
box, or NULL on error
Notes:
     (1) This clips the box to the +quad.  If no part of the
         box is in the +quad, this returns NULL.
     (2) We allow you to make a box with w = 0 and/or h = 0.
         This does not represent a valid region, but it is useful
         as a placeholder in a boxa for which the index of the
         box in the boxa is important.  This is an atypical
         situation; usually you want to put only valid boxes with
         nonzero width and height in a boxa.  If you have a boxa
         with invalid boxes, the accessor boxaGetValidBox()
         will return NULL on each invalid box.
     (3) If you want to create only valid boxes, use boxCreateValid(),
         which returns NULL if either w or h is 0.

Definition at line 164 of file boxbasic.c.

References boxSetGeometry(), and Box::refcount.

Referenced by boxaAdjustSides(), boxaaFlattenAligned(), boxaaFlattenToBoxa(), boxaaGetExtent(), boxaaQuadtreeRegions(), boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaConstrainSize(), boxAdjustSides(), boxaGenerateSubboxes(), boxaGetExtent(), boxaInitFull(), boxaLinearFit(), boxaModifyWithBoxa(), boxaReadStream(), boxaSplitEvenOdd(), boxaWindowedMedian(), boxBoundingRegion(), boxCopy(), boxCreateValid(), boxOverlapRegion(), boxRotateOrth(), boxTransform(), boxTransformOrdered(), ccbaReadStream(), generatePtaGrid(), ioFormatTest(), makeMosaicStrips(), pixaDisplayTiledByIndex(), pixaSetFullSizeBoxa(), pixCropAlignedToCentroid(), pixPrepare1bpp(), pixTilingGetTile(), pixWarpStereoscopic(), ptaConvertToBox(), ptaConvertToBoxa(), and ptaGetBoundingRegion().

◆ boxCreateValid()

BOX* boxCreateValid ( l_int32  x,
l_int32  y,
l_int32  w,
l_int32  h 
)

boxCreateValid()

Parameters
[in]x,y,w,h
Returns
box, or NULL on error
Notes:
     (1) This returns NULL if either w = 0 or h = 0.

Definition at line 209 of file boxbasic.c.

References boxCreate().

◆ boxDestroy()

void boxDestroy ( BOX **  pbox)

boxDestroy()

Parameters
[in,out]pboxwill be set to null before returning
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the box.
     (2) Always nulls the input ptr.

Definition at line 277 of file boxbasic.c.

References boxChangeRefcount(), and boxGetRefcount().

Referenced by boxaaAlignBox(), boxaAdjustHeightToTarget(), boxaAdjustSides(), boxaAdjustWidthToTarget(), boxaaWriteStream(), boxaClear(), boxaClipToBox(), boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaCompareRegions(), boxaConstrainSize(), boxaContainedInBox(), boxaContainedInBoxa(), boxaContainedInBoxCount(), boxaConvertToPta(), boxaDestroy(), boxaDisplayTiled(), boxaEqual(), boxaExtractSortedPattern(), boxaFillAll(), boxaGenerateSubboxes(), boxaGetBoxGeometry(), boxaGetCoverage(), boxaGetNearestToLine(), boxaGetNearestToPt(), boxaGetSizes(), boxaGetValidBox(), boxaHandleOverlaps(), boxaIntersectsBox(), boxaIntersectsBoxCount(), boxaIsFull(), boxaLinearFit(), boxaModifyWithBoxa(), boxaPruneSortedOnOverlap(), boxaReconcilePairWidth(), boxaRemoveBox(), boxaRemoveBoxAndSave(), boxaReplaceBox(), boxaRotateOrth(), boxaSelectPivotBox(), boxaSetSide(), boxaSimilar(), boxaTransform(), boxaTransformOrdered(), boxaWriteStream(), boxCheckIfOverlapIsBig(), boxClipToRectangleParams(), boxOverlapArea(), boxOverlapFraction(), ccbaDisplayImage1(), dewarpShowResults(), generatePtaaBoxa(), generatePtaaHashBoxa(), generatePtaBoxa(), generatePtaHashBoxa(), ioFormatTest(), partelDestroy(), pixaClipToForeground(), pixacompGetBoxGeometry(), pixaCreateFromBoxa(), pixAddWithIndicator(), pixaDisplayBoxaa(), pixaGetBoxGeometry(), pixaRotateOrth(), pixBlendBoxaRandom(), pixClipRectangle(), pixClipRectangles(), pixCompareGrayByHisto(), pixPrepare1bpp(), pixRemoveWithIndicator(), pixTilingGetTile(), recogAverageSamples(), recogExtractNumbers(), recogRescoreDidResult(), selCreateFromPta(), and showExtractNumbers().

◆ boxGetGeometry()

l_int32 boxGetGeometry ( BOX box,
l_int32 *  px,
l_int32 *  py,
l_int32 *  pw,
l_int32 *  ph 
)

◆ boxGetRefcount()

l_int32 boxGetRefcount ( BOX box)

Return the current reference count of box.

Parameters
[in]boxptr to Box
Returns
refcount

Definition at line 431 of file boxbasic.c.

References Box::refcount.

Referenced by boxDestroy().

◆ boxGetSideLocations()

l_int32 boxGetSideLocations ( BOX box,
l_int32 *  pl,
l_int32 *  pr,
l_int32 *  pt,
l_int32 *  pb 
)

boxGetSideLocations()

Parameters
[in]box
[out]pl,pt,pr,pb[optional] each can be null
Returns
0 if OK, 1 on error
Notes:
     (1) All returned values are within the box.

Definition at line 370 of file boxbasic.c.

References boxGetGeometry().

Referenced by boxSimilar().

◆ boxIsValid()

l_int32 boxIsValid ( BOX box,
l_int32 *  pvalid 
)

boxIsValid()

Parameters
[in]box
[out]pvalid1 if valid; 0 otherwise
Returns
0 if OK, 1 on error

Definition at line 469 of file boxbasic.c.

References Box::h, and Box::w.

◆ boxPrintStreamInfo()

l_int32 boxPrintStreamInfo ( FILE *  fp,
BOX box 
)

boxPrintStreamInfo()

Parameters
[in]fpfile stream
[in]box
Returns
0 if OK, 1 on error
Notes:
     (1) This outputs debug info.  Use serialization functions to
         write to file if you want to read the data back.

Definition at line 2323 of file boxbasic.c.

References Box::h, Box::w, Box::x, and Box::y.

◆ boxSetGeometry()

l_int32 boxSetGeometry ( BOX box,
l_int32  x,
l_int32  y,
l_int32  w,
l_int32  h 
)

boxSetGeometry()

Parameters
[in]box
[in]x,y,w,h[optional] use -1 to leave unchanged
Returns
0 if OK, 1 on error

Definition at line 339 of file boxbasic.c.

References Box::h, Box::w, Box::x, and Box::y.

Referenced by boxaAdjustHeightToTarget(), boxaAdjustWidthToTarget(), boxAdjustSides(), boxaReconcilePairWidth(), boxaSetSide(), boxCreate(), boxRelocateOneSide(), and boxSetSideLocations().

◆ boxSetSideLocations()

l_int32 boxSetSideLocations ( BOX box,
l_int32  l,
l_int32  r,
l_int32  t,
l_int32  b 
)

boxSetSideLocations()

Parameters
[in]box
[in]l,r,t,b[optional] use -1 to leave unchanged
Returns
0 if OK, 1 on error

Definition at line 404 of file boxbasic.c.

References boxSetGeometry(), Box::h, Box::w, Box::x, and Box::y.

Variable Documentation

◆ INITIAL_PTR_ARRAYSIZE

const l_int32 INITIAL_PTR_ARRAYSIZE = 20
static

n'import quoi

Definition at line 135 of file boxbasic.c.

Referenced by boxaaCreate(), and boxaCreate().