Leptonica 1.68
C Image Processing Library

boxbasic.c File Reference

Implementation of Box, Boxa (Box array), and Boxaa classes. More...

#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 boxGetRefcount (BOX *box)
l_int32 boxChangeRefcount (BOX *box, l_int32 delta)
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)
l_int32 boxaGetBoxGeometry (BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
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 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 boxaaGetCount (BOXAA *baa)
l_int32 boxaaGetBoxCount (BOXAA *baa)
BOXAboxaaGetBoxa (BOXAA *baa, l_int32 index, l_int32 accessflag)
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)
BOXAAboxaaRead (const char *filename)
BOXAAboxaaReadStream (FILE *fp)
l_int32 boxaaWrite (const char *filename, BOXAA *baa)
l_int32 boxaaWriteStream (FILE *fp, BOXAA *baa)
BOXAboxaRead (const char *filename)
BOXAboxaReadStream (FILE *fp)
l_int32 boxaWrite (const char *filename, BOXA *boxa)
l_int32 boxaWriteStream (FILE *fp, BOXA *boxa)
l_int32 boxPrintStreamInfo (FILE *fp, BOX *box)

Variables

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20

Detailed Description

Implementation of Box, Boxa (Box array), and Boxaa classes.

 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   boxGetRefcount()
         l_int32   boxChangeRefcount()

    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()
         l_int32   boxaGetBoxGeometry()

    Boxa array modifiers
         l_int32   boxaReplaceBox()
         l_int32   boxaInsertBox()
         l_int32   boxaRemoveBox()
         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()

    Boxaa accessors
         l_int32   boxaaGetCount()
         l_int32   boxaaGetBoxCount()
         BOXA     *boxaaGetBoxa()

    Boxa array modifiers
         l_int32   boxaaReplaceBoxa()
         l_int32   boxaaInsertBoxa()
         l_int32   boxaaRemoveBoxa()
         l_int32   boxaaAddBox()

    Boxaa serialized I/O
         BOXAA    *boxaaRead()
         BOXAA    *boxaaReadStream()
         l_int32   boxaaWrite()
         l_int32   boxaaWriteStream()

    Boxa serialized I/O
         BOXA     *boxaRead()
         BOXA     *boxaReadStream()
         l_int32   boxaWrite()
         l_int32   boxaWriteStream()

    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

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

boxCreate()

Input: x, y, w, h Return: 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 133 of file boxbasic.c.

References boxSetGeometry(), CALLOC, ERROR_PTR, NULL, PROCNAME, and Box::refcount.

Referenced by boxaaGetExtent(), boxaaQuadtreeRegions(), boxAdjustSides(), boxaGenerateSubboxes(), boxaGetExtent(), boxaGetRankSize(), boxaGetWhiteblocks(), boxaReadStream(), boxBoundingRegion(), boxCopy(), boxCreateValid(), boxOverlapRegion(), boxRotateOrth(), boxTransform(), boxTransformOrdered(), ccbaReadStream(), finalPositioningForAlignment(), generateMediaboxPdf(), GenerateSetOfMargePix(), identifyWatershedBasin(), jbDataRender(), main(), pixBlend(), pixBlendGrayAdapt(), pixClipBoxToEdges(), pixClipBoxToForeground(), pixClipMasked(), pixClipToForeground(), pixDeskewBarcode(), pixFindHistoPeaksHSV(), pixFindLargestRectangle(), pixGetCCBorders(), pixGetLocalSkewAngles(), pixGetOuterBorderPta(), pixPaintSelfThroughMask(), pixSaveTiledOutline(), pixSearchForRectangle(), pixSeedfill4BB(), pixSeedfill8BB(), pixSplitComponentIntoBoxa(), pixTilingGetTile(), pixWarpStereoscopic(), ptaConvertToBoxa(), and ptaGetBoundingRegion().

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

boxCreateValid()

Input: x, y, w, h Return: box, or null on error

Notes: (1) This returns NULL if either w = 0 or h = 0.

Definition at line 176 of file boxbasic.c.

References boxCreate(), ERROR_PTR, NULL, and PROCNAME.

BOX* boxCopy ( BOX box)
BOX* boxClone ( BOX box)

boxClone()

Input: box Return: ptr to same box, or null on error

Definition at line 218 of file boxbasic.c.

References boxChangeRefcount(), ERROR_PTR, NULL, and PROCNAME.

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

void boxDestroy ( BOX **  pbox)

boxDestroy()

Input: &box (<will be="" set="" to="" null="" before="" returning>="">) Return: void

Notes: (1) Decrements the ref count and, if 0, destroys the box. (2) Always nulls the input ptr.

Definition at line 242 of file boxbasic.c.

References boxChangeRefcount(), boxGetRefcount(), FREE, L_WARNING, NULL, and PROCNAME.

Referenced by boxaaDisplay(), boxaaWriteStream(), boxaClear(), boxaClipToBox(), boxaCombineOverlaps(), boxaContainedInBox(), boxaDestroy(), boxaEqual(), boxaExtractSortedPattern(), boxaGenerateSubboxes(), boxaGetBoxGeometry(), boxaGetCoverage(), boxaGetNearestToPt(), boxaGetValidBox(), boxaGetWhiteblocks(), boxaIntersectsBox(), boxaPruneSortedOnOverlap(), boxaRemoveBox(), boxaReplaceBox(), boxaRotateOrth(), boxaSelectPivotBox(), boxaTransform(), boxaTransformOrdered(), boxaWriteStream(), boxCheckIfOverlapIsBig(), boxOverlapFraction(), ccbaDisplayImage1(), ccbaGenerateSinglePath(), finalPositioningForAlignment(), generatePtaaBoxa(), generatePtaaHashBoxa(), generatePtaBoxa(), GenerateSetOfMargePix(), jbDataRender(), jbGetULCorners(), main(), partelDestroy(), pdfdataDestroy(), pixacompGetBoxGeometry(), pixaCreateFromBoxa(), pixAddWithIndicator(), pixaGenerateFont(), pixaGetBoxGeometry(), pixBlend(), pixBlendBoxaRandom(), pixBlendGrayAdapt(), pixClipBoxToEdges(), pixClipBoxToForeground(), pixClipMasked(), pixClipRectangle(), pixClipToForeground(), pixConvertToPdfDataSegmented(), pixDeskewBarcode(), pixDrawBoxaRandom(), pixExtractBarcodes(), pixFindHistoPeaksHSV(), pixGetAllCCBorders(), pixGetCCBorders(), pixGetLocalSkewAngles(), pixGetOuterBorderPta(), pixGetOuterBordersPtaa(), pixMaskBoxa(), pixMeanInRectangle(), pixPaintBoxa(), pixPaintBoxaRandom(), pixPaintSelfThroughMask(), pixQuadtreeMean(), pixQuadtreeVariance(), pixRemoveWithIndicator(), pixScanForEdge(), pixScanForForeground(), pixSetBlackOrWhiteBoxa(), pixSetInRectArbitrary(), pixSplitComponentIntoBoxa(), pixSplitIntoBoxa(), pixSumPixelValues(), pixTilingGetTile(), pixUpDownDetectGeneral(), pixUpDownDetectGeneralDwa(), pixVarianceInRectangle(), pixWarpStereoscopic(), RenderHashedBoxa(), RenderTransformedBoxa(), and selCreateFromPta().

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 
)

boxSetGeometry()

Input: box x, y, w, h (use -1 to leave unchanged) Return: 0 if OK, 1 on error

Definition at line 304 of file boxbasic.c.

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

Referenced by boxAdjustSides(), boxCreate(), and boxRelocateOneSide().

l_int32 boxGetRefcount ( BOX box)

Definition at line 323 of file boxbasic.c.

References ERROR_INT, PROCNAME, Box::refcount, and UNDEF.

Referenced by boxDestroy().

l_int32 boxChangeRefcount ( BOX box,
l_int32  delta 
)

Definition at line 335 of file boxbasic.c.

References ERROR_INT, PROCNAME, and Box::refcount.

Referenced by boxClone(), and boxDestroy().

BOXA* boxaCopy ( BOXA boxa,
l_int32  copyflag 
)

boxaCopy()

Input: boxa copyflag (L_COPY, L_CLONE, L_COPY_CLONE) Return: new boxa, or null on error

Notes: (1) See pix.h for description of the copyflag. (2) The copy-clone makes a new boxa that holds clones of each box.

Definition at line 392 of file boxbasic.c.

References boxaAddBox(), boxaCreate(), boxaGetBox(), ERROR_PTR, L_CLONE, L_COPY, L_COPY_CLONE, L_INSERT, Boxa::n, Boxa::nalloc, NULL, PROCNAME, and Boxa::refcount.

Referenced by boxaaAddBoxa(), boxaaGetBoxa(), boxaCombineOverlaps(), boxaGetWhiteblocks(), boxaPermuteRandom(), boxaPruneSortedOnOverlap(), boxaRotateOrth(), boxaSelectWithIndicator(), main(), pixaaGetBoxa(), pixacompGetBoxa(), pixaGetBoxa(), pixConnCompPixa(), and pixDeskewBarcode().

void boxaDestroy ( BOXA **  pboxa)

boxaDestroy()

Input: &boxa (<will be="" set="" to="" null="" before="" returning>="">) Return: void

Note:

  • Decrements the ref count and, if 0, destroys the boxa.
  • Always nulls the input ptr.

Definition at line 436 of file boxbasic.c.

References Boxa::box, boxDestroy(), FREE, L_WARNING, Boxa::n, NULL, PROCNAME, and Boxa::refcount.

Referenced by boxaaAddBox(), boxaaAlignBox(), boxaaDestroy(), boxaaDisplay(), boxaaFlattenToBoxa(), boxaaGetBoxCount(), boxaaRemoveBoxa(), boxaaReplaceBoxa(), boxaaWriteStream(), boxaCombineOverlaps(), boxaGetWhiteblocks(), boxaSort2d(), BoxaSortTest(), ccbDestroy(), convertSegmentedFilesToPdf(), count_pieces(), count_pieces2(), DoPageSegmentation(), jbAddPage(), jbGetComponents(), jbWordsInTextlines(), main(), partelDestroy(), pixaAddBorderGeneral(), pixaaDestroy(), pixaaDisplay(), pixaaReadStream(), pixacompCreateFromPixa(), pixacompDestroy(), pixacompReadStream(), pixaCreateFromPixacomp(), pixaDestroy(), pixaDisplay(), pixaDisplayOnColor(), pixaDisplayRandomCmap(), pixaEqual(), pixaGenerateFont(), pixaJoin(), pixaReadStream(), pixaSelectBySize(), PixaSortTest(), pixConnCompPixa(), pixDeskewBarcode(), pixDisplayMatchedPattern(), pixExtractBarcodes(), pixFillHolesToBoundingRect(), pixFindBaselines(), pixFindRectangleComps(), pixGetAllCCBorders(), pixGetCCBorders(), pixGetOuterBordersPtaa(), pixGetRegionsBinary(), pixGetTextlineCenters(), pixGetWordBoxesInTextlines(), pixGetWordsInTextlines(), pixItalicWords(), pixMaskConnComp(), pixMorphSequenceByComponent(), pixMorphSequenceByRegion(), pixPaintSelfThroughMask(), pixQuadtreeMean(), pixQuadtreeVariance(), pixQualifyLocalMinima(), pixRemoveMatchedPattern(), pixSelectByAreaFraction(), pixSelectByAreaPerimRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), pixSelectiveConnCompFill(), pixSelectMinInConnComp(), pixSmoothConnectedRegions(), pixSplitComponentIntoBoxa(), pixSplitIntoBoxa(), pixUpDownDetectGeneral(), pixUpDownDetectGeneralDwa(), pixWordMaskByDilation(), and ptaaGetBoundaryPixels().

l_int32 boxaExtendArray ( BOXA boxa)

boxaExtendArray()

Input: boxa Return: 0 if OK; 1 on error

Notes: (1) Reallocs with doubled size of ptr array.

Definition at line 519 of file boxbasic.c.

References boxaExtendArrayToSize(), ERROR_INT, Boxa::nalloc, and PROCNAME.

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

l_int32 boxaExtendArrayToSize ( BOXA boxa,
l_int32  size 
)

boxaExtendArrayToSize()

Input: boxa size (new size of boxa array) Return: 0 if OK; 1 on error

Notes: (1) If necessary, reallocs new boxa ptr array to .

Definition at line 541 of file boxbasic.c.

References Boxa::box, ERROR_INT, Boxa::nalloc, NULL, PROCNAME, reallocNew(), and size.

Referenced by boxaExtendArray(), and pixaExtendArrayToSize().

l_int32 boxaGetCount ( BOXA boxa)

boxaGetCount()

Input: boxa Return: count (of all boxes); 0 if no boxes or on error

Definition at line 570 of file boxbasic.c.

References ERROR_INT, Boxa::n, and PROCNAME.

Referenced by boxaaAlignBox(), boxaAddBox(), boxaaDisplay(), boxaaFlattenToBoxa(), boxaaGetBoxCount(), boxaaGetExtent(), boxaBinSort(), boxaClear(), boxaClipToBox(), boxaCombineOverlaps(), boxaContainedInBox(), boxaConvertToPta(), boxaEqual(), boxaExtractSortedPattern(), boxaGetCoverage(), boxaGetExtent(), boxaGetMedian(), boxaGetNearestToPt(), boxaGetRankSize(), boxaGetValidCount(), boxaGetWhiteblocks(), boxaInsertBox(), boxaIntersectsBox(), boxaJoin(), boxaLocationRange(), boxaMakeSizeIndicator(), boxaPermutePseudorandom(), boxaPermuteRandom(), boxaPruneSortedOnOverlap(), boxaRemoveBox(), boxaRotateOrth(), boxaSelectPivotBox(), boxaSizeRange(), boxaSort(), boxaSort2d(), boxaSort2dByIndex(), boxaSortByIndex(), BoxaSortTest(), boxaSwapBoxes(), boxaTransform(), boxaTransformOrdered(), boxaWriteStream(), boxCheckIfOverlapIsBig(), convertSegmentedFilesToPdf(), count_pieces(), count_pieces2(), generatePtaaBoxa(), generatePtaaHashBoxa(), generatePtaBoxa(), jbAddPageComponents(), jbGetULCorners(), main(), pixaaDisplay(), pixaBinSort(), pixacompGetBoxaCount(), pixaCreateFromBoxa(), pixaGenerateFont(), pixaGetBoxaCount(), pixaRemovePix(), pixaSort(), pixBlendBoxaRandom(), pixConvertToPdfDataSegmented(), pixDeskewBarcode(), pixDisplayMatchedPattern(), pixDrawBoxa(), pixDrawBoxaRandom(), pixExtractBarcodes(), pixFillHolesToBoundingRect(), pixFindBaselines(), pixGetAllCCBorders(), pixGetCCBorders(), pixGetOuterBordersPtaa(), pixMaskBoxa(), pixMaskConnComp(), pixPaintBoxa(), pixPaintBoxaRandom(), pixQuadtreeMean(), pixQuadtreeVariance(), pixRemoveMatchedPattern(), pixSelectiveConnCompFill(), pixSelectMinInConnComp(), pixSetBlackOrWhiteBoxa(), pixSmoothConnectedRegions(), pixSplitIntoBoxa(), pixUpDownDetectGeneral(), pixUpDownDetectGeneralDwa(), pixWordMaskByDilation(), ptaaGetBoundaryPixels(), RenderHashedBoxa(), and RenderTransformedBoxa().

l_int32 boxaGetValidCount ( BOXA boxa)

boxaGetValidCount()

Input: boxa Return: count (of valid boxes); 0 if no valid boxes or on error

Definition at line 587 of file boxbasic.c.

References boxaGetBoxGeometry(), boxaGetCount(), ERROR_INT, NULL, and PROCNAME.

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

boxaGetBox()

Input: boxa index (to the index-th box) accessflag (L_COPY or L_CLONE) Return: box, or null on error

Definition at line 615 of file boxbasic.c.

References Boxa::box, boxClone(), boxCopy(), ERROR_PTR, L_CLONE, L_COPY, Boxa::n, NULL, and PROCNAME.

Referenced by boxaaDisplay(), boxaaFlattenToBoxa(), boxaClipToBox(), boxaCombineOverlaps(), boxaContainedInBox(), boxaCopy(), boxaEqual(), boxaExtractSortedPattern(), boxaGetBoxGeometry(), boxaGetCoverage(), boxaGetNearestToPt(), boxaGetValidBox(), boxaGetWhiteblocks(), boxaIntersectsBox(), boxaJoin(), boxaPruneSortedOnOverlap(), boxaRotateOrth(), boxaSelectPivotBox(), boxaSelectWithIndicator(), boxaSort2d(), boxaSort2dByIndex(), boxaSortByIndex(), BoxaSortTest(), boxaTransform(), boxaTransformOrdered(), boxaWriteStream(), boxCheckIfOverlapIsBig(), ccbaDisplayImage1(), ccbaGenerateSinglePath(), generatePtaaBoxa(), generatePtaaHashBoxa(), generatePtaBoxa(), jbClassifyCorrelation(), jbClassifyRankHaus(), jbGetULCorners(), main(), pixaCreateFromBoxa(), pixaGenerateFont(), pixBlendBoxaRandom(), pixConvertToPdfDataSegmented(), pixDeskewBarcode(), pixDrawBoxaRandom(), pixExtractBarcodes(), pixFindRectangleComps(), pixGetCCBorders(), pixGetOuterBordersPtaa(), pixMaskBoxa(), pixPaintBoxa(), pixPaintBoxaRandom(), pixQuadtreeMean(), pixQuadtreeVariance(), pixSetBlackOrWhiteBoxa(), pixSplitComponentIntoBoxa(), pixSplitIntoBoxa(), pixUpDownDetectGeneral(), pixUpDownDetectGeneralDwa(), RenderHashedBoxa(), and RenderTransformedBoxa().

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

boxaGetValidBox()

Input: boxa index (to the index-th box) accessflag (L_COPY or L_CLONE) Return: 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 652 of file boxbasic.c.

References boxaGetBox(), boxDestroy(), boxGetGeometry(), ERROR_PTR, NULL, and PROCNAME.

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

boxaReplaceBox()

Input: boxa index (to the index-th box) box (insert to replace existing one) Return: 0 if OK, 1 on error

Notes: (1) In-place replacement of one box. (2) The previous box at that location is destroyed.

Definition at line 726 of file boxbasic.c.

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

Referenced by boxaCombineOverlaps(), boxaInitFull(), pixaAddBorderGeneral(), and pixaReplacePix().

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

boxaInsertBox()

Input: boxa index (location in boxa to insert new value) box (new box to be inserted) Return: 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 762 of file boxbasic.c.

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

Referenced by main(), and pixaInsertPix().

l_int32 boxaRemoveBox ( BOXA boxa,
l_int32  index 
)

boxaRemoveBox()

Input: boxa index (of box to be removed) Return: 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 805 of file boxbasic.c.

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

Referenced by main(), pixaGenerateFont(), and pixaRemovePix().

l_int32 boxaInitFull ( BOXA boxa,
BOX box 
)

boxaInitFull()

Input: boxa (typically empty) box (to be replicated into the entire ptr array) Return: 0 if OK, 1 on error

Notes: (1) This initializes a boxa by filling up the entire box ptr array with copies of . Any existing boxes are destroyed. After this oepration, 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); Box *box = boxCreate(...); boxaInitFull(boxa, box); If we have an existing boxa with a smaller ptr array, it can be reused: boxaExtendArrayToSize(boxa, max); Box *box = boxCreate(...); boxaInitFull(boxa, box); 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, you can initialize the array with invalid boxes that have w = 0 and/or h = 0. Then boxaGetValidBox() will return NULL for the invalid boxes.

Definition at line 864 of file boxbasic.c.

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

Referenced by pixaInitFull().

l_int32 boxaClear ( BOXA boxa)

boxaClear()

Input: boxa Return: 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 898 of file boxbasic.c.

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

Referenced by pixaClear().

BOXAA* boxaaCreate ( l_int32  n)

boxaaCreate()

Input: size of boxa ptr array to be alloc'd (0 for default) Return: baa, or null on error

Definition at line 925 of file boxbasic.c.

References Boxaa::boxa, CALLOC, ERROR_PTR, INITIAL_PTR_ARRAYSIZE, Boxaa::n, Boxaa::nalloc, NULL, and PROCNAME.

Referenced by boxaaCopy(), boxaaQuadtreeRegions(), boxaaReadStream(), boxaSort2d(), boxaSort2dByIndex(), and main().

BOXAA* boxaaCopy ( BOXAA baas,
l_int32  copyflag 
)

boxaaCopy()

Input: baas (input boxaa to be copied) copyflag (L_COPY, L_CLONE) Return: 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 959 of file boxbasic.c.

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

void boxaaDestroy ( BOXAA **  pbaa)

boxaaDestroy()

Input: &boxaa (<will be="" set="" to="" null="" before="" returning>="">) Return: void

Definition at line 991 of file boxbasic.c.

References Boxaa::boxa, boxaDestroy(), FREE, L_WARNING, Boxaa::n, NULL, and PROCNAME.

Referenced by boxaSort2d(), main(), pixGetWordBoxesInTextlines(), pixGetWordsInTextlines(), pixQuadtreeMean(), and pixQuadtreeVariance().

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

boxaaAddBoxa()

Input: boxaa boxa (to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK, 1 on error

Definition at line 1029 of file boxbasic.c.

References Boxaa::boxa, boxaaExtendArray(), boxaaGetCount(), boxaCopy(), ERROR_INT, L_CLONE, L_COPY, L_INSERT, Boxaa::n, Boxaa::nalloc, and PROCNAME.

Referenced by boxaaCopy(), boxaaQuadtreeRegions(), boxaaReadStream(), boxaSort2d(), boxaSort2dByIndex(), and main().

l_int32 boxaaExtendArray ( BOXAA baa)

boxaaExtendArray()

Input: boxaa Return: 0 if OK, 1 on error

Definition at line 1066 of file boxbasic.c.

References Boxaa::boxa, ERROR_INT, Boxaa::nalloc, NULL, PROCNAME, and reallocNew().

Referenced by boxaaAddBoxa(), and boxaaInsertBoxa().

l_int32 boxaaGetBoxCount ( BOXAA baa)

boxaaGetBoxCount()

Input: boxaa Return: count (number of boxes), or 0 if no boxes or on error

Definition at line 1111 of file boxbasic.c.

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

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

boxaaGetBoxa()

Input: boxaa index (to the index-th boxa) accessflag (L_COPY or L_CLONE) Return: boxa, or null on error

Definition at line 1141 of file boxbasic.c.

References Boxaa::boxa, boxaaGetCount(), boxaCopy(), ERROR_PTR, L_CLONE, L_COPY, NULL, and PROCNAME.

Referenced by boxaaAddBox(), boxaaAlignBox(), boxaaCopy(), boxaaDisplay(), boxaaFlattenToBoxa(), boxaaGetBoxCount(), boxaaGetExtent(), boxaaWriteStream(), boxaSort2d(), convertSegmentedFilesToPdf(), pixQuadtreeMean(), and pixQuadtreeVariance().

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

boxaaReplaceBoxa()

Input: boxaa index (to the index-th boxa) boxa (insert and replace any existing one) Return: 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 1175 of file boxbasic.c.

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

Referenced by boxaSort2d().

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

boxaaInsertBoxa()

Input: boxaa index (location in boxaa to insert new boxa) boxa (new boxa to be inserted) Return: 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 1214 of file boxbasic.c.

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

l_int32 boxaaRemoveBoxa ( BOXAA baa,
l_int32  index 
)

boxaaRemoveBoxa()

Input: boxaa index (of the boxa to be removed) Return: 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 1258 of file boxbasic.c.

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

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

boxaaAddBox()

Input: boxaa index (of boxa with boxaa) box (to be added) accessflag (L_INSERT, L_COPY or L_CLONE) Return: 0 if OK, 1 on error

Notes: (1) Adds to an existing boxa only.

Definition at line 1296 of file boxbasic.c.

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

Referenced by boxaSort2d().

BOXAA* boxaaRead ( const char *  filename)

boxaaRead()

Input: filename Return: boxaa, or null on error

Definition at line 1330 of file boxbasic.c.

References boxaaReadStream(), ERROR_PTR, fopenReadStream(), NULL, and PROCNAME.

Referenced by main().

BOXAA* boxaaReadStream ( FILE *  fp)

boxaaReadStream()

Input: stream Return: boxaa, or null on error

Definition at line 1359 of file boxbasic.c.

References BOXAA_VERSION_NUMBER, boxaaAddBoxa(), boxaaCreate(), boxaReadStream(), ERROR_PTR, L_INSERT, NULL, PROCNAME, and version.

Referenced by boxaaRead().

l_int32 boxaaWrite ( const char *  filename,
BOXAA baa 
)

boxaaWrite()

Input: filename boxaa Return: 0 if OK, 1 on error

Definition at line 1401 of file boxbasic.c.

References boxaaWriteStream(), ERROR_INT, fopenWriteStream(), NULL, and PROCNAME.

Referenced by main().

l_int32 boxaaWriteStream ( FILE *  fp,
BOXAA baa 
)

boxaaWriteStream()

Input: stream boxaa Return: 0 if OK, 1 on error

Definition at line 1431 of file boxbasic.c.

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

Referenced by boxaaWrite(), and main().

BOXA* boxaRead ( const char *  filename)

boxaRead()

Input: filename Return: boxa, or null on error

Definition at line 1474 of file boxbasic.c.

References boxaReadStream(), ERROR_PTR, fopenReadStream(), NULL, and PROCNAME.

BOXA* boxaReadStream ( FILE *  fp)

boxaReadStream()

Input: stream Return: boxa, or null on error

Definition at line 1503 of file boxbasic.c.

References BOXA_VERSION_NUMBER, boxaAddBox(), boxaCreate(), boxCreate(), ERROR_PTR, L_INSERT, NULL, PROCNAME, and version.

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

l_int32 boxaWrite ( const char *  filename,
BOXA boxa 
)

boxaWrite()

Input: filename boxa Return: 0 if OK, 1 on error

Definition at line 1546 of file boxbasic.c.

References boxaWriteStream(), ERROR_INT, fopenWriteStream(), NULL, and PROCNAME.

Referenced by BoxaSortTest(), DoPageSegmentation(), main(), PixaSortTest(), pixGetRegionsBinary(), and pixItalicWords().

l_int32 boxaWriteStream ( FILE *  fp,
BOXA boxa 
)
l_int32 boxPrintStreamInfo ( FILE *  fp,
BOX box 
)

boxPrintStreamInfo()

Input: stream box Return: 0 if OK, 1 on error

Notes: (1) This outputs information about the box, for debugging. (2) Use serialization functions to write to file if you want to read the data back.

Definition at line 1619 of file boxbasic.c.

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

Referenced by pixGetCCBorders(), and pixSplitComponentIntoBoxa().


Variable Documentation

const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static]

Definition at line 106 of file boxbasic.c.

Referenced by boxaaCreate(), and boxaCreate().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines