comparison mupdf-source/thirdparty/leptonica/src/dewarp.h @ 2:b50eed0cc0ef upstream

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