array.h 6.2 KB

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