Leptonica  1.83.1
Image processing and image analysis suite
pixabasic.c File Reference
#include <string.h>
#include "allheaders.h"
#include "pix_internal.h"

Go to the source code of this file.

Functions

static l_int32 pixaExtendArray (PIXA *pixa)
 
static l_int32 pixaaExtendArray (PIXAA *paa)
 
PIXApixaCreate (l_int32 n)
 
PIXApixaCreateFromPix (PIX *pixs, l_int32 n, l_int32 cellw, l_int32 cellh)
 
PIXApixaCreateFromBoxa (PIX *pixs, BOXA *boxa, l_int32 start, l_int32 num, l_int32 *pcropwarn)
 
PIXApixaSplitPix (PIX *pixs, l_int32 nx, l_int32 ny, l_int32 borderwidth, l_uint32 bordercolor)
 
void pixaDestroy (PIXA **ppixa)
 
PIXApixaCopy (PIXA *pixa, l_int32 copyflag)
 
l_ok pixaAddPix (PIXA *pixa, PIX *pix, l_int32 copyflag)
 
l_ok pixaAddBox (PIXA *pixa, BOX *box, l_int32 copyflag)
 
l_ok pixaExtendArrayToSize (PIXA *pixa, size_t size)
 
l_int32 pixaGetCount (PIXA *pixa)
 
PIXpixaGetPix (PIXA *pixa, l_int32 index, l_int32 accesstype)
 
l_ok pixaGetPixDimensions (PIXA *pixa, l_int32 index, l_int32 *pw, l_int32 *ph, l_int32 *pd)
 
BOXApixaGetBoxa (PIXA *pixa, l_int32 accesstype)
 
l_int32 pixaGetBoxaCount (PIXA *pixa)
 
BOXpixaGetBox (PIXA *pixa, l_int32 index, l_int32 accesstype)
 
l_ok pixaGetBoxGeometry (PIXA *pixa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
 
l_ok pixaSetBoxa (PIXA *pixa, BOXA *boxa, l_int32 accesstype)
 
PIX ** pixaGetPixArray (PIXA *pixa)
 
l_ok pixaVerifyDepth (PIXA *pixa, l_int32 *psame, l_int32 *pmaxd)
 
l_ok pixaVerifyDimensions (PIXA *pixa, l_int32 *psame, l_int32 *pmaxw, l_int32 *pmaxh)
 
l_ok pixaIsFull (PIXA *pixa, l_int32 *pfullpa, l_int32 *pfullba)
 
l_ok pixaCountText (PIXA *pixa, l_int32 *pntext)
 
l_ok pixaSetText (PIXA *pixa, const char *text, SARRAY *sa)
 
void *** pixaGetLinePtrs (PIXA *pixa, l_int32 *psize)
 
l_ok pixaWriteStreamInfo (FILE *fp, PIXA *pixa)
 
l_ok pixaReplacePix (PIXA *pixa, l_int32 index, PIX *pix, BOX *box)
 
l_ok pixaInsertPix (PIXA *pixa, l_int32 index, PIX *pixs, BOX *box)
 
l_ok pixaRemovePix (PIXA *pixa, l_int32 index)
 
l_ok pixaRemovePixAndSave (PIXA *pixa, l_int32 index, PIX **ppix, BOX **pbox)
 
l_ok pixaRemoveSelected (PIXA *pixa, NUMA *naindex)
 
l_ok pixaInitFull (PIXA *pixa, PIX *pix, BOX *box)
 
l_ok pixaClear (PIXA *pixa)
 
l_ok pixaJoin (PIXA *pixad, PIXA *pixas, l_int32 istart, l_int32 iend)
 
PIXApixaInterleave (PIXA *pixa1, PIXA *pixa2, l_int32 copyflag)
 
l_ok pixaaJoin (PIXAA *paad, PIXAA *paas, l_int32 istart, l_int32 iend)
 
PIXAApixaaCreate (l_int32 n)
 
PIXAApixaaCreateFromPixa (PIXA *pixa, l_int32 n, l_int32 type, l_int32 copyflag)
 
void pixaaDestroy (PIXAA **ppaa)
 
l_ok pixaaAddPixa (PIXAA *paa, PIXA *pixa, l_int32 copyflag)
 
l_ok pixaaAddPix (PIXAA *paa, l_int32 index, PIX *pix, BOX *box, l_int32 copyflag)
 
l_ok pixaaAddBox (PIXAA *paa, BOX *box, l_int32 copyflag)
 
l_int32 pixaaGetCount (PIXAA *paa, NUMA **pna)
 
PIXApixaaGetPixa (PIXAA *paa, l_int32 index, l_int32 accesstype)
 
BOXApixaaGetBoxa (PIXAA *paa, l_int32 accesstype)
 
PIXpixaaGetPix (PIXAA *paa, l_int32 index, l_int32 ipix, l_int32 accessflag)
 
l_ok pixaaVerifyDepth (PIXAA *paa, l_int32 *psame, l_int32 *pmaxd)
 
l_ok pixaaVerifyDimensions (PIXAA *paa, l_int32 *psame, l_int32 *pmaxw, l_int32 *pmaxh)
 
l_int32 pixaaIsFull (PIXAA *paa, l_int32 *pfull)
 
l_ok pixaaInitFull (PIXAA *paa, PIXA *pixa)
 
l_ok pixaaReplacePixa (PIXAA *paa, l_int32 index, PIXA *pixa)
 
l_ok pixaaClear (PIXAA *paa)
 
l_ok pixaaTruncate (PIXAA *paa)
 
PIXApixaRead (const char *filename)
 
PIXApixaReadStream (FILE *fp)
 
PIXApixaReadMem (const l_uint8 *data, size_t size)
 
l_ok pixaWriteDebug (const char *fname, PIXA *pixa)
 
l_ok pixaWrite (const char *filename, PIXA *pixa)
 
l_ok pixaWriteStream (FILE *fp, PIXA *pixa)
 
l_ok pixaWriteMem (l_uint8 **pdata, size_t *psize, PIXA *pixa)
 
PIXApixaReadBoth (const char *filename)
 
PIXAApixaaReadFromFiles (const char *dirname, const char *substr, l_int32 first, l_int32 nfiles)
 
PIXAApixaaRead (const char *filename)
 
PIXAApixaaReadStream (FILE *fp)
 
PIXAApixaaReadMem (const l_uint8 *data, size_t size)
 
l_ok pixaaWrite (const char *filename, PIXAA *paa)
 
l_ok pixaaWriteStream (FILE *fp, PIXAA *paa)
 
l_ok pixaaWriteMem (l_uint8 **pdata, size_t *psize, PIXAA *paa)
 

Variables

static const size_t MaxInitPtrArraySize = 100000
 
static const size_t MaxPixaPtrArraySize = 5000000
 
static const size_t MaxPixaaPtrArraySize = 1000000
 
static const size_t InitialPtrArraySize = 20
 

Detailed Description


     Pixa creation, destruction, copying
          PIXA     *pixaCreate()
          PIXA     *pixaCreateFromPix()
          PIXA     *pixaCreateFromBoxa()
          PIXA     *pixaSplitPix()
          void      pixaDestroy()
          PIXA     *pixaCopy()

     Pixa addition
          l_int32   pixaAddPix()
          l_int32   pixaAddBox()
          static l_int32   pixaExtendArray()
          l_int32   pixaExtendArrayToSize()

     Pixa accessors
          l_int32   pixaGetCount()
          PIX      *pixaGetPix()
          l_int32   pixaGetPixDimensions()
          BOXA     *pixaGetBoxa()
          l_int32   pixaGetBoxaCount()
          BOX      *pixaGetBox()
          l_int32   pixaGetBoxGeometry()
          l_int32   pixaSetBoxa()
          PIX     **pixaGetPixArray()
          l_int32   pixaVerifyDepth()
          l_int32   pixaVerifyDimensions()
          l_int32   pixaIsFull()
          l_int32   pixaCountText()
          l_int32   pixaSetText()
          void   ***pixaGetLinePtrs()

     Pixa output info
          l_int32   pixaWriteStreamInfo()

     Pixa array modifiers
          l_int32   pixaReplacePix()
          l_int32   pixaInsertPix()
          l_int32   pixaRemovePix()
          l_int32   pixaRemovePixAndSave()
          l_int32   pixaRemoveSelected()
          l_int32   pixaInitFull()
          l_int32   pixaClear()

     Pixa and Pixaa combination
          l_int32   pixaJoin()
          PIXA     *pixaInterleave()
          l_int32   pixaaJoin()

     Pixaa creation, destruction
          PIXAA    *pixaaCreate()
          PIXAA    *pixaaCreateFromPixa()
          void      pixaaDestroy()

     Pixaa addition
          l_int32   pixaaAddPixa()
          static l_int32   pixaaExtendArray()
          l_int32   pixaaAddPix()
          l_int32   pixaaAddBox()

     Pixaa accessors
          l_int32   pixaaGetCount()
          PIXA     *pixaaGetPixa()
          BOXA     *pixaaGetBoxa()
          PIX      *pixaaGetPix()
          l_int32   pixaaVerifyDepth()
          l_int32   pixaaVerifyDimensions()
          l_int32   pixaaIsFull()

     Pixaa array modifiers
          l_int32   pixaaInitFull()
          l_int32   pixaaReplacePixa()
          l_int32   pixaaClear()
          l_int32   pixaaTruncate()

     Pixa serialized I/O  (requires png support)
          PIXA     *pixaRead()
          PIXA     *pixaReadStream()
          PIXA     *pixaReadMem()
          l_int32   pixaWriteDebug()
          l_int32   pixaWrite()
          l_int32   pixaWriteStream()
          l_int32   pixaWriteMem()
          PIXA     *pixaReadBoth()

     Pixaa serialized I/O  (requires png support)
          PIXAA    *pixaaReadFromFiles()
          PIXAA    *pixaaRead()
          PIXAA    *pixaaReadStream()
          PIXAA    *pixaaReadMem()
          l_int32   pixaaWrite()
          l_int32   pixaaWriteStream()
          l_int32   pixaaWriteMem()


  Important note on reference counting:
    Reference counting for the Pixa is analogous to that for the Boxa.
    See pix.h for details.   pixaCopy() provides three possible modes
    of copy.  The basic rule is that however a Pixa is obtained
    (e.g., from pixaCreate*(), pixaCopy(), or a Pixaa accessor),
    it is necessary to call pixaDestroy() on it.

Definition in file pixabasic.c.

Function Documentation

◆ pixaaAddBox()

l_ok pixaaAddBox ( PIXAA paa,
BOX box,
l_int32  copyflag 
)

pixaaAddBox()

Parameters
[in]paa
[in]box
[in]copyflagL_INSERT, L_COPY, L_CLONE
Returns
0 if OK, 1 on error
Notes:
     (1) The box can be used, for example, to hold the support region
         of a pixa that is being added to the pixaa.

Definition at line 2016 of file pixabasic.c.

References Pixaa::boxa, boxaAddBox(), L_CLONE, L_COPY, and L_INSERT.

◆ pixaaAddPix()

l_ok pixaaAddPix ( PIXAA paa,
l_int32  index,
PIX pix,
BOX box,
l_int32  copyflag 
)

pixaaAddPix()

Parameters
[in]paainput paa
[in]indexindex of pixa in paa
[in]pixto be added
[in]box[optional] to be added
[in]copyflagL_INSERT, L_COPY, L_CLONE
Returns
0 if OK; 1 on error

Definition at line 1979 of file pixabasic.c.

References L_CLONE, pixaAddBox(), pixaAddPix(), pixaaGetPixa(), and pixaDestroy().

Referenced by recogAddAllSamples(), and recogTrainingFinished().

◆ pixaaAddPixa()

l_ok pixaaAddPixa ( PIXAA paa,
PIXA pixa,
l_int32  copyflag 
)

pixaaAddPixa()

Parameters
[in]paa
[in]pixato be added
[in]copyflagL_INSERT inserts the pixa directly; L_COPY makes a new pixa and copies each pix and each box; L_CLONE gives a new handle to the input pixa; L_COPY_CLONE makes a new pixa and inserts clones of all pix and boxes
Returns
0 if OK; 1 on error

Definition at line 1898 of file pixabasic.c.

References L_CLONE, L_COPY, L_COPY_CLONE, L_INSERT, Pixaa::n, Pixaa::nalloc, Pixaa::pixa, pixaaExtendArray(), pixaaGetCount(), pixaCopy(), and pixaDestroy().

Referenced by pixaaCreateFromPixa(), pixaaJoin(), pixaaReadFromFiles(), pixaaScaleToSize(), pixaaScaleToSizeVar(), pixaaSelectRange(), pixaSort2dByIndex(), recogAddAllSamples(), and recogDebugAverages().

◆ pixaaClear()

l_ok pixaaClear ( PIXAA paa)

pixaaClear()

Parameters
[in]paa
Returns
0 if OK, 1 on error
Notes:
     (1) This destroys all pixa in the pixaa, and nulls the ptrs
         in the pixa ptr array.

Definition at line 2406 of file pixabasic.c.

References Pixaa::n, Pixaa::pixa, pixaaGetCount(), and pixaDestroy().

◆ pixaaCreate()

PIXAA* pixaaCreate ( l_int32  n)

pixaaCreate()

Parameters
[in]ninitial number of pixa ptrs
Returns
paa, or NULL on error
Notes:
     (1) A pixaa provides a 2-level hierarchy of images.
         A common use is for segmentation masks, which are
         inexpensive to store in png format.
     (2) For example, suppose you want a mask for each textline
         in a two-column page.  The textline masks for each column
         can be represented by a pixa, of which there are 2 in the pixaa.
         The boxes for the textline mask components within a column
         can have their origin referred to the column rather than the page.
         Then the boxa field can be used to represent the two box (regions)
         for the columns, and the (x,y) components of each box can
         be used to get the absolute position of the textlines on
         the page.

Definition at line 1758 of file pixabasic.c.

Referenced by pixaaCreateFromPixa(), pixaaReadFromFiles(), pixaaScaleToSize(), pixaaScaleToSizeVar(), pixaaSelectRange(), pixaSort2dByIndex(), recogDebugAverages(), and recogTrainingFinished().

◆ pixaaCreateFromPixa()

PIXAA* pixaaCreateFromPixa ( PIXA pixa,
l_int32  n,
l_int32  type,
l_int32  copyflag 
)

pixaaCreateFromPixa()

Parameters
[in]pixa
[in]nnumber specifying subdivision of pixa
[in]typeL_CHOOSE_CONSECUTIVE, L_CHOOSE_SKIP_BY
[in]copyflagL_CLONE, L_COPY
Returns
paa, or NULL on error
Notes:
     (1) This subdivides a pixa into a set of smaller pixa that
         are accumulated into a pixaa.
     (2) If type == L_CHOOSE_CONSECUTIVE, the first 'n' pix are
         put in a pixa and added to pixaa, then the next 'n', etc.
         If type == L_CHOOSE_SKIP_BY, the first pixa is made by
         aggregating pix[0], pix[n], pix[2*n], etc.
     (3) The copyflag specifies if each new pix is a copy or a clone.

Definition at line 1799 of file pixabasic.c.

References L_CHOOSE_CONSECUTIVE, L_CHOOSE_SKIP_BY, L_CLONE, L_COPY, L_INSERT, pixaaAddPixa(), pixaaCreate(), pixaAddPix(), pixaCreate(), pixaGetCount(), and pixaGetPix().

◆ pixaAddBox()

l_ok pixaAddBox ( PIXA pixa,
BOX box,
l_int32  copyflag 
)

◆ pixaAddPix()

l_ok pixaAddPix ( PIXA pixa,
PIX pix,
l_int32  copyflag 
)

pixaAddPix()

Parameters
[in]pixa
[in]pixto be added
[in]copyflagL_INSERT, L_COPY, L_CLONE
Returns
0 if OK; 1 on error

Definition at line 493 of file pixabasic.c.

References L_CLONE, L_COPY, L_INSERT, Pixa::n, Pixa::nalloc, Pixa::pix, pixaExtendArray(), pixaGetCount(), pixClone(), pixCopy(), and pixDestroy().

Referenced by boxaCombineOverlaps(), boxaCombineOverlapsInPair(), boxaCompareRegions(), boxaDisplayTiled(), dewarpaShowArrays(), evalColorfillData(), fpixaDisplayQuadtree(), makeColorfillTestData(), pixaaAddPix(), pixaaCreateFromPixa(), pixaAddBorderGeneral(), pixaAddPixWithText(), pixaAddTextlines(), pixaAddTextNumber(), pixaaDisplayByPixa(), pixaaDisplayTiledAndScaled(), pixaaFlattenToPixa(), pixaClipToForeground(), pixaClipToPix(), pixaConstrainedSelect(), pixaConvertTo1(), pixaConvertTo32(), pixaConvertTo8(), pixaConvertTo8Colormap(), pixaConvertToNUpPixa(), pixaConvertToSameDepth(), pixaCopy(), pixaCreateFromBoxa(), pixaCreateFromPix(), pixaCreateFromPixacomp(), pixaDisplayBoxaa(), pixaDisplayMultiTiled(), pixaDisplayOnLattice(), pixaDisplayPairTiledInColumns(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledByIndex(), pixaDisplayTiledInRows(), pixaDisplayTiledWithText(), pixaInterleave(), pixaJoin(), pixaModifyStrokeWidth(), pixaMorphSequenceByComponent(), pixaReadFilesSA(), pixaReadMemMultipageTiff(), pixaReadMultipageTiff(), pixaRotateOrth(), pixaScaleToSizeRel(), pixaSelectRange(), pixaSelectWithIndicator(), pixaSelectWithString(), pixaSetStrokeWidth(), pixaSort2dByIndex(), pixaSortByIndex(), pixaSplitIntoFiles(), pixaSplitPix(), pixaThinConnected(), pixaTranslate(), pixAutoPhotoinvert(), pixClipRectangles(), pixCompareGrayByHisto(), pixCompareWithTranslation(), pixDecideIfTable(), pixDisplayColorArray(), pixDisplayOutliers(), pixMakeGamutRGB(), recogAddDigitPadTemplates(), recogAverageSamples(), recogDebugAverages(), recogDisplayOutlier(), recogFilterPixaBySize(), recogShowAverageTemplates(), recogShowMatch(), recogShowMatchesInRange(), recogTrainFromBoot(), selaAddCrossJunctions(), selaAddTJunctions(), selaDisplayInPix(), showExtractNumbers(), and wshedSaveBasin().

◆ pixaaDestroy()

void pixaaDestroy ( PIXAA **  ppaa)

pixaaDestroy()

Parameters
[in,out]ppaause ptr address so it will be nulled
Returns
void

Definition at line 1859 of file pixabasic.c.

References Pixaa::boxa, boxaDestroy(), Pixaa::n, Pixaa::pixa, and pixaDestroy().

Referenced by pixGetWordsInTextlines(), recogDestroy(), recogFilterPixaBySize(), and recogTrainingFinished().

◆ pixaaExtendArray()

static l_int32 pixaaExtendArray ( PIXAA paa)
static

pixaaExtendArray()

Parameters
[in]paa
Returns
0 if OK; 1 on error
Notes:
     (1) The max number of pixa ptrs is 1M.

Definition at line 1946 of file pixabasic.c.

References Pixaa::nalloc.

Referenced by pixaaAddPixa().

◆ pixaaGetBoxa()

BOXA* pixaaGetBoxa ( PIXAA paa,
l_int32  accesstype 
)

pixaaGetBoxa()

Parameters
[in]paa
[in]accesstypeL_COPY, L_CLONE
Returns
boxa, or NULL on error
Notes:
     (1) L_COPY returns a copy; L_CLONE returns a new reference to the boxa.
     (2) In both cases, invoke boxaDestroy() on the returned boxa.

Definition at line 2132 of file pixabasic.c.

References Pixaa::boxa, boxaCopy(), L_CLONE, and L_COPY.

Referenced by pixaaDisplay().

◆ pixaaGetCount()

◆ pixaaGetPix()

PIX* pixaaGetPix ( PIXAA paa,
l_int32  index,
l_int32  ipix,
l_int32  accessflag 
)

pixaaGetPix()

Parameters
[in]paa
[in]indexindex into the pixa array in the pixaa
[in]ipixindex into the pix array in the pixa
[in]accessflagL_COPY or L_CLONE
Returns
pix, or NULL on error

Definition at line 2154 of file pixabasic.c.

References L_CLONE, pixaaGetPixa(), pixaDestroy(), and pixaGetPix().

Referenced by recogDebugAverages(), recogDisplayOutlier(), and recogShowPath().

◆ pixaaGetPixa()

PIXA* pixaaGetPixa ( PIXAA paa,
l_int32  index,
l_int32  accesstype 
)

pixaaGetPixa()

Parameters
[in]paa
[in]indexto the index-th pixa
[in]accesstypeL_COPY, L_CLONE, L_COPY_CLONE
Returns
pixa, or NULL on error
Notes:
     (1) L_COPY makes a new pixa with a copy of every pix
     (2) L_CLONE just makes a new reference to the pixa,
         and bumps the counter.  You would use this, for example,
         when you need to extract some data from a pix within a
         pixa within a pixaa.
     (3) L_COPY_CLONE makes a new pixa with a clone of every pix
         and box
     (4) In all cases, you must invoke pixaDestroy() on the returned pixa

Definition at line 2096 of file pixabasic.c.

References L_CLONE, L_COPY, L_COPY_CLONE, Pixaa::n, Pixaa::pixa, and pixaCopy().

Referenced by pixaaAddPix(), pixaaDisplay(), pixaaDisplayByPixa(), pixaaDisplayTiledAndScaled(), pixaaFlattenToPixa(), pixaaGetCount(), pixaaGetPix(), pixaaIsFull(), pixaaJoin(), pixaaScaleToSize(), pixaaScaleToSizeVar(), pixaaSelectRange(), pixaaSizeRange(), pixaaTruncate(), pixaaVerifyDepth(), pixaaVerifyDimensions(), pixaaWriteStream(), recogAddAllSamples(), recogAddCharstrLabels(), recogAverageSamples(), recogDebugAverages(), recogFilterPixaBySize(), and recogTrainingFinished().

◆ pixaaInitFull()

l_ok pixaaInitFull ( PIXAA paa,
PIXA pixa 
)

pixaaInitFull()

Parameters
[in]paatypically empty
[in]pixato be replicated into the entire pixa ptr array
Returns
0 if OK, 1 on error
Notes:
     (1) This initializes a pixaa by filling up the entire pixa ptr array
         with copies of pixa.  Any existing pixa are destroyed.
     (2) Example usage.  This function is useful to prepare for a
         random insertion (or replacement) of pixa into a pixaa.
         To randomly insert pixa into a pixaa, up to some index "max":
            Pixaa *paa = pixaaCreate(max);
            Pixa *pixa = pixaCreate(1);  // if you want little memory
            pixaaInitFull(paa, pixa);  // copy it to entire array
            pixaDestroy(&pixa);  // no longer needed
         The initialization allows the pixaa to always be properly filled.

Definition at line 2335 of file pixabasic.c.

References L_COPY, Pixaa::n, Pixaa::nalloc, pixaaReplacePixa(), and pixaCopy().

Referenced by recogTrainingFinished().

◆ pixaaIsFull()

l_int32 pixaaIsFull ( PIXAA paa,
l_int32 *  pfull 
)

pixaaIsFull()

Parameters
[in]paa
[out]pfull1 if all pixa in the paa have full pix arrays
Returns
return 0 if OK, 1 on error
Notes:
     (1) Does not require boxa associated with each pixa to be full.

Definition at line 2285 of file pixabasic.c.

References L_CLONE, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), and pixaIsFull().

◆ pixaaJoin()

l_ok pixaaJoin ( PIXAA paad,
PIXAA paas,
l_int32  istart,
l_int32  iend 
)

pixaaJoin()

Parameters
[in]paaddest pixaa; add to this one
[in]paas[optional] source pixaa; add from this one
[in]istartstarting index in pixaas
[in]iendending index in pixaas; use -1 to cat all
Returns
0 if OK, 1 on error
Notes:
     (1) This appends a clone of each indicated pixa in paas to pixaad
     (2) istart < 0 is taken to mean 'read from the start' (istart = 0)
     (3) iend < 0 means 'read to the end'

Definition at line 1702 of file pixabasic.c.

References L_CLONE, L_INSERT, pixaaAddPixa(), pixaaGetCount(), and pixaaGetPixa().

◆ pixaaRead()

PIXAA* pixaaRead ( const char *  filename)

pixaaRead()

Parameters
[in]filename
Returns
paa, or NULL on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 2880 of file pixabasic.c.

References fopenReadStream(), and pixaaReadStream().

◆ pixaaReadFromFiles()

PIXAA* pixaaReadFromFiles ( const char *  dirname,
const char *  substr,
l_int32  first,
l_int32  nfiles 
)

pixaaReadFromFiles()

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
paa, or NULL on error or if no pixa files are found.
Notes:
     (1) The files must be serialized pixa files (e.g., *.pa)
         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 2832 of file pixabasic.c.

References getSortedPathnamesInDirectory(), L_INSERT, L_NOCOPY, pixaaAddPixa(), pixaaCreate(), pixaRead(), sarrayDestroy(), sarrayGetCount(), and sarrayGetString().

◆ pixaaReadMem()

PIXAA* pixaaReadMem ( const l_uint8 *  data,
size_t  size 
)

pixaaReadMem()

Parameters
[in]dataof serialized pixaa
[in]sizeof data in bytes
Returns
paa, or NULL on error

Definition at line 2977 of file pixabasic.c.

References fopenReadFromMemory(), and pixaaReadStream().

◆ pixaaReadStream()

PIXAA* pixaaReadStream ( FILE *  fp)

pixaaReadStream()

Parameters
[in]fpfile stream
Returns
paa, or NULL on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.
     (2) It is OK for the pixaa to be empty.

Definition at line 2916 of file pixabasic.c.

References PIXAA_VERSION_NUMBER.

Referenced by pixaaRead(), and pixaaReadMem().

◆ pixaaReplacePixa()

l_ok pixaaReplacePixa ( PIXAA paa,
l_int32  index,
PIXA pixa 
)

pixaaReplacePixa()

Parameters
[in]paa
[in]indexto the index-th pixa
[in]pixainsert to replace existing one
Returns
0 if OK, 1 on error
Notes:
     (1) This allows random insertion of a pixa into a pixaa, with
         destruction of any existing pixa at that location.
         The input pixa is now owned by the pixaa.
     (2) No other pixa in the array are affected.
     (3) The index must be within the allowed set.

Definition at line 2375 of file pixabasic.c.

References Pixaa::n, Pixaa::pixa, and pixaDestroy().

Referenced by pixaaInitFull().

◆ pixaaTruncate()

l_ok pixaaTruncate ( PIXAA paa)

pixaaTruncate()

Parameters
[in]paa
Returns
0 if OK, 1 on error
Notes:
     (1) This identifies the largest index containing a pixa that
         has any pix within it, destroys all pixa above that index,
         and resets the count.

Definition at line 2435 of file pixabasic.c.

References L_CLONE, Pixaa::n, Pixaa::pixa, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), and pixaGetCount().

Referenced by recogTrainingFinished().

◆ pixaaVerifyDepth()

l_ok pixaaVerifyDepth ( PIXAA paa,
l_int32 *  psame,
l_int32 *  pmaxd 
)

pixaaVerifyDepth()

Parameters
[in]paa
[out]psame1 if all pix have the same depth; 0 otherwise
[out]pmaxd[optional] max depth of all pix in pixaa
Returns
0 if OK; 1 on error
Notes:
     (1) It is considered to be an error if any pixa have no pix.

Definition at line 2185 of file pixabasic.c.

References L_CLONE, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), and pixaVerifyDepth().

◆ pixaaVerifyDimensions()

l_ok pixaaVerifyDimensions ( PIXAA paa,
l_int32 *  psame,
l_int32 *  pmaxw,
l_int32 *  pmaxh 
)

pixaaVerifyDimensions()

Parameters
[in]paa
[out]psame1 if all pix have the same depth; 0 otherwise
[out]pmaxw[optional] max width of all pix in pixaa
[out]pmaxh[optional] max height of all pix in pixaa
Returns
0 if OK; 1 on error
Notes:
     (1) It is considered to be an error if any pixa have no pix.

Definition at line 2233 of file pixabasic.c.

References L_CLONE, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), and pixaVerifyDimensions().

◆ pixaaWrite()

l_ok pixaaWrite ( const char *  filename,
PIXAA paa 
)

pixaaWrite()

Parameters
[in]filename
[in]paa
Returns
0 if OK, 1 on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 3009 of file pixabasic.c.

References fopenWriteStream(), and pixaaWriteStream().

◆ pixaaWriteMem()

l_ok pixaaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PIXAA paa 
)

pixaaWriteMem()

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

Definition at line 3092 of file pixabasic.c.

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

◆ pixaaWriteStream()

l_ok pixaaWriteStream ( FILE *  fp,
PIXAA paa 
)

pixaaWriteStream()

Parameters
[in]fpfile stream opened for "wb"
[in]paa
Returns
0 if OK, 1 on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 3048 of file pixabasic.c.

References Pixaa::boxa, boxaWriteStream(), L_CLONE, PIXAA_VERSION_NUMBER, pixaaGetCount(), pixaaGetPixa(), pixaDestroy(), and pixaWriteStream().

Referenced by pixaaWrite(), and pixaaWriteMem().

◆ pixaClear()

l_ok pixaClear ( PIXA pixa)

pixaClear()

Parameters
[in]pixa
Returns
0 if OK, 1 on error
Notes:
     (1) This destroys all pix in the pixa, as well as
         all boxes in the boxa.  The ptrs in the pix ptr array
         are all null'd.  The number of allocated pix, n, is set to 0.

Definition at line 1549 of file pixabasic.c.

References Pixa::boxa, boxaClear(), Pixa::n, Pixa::pix, pixaGetCount(), and pixDestroy().

◆ pixaCopy()

PIXA* pixaCopy ( PIXA pixa,
l_int32  copyflag 
)

pixaCopy()

Parameters
[in]pixa
[in]copyflagsee pix.h for details: L_COPY makes a new pixa and copies each pix and each box; L_CLONE gives a new ref-counted handle to the input pixa; L_COPY_CLONE makes a new pixa and inserts clones of all pix and boxes
Returns
new pixa, or NULL on error

Definition at line 442 of file pixabasic.c.

References L_CLONE, L_COPY, L_COPY_CLONE, L_INSERT, Pixa::n, pixaAddBox(), pixaAddPix(), pixaCreate(), pixaGetBox(), pixaGetBoxaCount(), pixaGetPix(), and Pixa::refcount.

Referenced by pixaaAddPixa(), pixaaGetPixa(), pixaaInitFull(), pixaConvertToSameDepth(), pixaDisplayMultiTiled(), pixaDisplayOnLattice(), pixaDisplayTiled(), pixaExtendByMorph(), pixaRotateOrth(), pixaScaleToSize(), pixaSelectToPdf(), pixaSelectWithIndicator(), pixaSort(), pixaTranslate(), recogFilterPixaBySize(), recogTrainFromBoot(), and wshedBasins().

◆ pixaCountText()

l_ok pixaCountText ( PIXA pixa,
l_int32 *  pntext 
)

pixaCountText()

Parameters
[in]pixa
[out]pntextnumber of pix with non-empty text strings
Returns
0 if OK, 1 on error.
Notes:
     (1) All pix have non-empty text strings if the returned value ntext
         equals the pixa count.

Definition at line 1041 of file pixabasic.c.

References L_CLONE, pixaGetCount(), pixaGetPix(), pixDestroy(), and pixGetText().

Referenced by recogCreateFromPixaNoFinish().

◆ pixaCreate()

PIXA* pixaCreate ( l_int32  n)

pixaCreate()

Parameters
[in]ninitial number of ptrs
Returns
pixa, or NULL on error
Notes:
     (1) This creates an empty boxa.

Definition at line 167 of file pixabasic.c.

Referenced by bilateralCreate(), boxaCompareRegions(), boxaDisplayTiled(), dewarpaShowArrays(), fpixaDisplayQuadtree(), makeColorfillTestData(), partifyFiles(), pixaaCreateFromPixa(), pixaAddBorderGeneral(), pixaAddTextlines(), pixaAddTextNumber(), pixaaDisplayByPixa(), pixaaDisplayTiledAndScaled(), pixaaFlattenToPixa(), pixaClipToForeground(), pixaClipToPix(), pixaConstrainedSelect(), pixaConvertTo1(), pixaConvertTo32(), pixaConvertTo8(), pixaConvertTo8Colormap(), pixaConvertToGivenDepth(), pixaConvertToNUpPixa(), pixaConvertToSameDepth(), pixaCopy(), pixaCreateFromBoxa(), pixaCreateFromPix(), pixaCreateFromPixacomp(), pixaDisplayBoxaa(), pixaDisplayMultiTiled(), pixaDisplayOnLattice(), pixaDisplayPairTiledInColumns(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledByIndex(), pixaDisplayTiledInColumns(), pixaDisplayTiledInRows(), pixaDisplayTiledWithText(), pixaInterleave(), pixaMakeFromTiledPix(), pixaMakeFromTiledPixa(), pixaModifyStrokeWidth(), pixaMorphSequenceByComponent(), pixaReadFilesSA(), pixaReadMemMultipageTiff(), pixaReadMultipageTiff(), pixaRotateOrth(), pixaScale(), pixaScaleBySampling(), pixaScaleToSize(), pixaScaleToSizeRel(), pixaSelectRange(), pixaSelectWithIndicator(), pixaSelectWithString(), pixaSetStrokeWidth(), pixaSort2dByIndex(), pixaSortByIndex(), pixaSplitIntoFiles(), pixaSplitPix(), pixaThinConnected(), pixaTranslate(), pixClipRectangles(), pixCompareGrayByHisto(), pixComparePhotoRegionsByHisto(), pixCompareWithTranslation(), pixDisplayColorArray(), pixDisplayOutliers(), pixMakeGamutRGB(), recogAddAllSamples(), recogAverageSamples(), recogDebugAverages(), recogDisplayOutlier(), recogFilterPixaBySize(), recogIdentifyPixa(), recogShowAverageTemplates(), recogShowMatch(), recogShowMatchesInRange(), recogTrainFromBoot(), recogTrainingFinished(), selaAddCrossJunctions(), selaAddTJunctions(), selaDisplayInPix(), and showExtractNumbers().

◆ pixaCreateFromBoxa()

PIXA* pixaCreateFromBoxa ( PIX pixs,
BOXA boxa,
l_int32  start,
l_int32  num,
l_int32 *  pcropwarn 
)

pixaCreateFromBoxa()

Parameters
[in]pixs
[in]boxa
[in]startfirst box to use
[in]numnumber of boxes; use 0 to go to the end
[out]pcropwarn[optional] TRUE if the boxa extent is larger than pixs.
Returns
pixad, or NULL on error
Notes:
     (1) This simply extracts from pixs the region corresponding to each
         box in the boxa.  To extract all the regions, set both start
         and num to 0.
     (2) The 5th 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.

Definition at line 268 of file pixabasic.c.

References boxaGetBox(), boxaGetCount(), boxaGetExtent(), boxDestroy(), L_COPY, L_INSERT, pixaAddBox(), pixaAddPix(), pixaCreate(), pixClipRectangle(), and pixGetDimensions().

Referenced by pixaMakeFromTiledPix(), and pixGetWordsInTextlines().

◆ pixaCreateFromPix()

PIXA* pixaCreateFromPix ( PIX pixs,
l_int32  n,
l_int32  cellw,
l_int32  cellh 
)

pixaCreateFromPix()

Parameters
[in]pixswith individual components on a lattice
[in]nnumber of components
[in]cellwwidth of each cell
[in]cellhheight of each cell
Returns
pixa, or NULL on error
Notes:
     (1) For bpp = 1, we truncate each retrieved pix to the ON
         pixels, which we assume for now start at (0,0)

Definition at line 204 of file pixabasic.c.

References L_COPY, L_INSERT, PIX_SRC, pixaAddPix(), pixaCreate(), pixaDestroy(), pixClipToForeground(), pixCreate(), pixDestroy(), pixGetDimensions(), and pixRasterop().

◆ pixaDestroy()

void pixaDestroy ( PIXA **  ppixa)

pixaDestroy()

Parameters
[in,out]ppixause ptr address so it will be nulled
Notes:
     (1) Decrements the ref count and, if 0, destroys the pixa.
     (2) Always nulls the input ptr.

Definition at line 404 of file pixabasic.c.

References Pixa::boxa, boxaDestroy(), Pixa::n, Pixa::pix, pixDestroy(), and Pixa::refcount.

Referenced by bilateralDestroy(), bmfDestroy(), boxaCompareRegions(), boxaDisplayTiled(), convertTiffMultipageToPdf(), convertToNUpPixa(), evalColorfillData(), l_colorfillDestroy(), pixaaAddPix(), pixaaAddPixa(), pixaaClear(), pixaaDestroy(), pixaaDisplay(), pixaaDisplayByPixa(), pixaaDisplayTiledAndScaled(), pixaaFlattenToPixa(), pixaaGetCount(), pixaaGetPix(), pixaaIsFull(), pixaaReplacePixa(), pixaaScaleToSize(), pixaaScaleToSizeVar(), pixaaSizeRange(), pixaaTruncate(), pixaaVerifyDepth(), pixaaVerifyDimensions(), pixaaWriteStream(), pixaCompareInPdf(), pixacompDisplayTiledAndScaled(), pixaConvertToNUpPixa(), pixaConvertToSameDepth(), pixaCreateFromPix(), pixaDisplayMultiTiled(), pixaDisplayPairTiledInColumns(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledByIndex(), pixaDisplayTiledInRows(), pixaDisplayTiledWithText(), pixaMakeFromTiledPixa(), pixaMorphSequenceByComponent(), pixaRotateOrth(), pixaSelectToPdf(), pixaSplitPix(), pixaTranslate(), pixCompareGrayByHisto(), pixComparePhotoRegionsByHisto(), pixCompareWithTranslation(), pixDisplayColorArray(), pixDisplayOutliers(), pixGetGrayHistogramTiled(), pixGetWordsInTextlines(), pixMakeGamutRGB(), pixMorphSequenceByComponent(), pixSelectByArea(), pixSelectByAreaFraction(), pixSelectByPerimSizeRatio(), pixSelectByPerimToAreaRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), recogAddAllSamples(), recogAddCharstrLabels(), recogAddDigitPadTemplates(), recogAverageSamples(), recogCreateFromRecog(), recogDebugAverages(), recogDestroy(), recogDisplayOutlier(), recogFilterPixaBySize(), recogMakeBootDigitRecog(), recogMakeBootDigitTemplates(), recogPadDigitTrainingSet(), recogRemoveOutliers1(), recogRemoveOutliers2(), recogShowAverageTemplates(), recogShowMatch(), recogTrainFromBoot(), recogTrainingFinished(), selaDisplayInPix(), wshedDestroy(), wshedRenderColors(), and wshedRenderFill().

◆ pixaExtendArray()

static l_int32 pixaExtendArray ( PIXA pixa)
static

pixaExtendArray()

Parameters
[in]pixa
Returns
0 if OK; 1 on error
Notes:
     (1) Doubles the size of the pixa and boxa ptr arrays.
     (2) The max number of pix in the array is 5 million.

Definition at line 569 of file pixabasic.c.

References Pixa::nalloc, and pixaExtendArrayToSize().

Referenced by pixaAddPix(), and pixaInsertPix().

◆ pixaExtendArrayToSize()

l_ok pixaExtendArrayToSize ( PIXA pixa,
size_t  size 
)

pixaExtendArrayToSize()

Parameters
[in]pixa
[in]sizenumber of pix ptrs in new array
Returns
0 if OK; 1 on error
Notes:
     (1) If necessary, reallocs new pixa and boxa ptrs arrays to size.
         The pixa and boxa ptr arrays must always be equal in size.
     (2) The max number of pix ptrs is 5M.

Definition at line 593 of file pixabasic.c.

References Pixa::nalloc.

Referenced by pixaExtendArray().

◆ pixaGetBox()

BOX* pixaGetBox ( PIXA pixa,
l_int32  index,
l_int32  accesstype 
)

pixaGetBox()

Parameters
[in]pixa
[in]indexto the index-th pix
[in]accesstypeL_COPY or L_CLONE
Returns
box if null, not automatically an error, or NULL on error
Notes:
     (1) There is always a boxa with a pixa, and it is initialized so
         that each box ptr is NULL.
     (2) In general, we expect that there is either a box associated
         with each pix, or no boxes at all in the boxa.
     (3) Having no boxes is thus not an automatic error.  Whether it
         is an actual error is determined by the calling program.
         If the caller expects to get a box, it is an error; see, e.g.,
         pixaGetBoxGeometry().

Definition at line 764 of file pixabasic.c.

References Boxa::box, Pixa::boxa, boxClone(), boxCopy(), L_CLONE, L_COPY, and Boxa::n.

Referenced by evalColorfillData(), pixaAddBorderGeneral(), pixaaFlattenToPixa(), pixaClipToPix(), pixaCopy(), pixAddWithIndicator(), pixaGetBoxGeometry(), pixaInterleave(), pixaMorphSequenceByComponent(), pixaRotateOrth(), pixaSelectWithIndicator(), pixaSelectWithString(), pixaSort2dByIndex(), pixaSortByIndex(), and pixRemoveWithIndicator().

◆ pixaGetBoxa()

BOXA* pixaGetBoxa ( PIXA pixa,
l_int32  accesstype 
)

◆ pixaGetBoxaCount()

l_int32 pixaGetBoxaCount ( PIXA pixa)

◆ pixaGetBoxGeometry()

l_ok pixaGetBoxGeometry ( PIXA pixa,
l_int32  index,
l_int32 *  px,
l_int32 *  py,
l_int32 *  pw,
l_int32 *  ph 
)

pixaGetBoxGeometry()

Parameters
[in]pixa
[in]indexto the index-th box
[out]px,py,pw,ph[optional] each can be null
Returns
0 if OK, 1 on error

Definition at line 800 of file pixabasic.c.

References boxDestroy(), boxGetGeometry(), L_CLONE, Pixa::n, and pixaGetBox().

Referenced by pixaDisplayRandomCmap(), pixMorphSequenceByComponent(), and wshedRenderFill().

◆ pixaGetCount()

l_int32 pixaGetCount ( PIXA pixa)

pixaGetCount()

Parameters
[in]pixa
Returns
count, or 0 if no pixa

Definition at line 629 of file pixabasic.c.

References Pixa::n.

Referenced by bilateralApply(), boxaDisplayTiled(), boxaReconcileSidesByMedian(), evalColorfillData(), pixaAccumulateSamples(), pixaaCreateFromPixa(), pixaAddBorderGeneral(), pixaAddPix(), pixaAddTextlines(), pixaAddTextNumber(), pixaaFlattenToPixa(), pixaaGetCount(), pixaAnyColormaps(), pixaaTruncate(), pixaBinSort(), pixaCentroids(), pixaClear(), pixaClipToForeground(), pixaClipToPix(), pixaCompareInPdf(), pixaComparePhotoRegionsByHisto(), pixaConstrainedSelect(), pixaConvertTo1(), pixaConvertTo32(), pixaConvertTo8(), pixaConvertTo8Colormap(), pixaConvertToGivenDepth(), pixaConvertToNUpPixa(), pixaConvertToPdfData(), pixaConvertToSameDepth(), pixaCountPixels(), pixaCountText(), pixAddWithIndicator(), pixaDisplay(), pixaDisplayBoxaa(), pixaDisplayMultiTiled(), pixaDisplayOnLattice(), pixaDisplayPairTiledInColumns(), pixaDisplayRandomCmap(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledByIndex(), pixaDisplayTiledInColumns(), pixaDisplayTiledInRows(), pixaDisplayTiledWithText(), pixaDisplayUnsplit(), pixaEqual(), pixaFindAreaFraction(), pixaFindDimensions(), pixaFindPerimSizeRatio(), pixaFindPerimToAreaRatio(), pixaFindStrokeWidth(), pixaFindWidthHeightProduct(), pixaFindWidthHeightRatio(), pixaGetAlignedStats(), pixaGetDepthInfo(), pixaGetLinePtrs(), pixaHasColor(), pixaInsertPix(), pixaInterleave(), pixaIsFull(), pixaJoin(), pixaMakeSizeIndicator(), pixaModifyStrokeWidth(), pixaMorphSequenceByComponent(), pixaRemovePix(), pixaRemovePixAndSave(), pixaRenderComponent(), pixaRotateOrth(), pixaScale(), pixaScaleBySampling(), pixaScaleToSize(), pixaScaleToSizeRel(), pixaSelectByNumConnComp(), pixaSelectRange(), pixaSelectToPdf(), pixaSelectWithString(), pixaSetFullSizeBoxa(), pixaSetStrokeWidth(), pixaSetText(), pixaSizeRange(), pixaSort(), pixaSort2dByIndex(), pixaSortByIndex(), pixaSplitIntoFiles(), pixaThinConnected(), pixaTranslate(), pixaVerifyDepth(), pixaVerifyDimensions(), pixaWriteMemMultipageTiff(), pixaWriteMultipageTiff(), pixaWriteStream(), pixaWriteStreamInfo(), pixDisplayOutliers(), pixMorphSequenceByComponent(), pixReadBarcodes(), pixRemoveWithIndicator(), pixSelectByArea(), pixSelectByAreaFraction(), pixSelectByPerimSizeRatio(), pixSelectByPerimToAreaRatio(), pixSelectBySize(), pixSelectByWidthHeightRatio(), recogAddAllSamples(), recogAddCharstrLabels(), recogAddDigitPadTemplates(), recogAverageSamples(), recogCreateFromPixaNoFinish(), recogDebugAverages(), recogFilterPixaBySize(), recogIdentifyPixa(), recogShowMatchesInRange(), recogTrainFromBoot(), recogTrainingFinished(), selaCreateFromColorPixa(), and wshedRenderFill().

◆ pixaGetLinePtrs()

void*** pixaGetLinePtrs ( PIXA pixa,
l_int32 *  psize 
)

pixaGetLinePtrs()

Parameters
[in]pixaof pix that all have the same depth
[out]psize[optional] number of pix in the pixa
Returns
array of array of line ptrs, or NULL on error
Notes:
     (1) See pixGetLinePtrs() for details.
     (2) It is best if all pix in the pixa are the same size.
         The size of each line ptr array is equal to the height
         of the pix that it refers to.
     (3) This is an array of arrays.  To destroy it:
           for (i = 0; i < size; i++)
               LEPT_FREE(lineset[i]);
           LEPT_FREE(lineset);

Definition at line 1144 of file pixabasic.c.

References L_CLONE, pixaGetCount(), pixaGetPix(), pixaVerifyDepth(), pixDestroy(), and pixGetLinePtrs().

◆ pixaGetPix()

PIX* pixaGetPix ( PIXA pixa,
l_int32  index,
l_int32  accesstype 
)

pixaGetPix()

Parameters
[in]pixa
[in]indexto the index-th pix
[in]accesstypeL_COPY or L_CLONE
Returns
pix, or NULL on error

Definition at line 647 of file pixabasic.c.

References L_CLONE, L_COPY, Pixa::n, Pixa::pix, pixClone(), and pixCopy().

Referenced by bmfGetPix(), boxaDisplayTiled(), evalColorfillData(), pixaAccumulateSamples(), pixaaCreateFromPixa(), pixaAddBorderGeneral(), pixaAddTextlines(), pixaAddTextNumber(), pixaaDisplay(), pixaaFlattenToPixa(), pixaaGetPix(), pixaAnyColormaps(), pixaCentroids(), pixaClipToForeground(), pixaClipToPix(), pixaComparePhotoRegionsByHisto(), pixaConstrainedSelect(), pixaConvertTo1(), pixaConvertTo32(), pixaConvertTo8(), pixaConvertTo8Colormap(), pixaConvertToGivenDepth(), pixaConvertToNUpPixa(), pixaConvertToPdfData(), pixaConvertToSameDepth(), pixaCopy(), pixaCountPixels(), pixaCountText(), pixAddWithIndicator(), pixaDisplay(), pixaDisplayBoxaa(), pixaDisplayMultiTiled(), pixaDisplayOnLattice(), pixaDisplayPairTiledInColumns(), pixaDisplayRandomCmap(), pixaDisplayTiled(), pixaDisplayTiledAndScaled(), pixaDisplayTiledByIndex(), pixaDisplayTiledInColumns(), pixaDisplayTiledInRows(), pixaDisplayTiledWithText(), pixaDisplayUnsplit(), pixaEqual(), pixaFindAreaFraction(), pixaFindDimensions(), pixaFindPerimSizeRatio(), pixaFindPerimToAreaRatio(), pixaFindStrokeWidth(), pixaFindWidthHeightProduct(), pixaFindWidthHeightRatio(), pixaGetLinePtrs(), pixaGetPixDimensions(), pixaHasColor(), pixaInterleave(), pixaIsFull(), pixaJoin(), pixaMakeFromTiledPixa(), pixaModifyStrokeWidth(), pixaMorphSequenceByComponent(), pixaRemovePixAndSave(), pixaRotateOrth(), pixaScale(), pixaScaleBySampling(), pixaScaleToSize(), pixaScaleToSizeRel(), pixaSelectByNumConnComp(), pixaSelectRange(), pixaSelectWithIndicator(), pixaSelectWithString(), pixaSetFullSizeBoxa(), pixaSetStrokeWidth(), pixaSetText(), pixaSizeRange(), pixaSort2dByIndex(), pixaSortByIndex(), pixaSplitIntoFiles(), pixaThinConnected(), pixaTranslate(), pixaWriteMemMultipageTiff(), pixaWriteMultipageTiff(), pixaWriteStream(), pixaWriteStreamInfo(), pixCompareTilesByHisto(), pixCompareWithTranslation(), pixDisplayOutliers(), pixGetGrayHistogramTiled(), pixMorphSequenceByComponent(), pixReadBarcodes(), pixRemoveWithIndicator(), recogAddAllSamples(), recogAddCharstrLabels(), recogAddDigitPadTemplates(), recogCreateFromPixaNoFinish(), recogDisplayOutlier(), recogFilterPixaBySize(), recogGetWindowedArea(), recogIdentifyPixa(), recogMakeDecodingArray(), recogShowAverageTemplates(), recogShowMatchesInRange(), recogShowPath(), recogTrainFromBoot(), recogTrainingFinished(), selaCreateFromColorPixa(), selaDisplayInPix(), and wshedRenderFill().

◆ pixaGetPixArray()

PIX** pixaGetPixArray ( PIXA pixa)

pixaGetPixArray()

Parameters
[in]pixa
Returns
pix array, or NULL on error
Notes:
     (1) This returns a ptr to the actual array.  The array is
         owned by the pixa, so it must not be destroyed.
     (2) The caller should always check if the return value is NULL
         before accessing any of the pix ptrs in this array!

Definition at line 877 of file pixabasic.c.

References Pixa::pix.

◆ pixaGetPixDimensions()

l_ok pixaGetPixDimensions ( PIXA pixa,
l_int32  index,
l_int32 *  pw,
l_int32 *  ph,
l_int32 *  pd 
)

◆ pixaInitFull()

l_ok pixaInitFull ( PIXA pixa,
PIX pix,
BOX box 
)

pixaInitFull()

Parameters
[in]pixatypically empty
[in]pix[optional] to be replicated to the entire pixa ptr array
[in]box[optional] to be replicated to the entire boxa ptr array
Returns
0 if OK, 1 on error
Notes:
     (1) This initializes a pixa by filling up the entire pix ptr array
         with copies of pix.  If pix == NULL, we use a tiny placeholder
         pix (w = h = d = 1).  Any existing pix are destroyed.
         It also optionally fills the boxa with copies of box.
         After this operation, the numbers of pix and (optionally)
         boxes are equal to the number of allocated ptrs.
     (2) Note that we use pixaReplacePix() instead of pixaInsertPix().
         They both have the same effect when inserting into a NULL ptr
         in the pixa ptr array:
     (3) If the boxa is not initialized (i.e., filled with boxes),
         later insertion of boxes will cause an error, because the
         'n' field is 0.
     (4) Example usage.  This function is useful to prepare for a
         random insertion (or replacement) of pix into a pixa.
         To randomly insert pix into a pixa, without boxes, up to
         some index "max":
            Pixa *pixa = pixaCreate(max);
            pixaInitFull(pixa, NULL, NULL);
         An existing pixa with a smaller ptr array can also be reused:
            pixaExtendArrayToSize(pixa, max);
            pixaInitFull(pixa, NULL, NULL);
         The initialization allows the pixa to always be properly
         filled, even if all pix (and boxes) are not later replaced.

Definition at line 1509 of file pixabasic.c.

References Pixa::boxa, boxaInitFull(), Pixa::n, Pixa::nalloc, pixaReplacePix(), pixCopy(), and pixCreate().

◆ pixaInsertPix()

l_ok pixaInsertPix ( PIXA pixa,
l_int32  index,
PIX pixs,
BOX box 
)

pixaInsertPix()

Parameters
[in]pixa
[in]indexat which pix is to be inserted
[in]pixsnew pix to be inserted
[in]box[optional] new box to be inserted
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts pixa[i] --> pixa[i + 1] for all i >= index,
         and then inserts at pixa[index].
     (2) To insert at the beginning of the array, set index = 0.
     (3) It should not be used repeatedly on large arrays,
         because the function is O(n).
     (4) To append a pix to a pixa, it's easier to use pixaAddPix().

Definition at line 1294 of file pixabasic.c.

References Pixa::boxa, boxaExtendArray(), boxaInsertBox(), Pixa::n, Pixa::nalloc, Pixa::pix, pixaExtendArray(), and pixaGetCount().

◆ pixaInterleave()

PIXA* pixaInterleave ( PIXA pixa1,
PIXA pixa2,
l_int32  copyflag 
)

pixaInterleave()

Parameters
[in]pixa1first src pixa
[in]pixa2second src pixa
[in]copyflagL_CLONE, L_COPY
Returns
pixa interleaved from sources, or NULL on error.
Notes:
     (1) copyflag determines if the pix are copied or cloned.
         The boxes, if they exist, are copied.
     (2) If the two pixa have different sizes, a warning is issued,
         and the number of pairs returned is the minimum size.

Definition at line 1639 of file pixabasic.c.

References L_CLONE, L_COPY, L_INSERT, pixaAddBox(), pixaAddPix(), pixaCreate(), pixaGetBox(), pixaGetBoxaCount(), pixaGetCount(), and pixaGetPix().

Referenced by pixaCompareInPdf().

◆ pixaIsFull()

l_ok pixaIsFull ( PIXA pixa,
l_int32 *  pfullpa,
l_int32 *  pfullba 
)

pixaIsFull()

Parameters
[in]pixa
[out]pfullpa[optional] 1 if pixa is full
[out]pfullba[optional] 1 if boxa is full
Returns
0 if OK, 1 on error
Notes:
     (1) A pixa is "full" if the array of pix is fully
         occupied from index 0 to index (pixa->n - 1).

Definition at line 993 of file pixabasic.c.

References boxaDestroy(), boxaIsFull(), L_CLONE, pixaGetBoxa(), pixaGetCount(), pixaGetPix(), and pixDestroy().

Referenced by pixaaIsFull(), and recogCreateFromPixaNoFinish().

◆ pixaJoin()

l_ok pixaJoin ( PIXA pixad,
PIXA pixas,
l_int32  istart,
l_int32  iend 
)

pixaJoin()

Parameters
[in]pixaddest pixa; add to this one
[in]pixas[optional] source pixa; add from this one
[in]istartstarting index in pixas
[in]iendending index in pixas; use -1 to cat all
Returns
0 if OK, 1 on error
Notes:
     (1) This appends a clone of each indicated pix in pixas to pixad
     (2) istart < 0 is taken to mean 'read from the start' (istart = 0)
     (3) iend < 0 means 'read to the end'
     (4) If pixas is NULL or contains no pix, this is a no-op.

Definition at line 1585 of file pixabasic.c.

References boxaDestroy(), boxaJoin(), L_CLONE, L_INSERT, pixaAddPix(), pixaGetBoxa(), pixaGetBoxaCount(), pixaGetCount(), and pixaGetPix().

Referenced by pixaMakeFromTiledPixa(), recogFilterPixaBySize(), and recogMakeBootDigitTemplates().

◆ pixaRead()

PIXA* pixaRead ( const char *  filename)

pixaRead()

Parameters
[in]filename
Returns
pixa, or NULL on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 2480 of file pixabasic.c.

References fopenReadStream(), and pixaReadStream().

Referenced by pixaaReadFromFiles(), and pixaReadBoth().

◆ pixaReadBoth()

PIXA* pixaReadBoth ( const char *  filename)

pixaReadBoth()

Parameters
[in]filename
Returns
pixa, or NULL on error
Notes:
     (1) This reads serialized files of either a pixa or a pixacomp,
         and returns a pixa in memory.  It requires png and jpeg libraries.

Definition at line 2777 of file pixabasic.c.

References L_COPY, l_getStructStrFromFile(), L_STR_NAME, pixacompDestroy(), pixacompRead(), pixaCreateFromPixacomp(), and pixaRead().

◆ pixaReadMem()

PIXA* pixaReadMem ( const l_uint8 *  data,
size_t  size 
)

pixaReadMem()

Parameters
[in]dataof serialized pixa
[in]sizeof data in bytes
Returns
pixa, or NULL on error

Definition at line 2578 of file pixabasic.c.

References fopenReadFromMemory(), and pixaReadStream().

◆ pixaReadStream()

PIXA* pixaReadStream ( FILE *  fp)

pixaReadStream()

Parameters
[in]fpfile stream
Returns
pixa, or NULL on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.
     (2) It is OK for the pixa to be empty.

Definition at line 2516 of file pixabasic.c.

References PIXA_VERSION_NUMBER.

Referenced by pixaRead(), and pixaReadMem().

◆ pixaRemovePix()

l_ok pixaRemovePix ( PIXA pixa,
l_int32  index 
)

pixaRemovePix()

Parameters
[in]pixa
[in]indexof pix to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts pixa[i] --> pixa[i - 1] for all i > index.
     (2) It should not be used repeatedly on large arrays,
         because the function is O(n).
     (3) The corresponding box is removed as well, if it exists.

Definition at line 1345 of file pixabasic.c.

References Pixa::boxa, boxaGetCount(), boxaRemoveBox(), Pixa::n, Pixa::pix, pixaGetCount(), and pixDestroy().

Referenced by pixaRemoveSelected().

◆ pixaRemovePixAndSave()

l_ok pixaRemovePixAndSave ( PIXA pixa,
l_int32  index,
PIX **  ppix,
BOX **  pbox 
)

pixaRemovePixAndSave()

Parameters
[in]pixa
[in]indexof pix to be removed
[out]ppix[optional] removed pix
[out]pbox[optional] removed box
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts pixa[i] --> pixa[i - 1] for all i > index.
     (2) It should not be used repeatedly on large arrays,
         because the function is O(n).
     (3) The corresponding box is removed as well, if it exists.
     (4) The removed pix and box can either be retained or destroyed.

Definition at line 1397 of file pixabasic.c.

References Pixa::boxa, boxaGetCount(), boxaRemoveBoxAndSave(), L_CLONE, Pixa::n, Pixa::pix, pixaGetCount(), pixaGetPix(), and pixDestroy().

◆ pixaRemoveSelected()

l_ok pixaRemoveSelected ( PIXA pixa,
NUMA naindex 
)

pixaRemoveSelected()

Parameters
[in]pixa
[in]naindexnuma of indices of pix to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This gives error messages for invalid indices

Definition at line 1449 of file pixabasic.c.

References L_SORT_DECREASING, numaDestroy(), numaGetCount(), numaGetIValue(), numaSort(), and pixaRemovePix().

◆ pixaReplacePix()

l_ok pixaReplacePix ( PIXA pixa,
l_int32  index,
PIX pix,
BOX box 
)

pixaReplacePix()

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

Definition at line 1246 of file pixabasic.c.

References Pixa::boxa, boxaReplaceBox(), Pixa::n, Boxa::n, Pixa::pix, and pixDestroy().

Referenced by pixaAddBorderGeneral(), and pixaInitFull().

◆ pixaSetBoxa()

l_ok pixaSetBoxa ( PIXA pixa,
BOXA boxa,
l_int32  accesstype 
)

pixaSetBoxa()

Parameters
[in]pixa
[in]boxa
[in]accesstypeL_INSERT, L_COPY, L_CLONE
Returns
0 if OK, 1 on error
Notes:
     (1) This destroys the existing boxa in the pixa.

Definition at line 840 of file pixabasic.c.

References Pixa::boxa, boxaCopy(), boxaDestroy(), L_CLONE, L_COPY, and L_INSERT.

Referenced by pixaConvertTo1(), pixaConvertTo32(), pixaConvertTo8(), pixaConvertTo8Colormap(), pixaConvertToSameDepth(), pixaSetFullSizeBoxa(), and pixaTranslate().

◆ pixaSetText()

l_ok pixaSetText ( PIXA pixa,
const char *  text,
SARRAY sa 
)

pixaSetText()

Parameters
[in]pixa
[in]text[optional] single text string, to insert in each pix
[in]sa[optional] array of text strings, to insert in each pix
Returns
0 if OK, 1 on error.
Notes:
     (1) To clear all the text fields, use sa == NULL and text == NULL.
     (2) Otherwise, this replaces all text fields with a copy of a string,
         either the same string or a string from sa.
     (3) To set all the text fields to the same value text, use sa = NULL.
     (4) If sa is defined, ignore text and use the strings in sa.
         sa must have the same count as pixa.

Definition at line 1087 of file pixabasic.c.

References L_CLONE, L_NOCOPY, pixaGetCount(), pixaGetPix(), pixDestroy(), pixSetText(), sarrayGetCount(), and sarrayGetString().

Referenced by pixaDisplayPairTiledInColumns(), and pixaMakeFromTiledPixa().

◆ pixaSplitPix()

PIXA* pixaSplitPix ( PIX pixs,
l_int32  nx,
l_int32  ny,
l_int32  borderwidth,
l_uint32  bordercolor 
)

pixaSplitPix()

Parameters
[in]pixswith individual components on a lattice
[in]nxnumber of mosaic cells horizontally
[in]nynumber of mosaic cells vertically
[in]borderwidthof added border on all sides
[in]bordercolorin our RGBA format: 0xrrggbbaa
Returns
pixa, or NULL on error
Notes:
     (1) This is a variant on pixaCreateFromPix(), where we
         simply divide the image up into (approximately) equal
         subunits.  If you want the subimages to have essentially
         the same aspect ratio as the input pix, use nx = ny.
     (2) If borderwidth is 0, we ignore the input bordercolor and
         redefine it to white.
     (3) The bordercolor is always used to initialize each tiled pix,
         so that if the src is clipped, the unblitted part will
         be this color.  This avoids 1 pixel wide black stripes at the
         left and lower edges.

Definition at line 344 of file pixabasic.c.

References L_INSERT, PIX_SRC, pixaAddPix(), pixaCreate(), pixaDestroy(), pixClearAll(), pixCopyColormap(), pixCreate(), pixGetDimensions(), pixRasterop(), pixSetAll(), and pixSetAllArbitrary().

Referenced by pixCompareTilesByHisto(), and pixGetGrayHistogramTiled().

◆ pixaVerifyDepth()

l_ok pixaVerifyDepth ( PIXA pixa,
l_int32 *  psame,
l_int32 *  pmaxd 
)

pixaVerifyDepth()

Parameters
[in]pixa
[out]psame1 if depth is the same for all pix; 0 otherwise
[out]pmaxd[optional] max depth of all pix
Returns
0 if OK, 1 on error
Notes:
     (1) It is considered to be an error if there are no pix.

Definition at line 900 of file pixabasic.c.

References pixaGetCount(), and pixaGetPixDimensions().

Referenced by pixaaVerifyDepth(), pixaDisplayOnLattice(), pixaDisplayRandomCmap(), pixaFindStrokeWidth(), pixaGetLinePtrs(), pixaModifyStrokeWidth(), pixaSetStrokeWidth(), pixaThinConnected(), recogCreateFromPixaNoFinish(), and recogTrainFromBoot().

◆ pixaVerifyDimensions()

l_ok pixaVerifyDimensions ( PIXA pixa,
l_int32 *  psame,
l_int32 *  pmaxw,
l_int32 *  pmaxh 
)

pixaVerifyDimensions()

Parameters
[in]pixa
[out]psame1 if dimensions are the same for all pix; 0 otherwise
[out]pmaxw[optional] max width of all pix
[out]pmaxh[optional] max height of all pix
Returns
0 if OK, 1 on error
Notes:
     (1) It is considered to be an error if there are no pix.

Definition at line 944 of file pixabasic.c.

References pixaGetCount(), and pixaGetPixDimensions().

Referenced by pixaaVerifyDimensions().

◆ pixaWrite()

l_ok pixaWrite ( const char *  filename,
PIXA pixa 
)

pixaWrite()

Parameters
[in]filename
[in]pixa
Returns
0 if OK, 1 on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 2639 of file pixabasic.c.

References fopenWriteStream(), and pixaWriteStream().

Referenced by pixaWriteDebug().

◆ pixaWriteDebug()

l_ok pixaWriteDebug ( const char *  fname,
PIXA pixa 
)

pixaWriteDebug()

Parameters
[in]fname
[in]pixa
Returns
0 if OK; 1 on error
Notes:
     (1) Debug version, intended for use in the library when writing
         to files in a temp directory with names that are compiled in.
         This is used instead of pixaWrite() for all such library calls.
     (2) The global variable LeptDebugOK defaults to 0, and can be set
         or cleared by the function setLeptDebugOK().

Definition at line 2613 of file pixabasic.c.

References pixaWrite().

Referenced by pixaSplitIntoFiles().

◆ pixaWriteMem()

l_ok pixaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
PIXA pixa 
)

pixaWriteMem()

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

Definition at line 2723 of file pixabasic.c.

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

◆ pixaWriteStream()

l_ok pixaWriteStream ( FILE *  fp,
PIXA pixa 
)

pixaWriteStream()

Parameters
[in]fpfile stream opened for "wb"
[in]pixa
Returns
0 if OK, 1 on error
Notes:
     (1) The pix are stored in the file as png.
         If the png library is not linked, this will fail.

Definition at line 2678 of file pixabasic.c.

References Pixa::boxa, boxaWriteStream(), L_CLONE, PIXA_VERSION_NUMBER, pixaGetCount(), pixaGetPix(), pixDestroy(), pixWriteStreamPng(), Pix::xres, and Pix::yres.

Referenced by pixaaWriteStream(), pixaWrite(), and pixaWriteMem().

◆ pixaWriteStreamInfo()

l_ok pixaWriteStreamInfo ( FILE *  fp,
PIXA pixa 
)

pixaWriteStreamInfo()

Parameters
[in]fpfile stream
[in]pixa
Returns
0 if OK, 1 on error.
Notes:
     (1) For each pix in the pixa, write out the pix dimensions, spp,
         text string (if it exists), and cmap info.

Definition at line 1190 of file pixabasic.c.

References L_CLONE, pixaGetCount(), pixaGetPix(), and pixGetDimensions().

Variable Documentation

◆ InitialPtrArraySize

const size_t InitialPtrArraySize = 20
static

n'importe quoi

Definition at line 146 of file pixabasic.c.