Leptonica 1.54
Файл src/pixabasic.c
#include <string.h>
#include "allheaders.h"

Функции

PIXApixaCreate (l_int32 n)
PIXApixaCreateFromPix (PIX *pixs, l_int32 n, l_int32 cellw, l_int32 cellh)
PIXApixaCreateFromBoxa (PIX *pixs, BOXA *boxa, 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_int32 pixaAddPix (PIXA *pixa, PIX *pix, l_int32 copyflag)
l_int32 pixaExtendArray (PIXA *pixa)
l_int32 pixaExtendArrayToSize (PIXA *pixa, l_int32 size)
l_int32 pixaAddBox (PIXA *pixa, BOX *box, l_int32 copyflag)
l_int32 pixaGetCount (PIXA *pixa)
l_int32 pixaChangeRefcount (PIXA *pixa, l_int32 delta)
PIXpixaGetPix (PIXA *pixa, l_int32 index, l_int32 accesstype)
l_int32 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_int32 pixaGetBoxGeometry (PIXA *pixa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
PIX ** pixaGetPixArray (PIXA *pixa)
l_int32 pixaReplacePix (PIXA *pixa, l_int32 index, PIX *pix, BOX *box)
l_int32 pixaInsertPix (PIXA *pixa, l_int32 index, PIX *pixs, BOX *box)
l_int32 pixaRemovePix (PIXA *pixa, l_int32 index)
l_int32 pixaInitFull (PIXA *pixa, PIX *pix, BOX *box)
l_int32 pixaClear (PIXA *pixa)
l_int32 pixaJoin (PIXA *pixad, PIXA *pixas, 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 **ppixaa)
l_int32 pixaaAddPixa (PIXAA *pixaa, PIXA *pixa, l_int32 copyflag)
l_int32 pixaaExtendArray (PIXAA *pixaa)
l_int32 pixaaAddBox (PIXAA *pixaa, BOX *box, l_int32 copyflag)
l_int32 pixaaGetCount (PIXAA *pixaa)
PIXApixaaGetPixa (PIXAA *pixaa, l_int32 index, l_int32 accesstype)
BOXApixaaGetBoxa (PIXAA *pixaa, l_int32 accesstype)
PIXApixaRead (const char *filename)
PIXApixaReadStream (FILE *fp)
l_int32 pixaWrite (const char *filename, PIXA *pixa)
l_int32 pixaWriteStream (FILE *fp, PIXA *pixa)
PIXAApixaaRead (const char *filename)
PIXAApixaaReadStream (FILE *fp)
l_int32 pixaaWrite (const char *filename, PIXAA *pixaa)
l_int32 pixaaWriteStream (FILE *fp, PIXAA *pixaa)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 20

Функции

l_int32 pixaaAddBox ( PIXAA pixaa,
BOX box,
l_int32  copyflag 
)

pixaaAddBox()

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.

l_int32 pixaaAddPixa ( PIXAA pixaa,
PIXA pixa,
l_int32  copyflag 
)

pixaaAddPixa()

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

PIXAA* pixaaCreate ( l_int32  n)

pixaaCreate()

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.

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

pixaaCreateFromPixa()

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.

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

pixaAddBox()

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 
)

pixaAddPix()

Input: pixa pix (to be added) copyflag (L_INSERT, L_COPY, L_CLONE) Return: 0 if OK; 1 on error

void pixaaDestroy ( PIXAA **  ppixaa)

pixaaDestroy()

Input: &pixaa <to be="" nulled>=""> Return: void

l_int32 pixaaExtendArray ( PIXAA pixaa)

pixaaExtendArray()

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

BOXA* pixaaGetBoxa ( PIXAA pixaa,
l_int32  accesstype 
)

pixaaGetBoxa()

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.

l_int32 pixaaGetCount ( PIXAA pixaa)

pixaaGetCount()

Input: pixaa Return: count, or 0 if no pixaa

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

pixaaGetPixa()

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)

pixaaRead()

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)

pixaaReadStream()

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.

l_int32 pixaaWrite ( const char *  filename,
PIXAA pixaa 
)

pixaaWrite()

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.

l_int32 pixaaWriteStream ( FILE *  fp,
PIXAA pixaa 
)

pixaaWriteStream()

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.

l_int32 pixaChangeRefcount ( PIXA pixa,
l_int32  delta 
)

pixaChangeRefcount()

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

l_int32 pixaClear ( PIXA pixa)

pixaClear()

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.

PIXA* pixaCopy ( PIXA pixa,
l_int32  copyflag 
)

pixaCopy()

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.

PIXA* pixaCreate ( l_int32  n)

pixaCreate()

Input: n (initial number of ptrs) Return: pixa, or null on error

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

pixaCreateFromBoxa()

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.

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

pixaCreateFromPix()

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)

pixaDestroy()

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.

l_int32 pixaExtendArray ( PIXA pixa)

pixaExtendArray()

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 
)

pixaExtendArrayToSize()

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 
)

pixaGetBox()

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 
)

pixaGetBoxa()

Input: pixa accesstype (L_COPY, L_CLONE, L_COPY_CLONE) Return: boxa, or null on error

l_int32 pixaGetBoxaCount ( PIXA pixa)

pixaGetBoxaCount()

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 
)

pixaGetBoxGeometry()

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)

pixaGetCount()

Input: pixa Return: count, or 0 if no pixa

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

pixaGetPix()

Input: pixa index (to the index-th pix) accesstype (L_COPY or L_CLONE) Return: pix, or null on error

PIX** pixaGetPixArray ( PIXA pixa)

pixaGetPixArray()

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 
)

pixaGetPixDimensions()

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 
)

pixaInitFull()

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.

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

pixaInsertPix()

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 pixaJoin ( PIXA pixad,
PIXA pixas,
l_int32  istart,
l_int32  iend 
)

pixaJoin()

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)

pixaRead()

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)

pixaReadStream()

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 
)

pixaRemovePix()

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.

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

pixaReplacePix()

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 
)

pixaSplitPix()

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 pixaWrite ( const char *  filename,
PIXA pixa 
)

pixaWrite()

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 
)

pixaWriteStream()

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]