Leptonica
1.54
|
l_int32 pixaaAddBox | ( | PIXAA * | paa, |
BOX * | box, | ||
l_int32 | copyflag | ||
) |
Input: paa box copyflag (L_INSERT, L_COPY, L_CLONE) Return: 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.
Input: paa (input paa) index (index of pixa in paa) pix (to be added) box (<optional> to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK; 1 on error
l_int32 pixaaAddPixa | ( | PIXAA * | paa, |
PIXA * | pixa, | ||
l_int32 | copyflag | ||
) |
Input: paa pixa (to be added) copyflag: L_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 Return: 0 if OK; 1 on error
l_int32 pixaaClear | ( | PIXAA * | paa | ) |
Input: paa Return: 0 if OK, 1 on error
Notes: (1) This destroys all pixa in the pixaa, and nulls the ptrs in the pixa ptr array.
PIXAA* pixaaCreate | ( | l_int32 | n | ) |
Input: n (initial number of pixa ptrs) Return: 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.
Input: pixa n (number specifying subdivision of pixa) type (L_CHOOSE_CONSECUTIVE, L_CHOOSE_SKIP_BY) copyflag (L_CLONE, L_COPY) Return: 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.
l_int32 pixaAddBox | ( | PIXA * | pixa, |
BOX * | box, | ||
l_int32 | copyflag | ||
) |
Input: pixa box copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK, 1 on error
l_int32 pixaAddPix | ( | PIXA * | pixa, |
PIX * | pix, | ||
l_int32 | copyflag | ||
) |
Input: pixa pix (to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK; 1 on error
void pixaaDestroy | ( | PIXAA ** | ppaa | ) |
Input: &paa <to be="" nulled>=""> Return: void
l_int32 pixaaExtendArray | ( | PIXAA * | paa | ) |
Input: paa Return: 0 if OK; 1 on error
BOXA* pixaaGetBoxa | ( | PIXAA * | paa, |
l_int32 | accesstype | ||
) |
Input: paa accesstype (L_COPY, L_CLONE) Return: 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.
l_int32 pixaaGetCount | ( | PIXAA * | paa, |
NUMA ** | pna | ||
) |
Input: paa &na (<optional return>=""> number of pix in each pixa) Return: count, or 0 if no pixaa
Notes: (1) If paa is empty, a returned na will also be empty.
Input: paa index (index into the pixa array in the pixaa) ipix (index into the pix array in the pixa) accessflag (L_COPY or L_CLONE) Return: pix, or null on error
PIXA* pixaaGetPixa | ( | PIXAA * | paa, |
l_int32 | index, | ||
l_int32 | accesstype | ||
) |
Input: paa index (to the index-th pixa) accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: 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
l_int32 pixaaInitFull | ( | PIXAA * | paa, |
PIXA * | pixa | ||
) |
Input: paa (typically empty) pixa (to be replicated into the entire pixa ptr array) Return: 0 if OK, 1 on error
Notes: (1) This initializes a pixaa by filling up the entire pixa ptr array with copies of . 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.
l_int32 pixaaIsFull | ( | PIXAA * | paa, |
l_int32 * | pfull | ||
) |
Input: paa &full (<return> 1 if all pixa in the paa have full pix arrays) Return: return 0 if OK, 1 on error
Notes: (1) Does not require boxa associated with each pixa to be full.
Input: paad (dest pixaa; add to this one) paas (<optional> source pixaa; add from this one) istart (starting index in pixaas) iend (ending index in pixaas; use -1 to cat all) Return: 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'
Input: filename Return: 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.
PIXAA* pixaaReadFromFiles | ( | const char * | dirname, |
const char * | substr, | ||
l_int32 | first, | ||
l_int32 | nfiles | ||
) |
Input: dirname (directory) substr (<optional> substring filter on filenames; can be NULL) first (0-based) nfiles (use 0 for everything from to the end) Return: 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 to filter filenames in the directory. If == NULL, this takes all files. (3) After filtering, use and to select a contiguous set of files, that have been lexically sorted in increasing order.
PIXAA* pixaaReadStream | ( | FILE * | fp | ) |
Input: stream Return: 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.
l_int32 pixaaReplacePixa | ( | PIXAA * | paa, |
l_int32 | index, | ||
PIXA * | pixa | ||
) |
Input: paa index (to the index-th pixa) pixa (insert to replace existing one) Return: 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.
l_int32 pixaaTruncate | ( | PIXAA * | paa | ) |
Input: paa Return: 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.
l_int32 pixaaVerifyDepth | ( | PIXAA * | paa, |
l_int32 * | pmaxdepth | ||
) |
Input: paa &maxdepth (<optional return>=""> max depth of all pix in pixaa) Return: depth (return 0 if they're not all the same, or on error)
l_int32 pixaaWrite | ( | const char * | filename, |
PIXAA * | paa | ||
) |
Input: filename paa Return: 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.
l_int32 pixaaWriteStream | ( | FILE * | fp, |
PIXAA * | paa | ||
) |
Input: stream (opened for "wb") paa Return: 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.
l_int32 pixaChangeRefcount | ( | PIXA * | pixa, |
l_int32 | delta | ||
) |
Input: pixa Return: 0 if OK, 1 on error
Input: pixa Return: 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.
Input: pixas copyflag (see 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 Return: new pixa, or null on error
l_int32 pixaCountText | ( | PIXA * | pixa, |
l_int32 * | pntext | ||
) |
Input: pixa &ntext (<return> number of pix with non-empty text strings) Return: 0 if OK, 1 on error.
Notes: (1) All pix have non-empty text strings if the returned value equals the pixa count.
PIXA* pixaCreate | ( | l_int32 | n | ) |
Input: n (initial number of ptrs) Return: pixa, or null on error
Notes: (1) This creates an empty boxa.
PIXA* pixaCreateFromBoxa | ( | PIX * | pixs, |
BOXA * | boxa, | ||
l_int32 * | pcropwarn | ||
) |
Input: pixs boxa &cropwarn (<optional return>=""> TRUE if the boxa extent is larger than pixs. Return: pixad, or null on error
Notes: (1) This simply extracts from pixs the region corresponding to each box in the boxa. (2) The 3rd arg is optional. If the extent of the boxa exceeds the size of the pixa, so that some boxes are either clipped or entirely outside the pix, a warning is returned as TRUE. (3) pixad will have only the properly clipped elements, and the internal boxa will be correct.
Input: pixs (with individual components on a lattice) n (number of components) cellw (width of each cell) cellh (height of each cell) Return: 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)
void pixaDestroy | ( | PIXA ** | ppixa | ) |
Input: &pixa (<can be="" nulled>="">) Return: void
Notes: (1) Decrements the ref count and, if 0, destroys the pixa. (2) Always nulls the input ptr.
static l_int32 pixaExtendArray | ( | PIXA * | pixa | ) | [static] |
Input: pixa Return: 0 if OK; 1 on error
Notes: (1) Doubles the size of the pixa and boxa ptr arrays.
l_int32 pixaExtendArrayToSize | ( | PIXA * | pixa, |
l_int32 | size | ||
) |
Input: pixa Return: 0 if OK; 1 on error
Notes: (1) If necessary, reallocs new pixa and boxa ptrs arrays to . The pixa and boxa ptr arrays must always be equal in size.
BOX* pixaGetBox | ( | PIXA * | pixa, |
l_int32 | index, | ||
l_int32 | accesstype | ||
) |
Input: pixa index (to the index-th pix) accesstype (L_COPY or L_CLONE) Return: 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().
BOXA* pixaGetBoxa | ( | PIXA * | pixa, |
l_int32 | accesstype | ||
) |
Input: pixa accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: boxa, or null on error
l_int32 pixaGetBoxaCount | ( | PIXA * | pixa | ) |
Input: pixa Return: count, or 0 on error
l_int32 pixaGetBoxGeometry | ( | PIXA * | pixa, |
l_int32 | index, | ||
l_int32 * | px, | ||
l_int32 * | py, | ||
l_int32 * | pw, | ||
l_int32 * | ph | ||
) |
Input: pixa index (to the index-th box) &x, &y, &w, &h (<optional return>="">; each can be null) Return: 0 if OK, 1 on error
l_int32 pixaGetCount | ( | PIXA * | pixa | ) |
Input: pixa Return: count, or 0 if no pixa
void*** pixaGetLinePtrs | ( | PIXA * | pixa, |
l_int32 * | psize | ||
) |
Input: pixa (of pix that all have the same depth) &size (<optional return>=""> number of pix in the pixa) Return: 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);
PIX* pixaGetPix | ( | PIXA * | pixa, |
l_int32 | index, | ||
l_int32 | accesstype | ||
) |
Input: pixa index (to the index-th pix) accesstype (L_COPY or L_CLONE) Return: pix, or null on error
PIX** pixaGetPixArray | ( | PIXA * | pixa | ) |
Input: pixa Return: 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!
l_int32 pixaGetPixDimensions | ( | PIXA * | pixa, |
l_int32 | index, | ||
l_int32 * | pw, | ||
l_int32 * | ph, | ||
l_int32 * | pd | ||
) |
Input: pixa index (to the index-th box) &w, &h, &d (<optional return>="">; each can be null) Return: 0 if OK, 1 on error
l_int32 pixaInitFull | ( | PIXA * | pixa, |
PIX * | pix, | ||
BOX * | box | ||
) |
Input: pixa (typically empty) pix (<optional> to be replicated into the entire pixa ptr array) box (<optional> to be replicated into the entire boxa ptr array) Return: 0 if OK, 1 on error
Notes: (1) This initializes a pixa by filling up the entire pix ptr array with copies of . If == 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 . 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.
Input: pixa index (at which pix is to be inserted) pixs (new pix to be inserted) box (<optional> new box to be inserted) Return: 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().
l_int32 pixaIsFull | ( | PIXA * | pixa, |
l_int32 * | pfullpa, | ||
l_int32 * | pfullba | ||
) |
Input: pixa &fullpa (<optional return>=""> 1 if pixa is full) &fullba (<optional return>=""> 1 if boxa is full) Return: 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).
Input: pixad (dest pixa; add to this one) pixas (<optional> source pixa; add from this one) istart (starting index in pixas) iend (ending index in pixas; use -1 to cat all) Return: 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.
Input: filename Return: 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.
PIXA* pixaReadStream | ( | FILE * | fp | ) |
Input: stream Return: 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.
l_int32 pixaRemovePix | ( | PIXA * | pixa, |
l_int32 | index | ||
) |
Input: pixa index (of pix to be removed) Return: 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.
Input: pixa index (of pix to be removed) &pix (<optional return>=""> removed pix) &box (<optional return>=""> removed box) Return: 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.
Input: pixa index (to the index-th pix) pix (insert to replace existing one) box (<optional> insert to replace existing) Return: 0 if OK, 1 on error
Notes: (1) In-place replacement of one pix. (2) The previous pix at that location is destroyed.
l_int32 pixaSetBoxa | ( | PIXA * | pixa, |
BOXA * | boxa, | ||
l_int32 | accesstype | ||
) |
Input: pixa boxa accesstype (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK, 1 on error
Notes: (1) This destroys the existing boxa in the pixa.
PIXA* pixaSplitPix | ( | PIX * | pixs, |
l_int32 | nx, | ||
l_int32 | ny, | ||
l_int32 | borderwidth, | ||
l_uint32 | bordercolor | ||
) |
Input: pixs (with individual components on a lattice) nx (number of mosaic cells horizontally) ny (number of mosaic cells vertically) borderwidth (of added border on all sides) bordercolor (in our RGBA format: 0xrrggbbaa) Return: 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.
l_int32 pixaVerifyDepth | ( | PIXA * | pixa, |
l_int32 * | pmaxdepth | ||
) |
Input: pixa &maxdepth (<optional return>=""> max depth of all pix) Return: depth (return 0 if they're not all the same, or on error)
Notes: (1) It is considered to be an error if there are no pix.
Input: filename pixa Return: 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.
l_int32 pixaWriteStream | ( | FILE * | fp, |
PIXA * | pixa | ||
) |
Input: stream (opened for "wb") pixa Return: 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.
l_int32 pixaWriteStreamInfo | ( | FILE * | fp, |
PIXA * | pixa | ||
) |
Input: stream pixa Return: 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.
const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static] |