dewarp.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_DEWARP_H
  27. #define LEPTONICA_DEWARP_H
  28. /*
  29. * dewarp.h
  30. *
  31. * Data structure to hold arrays and results for generating
  32. * horizontal and vertical disparity arrays based on textlines.
  33. * Each disparity array is two-dimensional. The vertical disparity
  34. * array gives a vertical displacement, relative to the lowest point
  35. * in the textlines. The horizontal disparty array gives a horizontal
  36. * displacement, relative to the minimum values (for even pages)
  37. * or maximum values (for odd pages) of the left and right ends of
  38. * full textlines. Horizontal alignment always involves translations
  39. * away from the book gutter.
  40. *
  41. * We have intentionally separated the process of building models
  42. * from the rendering process that uses the models. For any page,
  43. * the building operation either creates an actual model (that is,
  44. * a model with at least the vertical disparity being computed, and
  45. * for which the 'success' flag is set) or fails to create a model.
  46. * However, at rendering time, a page can have one of two different
  47. * types of models.
  48. * (1) A valid model is an actual model that meets the rendering
  49. * constraints, which are limits on model curvature parameters.
  50. * See dewarpaTestForValidModel() for details.
  51. * Valid models are identified by dewarpaInsertRefModels(),
  52. * which sets the 'vvalid' and 'hvalid' fields. Only valid
  53. * models are used for rendering.
  54. * (2) A reference model is used by a page that doesn't have
  55. * a valid model, but has a nearby valid model of the same
  56. * parity (even/odd page) that it can use. The range in pages
  57. * to search for a valid model is given by the 'maxdist' field.
  58. *
  59. * If a valid vertical disparity model (VDM) is not available,
  60. * just use the input image. Otherwise, assuming the VDM is available:
  61. * (a) with useboth == 0, we use only the VDM.
  62. * (b) with useboth == 1, we require using the VDM and, if a valid
  63. * horizontal disparity model (HDM) is available, we also use it.
  64. *
  65. * The 'maxdist' parameter is input when the dewarpa is created.
  66. * The other rendering parameters have default values given in dewarp.c.
  67. * All parameters used by rendering can be set (or reset) using accessors.
  68. *
  69. * After dewarping, use of the VDM will cause all points on each
  70. * altered curve to have a y-value equal to the minimum. Use of
  71. * the HDA will cause the left and right edges of the textlines
  72. * to be vertically aligned if they had been typeset flush-left
  73. * and flush-right, respectively.
  74. *
  75. * The sampled disparity arrays are expanded to full resolution,
  76. * using linear interpolation, and this is further expanded
  77. * by slope continuation to the right and below if the image
  78. * is larger than the full resolution disparity arrays. Then
  79. * the disparity correction can be applied to the input image.
  80. * If the input pix are 2x reduced, the expansion from sampled
  81. * to full res uses the product of (sampling) * (redfactor).
  82. *
  83. * The most accurate results are produced at full resolution, and
  84. * this is generally recommended.
  85. */
  86. /* Note on versioning of the serialization of this data structure:
  87. * The dewarping utility and the stored data can be expected to change.
  88. * In most situations, the serialized version is ephemeral -- it is
  89. * not needed after being used. No functions will be provided to
  90. * convert between different versions. */
  91. #define DEWARP_VERSION_NUMBER 4
  92. struct L_Dewarpa
  93. {
  94. l_int32 nalloc; /* size of dewarp ptr array */
  95. l_int32 maxpage; /* maximum page number in array */
  96. struct L_Dewarp **dewarp; /* array of ptrs to page dewarp */
  97. struct L_Dewarp **dewarpcache; /* array of ptrs to cached dewarps */
  98. struct Numa *namodels; /* list of page numbers for pages */
  99. /* with page models */
  100. struct Numa *napages; /* list of page numbers with either */
  101. /* page models or ref page models */
  102. l_int32 redfactor; /* reduction factor of input: 1 or 2 */
  103. l_int32 sampling; /* disparity arrays sampling factor */
  104. l_int32 minlines; /* min number of long lines required */
  105. l_int32 maxdist; /* max distance for getting ref pages */
  106. l_int32 max_linecurv; /* maximum abs line curvature, */
  107. /* in micro-units */
  108. l_int32 min_diff_linecurv; /* minimum abs diff line curvature */
  109. /* in micro-units */
  110. l_int32 max_diff_linecurv; /* maximum abs diff line curvature */
  111. /* in micro-units */
  112. l_int32 max_edgeslope; /* maximum abs left or right edge */
  113. /* slope, in milli-units */
  114. l_int32 max_edgecurv; /* maximum abs left or right edge */
  115. /* curvature, in micro-units */
  116. l_int32 max_diff_edgecurv; /* maximum abs diff left-right */
  117. /* edge curvature, in micro-units */
  118. l_int32 useboth; /* use both disparity arrays if */
  119. /* available; just vertical otherwise */
  120. l_int32 modelsready; /* invalid models have been removed */
  121. /* and refs built against valid set */
  122. };
  123. typedef struct L_Dewarpa L_DEWARPA;
  124. struct L_Dewarp
  125. {
  126. struct L_Dewarpa *dewa; /* ptr to parent (not owned) */
  127. struct Pix *pixs; /* source pix, 1 bpp */
  128. struct FPix *sampvdispar; /* sampled vert disparity array */
  129. struct FPix *samphdispar; /* sampled horiz disparity array */
  130. struct FPix *fullvdispar; /* full vert disparity array */
  131. struct FPix *fullhdispar; /* full horiz disparity array */
  132. struct Numa *namidys; /* sorted y val of midpoint each line */
  133. struct Numa *nacurves; /* sorted curvature of each line */
  134. l_int32 w; /* width of source image */
  135. l_int32 h; /* height of source image */
  136. l_int32 pageno; /* page number; important for reuse */
  137. l_int32 sampling; /* sampling factor of disparity arrays */
  138. l_int32 redfactor; /* reduction factor of pixs: 1 or 2 */
  139. l_int32 minlines; /* min number of long lines required */
  140. l_int32 nlines; /* number of long lines found */
  141. l_int32 mincurv; /* min line curvature in micro-units */
  142. l_int32 maxcurv; /* max line curvature in micro-units */
  143. l_int32 leftslope; /* left edge slope in milli-units */
  144. l_int32 rightslope; /* right edge slope in milli-units */
  145. l_int32 leftcurv; /* left edge curvature in micro-units */
  146. l_int32 rightcurv; /* right edge curvature in micro-units */
  147. l_int32 nx; /* number of sampling pts in x-dir */
  148. l_int32 ny; /* number of sampling pts in y-dir */
  149. l_int32 hasref; /* 0 if normal; 1 if has a refpage */
  150. l_int32 refpage; /* page with disparity model to use */
  151. l_int32 vsuccess; /* sets to 1 if vert disparity builds */
  152. l_int32 hsuccess; /* sets to 1 if horiz disparity builds */
  153. l_int32 vvalid; /* sets to 1 if valid vert disparity */
  154. l_int32 hvalid; /* sets to 1 if valid horiz disparity */
  155. l_int32 debug; /* sets to 1 if debug output requested */
  156. };
  157. typedef struct L_Dewarp L_DEWARP;
  158. #endif /* LEPTONICA_DEWARP_H */