comparison mupdf-source/thirdparty/tesseract/src/classify/adaptive.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: adaptive.h
3 ** Purpose: Interface to adaptive matcher.
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 #ifndef ADAPTIVE_H
18 #define ADAPTIVE_H
19
20 #include "intproto.h"
21 #include "oldlist.h"
22
23 #include <cstdio>
24
25 namespace tesseract {
26
27 struct TEMP_PROTO_STRUCT {
28 uint16_t ProtoId;
29 PROTO_STRUCT Proto;
30 };
31
32 struct TEMP_CONFIG_STRUCT {
33 TEMP_CONFIG_STRUCT() = default;
34 TEMP_CONFIG_STRUCT(int MaxProtoId, int FontinfoId);
35 ~TEMP_CONFIG_STRUCT();
36 uint8_t NumTimesSeen;
37 uint8_t ProtoVectorSize;
38 PROTO_ID MaxProtoId;
39 BIT_VECTOR Protos;
40 int FontinfoId; // font information inferred from pre-trained templates
41 };
42
43 struct PERM_CONFIG_STRUCT {
44 PERM_CONFIG_STRUCT() = default;
45 ~PERM_CONFIG_STRUCT();
46 UNICHAR_ID *Ambigs;
47 int FontinfoId; // font information inferred from pre-trained templates
48 };
49
50 union ADAPTED_CONFIG {
51 TEMP_CONFIG_STRUCT *Temp;
52 PERM_CONFIG_STRUCT *Perm;
53 };
54
55 struct ADAPT_CLASS_STRUCT {
56 ADAPT_CLASS_STRUCT();
57 ~ADAPT_CLASS_STRUCT();
58 uint8_t NumPermConfigs;
59 uint8_t MaxNumTimesSeen; // maximum number of times any TEMP_CONFIG_STRUCT was seen
60 // (cut at matcher_min_examples_for_prototyping)
61 BIT_VECTOR PermProtos;
62 BIT_VECTOR PermConfigs;
63 LIST TempProtos;
64 ADAPTED_CONFIG Config[MAX_NUM_CONFIGS];
65 };
66
67 class ADAPT_TEMPLATES_STRUCT {
68 public:
69 ADAPT_TEMPLATES_STRUCT() = default;
70 ADAPT_TEMPLATES_STRUCT(UNICHARSET &unicharset);
71 ~ADAPT_TEMPLATES_STRUCT();
72 INT_TEMPLATES_STRUCT *Templates;
73 int NumNonEmptyClasses;
74 uint8_t NumPermClasses;
75 ADAPT_CLASS_STRUCT *Class[MAX_NUM_CLASSES];
76 };
77
78 /*----------------------------------------------------------------------------
79 Public Function Prototypes
80 ----------------------------------------------------------------------------*/
81 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
82
83 #define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 && (Class)->TempProtos == NIL_LIST)
84
85 #define ConfigIsPermanent(Class, ConfigId) (test_bit((Class)->PermConfigs, ConfigId))
86
87 #define MakeConfigPermanent(Class, ConfigId) (SET_BIT((Class)->PermConfigs, ConfigId))
88
89 #define MakeProtoPermanent(Class, ProtoId) (SET_BIT((Class)->PermProtos, ProtoId))
90
91 #define TempConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Temp)
92
93 #define PermConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Perm)
94
95 #define IncreaseConfidence(TempConfig) ((TempConfig)->NumTimesSeen++)
96
97 void AddAdaptedClass(ADAPT_TEMPLATES_STRUCT *Templates, ADAPT_CLASS_STRUCT *Class, CLASS_ID ClassId);
98
99 ADAPT_CLASS_STRUCT *ReadAdaptedClass(tesseract::TFile *File);
100
101 PERM_CONFIG_STRUCT *ReadPermConfig(tesseract::TFile *File);
102
103 TEMP_CONFIG_STRUCT *ReadTempConfig(tesseract::TFile *File);
104
105 void WriteAdaptedClass(FILE *File, ADAPT_CLASS_STRUCT *Class, int NumConfigs);
106
107 void WritePermConfig(FILE *File, PERM_CONFIG_STRUCT *Config);
108
109 void WriteTempConfig(FILE *File, TEMP_CONFIG_STRUCT *Config);
110
111 } // namespace tesseract
112
113 #endif