Changes to include for 3.00

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@295 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
theraysmith 2009-07-11 02:24:22 +00:00
parent 0048516024
commit 530fa19672
22 changed files with 9252 additions and 0 deletions

32
include/allheaders.h Executable file
View File

@ -0,0 +1,32 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ALLHEADERS_H
#define LEPTONICA_ALLHEADERS_H
#define LIBLEPT_MAJOR_VERSION 1
#define LIBLEPT_MINOR_VERSION 61
#include "alltypes.h"
#ifndef NO_PROTOS
#include "leptprotos.h"
#endif /* NO_PROTOS */
#endif /* LEPTONICA_ALLHEADERS_H */

42
include/alltypes.h Executable file
View File

@ -0,0 +1,42 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ALLTYPES_H
#define LEPTONICA_ALLTYPES_H
#include "environ.h"
/* imaging */
#include "array.h"
#include "arrayaccess.h"
#include "bbuffer.h"
#include "bmf.h"
#include "ccbord.h"
#include "gplot.h"
#include "heap.h"
#include "jbclass.h"
#include "list.h"
#include "morph.h"
#include "pix.h"
#include "ptra.h"
#include "queue.h"
#include "stack.h"
#include "watershed.h"
/* i/o */
#include "imageio.h"
#endif /* LEPTONICA_ALLTYPES_H */

107
include/array.h Executable file
View File

@ -0,0 +1,107 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ARRAY_H
#define LEPTONICA_ARRAY_H
/*
* Contains the following structs:
* struct Numa
* struct Numaa
* struct Numa2d
* struct NumaHash
* struct Sarray
*
* Contains definitions for:
* Numa interpolation flags
*/
/*------------------------------------------------------------------------*
* Array Structs *
*------------------------------------------------------------------------*/
#define NUMA_VERSION_NUMBER 1
/* Number array: an array of floats */
struct Numa
{
l_int32 nalloc; /* size of allocated number array */
l_int32 n; /* number of numbers saved */
l_int32 refcount; /* reference count (1 if no clones) */
l_float32 startx; /* x value assigned to array[0] */
l_float32 delx; /* change in x value as i --> i + 1 */
l_float32 *array; /* number array */
};
typedef struct Numa NUMA;
/* Array of number arrays */
struct Numaa
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 n; /* number of Numa saved */
struct Numa **numa; /* array of Numa */
};
typedef struct Numaa NUMAA;
/* Sparse 2-dimensional array of number arrays */
struct Numa2d
{
l_int32 nrows; /* number of rows allocated for ptr array */
l_int32 ncols; /* number of cols allocated for ptr array */
l_int32 initsize; /* initial size of each numa that is made */
struct Numa ***numa; /* 2D array of Numa */
};
typedef struct Numa2d NUMA2D;
/* A hash table of Numas */
struct NumaHash
{
l_int32 nbuckets;
l_int32 initsize; /* initial size of each numa that is made */
struct Numa **numa;
};
typedef struct NumaHash NUMAHASH;
#define SARRAY_VERSION_NUMBER 1
/* String array: an array of C strings */
struct Sarray
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 n; /* number of strings allocated */
l_int32 refcount; /* reference count (1 if no clones) */
char **array; /* string array */
};
typedef struct Sarray SARRAY;
/*------------------------------------------------------------------------*
* Array flags *
*------------------------------------------------------------------------*/
/* Flags for interpolation in Numa */
enum {
L_LINEAR_INTERP = 1, /* linear */
L_QUADRATIC_INTERP = 2 /* quadratic */
};
#endif /* LEPTONICA_ARRAY_H */

190
include/arrayaccess.h Executable file
View File

@ -0,0 +1,190 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ARRAY_ACCESS_H
#define LEPTONICA_ARRAY_ACCESS_H
/*
* arrayaccess.h
*
* 1, 2, 4, 8, 16 and 32 bit data access within an array of 32-bit words
*
* This is used primarily to access 1, 2, 4, 8, 16 and 32 bit pixels
* in a line of image data, represented as an array of 32-bit words.
*
* pdata: pointer to first 32-bit word in the array
* n: index of the pixel in the array
*
* Function calls for these accessors are defined in arrayaccess.c.
*
* However, for efficiency we use the inline macros for all accesses.
* Even though the 2 and 4 bit set* accessors are more complicated,
* they are about 10% faster than the function calls.
*
* The 32 bit access is just a cast and ptr arithmetic. We include
* it so that the input ptr can be void*.
*
* At the end of this file is code for invoking the function calls
* instead of inlining.
*
* The macro SET_DATA_BIT_VAL(pdata, n, val) is a bit slower than
* if (val == 0)
* CLEAR_DATA_BIT(pdata, n);
* else
* SET_DATA_BIT(pdata, n);
*/
#if 1 /* Inline Accessors */
#ifndef COMPILER_MSVC
/*--------------------------------------------------*
* 1 bit access *
*--------------------------------------------------*/
#define GET_DATA_BIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 5)) >> (31 - ((n) & 31))) & 1)
#define SET_DATA_BIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 5)) |= (0x80000000 >> ((n) & 31)))
#define CLEAR_DATA_BIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 5)) &= ~(0x80000000 >> ((n) & 31)))
#define SET_DATA_BIT_VAL(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 5); \
*_TEMP_WORD_PTR_ &= ~(0x80000000 >> ((n) & 31)); \
*_TEMP_WORD_PTR_ |= ((val) << (31 - ((n) & 31))); \
})
/*--------------------------------------------------*
* 2 bit access *
*--------------------------------------------------*/
#define GET_DATA_DIBIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 4)) >> (2 * (15 - ((n) & 15)))) & 3)
#define SET_DATA_DIBIT(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 4); \
*_TEMP_WORD_PTR_ &= ~(0xc0000000 >> (2 * ((n) & 15))); \
*_TEMP_WORD_PTR_ |= ((val) << (30 - 2 * ((n) & 15))); \
})
#define CLEAR_DATA_DIBIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 4)) &= ~(0xc0000000 >> (2 * ((n) & 15))))
/*--------------------------------------------------*
* 4 bit access *
*--------------------------------------------------*/
#define GET_DATA_QBIT(pdata, n) \
((*((l_uint32 *)(pdata) + ((n) >> 3)) >> (4 * (7 - ((n) & 7)))) & 0xf)
#define SET_DATA_QBIT(pdata, n, val) \
({l_uint32 *_TEMP_WORD_PTR_; \
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 3); \
*_TEMP_WORD_PTR_ &= ~(0xf0000000 >> (4 * ((n) & 7))); \
*_TEMP_WORD_PTR_ |= ((val) << (28 - 4 * ((n) & 7))); \
})
#define CLEAR_DATA_QBIT(pdata, n) \
(*((l_uint32 *)(pdata) + ((n) >> 3)) &= ~(0xf0000000 >> (4 * ((n) & 7))))
/*--------------------------------------------------*
* 8 bit access *
*--------------------------------------------------*/
#ifdef L_BIG_ENDIAN
#define GET_DATA_BYTE(pdata, n) \
(*((l_uint8 *)(pdata) + (n)))
#else /* L_LITTLE_ENDIAN */
#define GET_DATA_BYTE(pdata, n) \
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3))
#endif /* L_BIG_ENDIAN */
#ifdef L_BIG_ENDIAN
#define SET_DATA_BYTE(pdata, n, val) \
(*((l_uint8 *)(pdata) + (n)) = (val))
#else /* L_LITTLE_ENDIAN */
#define SET_DATA_BYTE(pdata, n, val) \
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3) = (val))
#endif /* L_BIG_ENDIAN */
/*--------------------------------------------------*
* 16 bit access *
*--------------------------------------------------*/
#ifdef L_BIG_ENDIAN
#define GET_DATA_TWO_BYTES(pdata, n) \
(*((l_uint16 *)(pdata) + (n)))
#else /* L_LITTLE_ENDIAN */
#define GET_DATA_TWO_BYTES(pdata, n) \
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2))
#endif /* L_BIG_ENDIAN */
#ifdef L_BIG_ENDIAN
#define SET_DATA_TWO_BYTES(pdata, n, val) \
(*((l_uint16 *)(pdata) + (n)) = (val))
#else /* L_LITTLE_ENDIAN */
#define SET_DATA_TWO_BYTES(pdata, n, val) \
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2) = (val))
#endif /* L_BIG_ENDIAN */
/*--------------------------------------------------*
* 32 bit access *
*--------------------------------------------------*/
#define GET_DATA_FOUR_BYTES(pdata, n) \
(*((l_uint32 *)(pdata) + (n)))
#define SET_DATA_FOUR_BYTES(pdata, n, val) \
(*((l_uint32 *)(pdata) + (n)) = (val))
#endif /* COMPILER_MSVC */
#endif /* Inline Accessors */
/*--------------------------------------------------*
* Slower, using function calls for all accessors *
*--------------------------------------------------*/
#if 0 || COMPILER_MSVC
#define GET_DATA_BIT(pdata, n) l_getDataBit(pdata, n)
#define SET_DATA_BIT(pdata, n) l_setDataBit(pdata, n)
#define CLEAR_DATA_BIT(pdata, n) l_clearDataBit(pdata, n)
#define SET_DATA_BIT_VAL(pdata, n, val) l_setDataBitVal(pdata, n, val)
#define GET_DATA_DIBIT(pdata, n) l_getDataDibit(pdata, n)
#define SET_DATA_DIBIT(pdata, n, val) l_setDataDibit(pdata, n, val)
#define CLEAR_DATA_DIBIT(pdata, n) l_clearDataDibit(pdata, n)
#define GET_DATA_QBIT(pdata, n) l_getDataQbit(pdata, n)
#define SET_DATA_QBIT(pdata, n, val) l_setDataQbit(pdata, n, val)
#define CLEAR_DATA_QBIT(pdata, n) l_clearDataQbit(pdata, n)
#define GET_DATA_BYTE(pdata, n) l_getDataByte(pdata, n)
#define SET_DATA_BYTE(pdata, n, val) l_setDataByte(pdata, n, val)
#define GET_DATA_TWO_BYTES(pdata, n) l_getDataTwoBytes(pdata, n)
#define SET_DATA_TWO_BYTES(pdata, n, val) l_setDataTwoBytes(pdata, n, val)
#define GET_DATA_FOUR_BYTES(pdata, n) l_getDataFourBytes(pdata, n)
#define SET_DATA_FOUR_BYTES(pdata, n, val) l_setDataFourBytes(pdata, n, val)
#endif
#endif /* LEPTONICA_ARRAY_ACCESS_H */

46
include/bbuffer.h Executable file
View File

@ -0,0 +1,46 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_BBUFFER_H
#define LEPTONICA_BBUFFER_H
/*
* bbuffer.h
*
* Expandable byte buffer for reading data in from memory and
* writing data out to other memory.
*
* This implements a queue of bytes, so data read in is put
* on the "back" of the queue (i.e., the end of the byte array)
* and data written out is taken from the "front" of the queue
* (i.e., from an index marker "nwritten" that is initially set at
* the beginning of the array.) As usual with expandable
* arrays, we keep the size of the allocated array and the
* number of bytes that have been read into the array.
*
* For implementation details, see bbuffer.c.
*/
struct ByteBuffer
{
l_int32 nalloc; /* size of allocated byte array */
l_int32 n; /* number of bytes read into to the array */
l_int32 nwritten; /* number of bytes written from the array */
l_uint8 *array; /* byte array */
};
typedef struct ByteBuffer BBUFFER;
#endif /* LEPTONICA_BBUFFER_H */

51
include/bmf.h Executable file
View File

@ -0,0 +1,51 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_BMF_H
#define LEPTONICA_BMF_H
/*
* bmf.h
*
* Simple data structure to hold bitmap fonts and related data
*/
/* Constants for deciding when text block is divided into paragraphs */
enum {
SPLIT_ON_LEADING_WHITE = 1, /* tab or space at beginning of line */
SPLIT_ON_BLANK_LINE = 2, /* newline with optional white space */
SPLIT_ON_BOTH = 3 /* leading white space or newline */
};
struct Bmf
{
struct Pixa *pixa; /* pixa of bitmaps for 93 characters */
l_int32 size; /* font size (in points at 300 ppi) */
char *directory; /* directory containing font bitmaps */
l_int32 baseline1; /* baseline offset for ascii 33 - 57 */
l_int32 baseline2; /* baseline offset for ascii 58 - 91 */
l_int32 baseline3; /* baseline offset for ascii 93 - 126 */
l_int32 lineheight; /* max height of line of chars */
l_int32 kernwidth; /* pixel dist between char bitmaps */
l_int32 spacewidth; /* pixel dist between word bitmaps */
l_int32 vertlinesep; /* extra vertical space between text lines */
l_int32 *fonttab; /* table mapping ascii --> font index */
l_int32 *baselinetab; /* table mapping ascii --> baseline offset */
l_int32 *widthtab; /* table mapping ascii --> char width */
};
typedef struct Bmf BMF;
#endif /* LEPTONICA_BMF_H */

103
include/ccbord.h Executable file
View File

@ -0,0 +1,103 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_CCBORD_H
#define LEPTONICA_CCBORD_H
/*
* ccbord.h
*
* CCBord: represents a single connected component
* CCBorda: an array of CCBord
*/
/* Use in ccbaStepChainsToPixCoords() */
enum {
CCB_LOCAL_COORDS = 1,
CCB_GLOBAL_COORDS = 2
};
/* Use in ccbaGenerateSPGlobalLocs() */
enum {
CCB_SAVE_ALL_PTS = 1,
CCB_SAVE_TURNING_PTS = 2
};
/* CCBord contains:
*
* (1) a minimally-clipped bitmap of the component (pix),
* (2) a boxa consisting of:
* for the primary component:
* (xul, yul) pixel location in global coords
* (w, h) of the bitmap
* for the hole components:
* (x, y) in relative coordinates in primary component
* (w, h) of the hole border (which is 2 pixels
* larger in each direction than the hole itself)
* (3) a pta ('start') of the initial border pixel location for each
* closed curve, all in relative coordinates of the primary
* component. This is given for the primary component,
* followed by the hole components, if any.
* (4) a refcount of the ccbord; used internally when a ccbord
* is accessed from a ccborda (array of ccbord)
* (5) a ptaa for the chain code for the border in relative
* coordinates, where the first pta is the exterior border
* and all other pta are for interior borders (holes)
* (6) a ptaa for the global pixel loc rendition of the border,
* where the first pta is the exterior border and all other
* pta are for interior borders (holes).
* This is derived from the local or step chain code.
* (7) a numaa for the chain code for the border as orientation
* directions between successive border pixels, where
* the first numa is the exterior border and all other
* numa are for interior borders (holes). This is derived
* from the local chain code. The 8 directions are 0 - 7.
* (8) a pta for a single chain for each c.c., comprised of outer
* and hole borders, plus cut paths between them, all in
* local coords.
* (9) a pta for a single chain for each c.c., comprised of outer
* and hole borders, plus cut paths between them, all in
* global coords.
*/
struct CCBord
{
struct Pix *pix; /* component bitmap (min size) */
struct Boxa *boxa; /* regions of each closed curve */
struct Pta *start; /* initial border pixel locations */
l_int32 refcount; /* number of handles; start at 1 */
struct Ptaa *local; /* ptaa of chain pixels (local) */
struct Ptaa *global; /* ptaa of chain pixels (global) */
struct Numaa *step; /* numaa of chain code (step dir) */
struct Pta *splocal; /* pta of single chain (local) */
struct Pta *spglobal; /* pta of single chain (global) */
};
typedef struct CCBord CCBORD;
struct CCBorda
{
struct Pix *pix; /* input pix (may be null) */
l_int32 w; /* width of pix */
l_int32 h; /* height of pix */
l_int32 n; /* number of ccbord in ptr array */
l_int32 nalloc; /* number of ccbord ptrs allocated */
struct CCBord **ccb; /* ccb ptr array */
};
typedef struct CCBorda CCBORDA;
#endif /* LEPTONICA_CCBORD_H */

252
include/environ.h Executable file
View File

@ -0,0 +1,252 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_ENVIRON_H
#define LEPTONICA_ENVIRON_H
#if defined(WIN32) || defined(WIN64)
/* WINDOWS_SPECIFICS */
/* Provide intptr_t from the non-existent stdint.h. */
#if defined(WIN32)
typedef int intptr_t;
typedef unsigned int uintptr_t;
#else
typedef long int intptr_t;
typedef unsigned long int uintptr_t;
#endif
/* VC++6 doesn't seem to have powf, expf. */
#if (_MSC_VER <= 1400)
#define powf(x, y) (float)pow((double)(x), (double)(y))
#define expf(x) (float)exp((double)(x))
#endif
/* DLL EXPORT/IMPORT */
#ifdef LEPTONLIB_EXPORTS
#define LEPT_DLL __declspec(dllexport)
#elif defined(LEPTONLIB_IMPORTS)
#define LEPT_DLL __declspec(dllimport)
#else
#define LEPT_DLL
#endif
#else /* non-WINDOWS-SPECIFICS */
#include <stdint.h>
#define LEPT_DLL
#endif
/* FILE was undefined somewhere */
#include <stdio.h>
typedef intptr_t l_intptr_t;
typedef uintptr_t l_uintptr_t;
/*--------------------------------------------------------------------*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
* USER CONFIGURABLE *
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
* Environ variables with I/O libraries *
* Manual Configuration Only: NOT AUTO_CONF *
*--------------------------------------------------------------------*/
/*
* Leptonica provides interfaces to link to four external image I/O
* libraries, plus zlib. Setting any of these to 0 causes
* non-functioning stubs to be linked.
*/
#ifndef HAVE_CONFIG_H
#define HAVE_LIBJPEG 1
#define HAVE_LIBTIFF 1
#define HAVE_LIBPNG 1
#define HAVE_LIBZ 1
#define HAVE_LIBGIF 0
#define HAVE_LIBUNGIF 0
#endif /* ~HAVE_CONFIG_H */
/*
* On linux systems, you can do I/O between Pix and memory. Specifically,
* you can compress (write compressed data to memory from a Pix) and
* uncompress (read from compressed data in memory to a Pix).
* For all but TIFF and PS, these use the non-posix GNU functions
* fmemopen() and open_memstream(). These functions are not
* available on other systems. To use these functions in linux,
* you must define HAVE_FMEMOPEN to be 1 here.
*/
#ifndef HAVE_CONFIG_H
#define HAVE_FMEMOPEN 0
#endif /* ~HAVE_CONFIG_H */
/*--------------------------------------------------------------------*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
* USER CONFIGURABLE *
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
* Environ variables for uncompressed formatted image I/O *
*--------------------------------------------------------------------*/
/*
* Leptonica supplies image I/O for pnm, bmp and ps.
* Setting any of these to 0 causes non-functioning stubs to be linked.
*/
#define USE_BMPIO 1
#define USE_PNMIO 1
#define USE_PSIO 1
/*--------------------------------------------------------------------*
* Built-in types *
*--------------------------------------------------------------------*/
typedef signed char l_int8;
typedef unsigned char l_uint8;
typedef short l_int16;
typedef unsigned short l_uint16;
typedef int l_int32;
typedef unsigned int l_uint32;
typedef float l_float32;
typedef double l_float64;
/*------------------------------------------------------------------------*
* Standard macros *
*------------------------------------------------------------------------*/
#ifndef L_MIN
#define L_MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef L_MAX
#define L_MAX(x,y) (((x) > (y)) ? (x) : (y))
#endif
#ifndef L_ABS
#define L_ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
#endif
#ifndef L_SIGN
#define L_SIGN(x) (((x) < 0) ? -1 : 1)
#endif
#ifndef UNDEF
#define UNDEF -1
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*--------------------------------------------------------------------*
* Environ variables used within compiler invocation *
*--------------------------------------------------------------------*/
/*
* To control conditional compilation, one of two variables
*
* L_LITTLE_ENDIAN (e.g., for Intel X86)
* L_BIG_ENDIAN (e.g., for Sun SPARC, Mac Power PC)
*
* is defined when the GCC compiler is invoked.
* All code should compile properly for both hardware architectures.
*/
/*------------------------------------------------------------------------*
* Simple search state variables *
*------------------------------------------------------------------------*/
enum {
L_NOT_FOUND = 0,
L_FOUND = 1
};
/*------------------------------------------------------------------------*
* Standard memory allocation *
*
* These specify the memory management functions that are used
* on all heap data except for Pix. Memory management for Pix
* also defaults to malloc and free. See pix1.c for details.
*------------------------------------------------------------------------*/
#define MALLOC(blocksize) malloc(blocksize)
#define CALLOC(numelem, elemsize) calloc(numelem, elemsize)
#define REALLOC(ptr, blocksize) realloc(ptr, blocksize)
#define FREE(ptr) free(ptr)
/*------------------------------------------------------------------------*
* Control printing of error, warning, and info messages *
* *
* (Use -DNO_CONSOLE_IO on compiler line to prevent text output) *
*------------------------------------------------------------------------*/
#ifdef NO_CONSOLE_IO
#define PROCNAME(name)
#define ERROR_PTR(a,b,c) ((void *)(c))
#define ERROR_INT(a,b,c) ((l_int32)(c))
#define ERROR_FLOAT(a,b,c) ((l_float32)(c))
#define ERROR_VOID(a,b)
#define L_ERROR(a,b)
#define L_ERROR_STRING(a,b,c)
#define L_ERROR_INT(a,b,c)
#define L_ERROR_FLOAT(a,b,c)
#define L_WARNING(a,b)
#define L_WARNING_STRING(a,b,c)
#define L_WARNING_INT(a,b,c)
#define L_WARNING_FLOAT(a,b,c)
#define L_INFO(a,b)
#define L_INFO_STRING(a,b,c)
#define L_INFO_INT(a,b,c)
#define L_INFO_INT2(a,b,c,d)
#define L_INFO_FLOAT(a,b,c)
#define L_INFO_FLOAT2(a,b,c,d)
#else
#define PROCNAME(name) static const char procName[] = name
#define ERROR_PTR(a,b,c) returnErrorPtr((a),(b),(c))
#define ERROR_INT(a,b,c) returnErrorInt((a),(b),(c))
#define ERROR_FLOAT(a,b,c) returnErrorFloat((a),(b),(c))
#define ERROR_VOID(a,b) returnErrorVoid((a),(b))
#define L_ERROR(a,b) l_error((a),(b))
#define L_ERROR_STRING(a,b,c) l_errorString((a),(b),(c))
#define L_ERROR_INT(a,b,c) l_errorInt((a),(b),(c))
#define L_ERROR_FLOAT(a,b,c) l_errorFloat((a),(b),(c))
#define L_WARNING(a,b) l_warning((a),(b))
#define L_WARNING_STRING(a,b,c) l_warningString((a),(b),(c))
#define L_WARNING_INT(a,b,c) l_warningInt((a),(b),(c))
#define L_WARNING_FLOAT(a,b,c) l_warningFloat((a),(b),(c))
#define L_INFO(a,b) l_info((a),(b))
#define L_INFO_STRING(a,b,c) l_infoString((a),(b),(c))
#define L_INFO_INT(a,b,c) l_infoInt((a),(b),(c))
#define L_INFO_INT2(a,b,c,d) l_infoInt2((a),(b),(c),(d))
#define L_INFO_FLOAT(a,b,c) l_infoFloat((a),(b),(c))
#define L_INFO_FLOAT2(a,b,c,d) l_infoFloat2((a),(b),(c),(d))
#endif /* NO_CONSOLE_IO */
/*------------------------------------------------------------------------*
* snprintf() renamed in MSVC *
*------------------------------------------------------------------------*/
#if defined(__MINGW32__) || defined(WIN32)
#define snprintf _snprintf
#endif
#endif /* LEPTONICA_ENVIRON_H */

77
include/gplot.h Executable file
View File

@ -0,0 +1,77 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_GPLOT_H
#define LEPTONICA_GPLOT_H
/*
* gplot.h
*
* Data structures and parameters for generating gnuplot files
*/
#define GPLOT_VERSION_NUMBER 1
#define NUM_GPLOT_STYLES 5
enum GPLOT_STYLE {
GPLOT_LINES = 0,
GPLOT_POINTS = 1,
GPLOT_IMPULSES = 2,
GPLOT_LINESPOINTS = 3,
GPLOT_DOTS = 4
};
#define NUM_GPLOT_OUTPUTS 6
enum GPLOT_OUTPUT {
GPLOT_NONE = 0,
GPLOT_PNG = 1,
GPLOT_PS = 2,
GPLOT_EPS = 3,
GPLOT_X11 = 4,
GPLOT_LATEX = 5
};
enum GPLOT_SCALING {
GPLOT_LINEAR_SCALE = 0, /* default */
GPLOT_LOG_SCALE_X = 1,
GPLOT_LOG_SCALE_Y = 2,
GPLOT_LOG_SCALE_X_Y = 3
};
extern const char *gplotstylenames[]; /* used in gnuplot cmd file */
extern const char *gplotfilestyles[]; /* used in simple file input */
extern const char *gplotfileoutputs[]; /* used in simple file input */
struct GPlot
{
char *rootname; /* for cmd, data, output */
char *cmdname; /* command file name */
struct Sarray *cmddata; /* command file contents */
struct Sarray *datanames; /* data file names */
struct Sarray *plotdata; /* plot data (1 string/file) */
struct Sarray *plottitles; /* title for each individual plot */
struct Numa *plotstyles; /* plot style for individual plots */
l_int32 nplots; /* current number of plots */
char *outname; /* output file name */
l_int32 outformat; /* GPLOT_OUTPUT values */
l_int32 scaling; /* GPLOT_SCALING values */
char *title; /* optional */
char *xlabel; /* optional x axis label */
char *ylabel; /* optional y axis label */
};
typedef struct GPlot GPLOT;
#endif /* LEPTONICA_GPLOT_H */

73
include/heap.h Executable file
View File

@ -0,0 +1,73 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_HEAP_H
#define LEPTONICA_HEAP_H
/*
* heap.h
*
* Expandable priority queue configured as a heap for arbitrary void* data
*
* The L_Heap is used to implement a priority queue. The elements
* in the heap are ordered in either increasing or decreasing key value.
* The key is a float field 'keyval' that is required to be
* contained in the elements of the queue.
*
* The heap is a simple binary tree with the following constraints:
* - the key of each node is >= the keys of the two children
* - the tree is complete, meaning that each level (1, 2, 4, ...)
* is filled and the last level is filled from left to right
*
* The tree structure is implicit in the queue array, with the
* array elements numbered as a breadth-first search of the tree
* from left to right. It is thus guaranteed that the largest
* (or smallest) key belongs to the first element in the array.
*
* Heap sort is used to sort the array. Once an array has been
* sorted as a heap, it is convenient to use it as a priority queue,
* because the min (or max) elements are always at the root of
* the tree (element 0), and once removed, the heap can be
* resorted in not more than log[n] steps, where n is the number
* of elements on the heap. Likewise, if an arbitrary element is
* added to the end of the array A, the sorted heap can be restored
* in not more than log[n] steps.
*
* A L_Heap differs from a L_Queue in that the elements in the former
* are sorted by a key. Internally, the array is maintained
* as a queue, with a pointer to the end of the array. The
* head of the array always remains at array[0]. The array is
* maintained (sorted) as a heap. When an item is removed from
* the head, the last item takes its place (thus reducing the
* array length by 1), and this is followed by array element
* swaps to restore the heap property. When an item is added,
* it goes at the end of the array, and is swapped up to restore
* the heap. If the ptr array is full, adding another item causes
* the ptr array size to double.
*
* For further implementation details, see heap.c.
*/
struct L_Heap
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 n; /* number of elements stored in the heap */
void **array; /* ptr array */
l_int32 direction; /* L_SORT_INCREASING or L_SORT_DECREASING */
};
typedef struct L_Heap L_HEAP;
#endif /* LEPTONICA_HEAP_H */

59
include/imageio.h Executable file
View File

@ -0,0 +1,59 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_IMAGEIO_H
#define LEPTONICA_IMAGEIO_H
/* ------------------ Image file format types -------------- */
/*
* The IFF_DEFAULT flag is used to write the file out in the
* same (input) file format that the pix was read from. If the pix
* was not read from file, the input format field will be
* IFF_UNKNOWN and the output file format will be chosen to
* be compressed and lossless; namely, IFF_TIFF_G4 for d = 1
* and IFF_PNG for everything else.
*/
enum {
IFF_UNKNOWN = 0,
IFF_BMP = 1,
IFF_JFIF_JPEG = 2,
IFF_PNG = 3,
IFF_TIFF = 4,
IFF_TIFF_PACKBITS = 5,
IFF_TIFF_RLE = 6,
IFF_TIFF_G3 = 7,
IFF_TIFF_G4 = 8,
IFF_TIFF_LZW = 9,
IFF_TIFF_ZIP = 10,
IFF_PNM = 11,
IFF_PS = 12,
IFF_GIF = 13,
IFF_DEFAULT = 14
};
/* ------------------ Format header ids --------------- */
enum {
BMP_ID = 0x4d42,
TIFF_BIGEND_ID = 0x4d4d, /* MM - for 'motorola' */
TIFF_LITTLEEND_ID = 0x4949 /* II - for 'intel' */
};
/* ------------------ Format header ids --------------- */
enum {
L_HINT_GRAY = 1, /* only want grayscale information */
};
#endif /* LEPTONICA_IMAGEIO_H */

122
include/jbclass.h Executable file
View File

@ -0,0 +1,122 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_JBCLASS_H
#define LEPTONICA_JBCLASS_H
/*
* jbclass.h
*
* JbClasser
* JbData
*/
/* The JbClasser struct holds all the data accumulated during the
* classification process that can be used for a compressed
* jbig2-type representation of a set of images. This is created
* in an initialization process and added to as the selected components
* on each successive page are analyzed. */
struct JbClasser
{
struct Sarray *safiles; /* input page image file names */
l_int32 method; /* JB_RANKHAUS, JB_CORRELATION */
l_int32 components; /* JB_CONN_COMPS, JB_CHARACTERS or */
/* JB_WORDS */
l_int32 maxwidth; /* max component width allowed */
l_int32 maxheight; /* max component height allowed */
l_int32 npages; /* number of pages already processed */
l_int32 baseindex; /* number of components already processed */
/* on fully processed pages */
struct Numa *nacomps; /* number of components on each page */
l_int32 sizehaus; /* size of square struct element for haus */
l_float32 rankhaus; /* rank val of haus match, each way */
l_float32 thresh; /* thresh value for correlation score */
l_float32 weightfactor; /* corrects thresh value for heaver */
/* components; use 0 for no correction */
struct Numa *naarea; /* w * h of each template, without extra */
/* border pixels */
l_int32 w; /* max width of original src images */
l_int32 h; /* max height of original src images */
l_int32 nclass; /* current number of classes */
l_int32 keep_pixaa; /* If zero, pixaa isn't filled */
struct Pixaa *pixaa; /* instances for each class; unbordered */
struct Pixa *pixat; /* templates for each class; bordered */
/* and not dilated */
struct Pixa *pixatd; /* templates for each class; bordered */
/* and dilated */
struct NumaHash *nahash; /* Hash table to find templates by size */
struct Numa *nafgt; /* fg areas of undilated templates; */
/* only used for rank < 1.0 */
struct Pta *ptac; /* centroids of all bordered cc */
struct Pta *ptact; /* centroids of all bordered template cc */
struct Numa *naclass; /* array of class ids for each component */
struct Numa *napage; /* array of page nums for each component */
struct Pta *ptaul; /* array of UL corners at which the */
/* template is to be placed for each */
/* component */
struct Pta *ptall; /* similar to ptaul, but for LL corners */
};
typedef struct JbClasser JBCLASSER;
/* The JbData struct holds all the data required for
* the compressed jbig-type representation of a set of images.
* The data can be written to file, read back, and used
* to regenerate an approximate version of the original,
* which differs in two ways from the original:
* (1) It uses a template image for each c.c. instead of the
* original instance, for each occurrence on each page.
* (2) It discards components with either a height or width larger
* than the maximuma, given here by the lattice dimensions
* used for storing the templates. */
struct JbData
{
struct Pix *pix; /* template composite for all classes */
l_int32 npages; /* number of pages */
l_int32 w; /* max width of original page images */
l_int32 h; /* max height of original page images */
l_int32 nclass; /* number of classes */
l_int32 latticew; /* lattice width for template composite */
l_int32 latticeh; /* lattice height for template composite */
struct Numa *naclass; /* array of class ids for each component */
struct Numa *napage; /* array of page nums for each component */
struct Pta *ptaul; /* array of UL corners at which the */
/* template is to be placed for each */
/* component */
};
typedef struct JbData JBDATA;
/* Classifier methods */
enum {
JB_RANKHAUS = 0,
JB_CORRELATION = 1
};
/* For jbGetComponents(): type of component to extract from images */
enum {
JB_CONN_COMPS = 0,
JB_CHARACTERS = 1,
JB_WORDS = 2
};
/* These parameters are used for naming the two files
* in which the jbig2-like compressed data is stored. */
#define JB_TEMPLATE_EXT ".templates.png"
#define JB_DATA_EXT ".data"
#endif /* LEPTONICA_JBCLASS_H */

1602
include/leptprotos.h Executable file

File diff suppressed because it is too large Load Diff

76
include/list.h Executable file
View File

@ -0,0 +1,76 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_LIST_H
#define LEPTONICA_LIST_H
/*
* list.h
*
* Cell for double-linked lists
*
* This allows composition of a list of cells with
* prev, next and data pointers. Generic data
* structures hang on the list cell data pointers.
*
* The list is not circular because that would add much
* complexity in traversing the list under general
* conditions where list cells can be added and removed.
* The only disadvantage of not having the head point to
* the last cell is that the list must be traversed to
* find its tail. However, this traversal is fast, and
* the listRemoveFromTail() function updates the tail
* so there is no searching overhead with repeated use.
*
* The list macros are used to run through a list, and their
* use is encouraged. They are invoked, e.g., as
*
* DLLIST *head, *elem;
* ...
* L_BEGIN_LIST_FORWARD(head, elem)
* <do something with elem and/or elem->data >
* L_END_LIST
*
*/
struct DoubleLinkedList
{
struct DoubleLinkedList *prev;
struct DoubleLinkedList *next;
void *data;
};
typedef struct DoubleLinkedList DLLIST;
/* Simple list traverse macros */
#define L_BEGIN_LIST_FORWARD(head, element) \
{ \
DLLIST *_leptvar_nextelem_; \
for ((element) = (head); (element); (element) = _leptvar_nextelem_) { \
_leptvar_nextelem_ = (element)->next;
#define L_BEGIN_LIST_REVERSE(tail, element) \
{ \
DLLIST *_leptvar_prevelem_; \
for ((element) = (tail); (element); (element) = _leptvar_prevelem_) { \
_leptvar_prevelem_ = (element)->prev;
#define L_END_LIST }}
#endif /* LEPTONICA_LIST_H */

215
include/morph.h Executable file
View File

@ -0,0 +1,215 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_MORPH_H
#define LEPTONICA_MORPH_H
/*
* morph.h
*
* Contains the following structs:
* struct Sel
* struct Sela
* struct Kernel
*
* Contains definitions for:
* morphological b.c. flags
* structuring element types
* runlength flags for granulometry
* direction flags for grayscale morphology
* morphological operation flags
* standard border size
* grayscale intensity scaling flags
* morphological tophat flags
* arithmetic and logical operator flags
* grayscale morphology selection flags
* distance function b.c. flags
* image comparison flags
* color content flags
*/
/*-------------------------------------------------------------------------*
* Sel and Sel array *
*-------------------------------------------------------------------------*/
#define SEL_VERSION_NUMBER 1
struct Sel
{
l_int32 sy; /* sel height */
l_int32 sx; /* sel width */
l_int32 cy; /* y location of sel origin */
l_int32 cx; /* x location of sel origin */
l_int32 **data; /* {0,1,2}; data[i][j] in [row][col] order */
char *name; /* used to find sel by name */
};
typedef struct Sel SEL;
struct Sela
{
l_int32 n; /* number of sel actually stored */
l_int32 nalloc; /* size of allocated ptr array */
struct Sel **sel; /* sel ptr array */
};
typedef struct Sela SELA;
/*-------------------------------------------------------------------------*
* Kernel *
*-------------------------------------------------------------------------*/
#define KERNEL_VERSION_NUMBER 2
struct L_Kernel
{
l_int32 sy; /* kernel height */
l_int32 sx; /* kernel width */
l_int32 cy; /* y location of kernel origin */
l_int32 cx; /* x location of kernel origin */
l_float32 **data; /* data[i][j] in [row][col] order */
};
typedef struct L_Kernel L_KERNEL;
/*-------------------------------------------------------------------------*
* Morphological boundary condition flags *
*
* Two types of boundary condition for erosion.
* The global variable MORPH_BC takes on one of these two values.
* See notes in morph.c for usage.
*-------------------------------------------------------------------------*/
enum {
SYMMETRIC_MORPH_BC = 0,
ASYMMETRIC_MORPH_BC = 1
};
/*-------------------------------------------------------------------------*
* Structuring element types *
*-------------------------------------------------------------------------*/
enum {
SEL_DONT_CARE = 0,
SEL_HIT = 1,
SEL_MISS = 2
};
/*-------------------------------------------------------------------------*
* Runlength flags for granulometry *
*-------------------------------------------------------------------------*/
enum {
L_RUN_OFF = 0,
L_RUN_ON = 1
};
/*-------------------------------------------------------------------------*
* Direction flags for grayscale morphology, granulometry, *
* and composable Sels *
*-------------------------------------------------------------------------*/
enum {
L_HORIZ = 1,
L_VERT = 2
};
/*-------------------------------------------------------------------------*
* Morphological operation flags *
*-------------------------------------------------------------------------*/
enum {
L_MORPH_DILATE = 1,
L_MORPH_ERODE = 2,
L_MORPH_OPEN = 3,
L_MORPH_CLOSE = 4,
L_MORPH_HMT = 5
};
/*-------------------------------------------------------------------------*
* Grayscale intensity scaling flags *
*-------------------------------------------------------------------------*/
enum {
L_LINEAR_SCALE = 1,
L_LOG_SCALE = 2
};
/*-------------------------------------------------------------------------*
* Morphological tophat flags *
*-------------------------------------------------------------------------*/
enum {
L_TOPHAT_WHITE = 0,
L_TOPHAT_BLACK = 1
};
/*-------------------------------------------------------------------------*
* Arithmetic and logical operator flags *
* (use on grayscale images and Numas) *
*-------------------------------------------------------------------------*/
enum {
L_ARITH_ADD = 1,
L_ARITH_SUBTRACT = 2,
L_ARITH_MULTIPLY = 3, /* on numas only */
L_ARITH_DIVIDE = 4, /* on numas only */
L_UNION = 5, /* on numas only */
L_INTERSECTION = 6, /* on numas only */
L_SUBTRACTION = 7, /* on numas only */
L_EXCLUSIVE_OR = 8 /* on numas only */
};
/*-------------------------------------------------------------------------*
* Min/max selection flags *
*-------------------------------------------------------------------------*/
enum {
L_CHOOSE_MIN = 1,
L_CHOOSE_MAX = 2
};
/*-------------------------------------------------------------------------*
* Distance function b.c. flags *
*-------------------------------------------------------------------------*/
enum {
L_BOUNDARY_BG = 1, /* assume bg outside image */
L_BOUNDARY_FG = 2 /* assume fg outside image */
};
/*-------------------------------------------------------------------------*
* Image comparison flags *
*-------------------------------------------------------------------------*/
enum {
L_COMPARE_XOR = 1,
L_COMPARE_SUBTRACT = 2,
L_COMPARE_ABS_DIFF = 3
};
/*-------------------------------------------------------------------------*
* Color content flags *
*-------------------------------------------------------------------------*/
enum {
L_MAX_DIFF_FROM_AVERAGE_2 = 1,
L_MAX_MIN_DIFF_FROM_2 = 2
};
/*-------------------------------------------------------------------------*
* Standard size of border added around images for special processing *
*-------------------------------------------------------------------------*/
static const l_int32 ADDED_BORDER = 32; /* pixels, not bits */
#endif /* LEPTONICA_MORPH_H */

772
include/pix.h Executable file
View File

@ -0,0 +1,772 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_PIX_H
#define LEPTONICA_PIX_H
/*
* pix.h
*
* Contains the following structures:
* struct Pix
* struct PixColormap
* struct RGBA_Quad
* struct Pixa
* struct Pixaa
* struct Box
* struct Boxa
* struct Boxaa
* struct Pta
* struct Ptaa
* struct Pixacc
* struct PixTiling
* struct FPix
* struct DPix
*
* Contains definitions for:
* colors for RGB
* colormap conversion flags
* rasterop bit flags
* structure access flags (for insert, copy, clone, copy-clone)
* sorting flags (by type and direction)
* blending flags
* graphics pixel setting flags
* size filtering flags
* rotation and shear flags
* affine transform order flags *
* grayscale filling flags
* dithering flags
* distance flags
* statistical measures
* set selection flags
* text orientation flags
* edge orientation flags
* line orientation flags
* scan direction flags
* thinning flags
* runlength flags
* edge filter flags
* handling negative values in conversion to unsigned int
* relative to zero flags
*/
/*-------------------------------------------------------------------------*
* Basic Pix *
*-------------------------------------------------------------------------*/
struct Pix
{
l_uint32 w; /* width in pixels */
l_uint32 h; /* height in pixels */
l_uint32 d; /* depth in bits */
l_uint32 wpl; /* 32-bit words/line */
l_uint32 refcount; /* reference count (1 if no clones) */
l_uint32 xres; /* image res (ppi) in x direction */
/* (use 0 if unknown) */
l_uint32 yres; /* image res (ppi) in y direction */
/* (use 0 if unknown) */
l_int32 informat; /* input file format, IFF_* */
char *text; /* text string associated with pix */
struct PixColormap *colormap; /* colormap (may be null) */
l_uint32 *data; /* the image data */
};
typedef struct Pix PIX;
struct PixColormap
{
void *array; /* colormap table (array of RGBA_QUAD) */
l_int32 depth; /* of pix (1, 2, 4 or 8 bpp) */
l_int32 nalloc; /* number of color entries allocated */
l_int32 n; /* number of color entries used */
};
typedef struct PixColormap PIXCMAP;
/* Colormap table entry (after the BMP version).
* Note that the BMP format stores the colormap table exactly
* as it appears here, with color samples being stored sequentially,
* in the order (b,g,r,a). */
struct RGBA_Quad
{
l_uint8 blue;
l_uint8 green;
l_uint8 red;
l_uint8 reserved;
};
typedef struct RGBA_Quad RGBA_QUAD;
/*-------------------------------------------------------------------------*
* Colors for 32 bpp *
*-------------------------------------------------------------------------*/
/* Notes:
* (1) These are the byte indices for colors in 32 bpp images.
* They are used through the GET/SET_DATA_BYTE accessors.
* The 4th byte, typically known as the "alpha channel" and used
* for blending, is not explicitly used in leptonica.
* (2) If you redefine these values, functions that have the shifts
* hardcoded (instead of using the constants below) will break.
* These functions are labelled with "***" next to their names
* at the top of the files in which they are defined.
* Advice: Do not change these values!
* (3) The shifts to extract the red, green and blue components
* from a 32 bit pixel are defined in terms of these colors.
*/
enum {
COLOR_RED = 0,
COLOR_GREEN = 1,
COLOR_BLUE = 2,
L_ALPHA_CHANNEL = 3
};
static const l_int32 L_RED_SHIFT =
8 * (sizeof(l_uint32) - 1 - COLOR_RED); /* 24 */
static const l_int32 L_GREEN_SHIFT =
8 * (sizeof(l_uint32) - 1 - COLOR_GREEN); /* 16 */
static const l_int32 L_BLUE_SHIFT =
8 * (sizeof(l_uint32) - 1 - COLOR_BLUE); /* 8 */
static const l_int32 L_ALPHA_SHIFT =
8 * (sizeof(l_uint32) - 1 - L_ALPHA_CHANNEL); /* 0 */
/*-------------------------------------------------------------------------*
* Flags for colormap conversion *
*-------------------------------------------------------------------------*/
enum {
REMOVE_CMAP_TO_BINARY = 0,
REMOVE_CMAP_TO_GRAYSCALE = 1,
REMOVE_CMAP_TO_FULL_COLOR = 2,
REMOVE_CMAP_BASED_ON_SRC = 3
};
/*-------------------------------------------------------------------------*
*
* The following operation bit flags have been modified from
* Sun's pixrect.h.
*
* The 'op' in 'rasterop' is represented by an integer
* composed with Boolean functions using the set of five integers
* given below. The integers, and the op codes resulting from
* boolean expressions on them, need only be in the range from 0 to 15.
* The function is applied on a per-pixel basis.
*
* Examples: the op code representing ORing the src and dest
* is computed using the bit OR, as PIX_SRC | PIX_DST; the op
* code representing XORing src and dest is found from
* PIX_SRC ^ PIX_DST; the op code representing ANDing src and dest
* is found from PIX_SRC & PIX_DST. Note that
* PIX_NOT(PIX_CLR) = PIX_SET, and v.v., as they must be.
*
* We would like to use the following set of definitions:
*
* #define PIX_SRC 0xc
* #define PIX_DST 0xa
* #define PIX_NOT(op) ((op) ^ 0xf)
* #define PIX_CLR 0x0
* #define PIX_SET 0xf
*
* Now, these definitions differ from Sun's, in that Sun
* left-shifted each value by 1 pixel, and used the least
* significant bit as a flag for the "pseudo-operation" of
* clipping. We don't need this bit, because it is both
* efficient and safe ALWAYS to clip the rectangles to the src
* and dest images, which is what we do. See the notes in rop.h
* on the general choice of these bit flags.
*
* However, if you include Sun's xview package, you will get their
* definitions, and because I like using these flags, we will
* adopt the original Sun definitions to avoid redefinition conflicts.
*
* Then we have, for reference, the following 16 unique op flags:
*
* PIX_CLR 00000 0x0
* PIX_SET 11110 0x1e
* PIX_SRC 11000 0x18
* PIX_DST 10100 0x14
* PIX_NOT(PIX_SRC) 00110 0x06
* PIX_NOT(PIX_DST) 01010 0x0a
* PIX_SRC | PIX_DST 11100 0x1c
* PIX_SRC & PIX_DST 10000 0x10
* PIX_SRC ^ PIX_DST 01100 0x0c
* PIX_NOT(PIX_SRC) | PIX_DST 10110 0x16
* PIX_NOT(PIX_SRC) & PIX_DST 00100 0x04
* PIX_SRC | PIX_NOT(PIX_DST) 11010 0x1a
* PIX_SRC & PIX_NOT(PIX_DST) 01000 0x08
* PIX_NOT(PIX_SRC | PIX_DST) 00010 0x02
* PIX_NOT(PIX_SRC & PIX_DST) 01110 0x0e
* PIX_NOT(PIX_SRC ^ PIX_DST) 10010 0x12
*
*-------------------------------------------------------------------------*/
#define PIX_SRC (0xc << 1)
#define PIX_DST (0xa << 1)
#define PIX_NOT(op) ((op) ^ 0x1e)
#define PIX_CLR (0x0 << 1)
#define PIX_SET (0xf << 1)
#define PIX_PAINT (PIX_SRC | PIX_DST)
#define PIX_MASK (PIX_SRC & PIX_DST)
#define PIX_SUBTRACT (PIX_DST & PIX_NOT(PIX_SRC))
#define PIX_XOR (PIX_SRC ^ PIX_DST)
/*-------------------------------------------------------------------------*
*
* Important Notes:
*
* (1) The image data is stored in a single contiguous
* array of l_uint32, into which the pixels are packed.
* By "packed" we mean that there are no unused bits
* between pixels, except for end-of-line padding to
* satisfy item (2) below.
*
* (2) Every image raster line begins on a 32-bit word
* boundary within this array.
*
* (3) Pix image data is stored in 32-bit units, with the
* pixels ordered from left to right in the image being
* stored in order from the MSB to LSB within the word,
* for both big-endian and little-endian machines.
* This is the natural ordering for big-endian machines,
* as successive bytes are stored and fetched progressively
* to the right. However, for little-endians, when storing
* we re-order the bytes from this byte stream order, and
* reshuffle again for byte access on 32-bit entities.
* So if the bytes come in sequence from left to right, we
* store them on little-endians in byte order:
* 3 2 1 0 7 6 5 4 ...
* This MSB to LSB ordering allows left and right shift
* operations on 32 bit words to move the pixels properly.
*
* (4) For 24-bit color images, use 32 bpp data, leaving
* the fourth byte unused. Within each 4 byte pixel, the
* colors are ordered from MSB to LSB, as follows:
*
* | MSB | 2nd MSB | 3rd MSB | LSB |
* red green blue unused
* 0 1 2 3 (big-endian)
* 3 2 1 0 (little-endian)
*
* Because we use MSB to LSB ordering within the 32-bit word,
* the individual 8-bit samples can be accessed with
* GET_DATA_BYTE and SET_DATA_BYTE macros, using the
* (implicitly big-ending) ordering
* red: byte 0 (MSB)
* green: byte 1 (2nd MSB)
* blue: byte 2 (3rd MSB)
*
* This specific color assignment is made in this file,
* through the definitions of COLOR_RED, etc. Then the R, G
* and B sample values can be retrieved using
* redval = GET_DATA_BYTE(&pixel, COLOR_RED);
* greenval = GET_DATA_BYTE(&pixel, COLOR_GREEN);
* blueval = GET_DATA_BYTE(&pixel, COLOR_BLUE);
* and they can be set with
* SET_DATA_BYTE(&pixel, COLOR_RED, redval);
* SET_DATA_BYTE(&pixel, COLOR_GREEN, greenval);
* SET_DATA_BYTE(&pixel, COLOR_BLUE, blueval);
*
* For extra speed we extract the R, G and B colors directly
* by shifting and masking, explicitly using the values in
* L_RED_SHIFT, L_GREEN_SHIFT and L_BLUE_SHIFT:
* (pixel32 >> L_RED_SHIFT) & 0xff; (red)
* (pixel32 >> L_GREEN_SHIFT) & 0xff; (green)
* (pixel32 >> L_BLUE_SHIFT) & 0xff; (blue)
* All these operations work properly on both big- and little-endians.
*
* For a few situations, these color shift values are hard-coded.
* Changing the RGB color component ordering through the assignments
* in this file will cause functions marked with "***" to fail.
*
* (5) A reference count is held within each pix, giving the
* number of ptrs to the pix. When a pixClone() call
* is made, the ref count is increased by 1, and
* when a pixDestroy() call is made, the reference count
* of the pix is decremented. The pix is only destroyed
* when the reference count goes to zero.
*
* (6) The version numbers (below) are used in the serialization
* of these data structures. They are placed in the files,
* and rarely (if ever) change. Provision is currently made for
* backward compatibility in reading from boxaa version 2.
*
* (7) The serialization dependencies are as follows:
* pixaa : pixa : boxa
* boxaa : boxa
* So, for example, pixaa and boxaa can be changed without
* forcing a change in pixa or boxa. However, if pixa is
* changed, it forces a change in pixaa, and if boxa is
* changed, if forces a change in the other three.
* We define four version numbers:
* PIXAA_VERSION_NUMBER
* PIXA_VERSION_NUMBER
* BOXAA_VERSION_NUMBER
* BOXA_VERSION_NUMBER
*
*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*
* Array of pix *
*-------------------------------------------------------------------------*/
/* Serialization for primary data structures */
#define PIXAA_VERSION_NUMBER 2
#define PIXA_VERSION_NUMBER 2
#define BOXA_VERSION_NUMBER 2
#define BOXAA_VERSION_NUMBER 3
struct Pixa
{
l_int32 n; /* number of Pix in ptr array */
l_int32 nalloc; /* number of Pix ptrs allocated */
l_uint32 refcount; /* reference count (1 if no clones) */
struct Pix **pix; /* the array of ptrs to pix */
struct Boxa *boxa; /* array of boxes */
};
typedef struct Pixa PIXA;
struct Pixaa
{
l_int32 n; /* number of Pixa in ptr array */
l_int32 nalloc; /* number of Pixa ptrs allocated */
struct Pixa **pixa; /* array of ptrs to pixa */
struct Boxa *boxa; /* array of boxes */
};
typedef struct Pixaa PIXAA;
/*-------------------------------------------------------------------------*
* Basic rectangle and rectangle arrays *
*-------------------------------------------------------------------------*/
struct Box
{
l_int32 x;
l_int32 y;
l_int32 w;
l_int32 h;
l_uint32 refcount; /* reference count (1 if no clones) */
};
typedef struct Box BOX;
struct Boxa
{
l_int32 n; /* number of box in ptr array */
l_int32 nalloc; /* number of box ptrs allocated */
l_uint32 refcount; /* reference count (1 if no clones) */
struct Box **box; /* box ptr array */
};
typedef struct Boxa BOXA;
struct Boxaa
{
l_int32 n; /* number of boxa in ptr array */
l_int32 nalloc; /* number of boxa ptrs allocated */
struct Boxa **boxa; /* boxa ptr array */
};
typedef struct Boxaa BOXAA;
/*-------------------------------------------------------------------------*
* Array of points *
*-------------------------------------------------------------------------*/
#define PTA_VERSION_NUMBER 1
struct Pta
{
l_int32 n; /* actual number of pts */
l_int32 nalloc; /* size of allocated arrays */
l_int32 refcount; /* reference count (1 if no clones) */
l_float32 *x, *y; /* arrays of floats */
};
typedef struct Pta PTA;
/*-------------------------------------------------------------------------*
* Array of Pta *
*-------------------------------------------------------------------------*/
struct Ptaa
{
l_int32 n; /* number of pta in ptr array */
l_int32 nalloc; /* number of pta ptrs allocated */
struct Pta **pta; /* pta ptr array */
};
typedef struct Ptaa PTAA;
/*-------------------------------------------------------------------------*
* Pix accumulator container *
*-------------------------------------------------------------------------*/
struct Pixacc
{
l_int32 w; /* array width */
l_int32 h; /* array height */
l_int32 offset; /* used to allow negative */
/* intermediate results */
struct Pix *pix; /* the 32 bit accumulator pix */
};
typedef struct Pixacc PIXACC;
/*-------------------------------------------------------------------------*
* Pix tiling *
*-------------------------------------------------------------------------*/
struct PixTiling
{
struct Pix *pix; /* input pix (a clone) */
l_int32 nx; /* number of tiles horizontally */
l_int32 ny; /* number of tiles vertically */
l_int32 w; /* tile width */
l_int32 h; /* tile height */
l_int32 xoverlap; /* overlap on left and right */
l_int32 yoverlap; /* overlap on top and bottom */
l_int32 strip; /* strip for paint; default is TRUE */
};
typedef struct PixTiling PIXTILING;
/*-------------------------------------------------------------------------*
* FPix: pix with float array *
*-------------------------------------------------------------------------*/
struct FPix
{
l_int32 w; /* width in pixels */
l_int32 h; /* height in pixels */
l_int32 wpl; /* 32-bit words/line */
l_int32 refcount; /* reference count (1 if no clones) */
l_int32 xres; /* image res (ppi) in x direction */
/* (use 0 if unknown) */
l_int32 yres; /* image res (ppi) in y direction */
/* (use 0 if unknown) */
l_float32 *data; /* the float image data */
};
typedef struct FPix FPIX;
/*-------------------------------------------------------------------------*
* DPix: pix with double array *
*-------------------------------------------------------------------------*/
struct DPix
{
l_int32 w; /* width in pixels */
l_int32 h; /* height in pixels */
l_int32 wpl; /* 32-bit words/line */
l_int32 refcount; /* reference count (1 if no clones) */
l_int32 xres; /* image res (ppi) in x direction */
/* (use 0 if unknown) */
l_int32 yres; /* image res (ppi) in y direction */
/* (use 0 if unknown) */
l_float64 *data; /* the double image data */
};
typedef struct DPix DPIX;
/*-------------------------------------------------------------------------*
* Access and storage flags *
*-------------------------------------------------------------------------*/
/*
* For Pix, Box, Pta and Numa, there are 3 standard methods for handling
* the retrieval or insertion of a struct:
* (1) direct insertion (Don't do this if there is another handle
* somewhere to this same struct!)
* (2) copy (Always safe, sets up a refcount of 1 on the new object.
* Can be undesirable if very large, such as an image or
* an array of images.)
* (3) clone (Makes another handle to the same struct, and bumps the
* refcount up by 1. Safe to do unless you're changing
* data through one of the handles but don't want those
* changes to be seen by the other handle.)
*
* For Pixa and Boxa, which are structs that hold an array of clonable
* structs, there is an additional method:
* (4) copy-clone (Makes a new higher-level struct with a refcount
* of 1, but clones all the structs in the array.)
*
* Unlike the other structs, when retrieving a string from an Sarray,
* you are allowed to get a handle without a copy or clone (i.e., that
* you don't own!). You must not free or insert such a string!
* Specifically, for an Sarray, the copyflag for retrieval is either:
* TRUE (or 1 or L_COPY)
* or
* FALSE (or 0 or L_NOCOPY)
* For insertion, the copyflag is either:
* TRUE (or 1 or L_COPY)
* or
* FALSE (or 0 or L_INSERT)
* Note that L_COPY is always 1, and L_INSERT and L_NOCOPY are always 0.
*/
enum {
L_INSERT = 0, /* stuff it in; no copy, clone or copy-clone */
L_COPY = 1, /* make/use a copy of the object */
L_CLONE = 2, /* make/use clone (ref count) of the object */
L_COPY_CLONE = 3 /* make a new object and fill with with clones */
/* of each object in the array(s) */
};
static const l_int32 L_NOCOPY = 0; /* copyflag value in sarrayGetString() */
/*--------------------------------------------------------------------------*
* Sort flags *
*--------------------------------------------------------------------------*/
enum {
L_SORT_INCREASING = 1, /* sort in increasing order */
L_SORT_DECREASING = 2 /* sort in decreasing order */
};
enum {
L_SORT_BY_X = 3, /* sort box or c.c. by horiz location */
L_SORT_BY_Y = 4, /* sort box or c.c. by vert location */
L_SORT_BY_WIDTH = 5, /* sort box or c.c. by width */
L_SORT_BY_HEIGHT = 6, /* sort box or c.c. by height */
L_SORT_BY_MIN_DIMENSION = 7, /* sort box or c.c. by min dimension */
L_SORT_BY_MAX_DIMENSION = 8, /* sort box or c.c. by max dimension */
L_SORT_BY_PERIMETER = 9, /* sort box or c.c. by perimeter */
L_SORT_BY_AREA = 10, /* sort box or c.c. by area */
L_SORT_BY_ASPECT_RATIO = 11 /* sort box or c.c. by width/height ratio */
};
/*-------------------------------------------------------------------------*
* Blend flags *
*-------------------------------------------------------------------------*/
enum {
L_BLEND_WITH_INVERSE = 1, /* add some of src inverse to itself */
L_BLEND_TO_WHITE = 2, /* shift src colors towards white */
L_BLEND_TO_BLACK = 3, /* shift src colors towards black */
L_BLEND_GRAY = 4, /* blend src directly with blender */
L_BLEND_GRAY_WITH_INVERSE = 5 /* add amount of src inverse to itself, */
/* based on blender pix value */
};
enum {
L_PAINT_LIGHT = 1, /* colorize non-black pixels */
L_PAINT_DARK = 2 /* colorize non-white pixels */
};
/*-------------------------------------------------------------------------*
* Graphics pixel setting *
*-------------------------------------------------------------------------*/
enum {
L_SET_PIXELS = 1, /* set all bits in each pixel to 1 */
L_CLEAR_PIXELS = 2, /* set all bits in each pixel to 0 */
L_FLIP_PIXELS = 3 /* flip all bits in each pixel */
};
/*-------------------------------------------------------------------------*
* Size filter flags *
*-------------------------------------------------------------------------*/
enum {
L_SELECT_WIDTH = 1, /* width must satisfy constraint */
L_SELECT_HEIGHT = 2, /* height must satisfy constraint */
L_SELECT_IF_EITHER = 3, /* either width or height can satisfy */
L_SELECT_IF_BOTH = 4 /* both width and height must satisfy */
};
enum {
L_SELECT_IF_LT = 1, /* save if value is less than threshold */
L_SELECT_IF_GT = 2, /* save if value is more than threshold */
L_SELECT_IF_LTE = 3, /* save if value is <= to the threshold */
L_SELECT_IF_GTE = 4 /* save if value is >= to the threshold */
};
/*-------------------------------------------------------------------------*
* Rotate and shear flags *
*-------------------------------------------------------------------------*/
enum {
L_ROTATE_AREA_MAP = 1, /* use area map rotation, if possible */
L_ROTATE_SHEAR = 2, /* use shear rotation */
L_ROTATE_SAMPLING = 3 /* use sampling */
};
enum {
L_BRING_IN_WHITE = 1, /* bring in white pixels from the outside */
L_BRING_IN_BLACK = 2 /* bring in black pixels from the outside */
};
enum {
L_SHEAR_ABOUT_CORNER = 1, /* shear image about UL corner */
L_SHEAR_ABOUT_CENTER = 2 /* shear image about center */
};
/*-------------------------------------------------------------------------*
* Affine transform order flags *
*-------------------------------------------------------------------------*/
enum {
L_TR_SC_RO = 1, /* translate, scale, rotate */
L_SC_RO_TR = 2, /* scale, rotate, translate */
L_RO_TR_SC = 3, /* rotate, translate, scale */
L_TR_RO_SC = 4, /* translate, rotate, scale */
L_RO_SC_TR = 5, /* rotate, scale, translate */
L_SC_TR_RO = 6 /* scale, translate, rotate */
};
/*-------------------------------------------------------------------------*
* Grayscale fill flags *
*-------------------------------------------------------------------------*/
enum {
L_FILL_WHITE = 1, /* fill white pixels (e.g, in fg map) */
L_FILL_BLACK = 2 /* fill black pixels (e.g., in bg map) */
};
/*-------------------------------------------------------------------------*
* Dither parameters *
* If within this grayscale distance from black or white, *
* do not propagate excess or deficit to neighboring pixels. *
*-------------------------------------------------------------------------*/
enum {
DEFAULT_CLIP_LOWER_1 = 10, /* dist to black with no prop; 1 bpp */
DEFAULT_CLIP_UPPER_1 = 10, /* dist to black with no prop; 1 bpp */
DEFAULT_CLIP_LOWER_2 = 5, /* dist to black with no prop; 2 bpp */
DEFAULT_CLIP_UPPER_2 = 5 /* dist to black with no prop; 2 bpp */
};
/*-------------------------------------------------------------------------*
* Distance flags *
*-------------------------------------------------------------------------*/
enum {
L_MANHATTAN_DISTANCE = 1, /* L1 distance (e.g., in color space) */
L_EUCLIDEAN_DISTANCE = 2 /* L2 distance */
};
/*-------------------------------------------------------------------------*
* Statistical measures *
*-------------------------------------------------------------------------*/
enum {
L_MEAN_ABSVAL = 1, /* average of abs values */
L_MEDIAN_VAL = 2, /* median value of set */
L_MODE_VAL = 3, /* mode value of set */
L_MODE_COUNT = 4, /* mode count of set */
L_ROOT_MEAN_SQUARE = 5, /* rms of values */
L_STANDARD_DEVIATION = 6, /* standard deviation from mean */
L_VARIANCE = 7 /* variance of values */
};
/*-------------------------------------------------------------------------*
* Set selection flags *
*-------------------------------------------------------------------------*/
enum {
L_CHOOSE_CONSECUTIVE = 1, /* select 'n' consecutive */
L_CHOOSE_SKIP_BY = 2 /* select at intervals of 'n' */
};
/*-------------------------------------------------------------------------*
* Text orientation flags *
*-------------------------------------------------------------------------*/
enum {
L_TEXT_ORIENT_UNKNOWN = 0, /* low confidence on text orientation */
L_TEXT_ORIENT_UP = 1, /* portrait, text rightside-up */
L_TEXT_ORIENT_LEFT = 2, /* landscape, text up to left */
L_TEXT_ORIENT_DOWN = 3, /* portrait, text upside-down */
L_TEXT_ORIENT_RIGHT = 4 /* landscape, text up to right */
};
/*-------------------------------------------------------------------------*
* Edge orientation flags *
*-------------------------------------------------------------------------*/
enum {
L_HORIZONTAL_EDGES = 0, /* filters for horizontal edges */
L_VERTICAL_EDGES = 1, /* filters for vertical edges */
L_ALL_EDGES = 2 /* filters for all edges */
};
/*-------------------------------------------------------------------------*
* Line orientation flags *
*-------------------------------------------------------------------------*/
enum {
L_HORIZONTAL_LINE = 0, /* horizontal line */
L_POS_SLOPE_LINE = 1, /* 45 degree line with positive slope */
L_VERTICAL_LINE = 2, /* vertical line */
L_NEG_SLOPE_LINE = 3 /* 45 degree line with negative slope */
};
/*-------------------------------------------------------------------------*
* Scan direction flags *
*-------------------------------------------------------------------------*/
enum {
L_FROM_LEFT = 0, /* scan from left */
L_FROM_RIGHT = 1, /* scan from right */
L_FROM_TOP = 2, /* scan from top */
L_FROM_BOTTOM = 3 /* scan from bottom */
};
/*-------------------------------------------------------------------------*
* Thinning flags *
*-------------------------------------------------------------------------*/
enum {
L_THIN_FG = 1, /* thin foreground of 1 bpp image */
L_THIN_BG = 2 /* thin background of 1 bpp image */
};
/*-------------------------------------------------------------------------*
* Runlength flags *
*-------------------------------------------------------------------------*/
enum {
L_HORIZONTAL_RUNS = 0, /* determine runlengths of horizontal runs */
L_VERTICAL_RUNS = 1 /* determine runlengths of vertical runs */
};
/*-------------------------------------------------------------------------*
* Edge filter flags *
*-------------------------------------------------------------------------*/
enum {
L_SOBEL_EDGE = 1, /* Sobel edge filter */
L_TWO_SIDED_EDGE = 2 /* Two-sided edge filter */
};
/*-------------------------------------------------------------------------*
* Handling negative values in conversion to unsigned int *
*-------------------------------------------------------------------------*/
enum {
L_CLIP_TO_ZERO = 1, /* Clip negative values to 0 */
L_TAKE_ABSVAL = 2 /* Convert to positive using L_ABS() */
};
/*-------------------------------------------------------------------------*
* Relative to zero flags *
*-------------------------------------------------------------------------*/
enum {
L_LESS_THAN_ZERO = 1, /* Choose values less than zero */
L_EQUAL_TO_ZERO = 2, /* Choose values equal to zero */
L_GREATER_THAN_ZERO = 3 /* Choose values greater than zero */
};
#endif /* LEPTONICA_PIX_H */

3687
include/png.h Executable file

File diff suppressed because it is too large Load Diff

1496
include/pngconf.h Executable file

File diff suppressed because it is too large Load Diff

80
include/ptra.h Executable file
View File

@ -0,0 +1,80 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_PTRA_H
#define LEPTONICA_PTRA_H
/*
* Contains the following structs:
* struct L_Ptra
* struct L_Ptraa
*
* Contains definitions for:
* L_Ptra compaction flags for removal
* L_Ptra shifting flags for insert
* L_Ptraa accessor flags
*/
/*------------------------------------------------------------------------*
* Generic Ptr Array Structs *
*------------------------------------------------------------------------*/
/* Generic pointer array */
struct L_Ptra
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 imax; /* greatest valid index */
l_int32 nactual; /* actual number of stored elements */
void **array; /* ptr array */
};
typedef struct L_Ptra L_PTRA;
/* Array of generic pointer arrays */
struct L_Ptraa
{
l_int32 nalloc; /* size of allocated ptr array */
struct L_Ptra **ptra; /* array of ptra */
};
typedef struct L_Ptraa L_PTRAA;
/*------------------------------------------------------------------------*
* Array flags *
*------------------------------------------------------------------------*/
/* Flags for removal from L_Ptra */
enum {
L_NO_COMPACTION = 1, /* null the pointer only */
L_COMPACTION = 2 /* compact the array */
};
/* Flags for insertion into L_Ptra */
enum {
L_AUTO_DOWNSHIFT = 0, /* choose based on number of holes */
L_MIN_DOWNSHIFT = 1, /* downshifts min # of ptrs below insert */
L_FULL_DOWNSHIFT = 2 /* downshifts all ptrs below insert */
};
/* Accessor flags for L_Ptraa */
enum {
L_HANDLE_ONLY = 0, /* ptr to L_Ptra; caller can inspect only */
L_REMOVE = 1 /* caller owns; destroy or save in L_Ptraa */
};
#endif /* LEPTONICA_PTRA_H */

63
include/queue.h Executable file
View File

@ -0,0 +1,63 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_QUEUE_H
#define LEPTONICA_QUEUE_H
/*
* queue.h
*
* Expandable pointer queue for arbitrary void* data.
*
* The L_Queue is a fifo that implements a queue of void* pointers.
* It can be used to hold a queue of any type of struct.
*
* Internally, it maintains two counters:
* nhead: location of head (in ptrs) from the beginning
* of the array.
* nelem: number of ptr elements stored in the queue.
*
* The element at the head of the queue, which is the next to
* be removed, is array[nhead]. The location at the tail of the
* queue to which the next element will be added is
* array[nhead + nelem].
*
* As items are added to the queue, nelem increases.
* As items are removed, nhead increases and nelem decreases.
* Any time the tail reaches the end of the allocated array,
* all the pointers are shifted to the left, so that the head
* is at the beginning of the array.
* If the array becomes more than 3/4 full, it doubles in size.
*
* The auxiliary stack can be used in a wrapper for re-using
* items popped from the queue. It is not made by default.
*
* For further implementation details, see queue.c.
*/
struct L_Queue
{
l_int32 nalloc; /* size of allocated ptr array */
l_int32 nhead; /* location of head (in ptrs) from the */
/* beginning of the array */
l_int32 nelem; /* number of elements stored in the queue */
void **array; /* ptr array */
struct L_Stack *stack; /* auxiliary stack */
};
typedef struct L_Queue L_QUEUE;
#endif /* LEPTONICA_QUEUE_H */

55
include/stack.h Executable file
View File

@ -0,0 +1,55 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_STACK_H
#define LEPTONICA_STACK_H
/*
* stack.h
*
* Expandable pointer stack for arbitrary void* data.
*
* The L_Stack is an array of void * ptrs, onto which arbitrary
* objects can be stored. At any time, the number of
* stored objects is stack->n. The object at the bottom
* of the stack is at array[0]; the object at the top of
* the stack is at array[n-1]. New objects are added
* to the top of the stack, at the first available location,
* which is array[n]. Objects are removed from the top of the
* stack. When an attempt is made to remove an object from an
* empty stack, the result is null. When the stack becomes
* filled, so that n = nalloc, the size is doubled.
*
* The auxiliary stack can be used to store and remove
* objects for re-use. It must be created by a separate
* call to pstackCreate(). [Just imagine the chaos if
* pstackCreate() created the auxiliary stack!]
* pstackDestroy() checks for the auxiliary stack and removes it.
*/
/* Note that array[n] is the first null ptr in the array */
struct L_Stack
{
l_int32 nalloc; /* size of ptr array */
l_int32 n; /* number of stored elements */
void **array; /* ptr array */
struct L_Stack *auxstack; /* auxiliary stack */
};
typedef struct L_Stack L_STACK;
#endif /* LEPTONICA_STACK_H */

52
include/watershed.h Executable file
View File

@ -0,0 +1,52 @@
/*====================================================================*
- Copyright (C) 2001 Leptonica. All rights reserved.
- This software is distributed in the hope that it will be
- useful, but with NO WARRANTY OF ANY KIND.
- No author or distributor accepts responsibility to anyone for the
- consequences of using this software, or for whether it serves any
- particular purpose or works at all, unless he or she says so in
- writing. Everyone is granted permission to copy, modify and
- redistribute this source code, for commercial or non-commercial
- purposes, with the following restrictions: (1) the origin of this
- source code must not be misrepresented; (2) modified versions must
- be plainly marked as such; and (3) this notice may not be removed
- or altered from any source or modified source distribution.
*====================================================================*/
#ifndef LEPTONICA_WATERSHED_H
#define LEPTONICA_WATERSHED_H
/*
* watershed.h
*
* Simple data structure to hold watershed data.
* All data here is owned by the L_WShed and must be freed.
*/
struct L_WShed
{
struct Pix *pixs; /* clone of input 8 bpp pixs */
struct Pix *pixm; /* clone of input 1 bpp seed (marker) pixm */
l_int32 mindepth; /* minimum depth allowed for a watershed */
struct Pix *pixlab; /* 16 bpp label pix */
struct Pix *pixt; /* scratch pix for computing wshed regions */
void **lines8; /* line ptrs for pixs */
void **linem1; /* line ptrs for pixm */
void **linelab32; /* line ptrs for pixlab */
void **linet1; /* line ptrs for pixt */
struct Pixa *pixad; /* result: 1 bpp pixa of watersheds */
struct Pta *ptas; /* pta of initial seed pixels */
struct Numa *nasi; /* numa of seed indicators; 0 if completed */
struct Numa *nash; /* numa of initial seed heights */
struct Numa *namh; /* numa of initial minima heights */
struct Numa *nalevels; /* result: numa of watershed levels */
l_int32 nseeds; /* number of seeds (markers) */
l_int32 nother; /* number of minima different from seeds */
l_int32 *lut; /* lut for pixel indices */
struct Numa **links; /* back-links into lut, for updates */
l_int32 arraysize; /* size of links array */
l_int32 debug; /* set to 1 for debug output */
};
typedef struct L_WShed L_WSHED;
#endif /* LEPTONICA_WATERSHED_H */