Leptonica 1.54
|
Input: pixaa 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: pixaa 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
Input: n (initial number of pixa ptrs) Return: pixaa, 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: pixaa, 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.
Input: pixa box copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK, 1 on error
Input: pixa pix (to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK; 1 on error
void pixaaDestroy | ( | PIXAA ** | ppixaa | ) |
Input: &pixaa <to be="" nulled>=""> Return: void
Input: pixaa Return: 0 if OK; 1 on error
Input: pixaa 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.
Input: pixaa Return: count, or 0 if no pixaa
Input: pixaa 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
PIXAA* pixaaRead | ( | const char * | filename | ) |
Input: filename Return: pixaa, 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* pixaaReadStream | ( | FILE * | fp | ) |
Input: stream Return: pixaa, 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.
Input: filename pixaa 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.
Input: stream (opened for "wb") pixaa 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.
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: 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
Note: see pix.h for description of the copy types.
Input: n (initial number of ptrs) Return: pixa, or null on error
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
Note: 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.
Input: pixa Return: 0 if OK; 1 on error
Notes: (1) Doubles the size of the pixa and boxa ptr arrays.
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.
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().
Input: pixa accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: boxa, or null on error
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
Input: pixa Return: count, or 0 if no pixa
Input: pixa index (to the index-th pix) accesstype (L_COPY or L_CLONE) Return: pix, or null on error
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
Input: pixa (typically empty) pix (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 . Any existing pix are destroyed. It also fills the boxa with copies of . After this oepration, the numbers of pix and 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) 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, up to some index "max": Pixa *pixa = pixaCreate(max); Pix *pix = pixCreate(1, 1, 1); // little memory Box *box = boxCreate(...); pixaInitFull(pixa, pix, box); An existing pixa with a smaller ptr array can also be reused: pixaExtendArrayToSize(pixa, max); Pix *pix = pixCreate(...); Box *box = boxCreate(...); pixaInitFull(pixa, pix, box); For these situations, the pix should be small and disposable. 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().
Input: pixad (dest pixa; add to this one) pixas (source pixa; add from this one) istart (starting index in nas) iend (ending index in nas; use 0 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'
PIXA* pixaRead | ( | const char * | filename | ) |
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.
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 (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.
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.
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.
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.
const l_int32 INITIAL_PTR_ARRAYSIZE = 20 [static] |