comparison mupdf-source/thirdparty/leptonica/src/morph.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_MORPH_H
28 #define LEPTONICA_MORPH_H
29
30 /*!
31 * \file morph.h
32 *
33 * <pre>
34 * Contains the following structs:
35 * struct Sel
36 * struct Sela
37 * struct Kernel
38 *
39 * Contains definitions for:
40 * morphological b.c. flags
41 * structuring element types
42 * runlength flags for granulometry
43 * direction flags for grayscale morphology
44 * morphological operation flags
45 * standard border size
46 * grayscale intensity scaling flags
47 * morphological tophat flags
48 * arithmetic and logical operator flags
49 * grayscale morphology selection flags
50 * distance function b.c. flags
51 * image comparison flags
52 * </pre>
53 */
54
55 /*-------------------------------------------------------------------------*
56 * Sel and Sel array *
57 *-------------------------------------------------------------------------*/
58 #define SEL_VERSION_NUMBER 1
59
60 /*! Selection */
61 struct Sel
62 {
63 l_int32 sy; /*!< sel height */
64 l_int32 sx; /*!< sel width */
65 l_int32 cy; /*!< y location of sel origin */
66 l_int32 cx; /*!< x location of sel origin */
67 l_int32 **data; /*!< {0,1,2}; data[i][j] in [row][col] order */
68 char *name; /*!< used to find sel by name */
69 };
70 typedef struct Sel SEL;
71
72 /*! Array of Sel */
73 struct Sela
74 {
75 l_int32 n; /*!< number of sel actually stored */
76 l_int32 nalloc; /*!< size of allocated ptr array */
77 struct Sel **sel; /*!< sel ptr array */
78 };
79 typedef struct Sela SELA;
80
81
82 /*-------------------------------------------------------------------------*
83 * Kernel *
84 *-------------------------------------------------------------------------*/
85 #define KERNEL_VERSION_NUMBER 2
86
87 /*! Kernel */
88 struct L_Kernel
89 {
90 l_int32 sy; /*!< kernel height */
91 l_int32 sx; /*!< kernel width */
92 l_int32 cy; /*!< y location of kernel origin */
93 l_int32 cx; /*!< x location of kernel origin */
94 l_float32 **data; /*!< data[i][j] in [row][col] order */
95 };
96 typedef struct L_Kernel L_KERNEL;
97
98
99 /*-------------------------------------------------------------------------*
100 * Morphological boundary condition flags *
101 * *
102 * Two types of boundary condition for erosion. *
103 * The global variable MORPH_BC takes on one of these two values. *
104 * See notes in morph.c for usage. *
105 *-------------------------------------------------------------------------*/
106 /*! Morph Boundary */
107 enum {
108 SYMMETRIC_MORPH_BC = 0,
109 ASYMMETRIC_MORPH_BC = 1
110 };
111
112 /*-------------------------------------------------------------------------*
113 * Structuring element vals *
114 *-------------------------------------------------------------------------*/
115 /*! SEL Vals */
116 enum {
117 SEL_DONT_CARE = 0,
118 SEL_HIT = 1,
119 SEL_MISS = 2
120 };
121
122 /*-------------------------------------------------------------------------*
123 * Runlength flags for granulometry *
124 *-------------------------------------------------------------------------*/
125 /*! Runlength Polarity */
126 enum {
127 L_RUN_OFF = 0,
128 L_RUN_ON = 1
129 };
130
131 /*-------------------------------------------------------------------------*
132 * Direction flags for grayscale morphology, granulometry, *
133 * composable Sels, convolution, etc. *
134 *-------------------------------------------------------------------------*/
135 /*! Direction Flags */
136 enum {
137 L_HORIZ = 1,
138 L_VERT = 2,
139 L_BOTH_DIRECTIONS = 3
140 };
141
142 /*-------------------------------------------------------------------------*
143 * Morphological operation flags *
144 *-------------------------------------------------------------------------*/
145 /*! Morph Operator */
146 enum {
147 L_MORPH_DILATE = 1,
148 L_MORPH_ERODE = 2,
149 L_MORPH_OPEN = 3,
150 L_MORPH_CLOSE = 4,
151 L_MORPH_HMT = 5
152 };
153
154 /*-------------------------------------------------------------------------*
155 * Grayscale intensity scaling flags *
156 *-------------------------------------------------------------------------*/
157 /*! Pixel Value Scaling */
158 enum {
159 L_LINEAR_SCALE = 1,
160 L_LOG_SCALE = 2
161 };
162
163 /*-------------------------------------------------------------------------*
164 * Morphological tophat flags *
165 *-------------------------------------------------------------------------*/
166 /*! Morph Tophat */
167 enum {
168 L_TOPHAT_WHITE = 0,
169 L_TOPHAT_BLACK = 1
170 };
171
172 /*-------------------------------------------------------------------------*
173 * Arithmetic and logical operator flags *
174 * (use on grayscale images and Numas) *
175 *-------------------------------------------------------------------------*/
176 /*! ArithLogical Ops */
177 enum {
178 L_ARITH_ADD = 1,
179 L_ARITH_SUBTRACT = 2,
180 L_ARITH_MULTIPLY = 3, /* on numas only */
181 L_ARITH_DIVIDE = 4, /* on numas only */
182 L_UNION = 5, /* on numas only */
183 L_INTERSECTION = 6, /* on numas only */
184 L_SUBTRACTION = 7, /* on numas only */
185 L_EXCLUSIVE_OR = 8 /* on numas only */
186 };
187
188 /*-------------------------------------------------------------------------*
189 * Min/max selection flags *
190 *-------------------------------------------------------------------------*/
191 /*! MinMax Selection */
192 enum {
193 L_CHOOSE_MIN = 1, /* useful in a downscaling "erosion" */
194 L_CHOOSE_MAX = 2, /* useful in a downscaling "dilation" */
195 L_CHOOSE_MAXDIFF = 3, /* useful in a downscaling contrast */
196 L_CHOOSE_MIN_BOOST = 4, /* use a modification of the min value */
197 L_CHOOSE_MAX_BOOST = 5 /* use a modification of the max value */
198 };
199
200 /*-------------------------------------------------------------------------*
201 * Exterior value b.c. for distance function flags *
202 *-------------------------------------------------------------------------*/
203 /*! Exterior Value */
204 enum {
205 L_BOUNDARY_BG = 1, /* assume bg outside image */
206 L_BOUNDARY_FG = 2 /* assume fg outside image */
207 };
208
209 /*-------------------------------------------------------------------------*
210 * Image comparison flags *
211 *-------------------------------------------------------------------------*/
212 /*! Image Comparison */
213 enum {
214 L_COMPARE_XOR = 1,
215 L_COMPARE_SUBTRACT = 2,
216 L_COMPARE_ABS_DIFF = 3
217 };
218
219 /*-------------------------------------------------------------------------*
220 * Standard size of border added around images for special processing *
221 *-------------------------------------------------------------------------*/
222 static const l_int32 ADDED_BORDER = 32; /*!< pixels, not bits */
223
224
225 #endif /* LEPTONICA_MORPH_H */