1 /*====================================================================* 2 - Copyright (C) 2001 Leptonica. All rights reserved. 3 - 4 - Redistribution and use in source and binary forms, with or without 5 - modification, are permitted provided that the following conditions 6 - are met: 7 - 1. Redistributions of source code must retain the above copyright 8 - notice, this list of conditions and the following disclaimer. 9 - 2. Redistributions in binary form must reproduce the above 10 - copyright notice, this list of conditions and the following 11 - disclaimer in the documentation and/or other materials 12 - provided with the distribution. 13 - 14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY 18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 *====================================================================*/ 26 27 #ifndef LEPTONICA_ARRAY_H 28 #define LEPTONICA_ARRAY_H 29 30 /*! 31 * \file array.h 32 * 33 * <pre> 34 * Contains the following structs: 35 * struct Numa 36 * struct Numaa 37 * struct L_Dna 38 * struct L_Dnaa 39 * struct L_DnaHash 40 * struct Sarray 41 * struct L_Bytea 42 * 43 * Contains definitions for: 44 * Numa interpolation flags 45 * Numa and FPix border flags 46 * Numa data type conversion to string 47 * </pre> 48 */ 49 50 51 /*------------------------------------------------------------------------* 52 * Array Structs * 53 *------------------------------------------------------------------------*/ 54 55 /*! Numa version for serialization */ 56 #define NUMA_VERSION_NUMBER 1 57 58 /*! Number array: an array of floats */ 59 struct Numa 60 { 61 l_int32 nalloc; /*!< size of allocated number array */ 62 l_int32 n; /*!< number of numbers saved */ 63 l_int32 refcount; /*!< reference count (1 if no clones) */ 64 l_float32 startx; /*!< x value assigned to array[0] */ 65 l_float32 delx; /*!< change in x value as i --> i + 1 */ 66 l_float32 *array; /*!< number array */ 67 }; 68 typedef struct Numa NUMA; 69 70 /*! Array of number arrays */ 71 struct Numaa 72 { 73 l_int32 nalloc; /*!< size of allocated ptr array */ 74 l_int32 n; /*!< number of Numa saved */ 75 struct Numa **numa; /*!< array of Numa */ 76 }; 77 typedef struct Numaa NUMAA; 78 79 /*! Dna version for serialization */ 80 #define DNA_VERSION_NUMBER 1 81 82 /*! Double number array: an array of doubles */ 83 struct L_Dna 84 { 85 l_int32 nalloc; /*!< size of allocated number array */ 86 l_int32 n; /*!< number of numbers saved */ 87 l_int32 refcount; /*!< reference count (1 if no clones) */ 88 l_float64 startx; /*!< x value assigned to array[0] */ 89 l_float64 delx; /*!< change in x value as i --> i + 1 */ 90 l_float64 *array; /*!< number array */ 91 }; 92 typedef struct L_Dna L_DNA; 93 94 /*! Array of double number arrays */ 95 struct L_Dnaa 96 { 97 l_int32 nalloc; /*!< size of allocated ptr array */ 98 l_int32 n; /*!< number of L_Dna saved */ 99 struct L_Dna **dna; /*!< array of L_Dna */ 100 }; 101 typedef struct L_Dnaa L_DNAA; 102 103 /*! A hash table of Dnas */ 104 struct L_DnaHash 105 { 106 l_int32 nbuckets; 107 l_int32 initsize; /*!< initial size of each dna that is made */ 108 struct L_Dna **dna; /*!< array of L_Dna */ 109 }; 110 typedef struct L_DnaHash L_DNAHASH; 111 112 /*! Sarray version for serialization */ 113 #define SARRAY_VERSION_NUMBER 1 114 115 /*! String array: an array of C strings */ 116 struct Sarray 117 { 118 l_int32 nalloc; /*!< size of allocated ptr array */ 119 l_int32 n; /*!< number of strings allocated */ 120 l_int32 refcount; /*!< reference count (1 if no clones) */ 121 char **array; /*!< string array */ 122 }; 123 typedef struct Sarray SARRAY; 124 125 /*! Byte array (analogous to C++ "string") */ 126 struct L_Bytea 127 { 128 size_t nalloc; /*!< number of bytes allocated in data array */ 129 size_t size; /*!< number of bytes presently used */ 130 l_int32 refcount; /*!< reference count (1 if no clones) */ 131 l_uint8 *data; /*!< data array */ 132 }; 133 typedef struct L_Bytea L_BYTEA; 134 135 136 /*------------------------------------------------------------------------* 137 * Array flags * 138 *------------------------------------------------------------------------*/ 139 /*! Flags for interpolation in Numa */ 140 enum { 141 L_LINEAR_INTERP = 1, /*!< linear */ 142 L_QUADRATIC_INTERP = 2 /*!< quadratic */ 143 }; 144 145 /*! Flags for added borders in Numa and Fpix */ 146 enum { 147 L_CONTINUED_BORDER = 1, /*!< extended with same value */ 148 L_SLOPE_BORDER = 2, /*!< extended with constant normal derivative */ 149 L_MIRRORED_BORDER = 3 /*!< mirrored */ 150 }; 151 152 /*! Flags for data type converted from Numa */ 153 enum { 154 L_INTEGER_VALUE = 1, /*!< convert to integer */ 155 L_FLOAT_VALUE = 2 /*!< convert to float */ 156 }; 157 158 159 #endif /* LEPTONICA_ARRAY_H */ 160