ccbord.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_CCBORD_H
  27. #define LEPTONICA_CCBORD_H
  28. /*
  29. * ccbord.h
  30. *
  31. * CCBord: represents a single connected component
  32. * CCBorda: an array of CCBord
  33. */
  34. /* Use in ccbaStepChainsToPixCoords() */
  35. enum {
  36. CCB_LOCAL_COORDS = 1,
  37. CCB_GLOBAL_COORDS = 2
  38. };
  39. /* Use in ccbaGenerateSPGlobalLocs() */
  40. enum {
  41. CCB_SAVE_ALL_PTS = 1,
  42. CCB_SAVE_TURNING_PTS = 2
  43. };
  44. /* CCBord contains:
  45. *
  46. * (1) a minimally-clipped bitmap of the component (pix),
  47. * (2) a boxa consisting of:
  48. * for the primary component:
  49. * (xul, yul) pixel location in global coords
  50. * (w, h) of the bitmap
  51. * for the hole components:
  52. * (x, y) in relative coordinates in primary component
  53. * (w, h) of the hole border (which is 2 pixels
  54. * larger in each direction than the hole itself)
  55. * (3) a pta ('start') of the initial border pixel location for each
  56. * closed curve, all in relative coordinates of the primary
  57. * component. This is given for the primary component,
  58. * followed by the hole components, if any.
  59. * (4) a refcount of the ccbord; used internally when a ccbord
  60. * is accessed from a ccborda (array of ccbord)
  61. * (5) a ptaa for the chain code for the border in relative
  62. * coordinates, where the first pta is the exterior border
  63. * and all other pta are for interior borders (holes)
  64. * (6) a ptaa for the global pixel loc rendition of the border,
  65. * where the first pta is the exterior border and all other
  66. * pta are for interior borders (holes).
  67. * This is derived from the local or step chain code.
  68. * (7) a numaa for the chain code for the border as orientation
  69. * directions between successive border pixels, where
  70. * the first numa is the exterior border and all other
  71. * numa are for interior borders (holes). This is derived
  72. * from the local chain code. The 8 directions are 0 - 7.
  73. * (8) a pta for a single chain for each c.c., comprised of outer
  74. * and hole borders, plus cut paths between them, all in
  75. * local coords.
  76. * (9) a pta for a single chain for each c.c., comprised of outer
  77. * and hole borders, plus cut paths between them, all in
  78. * global coords.
  79. */
  80. struct CCBord
  81. {
  82. struct Pix *pix; /* component bitmap (min size) */
  83. struct Boxa *boxa; /* regions of each closed curve */
  84. struct Pta *start; /* initial border pixel locations */
  85. l_int32 refcount; /* number of handles; start at 1 */
  86. struct Ptaa *local; /* ptaa of chain pixels (local) */
  87. struct Ptaa *global; /* ptaa of chain pixels (global) */
  88. struct Numaa *step; /* numaa of chain code (step dir) */
  89. struct Pta *splocal; /* pta of single chain (local) */
  90. struct Pta *spglobal; /* pta of single chain (global) */
  91. };
  92. typedef struct CCBord CCBORD;
  93. struct CCBorda
  94. {
  95. struct Pix *pix; /* input pix (may be null) */
  96. l_int32 w; /* width of pix */
  97. l_int32 h; /* height of pix */
  98. l_int32 n; /* number of ccbord in ptr array */
  99. l_int32 nalloc; /* number of ccbord ptrs allocated */
  100. struct CCBord **ccb; /* ccb ptr array */
  101. };
  102. typedef struct CCBorda CCBORDA;
  103. #endif /* LEPTONICA_CCBORD_H */