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

Функции

static l_int32 numaExtendArray (NUMA *na)
static l_int32 numaaExtendArray (NUMAA *naa)
NUMAnumaCreate (l_int32 n)
NUMAnumaCreateFromIArray (l_int32 *iarray, l_int32 size)
NUMAnumaCreateFromFArray (l_float32 *farray, l_int32 size, l_int32 copyflag)
NUMAnumaCreateFromString (const char *str)
void numaDestroy (NUMA **pna)
NUMAnumaCopy (NUMA *na)
NUMAnumaClone (NUMA *na)
l_int32 numaEmpty (NUMA *na)
l_int32 numaAddNumber (NUMA *na, l_float32 val)
l_int32 numaInsertNumber (NUMA *na, l_int32 index, l_float32 val)
l_int32 numaRemoveNumber (NUMA *na, l_int32 index)
l_int32 numaReplaceNumber (NUMA *na, l_int32 index, l_float32 val)
l_int32 numaGetCount (NUMA *na)
l_int32 numaSetCount (NUMA *na, l_int32 newcount)
l_int32 numaGetFValue (NUMA *na, l_int32 index, l_float32 *pval)
l_int32 numaGetIValue (NUMA *na, l_int32 index, l_int32 *pival)
l_int32 numaSetValue (NUMA *na, l_int32 index, l_float32 val)
l_int32 numaShiftValue (NUMA *na, l_int32 index, l_float32 diff)
l_int32numaGetIArray (NUMA *na)
l_float32numaGetFArray (NUMA *na, l_int32 copyflag)
l_int32 numaGetRefcount (NUMA *na)
l_int32 numaChangeRefcount (NUMA *na, l_int32 delta)
l_int32 numaGetParameters (NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
l_int32 numaSetParameters (NUMA *na, l_float32 startx, l_float32 delx)
l_int32 numaCopyParameters (NUMA *nad, NUMA *nas)
SARRAYnumaConvertToSarray (NUMA *na, l_int32 size1, l_int32 size2, l_int32 addzeros, l_int32 type)
NUMAnumaRead (const char *filename)
NUMAnumaReadStream (FILE *fp)
l_int32 numaWrite (const char *filename, NUMA *na)
l_int32 numaWriteStream (FILE *fp, NUMA *na)
NUMAAnumaaCreate (l_int32 n)
NUMAAnumaaCreateFull (l_int32 nptr, l_int32 n)
l_int32 numaaTruncate (NUMAA *naa)
void numaaDestroy (NUMAA **pnaa)
l_int32 numaaAddNuma (NUMAA *naa, NUMA *na, l_int32 copyflag)
l_int32 numaaGetCount (NUMAA *naa)
l_int32 numaaGetNumaCount (NUMAA *naa, l_int32 index)
l_int32 numaaGetNumberCount (NUMAA *naa)
NUMA ** numaaGetPtrArray (NUMAA *naa)
NUMAnumaaGetNuma (NUMAA *naa, l_int32 index, l_int32 accessflag)
l_int32 numaaReplaceNuma (NUMAA *naa, l_int32 index, NUMA *na)
l_int32 numaaGetValue (NUMAA *naa, l_int32 i, l_int32 j, l_float32 *pfval, l_int32 *pival)
l_int32 numaaAddNumber (NUMAA *naa, l_int32 index, l_float32 val)
NUMAAnumaaRead (const char *filename)
NUMAAnumaaReadStream (FILE *fp)
l_int32 numaaWrite (const char *filename, NUMAA *naa)
l_int32 numaaWriteStream (FILE *fp, NUMAA *naa)

Переменные

static const l_int32 INITIAL_PTR_ARRAYSIZE = 50

Функции

l_int32 numaaAddNuma ( NUMAA naa,
NUMA na,
l_int32  copyflag 
)

numaaAddNuma()

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

l_int32 numaaAddNumber ( NUMAA naa,
l_int32  index,
l_float32  val 
)

numaaAddNumber()

Input: naa index (of numa within numaa) val (float or int to be added; stored as a float) Return: 0 if OK, 1 on error

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

numaaCreate()

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

NUMAA* numaaCreateFull ( l_int32  nptr,
l_int32  n 
)

numaaCreateFull()

Input: nptr: size of numa ptr array to be alloc'd n: size of individual numa arrays to be alloc'd (0 for default) Return: naa, or null on error

Notes: (1) This allocates numaa and fills the array with allocated numas. In use, after calling this function, use numaaAddNumber(naa, index, val); to add val to the index-th numa in naa.

l_int32 numaAddNumber ( NUMA na,
l_float32  val 
)

numaAddNumber()

Input: na val (float or int to be added; stored as a float) Return: 0 if OK, 1 on error

void numaaDestroy ( NUMAA **  pnaa)

numaaDestroy()

Input: &numaa <to be="" nulled="" if="" it="" exists>=""> Return: void

static l_int32 numaaExtendArray ( NUMAA naa) [static]

numaaExtendArray()

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

numaaGetCount()

Input: naa Return: count (number of numa), or 0 if no numa or on error

NUMA* numaaGetNuma ( NUMAA naa,
l_int32  index,
l_int32  accessflag 
)

numaaGetNuma()

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

l_int32 numaaGetNumaCount ( NUMAA naa,
l_int32  index 
)

numaaGetNumaCount()

Input: naa index (of numa in naa) Return: count of numbers in the referenced numa, or 0 on error.

numaaGetNumberCount()

Input: naa Return: count (total number of numbers in the numaa), or 0 if no numbers or on error

NUMA** numaaGetPtrArray ( NUMAA naa)

numaaGetPtrArray()

Input: naa Return: the internal array of ptrs to Numa, or null on error

Notes: (1) This function is convenient for doing direct manipulation on a fixed size array of Numas. To do this, it sets the count to the full size of the allocated array of Numa ptrs. The originating Numaa owns this array: DO NOT free it! (2) Intended usage: Numaa *naa = numaaCreate(n); Numa **array = numaaGetPtrArray(naa); ... [manipulate Numas directly on the array] numaaDestroy(&naa); (3) Cautions:

  • Do not free this array; it is owned by tne Numaa.
  • Do not call any functions on the Numaa, other than numaaDestroy() when you're finished with the array. Adding a Numa will force a resize, destroying the ptr array.
  • Do not address the array outside its allocated size. With the bare array, there are no protections. If the allocated size is n, array[n] is an error.
l_int32 numaaGetValue ( NUMAA naa,
l_int32  i,
l_int32  j,
l_float32 pfval,
l_int32 pival 
)

numaaGetValue()

Input: naa i (index of numa within numaa) j (index into numa) fval (<optional return>=""> float value) ival (<optional return>=""> int value) Return: 0 if OK, 1 on error

NUMAA* numaaRead ( const char *  filename)

numaaRead()

Input: filename Return: naa, or null on error

NUMAA* numaaReadStream ( FILE *  fp)

numaaReadStream()

Input: stream Return: naa, or null on error

l_int32 numaaReplaceNuma ( NUMAA naa,
l_int32  index,
NUMA na 
)

numaaReplaceNuma()

Input: naa index (to the index-th numa) numa (insert and replace any existing one) Return: 0 if OK, 1 on error

Notes: (1) Any existing numa is destroyed, and the input one is inserted in its place. (2) If the index is invalid, return 1 (error)

numaaTruncate()

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

Notes: (1) This identifies the largest index containing a numa that has any numbers within it, destroys all numa beyond that index, and resets the count.

l_int32 numaaWrite ( const char *  filename,
NUMAA naa 
)

numaaWrite()

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

l_int32 numaaWriteStream ( FILE *  fp,
NUMAA naa 
)

numaaWriteStream()

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

l_int32 numaChangeRefcount ( NUMA na,
l_int32  delta 
)

numaChangeRefCount()

Input: na delta (change to be applied) Return: 0 if OK, 1 on error

NUMA* numaClone ( NUMA na)

numaClone()

Input: na Return: ptr to same numa, or null on error

SARRAY* numaConvertToSarray ( NUMA na,
l_int32  size1,
l_int32  size2,
l_int32  addzeros,
l_int32  type 
)

numaConvertToSarray()

Input: na size1 (size of conversion field) size2 (for float conversion: size of field to the right of the decimal point) addzeros (for integer conversion: to add lead zeros) type (L_INTEGER_VALUE, L_FLOAT_VALUE) Return: a sarray of the float values converted to strings representing either integer or float values; or null on error.

Notes: (1) For integer conversion, size2 is ignored. For float conversion, addzeroes is ignored.

NUMA* numaCopy ( NUMA na)

numaCopy()

Input: na Return: copy of numa, or null on error

l_int32 numaCopyParameters ( NUMA nad,
NUMA nas 
)

numaCopyParameters()

Input: nad (destination Numa) nas (source Numa) Return: 0 if OK, 1 on error

numaCreate()

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

NUMA* numaCreateFromFArray ( l_float32 farray,
l_int32  size,
l_int32  copyflag 
)

numaCreateFromFArray()

Input: farray (float) size (of the array) copyflag (L_INSERT or L_COPY) Return: na, or null on error

Notes: (1) With L_INSERT, ownership of the input array is transferred to the returned numa, and all elements are considered to be valid.

NUMA* numaCreateFromIArray ( l_int32 iarray,
l_int32  size 
)

numaCreateFromIArray()

Input: iarray (integer) size (of the array) Return: na, or null on error

Notes: (1) We can't insert this int array into the numa, because a numa takes a float array. So this just copies the data from the input array into the numa. The input array continues to be owned by the caller.

NUMA* numaCreateFromString ( const char *  str)

numaCreateFromString()

Input: string (of comma-separated numbers) Return: na, or null on error

Notes: (1) The numbers can be ints or floats; they will be interpreted and stored as floats. To use them as integers (e.g., for indexing into arrays), use numaGetIValue(...).

void numaDestroy ( NUMA **  pna)

numaDestroy()

Input: &na (<to be="" nulled="" if="" it="" exists>="">) Return: void

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

l_int32 numaEmpty ( NUMA na)

numaEmpty()

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

Notes: (1) This does not change the allocation of the array. It just clears the number of stored numbers, so that the array appears to be empty.

static l_int32 numaExtendArray ( NUMA na) [static]

numaExtendArray()

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

numaGetCount()

Input: na Return: count, or 0 if no numbers or on error

l_float32* numaGetFArray ( NUMA na,
l_int32  copyflag 
)

numaGetFArray()

Input: na copyflag (L_NOCOPY or L_COPY) Return: either the bare internal array or a copy of it, or null on error

Notes: (1) If copyflag == L_COPY, it makes a copy which the caller is responsible for freeing. Otherwise, it operates directly on the bare array of the numa. (2) Very important: for L_NOCOPY, any writes to the array will be in the numa. Do not write beyond the size of the count field, because it will not be accessible from the numa! If necessary, be sure to set the count field to a larger number (such as the alloc size) BEFORE calling this function. Creating with numaMakeConstant() is another way to insure full initialization.

l_int32 numaGetFValue ( NUMA na,
l_int32  index,
l_float32 pval 
)

numaGetFValue()

Input: na index (into numa) &val (<return> float value; 0.0 on error) Return: 0 if OK; 1 on error

Notes: (1) Caller may need to check the function return value to decide if a 0.0 in the returned ival is valid.

numaGetIArray()

Input: na Return: a copy of the bare internal array, integerized by rounding, or null on error Notes: (1) A copy of the array is always made, because we need to generate an integer array from the bare float array. The caller is responsible for freeing the array. (2) The array size is determined by the number of stored numbers, not by the size of the allocated array in the Numa. (3) This function is provided to simplify calculations using the bare internal array, rather than continually calling accessors on the numa. It is typically used on an array of size 256.

l_int32 numaGetIValue ( NUMA na,
l_int32  index,
l_int32 pival 
)

numaGetIValue()

Input: na index (into numa) &ival (<return> integer value; 0 on error) Return: 0 if OK; 1 on error

Notes: (1) Caller may need to check the function return value to decide if a 0 in the returned ival is valid.

l_int32 numaGetParameters ( NUMA na,
l_float32 pstartx,
l_float32 pdelx 
)

numaGetParameters()

Input: na &startx (<optional return>=""> startx) &delx (<optional return>=""> delx) Return: 0 if OK, 1 on error

numaGetRefCount()

Input: na Return: refcount, or UNDEF on error

l_int32 numaInsertNumber ( NUMA na,
l_int32  index,
l_float32  val 
)

numaInsertNumber()

Input: na index (location in na to insert new value) val (float32 or integer to be added) Return: 0 if OK, 1 on error

Notes: (1) This shifts na[i] --> na[i + 1] for all i >= index, and then inserts val as na[index]. (2) It should not be used repeatedly on large arrays, because the function is O(n).

NUMA* numaRead ( const char *  filename)

numaRead()

Input: filename Return: na, or null on error

NUMA* numaReadStream ( FILE *  fp)

numaReadStream()

Input: stream Return: numa, or null on error

l_int32 numaRemoveNumber ( NUMA na,
l_int32  index 
)

numaRemoveNumber()

Input: na index (element to be removed) Return: 0 if OK, 1 on error

Notes: (1) This shifts na[i] --> na[i - 1] for all i > index. (2) It should not be used repeatedly on large arrays, because the function is O(n).

l_int32 numaReplaceNumber ( NUMA na,
l_int32  index,
l_float32  val 
)

numaReplaceNumber()

Input: na index (element to be replaced) val (new value to replace old one) Return: 0 if OK, 1 on error

l_int32 numaSetCount ( NUMA na,
l_int32  newcount 
)

numaSetCount()

Input: na newcount Return: 0 if OK, 1 on error

Notes: (1) If newcount <= na->nalloc, this resets na->n. Using newcount = 0 is equivalent to numaEmpty(). (2) If newcount > na->nalloc, this causes a realloc to a size na->nalloc = newcount. (3) All the previously unused values in na are set to 0.0.

l_int32 numaSetParameters ( NUMA na,
l_float32  startx,
l_float32  delx 
)

numaSetParameters()

Input: na startx (x value corresponding to na[0]) delx (difference in x values for the situation where the elements of na correspond to the evaulation of a function at equal intervals of size ) Return: 0 if OK, 1 on error

l_int32 numaSetValue ( NUMA na,
l_int32  index,
l_float32  val 
)

numaSetValue()

Input: na index (to element to be set) val (to set element) Return: 0 if OK; 1 on error

l_int32 numaShiftValue ( NUMA na,
l_int32  index,
l_float32  diff 
)

numaShiftValue()

Input: na index (to element to change relative to the current value) diff (increment if diff > 0 or decrement if diff < 0) Return: 0 if OK; 1 on error

l_int32 numaWrite ( const char *  filename,
NUMA na 
)

numaWrite()

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

l_int32 numaWriteStream ( FILE *  fp,
NUMA na 
)

numaWriteStream()

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


Переменные

const l_int32 INITIAL_PTR_ARRAYSIZE = 50 [static]