comparison mupdf-source/thirdparty/tesseract/src/classify/mfoutline.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 ** Filename: mfoutline.h
3 ** Purpose: Interface spec for fx outline structures
4 ** Author: Dan Johnson
5 **
6 ** (c) Copyright Hewlett-Packard Company, 1988.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 ******************************************************************************/
17
18 #ifndef MFOUTLINE_H
19 #define MFOUTLINE_H
20
21 #include "blobs.h"
22 #include "fpoint.h"
23 #include "oldlist.h"
24 #include "params.h"
25
26 namespace tesseract {
27
28 using MFOUTLINE = LIST;
29
30 enum DIRECTION : uint8_t { north, south, east, west, northeast, northwest, southeast, southwest };
31
32 struct MFEDGEPT {
33 // Inline functions for manipulating micro-feature outline edge points.
34
35 void ClearMark() {
36 ExtremityMark = false;
37 }
38
39 void MarkPoint() {
40 ExtremityMark = true;
41 }
42
43 FPOINT Point;
44 float Slope;
45 bool Hidden;
46 bool ExtremityMark;
47 DIRECTION Direction;
48 DIRECTION PreviousDirection;
49 };
50
51 enum OUTLINETYPE { outer, hole };
52
53 enum NORM_METHOD { baseline, character };
54
55 /**----------------------------------------------------------------------------
56 Macros
57 ----------------------------------------------------------------------------**/
58 #define AverageOf(A, B) (((A) + (B)) / 2)
59
60 // Constant for computing the scale factor to use to normalize characters.
61 const float MF_SCALE_FACTOR = 0.5f / kBlnXHeight;
62
63 // Inline functions for manipulating micro-feature outlines.
64
65 static inline bool DegenerateOutline(MFOUTLINE Outline) {
66 return (Outline == NIL_LIST) || (Outline == Outline->list_rest());
67 }
68
69 static inline MFEDGEPT *PointAt(MFOUTLINE Outline) {
70 return reinterpret_cast<MFEDGEPT *>(Outline->first_node());
71 }
72
73 static inline MFOUTLINE NextPointAfter(MFOUTLINE Outline) {
74 return Outline->list_rest();
75 }
76
77 static inline void MakeOutlineCircular(MFOUTLINE Outline) {
78 set_rest(last(Outline), Outline);
79 }
80
81 /**----------------------------------------------------------------------------
82 Public Function Prototypes
83 ----------------------------------------------------------------------------**/
84 void ComputeBlobCenter(TBLOB *Blob, TPOINT *BlobCenter);
85
86 LIST ConvertBlob(TBLOB *Blob);
87
88 MFOUTLINE ConvertOutline(TESSLINE *Outline);
89
90 LIST ConvertOutlines(TESSLINE *Outline, LIST ConvertedOutlines, OUTLINETYPE OutlineType);
91
92 void FilterEdgeNoise(MFOUTLINE Outline, float NoiseSegmentLength);
93
94 void FindDirectionChanges(MFOUTLINE Outline, float MinSlope, float MaxSlope);
95
96 void FreeMFOutline(void *agr); // MFOUTLINE Outline);
97
98 void FreeOutlines(LIST Outlines);
99
100 void MarkDirectionChanges(MFOUTLINE Outline);
101
102 MFOUTLINE NextExtremity(MFOUTLINE EdgePoint);
103
104 void NormalizeOutline(MFOUTLINE Outline, float XOrigin);
105
106 /*----------------------------------------------------------------------------
107 Private Function Prototypes
108 -----------------------------------------------------------------------------*/
109 void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction);
110
111 // Normalizes the Outline in-place using cn_denorm's local transformation,
112 // then converts from the integer feature range [0,255] to the clusterer
113 // feature range of [-0.5, 0.5].
114 void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm);
115
116 void ComputeDirection(MFEDGEPT *Start, MFEDGEPT *Finish, float MinSlope, float MaxSlope);
117
118 MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint);
119
120 } // namespace tesseract
121
122 #endif