Leptonica  1.73
Image processing and image analysis suite
Functions | Variables
bytearray.c File Reference
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 l_byteaExtendArrayToSize (L_BYTEA *ba, size_t size)
 
L_BYTEAl_byteaCreate (size_t nbytes)
 
L_BYTEAl_byteaInitFromMem (l_uint8 *data, size_t size)
 
L_BYTEAl_byteaInitFromFile (const char *fname)
 
L_BYTEAl_byteaInitFromStream (FILE *fp)
 
L_BYTEAl_byteaCopy (L_BYTEA *bas, l_int32 copyflag)
 
void l_byteaDestroy (L_BYTEA **pba)
 
size_t l_byteaGetSize (L_BYTEA *ba)
 
l_uint8 * l_byteaGetData (L_BYTEA *ba, size_t *psize)
 
l_uint8 * l_byteaCopyData (L_BYTEA *ba, size_t *psize)
 
l_int32 l_byteaAppendData (L_BYTEA *ba, l_uint8 *newdata, size_t newbytes)
 
l_int32 l_byteaAppendString (L_BYTEA *ba, char *str)
 
l_int32 l_byteaJoin (L_BYTEA *ba1, L_BYTEA **pba2)
 
l_int32 l_byteaSplit (L_BYTEA *ba1, size_t splitloc, L_BYTEA **pba2)
 
l_int32 l_byteaFindEachSequence (L_BYTEA *ba, l_uint8 *sequence, l_int32 seqlen, L_DNA **pda)
 
l_int32 l_byteaWrite (const char *fname, L_BYTEA *ba, size_t startloc, size_t endloc)
 
l_int32 l_byteaWriteStream (FILE *fp, L_BYTEA *ba, size_t startloc, size_t endloc)
 

Variables

static const l_int32 INITIAL_ARRAYSIZE = 200
 

Detailed Description

  Functions for handling byte arrays, in analogy with C++ 'strings'
     Creation, copy, clone, destruction
          L_BYTEA      *l_byteaCreate()
          L_BYTEA      *l_byteaInitFromMem()
          L_BYTEA      *l_byteaInitFromFile()
          L_BYTEA      *l_byteaInitFromStream()
          L_BYTEA      *l_byteaCopy()
          L_BYTEA      *l_byteaClone()
          void          l_byteaDestroy()
     Accessors
          size_t        l_byteaGetSize()
          l_uint8      *l_byteaGetData()
          l_uint8      *l_byteaCopyData()
     Appending
          l_int32       l_byteaAppendData()
          l_int32       l_byteaAppendString()
          static l_int32  l_byteaExtendArrayToSize()
     Join/Split
          l_int32       l_byteaJoin()
          l_int32       l_byteaSplit()
     Search
          l_int32       l_byteaFindEachSequence()
     Output to file
          l_int32       l_byteaWrite()
          l_int32       l_byteaWriteStream()
  The internal data array is always null-terminated, for ease of use
  in the event that it is an ascii string without null bytes.

Definition in file bytearray.c.

Function Documentation

◆ l_byteaAppendData()

l_int32 l_byteaAppendData ( L_BYTEA ba,
l_uint8 *  newdata,
size_t  newbytes 
)

l_byteaAppendData()

Parameters
[in]ba
[in]newdatabyte array to be appended
[in]newbytessize of data array
Returns
0 if OK, 1 on error

Definition at line 363 of file bytearray.c.

References L_Bytea::data, l_byteaExtendArrayToSize(), l_byteaGetSize(), L_Bytea::nalloc, and L_Bytea::size.

Referenced by l_byteaJoin(), and substituteObjectNumbers().

◆ l_byteaAppendString()

l_int32 l_byteaAppendString ( L_BYTEA ba,
char *  str 
)

l_byteaAppendString()

Parameters
[in]ba
[in]strnull-terminated string to be appended
Returns
0 if OK, 1 on error

Definition at line 396 of file bytearray.c.

References L_Bytea::data, l_byteaExtendArrayToSize(), l_byteaGetSize(), L_Bytea::nalloc, and L_Bytea::size.

Referenced by pathJoin(), and substituteObjectNumbers().

◆ l_byteaCopy()

L_BYTEA* l_byteaCopy ( L_BYTEA bas,
l_int32  copyflag 
)

l_byteaCopy()

Parameters
[in]bassource lba
[in]copyflagL_COPY, L_CLONE
Returns
clone or copy of bas, or NULL on error
Notes:
     (1) If cloning, up the refcount and return a ptr to bas.

Definition at line 213 of file bytearray.c.

References L_Bytea::data, l_byteaInitFromMem(), L_CLONE, L_Bytea::refcount, and L_Bytea::size.

◆ l_byteaCopyData()

l_uint8* l_byteaCopyData ( L_BYTEA ba,
size_t *  psize 
)

l_byteaCopyData()

Parameters
[in]ba
[out]psizesize of data in lba
Returns
copy of data in use in the data array, or NULL on error.
Notes:
     (1) The returned data is owned by the caller.  The input ba
         still owns the original data array.

Definition at line 333 of file bytearray.c.

References l_binaryCopy(), and l_byteaGetData().

◆ l_byteaCreate()

L_BYTEA* l_byteaCreate ( size_t  nbytes)

l_byteaCreate()

Parameters
[in]nbytesdetermines initial size of data array
Returns
l_bytea, or NULL on error
Notes:
     (1) The allocated array is n + 1 bytes.  This allows room
         for null termination.

Definition at line 93 of file bytearray.c.

Referenced by l_byteaInitFromMem(), l_byteaInitFromStream(), pathJoin(), and substituteObjectNumbers().

◆ l_byteaDestroy()

void l_byteaDestroy ( L_BYTEA **  pba)

l_byteaDestroy()

Parameters
[in,out]pbawill be set to null before returning
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the lba.
     (2) Always nulls the input ptr.
     (3) If the data has been previously removed, the lba will
         have been nulled, so this will do nothing.

Definition at line 245 of file bytearray.c.

References L_Bytea::data, and L_Bytea::refcount.

Referenced by convertSegmentedFilesToPdf(), l_byteaJoin(), pixaConvertToPdfData(), ptraConcatenatePdfToData(), saConcatenatePdfToData(), saConvertFilesToPdfData(), and saConvertUnscaledFilesToPdfData().

◆ l_byteaExtendArrayToSize()

static l_int32 l_byteaExtendArrayToSize ( L_BYTEA ba,
size_t  size 
)
static

l_byteaExtendArrayToSize()

Parameters
[in]ba
[in]sizenew size of lba data array
Returns
0 if OK; 1 on error

Definition at line 429 of file bytearray.c.

References L_Bytea::data, L_Bytea::nalloc, and reallocNew().

Referenced by l_byteaAppendData(), and l_byteaAppendString().

◆ l_byteaFindEachSequence()

l_int32 l_byteaFindEachSequence ( L_BYTEA ba,
l_uint8 *  sequence,
l_int32  seqlen,
L_DNA **  pda 
)

l_byteaFindEachSequence()

Parameters
[in]ba
[in]sequencesubarray of bytes to find in data
[in]seqlenlength of sequence, in bytes
[out]pdabyte positions of each occurrence of sequence
Returns
0 if OK, 1 on error

Definition at line 540 of file bytearray.c.

References arrayFindEachSequence(), and l_byteaGetData().

Referenced by parseTrailerPdf().

◆ l_byteaGetData()

l_uint8* l_byteaGetData ( L_BYTEA ba,
size_t *  psize 
)

l_byteaGetData()

Parameters
[in]ba
[out]psizesize of data in lba
Returns
ptr to existing data array, or NULL on error
Notes:
     (1) The returned ptr is owned by ba.  Do not free it!

Definition at line 304 of file bytearray.c.

References L_Bytea::data, and L_Bytea::size.

Referenced by l_byteaCopyData(), l_byteaFindEachSequence(), l_byteaJoin(), l_byteaSplit(), l_byteaWriteStream(), parseTrailerPdf(), and substituteObjectNumbers().

◆ l_byteaGetSize()

size_t l_byteaGetSize ( L_BYTEA ba)

l_byteaGetSize()

Parameters
[in]ba
Returns
size of stored byte array, or 0 on error

Definition at line 281 of file bytearray.c.

References L_Bytea::size.

Referenced by l_byteaAppendData(), and l_byteaAppendString().

◆ l_byteaInitFromFile()

L_BYTEA* l_byteaInitFromFile ( const char *  fname)

l_byteaInitFromFile()

Parameters
[in]fname
Returns
l_bytea, or NULL on error

Definition at line 149 of file bytearray.c.

References fopenReadStream(), and l_byteaInitFromStream().

Referenced by saConcatenatePdfToData().

◆ l_byteaInitFromMem()

L_BYTEA* l_byteaInitFromMem ( l_uint8 *  data,
size_t  size 
)

l_byteaInitFromMem()

Parameters
[in]datato be copied to the array
[in]sizeamount of data
Returns
l_bytea, or NULL on error

Definition at line 122 of file bytearray.c.

References L_Bytea::data, l_byteaCreate(), and L_Bytea::size.

Referenced by convertSegmentedFilesToPdf(), l_byteaCopy(), l_byteaSplit(), pixaConvertToPdfData(), saConvertFilesToPdfData(), and saConvertUnscaledFilesToPdfData().

◆ l_byteaInitFromStream()

L_BYTEA* l_byteaInitFromStream ( FILE *  fp)

l_byteaInitFromStream()

Parameters
[in]fpfile stream
Returns
l_bytea, or NULL on error

Definition at line 176 of file bytearray.c.

References L_Bytea::data, l_binaryReadStream(), l_byteaCreate(), and L_Bytea::size.

Referenced by l_byteaInitFromFile().

◆ l_byteaJoin()

l_int32 l_byteaJoin ( L_BYTEA ba1,
L_BYTEA **  pba2 
)

l_byteaJoin()

Parameters
[in]ba1
[in,out]pba2data array is added to the one in ba1, and then ba2 is destroyed
Returns
0 if OK, 1 on error
Notes:
     (1) It is a no-op, not an error, for ba2 to be null.

Definition at line 465 of file bytearray.c.

References l_byteaAppendData(), l_byteaDestroy(), and l_byteaGetData().

◆ l_byteaSplit()

l_int32 l_byteaSplit ( L_BYTEA ba1,
size_t  splitloc,
L_BYTEA **  pba2 
)

l_byteaSplit()

Parameters
[in]ba1lba to split; array bytes nulled beyond the split loc
[in]splitloclocation in ba1 to split; ba2 begins there
[out]pba2with data starting at splitloc
Returns
0 if OK, 1 on error

Definition at line 497 of file bytearray.c.

References l_byteaGetData(), l_byteaInitFromMem(), and L_Bytea::size.

◆ l_byteaWrite()

l_int32 l_byteaWrite ( const char *  fname,
L_BYTEA ba,
size_t  startloc,
size_t  endloc 
)

l_byteaWrite()

Parameters
[in]fnameoutput file
[in]ba
[in]startlocfirst byte to output
[in]endloclast byte to output; use 0 to write to the end of the data array
Returns
0 if OK, 1 on error

Definition at line 578 of file bytearray.c.

References fopenWriteStream(), and l_byteaWriteStream().

◆ l_byteaWriteStream()

l_int32 l_byteaWriteStream ( FILE *  fp,
L_BYTEA ba,
size_t  startloc,
size_t  endloc 
)

l_byteaWriteStream()

Parameters
[in]fpfile stream opened for binary write
[in]ba
[in]startlocfirst byte to output
[in]endloclast byte to output; use 0 to write to the end of the data array
Returns
0 if OK, 1 on error

Definition at line 612 of file bytearray.c.

References l_byteaGetData().

Referenced by l_byteaWrite().