Coverage Report

Created: 2026-01-13 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tesseract/src/classify/featdefs.h
Line
Count
Source
1
/******************************************************************************
2
 ** Filename:    featdefs.h
3
 ** Purpose:     Definitions of currently defined feature types.
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 FEATDEFS_H
19
#define FEATDEFS_H
20
21
#include "ocrfeatures.h"
22
23
#include <array>  // for std::array
24
#include <string> // for std::string
25
26
namespace tesseract {
27
28
/* Enumerate the different types of features currently defined. */
29
48
#define NUM_FEATURE_TYPES 4
30
extern TESS_API const char *const kMicroFeatureType;
31
extern TESS_API const char *const kCNFeatureType;
32
extern TESS_API const char *const kIntFeatureType;
33
extern TESS_API const char *const kGeoFeatureType;
34
35
/* A character is described by multiple sets of extracted features.  Each
36
  set contains a number of features of a particular type, for example, a
37
  set of bays, or a set of closures, or a set of microfeatures.  Each
38
  feature consists of a number of parameters.  All features within a
39
  feature set contain the same number of parameters.*/
40
41
struct FEATURE_DEFS_STRUCT {
42
  int32_t NumFeatureTypes;
43
  const FEATURE_DESC_STRUCT *FeatureDesc[NUM_FEATURE_TYPES];
44
};
45
using FEATURE_DEFS = FEATURE_DEFS_STRUCT *;
46
47
struct CHAR_DESC_STRUCT {
48
  /// Allocate a new character description, initialize its
49
  /// feature sets to be empty, and return it.
50
0
  CHAR_DESC_STRUCT(const FEATURE_DEFS_STRUCT &FeatureDefs) {
51
0
    NumFeatureSets = FeatureDefs.NumFeatureTypes;
52
0
  }
53
54
  /// Release the memory consumed by the specified character
55
  /// description and all of the features in that description.
56
0
  ~CHAR_DESC_STRUCT() {
57
0
    for (size_t i = 0; i < NumFeatureSets; i++) {
58
0
      delete FeatureSets[i];
59
0
    }
60
0
  }
61
62
  uint32_t NumFeatureSets;
63
  std::array<FEATURE_SET_STRUCT *, NUM_FEATURE_TYPES> FeatureSets;
64
};
65
66
/*----------------------------------------------------------------------
67
    Generic functions for manipulating character descriptions
68
----------------------------------------------------------------------*/
69
TESS_API
70
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs);
71
72
bool ValidCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC_STRUCT *CharDesc);
73
74
void WriteCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC_STRUCT *CharDesc, std::string &str);
75
76
TESS_API
77
CHAR_DESC_STRUCT *ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File);
78
79
TESS_API
80
uint32_t ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs, const char *ShortName);
81
82
/**----------------------------------------------------------------------------
83
        Global Data Definitions and Declarations
84
----------------------------------------------------------------------------**/
85
extern const FEATURE_DESC_STRUCT MicroFeatureDesc;
86
extern TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc;
87
extern const FEATURE_DESC_STRUCT CharNormDesc;
88
extern const FEATURE_DESC_STRUCT OutlineFeatDesc;
89
extern const FEATURE_DESC_STRUCT IntFeatDesc;
90
extern const FEATURE_DESC_STRUCT GeoFeatDesc;
91
92
} // namespace tesseract
93
94
#endif