array.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifndef LEPTONICA_ARRAY_H
  27. #define LEPTONICA_ARRAY_H
  28. /*!
  29. * \file array.h
  30. *
  31. * <pre>
  32. * Contains the following structs:
  33. * struct Numa
  34. * struct Numaa
  35. * struct L_Dna
  36. * struct L_Dnaa
  37. * struct L_DnaHash
  38. * struct Sarray
  39. * struct L_Bytea
  40. *
  41. * Contains definitions for:
  42. * Numa interpolation flags
  43. * Numa and FPix border flags
  44. * Numa data type conversion to string
  45. * </pre>
  46. */
  47. /*------------------------------------------------------------------------*
  48. * Array Structs *
  49. *------------------------------------------------------------------------*/
  50. /*! Numa version for serialization */
  51. #define NUMA_VERSION_NUMBER 1
  52. /*! Number array: an array of floats */
  53. struct Numa
  54. {
  55. l_int32 nalloc; /*!< size of allocated number array */
  56. l_int32 n; /*!< number of numbers saved */
  57. l_int32 refcount; /*!< reference count (1 if no clones) */
  58. l_float32 startx; /*!< x value assigned to array[0] */
  59. l_float32 delx; /*!< change in x value as i --> i + 1 */
  60. l_float32 *array; /*!< number array */
  61. };
  62. typedef struct Numa NUMA;
  63. /*! Array of number arrays */
  64. struct Numaa
  65. {
  66. l_int32 nalloc; /*!< size of allocated ptr array */
  67. l_int32 n; /*!< number of Numa saved */
  68. struct Numa **numa; /*!< array of Numa */
  69. };
  70. typedef struct Numaa NUMAA;
  71. /*! Dna version for serialization */
  72. #define DNA_VERSION_NUMBER 1
  73. /*! Double number array: an array of doubles */
  74. struct L_Dna
  75. {
  76. l_int32 nalloc; /*!< size of allocated number array */
  77. l_int32 n; /*!< number of numbers saved */
  78. l_int32 refcount; /*!< reference count (1 if no clones) */
  79. l_float64 startx; /*!< x value assigned to array[0] */
  80. l_float64 delx; /*!< change in x value as i --> i + 1 */
  81. l_float64 *array; /*!< number array */
  82. };
  83. typedef struct L_Dna L_DNA;
  84. /*! Array of double number arrays */
  85. struct L_Dnaa
  86. {
  87. l_int32 nalloc; /*!< size of allocated ptr array */
  88. l_int32 n; /*!< number of L_Dna saved */
  89. struct L_Dna **dna; /*!< array of L_Dna */
  90. };
  91. typedef struct L_Dnaa L_DNAA;
  92. /*! A hash table of Dnas */
  93. struct L_DnaHash
  94. {
  95. l_int32 nbuckets;
  96. l_int32 initsize; /*!< initial size of each dna that is made */
  97. struct L_Dna **dna; /*!< array of L_Dna */
  98. };
  99. typedef struct L_DnaHash L_DNAHASH;
  100. /*! Sarray version for serialization */
  101. #define SARRAY_VERSION_NUMBER 1
  102. /*! String array: an array of C strings */
  103. struct Sarray
  104. {
  105. l_int32 nalloc; /*!< size of allocated ptr array */
  106. l_int32 n; /*!< number of strings allocated */
  107. l_int32 refcount; /*!< reference count (1 if no clones) */
  108. char **array; /*!< string array */
  109. };
  110. typedef struct Sarray SARRAY;
  111. /*! Byte array (analogous to C++ "string") */
  112. struct L_Bytea
  113. {
  114. size_t nalloc; /*!< number of bytes allocated in data array */
  115. size_t size; /*!< number of bytes presently used */
  116. l_int32 refcount; /*!< reference count (1 if no clones) */
  117. l_uint8 *data; /*!< data array */
  118. };
  119. typedef struct L_Bytea L_BYTEA;
  120. /*------------------------------------------------------------------------*
  121. * Array flags *
  122. *------------------------------------------------------------------------*/
  123. /*! Flags for interpolation in Numa */
  124. enum {
  125. L_LINEAR_INTERP = 1, /*!< linear */
  126. L_QUADRATIC_INTERP = 2 /*!< quadratic */
  127. };
  128. /*! Flags for added borders in Numa and Fpix */
  129. enum {
  130. L_CONTINUED_BORDER = 1, /*!< extended with same value */
  131. L_SLOPE_BORDER = 2, /*!< extended with constant normal derivative */
  132. L_MIRRORED_BORDER = 3 /*!< mirrored */
  133. };
  134. /*! Flags for data type converted from Numa */
  135. enum {
  136. L_INTEGER_VALUE = 1, /*!< convert to integer */
  137. L_FLOAT_VALUE = 2 /*!< convert to float */
  138. };
  139. #endif /* LEPTONICA_ARRAY_H */