tesseract  4.0.0-1-g2a2b
cutoffs.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: cutoffs.c
3  ** Purpose: Routines to manipulate an array of class cutoffs.
4  ** Author: Dan Johnson
5  ** History: Wed Feb 20 09:28:51 1991, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 /*----------------------------------------------------------------------------
19  Include Files and Type Defines
20 ----------------------------------------------------------------------------*/
21 #include "cutoffs.h"
22 
23 #include <cstdio>
24 
25 #include "classify.h"
26 #include "globals.h"
27 #include "helpers.h"
28 #include "serialis.h"
29 #include "unichar.h"
30 
31 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
32 
33 #define MAX_CUTOFF 1000
34 
35 namespace tesseract {
47  char Class[UNICHAR_LEN + 1];
48  CLASS_ID ClassId;
49  int Cutoff;
50 
51  if (shape_table_ != nullptr) {
52  if (!shapetable_cutoffs_.DeSerialize(fp)) {
53  tprintf("Error during read of shapetable pffmtable!\n");
54  }
55  }
56  for (int i = 0; i < MAX_NUM_CLASSES; i++)
57  Cutoffs[i] = MAX_CUTOFF;
58 
59  const int kMaxLineSize = 100;
60  char line[kMaxLineSize];
61  while (fp->FGets(line, kMaxLineSize) != nullptr &&
62  sscanf(line, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d", Class,
63  &Cutoff) == 2) {
64  if (strcmp(Class, "NULL") == 0) {
65  ClassId = unicharset.unichar_to_id(" ");
66  } else {
67  ClassId = unicharset.unichar_to_id(Class);
68  }
69  Cutoffs[ClassId] = Cutoff;
70  }
71 }
72 
73 } // namespace tesseract
#define REALLY_QUOTE_IT(x)
Definition: cutoffs.cpp:31
char * FGets(char *buffer, int buffer_size)
Definition: serialis.cpp:248
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:209
bool DeSerialize(bool swap, FILE *fp)
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:36
#define UNICHAR_LEN
Definition: unichar.h:31
#define MAX_CUTOFF
Definition: cutoffs.cpp:33
UNICHARSET unicharset
Definition: ccutil.h:68
ShapeTable * shape_table_
Definition: classify.h:553
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
uint16_t CLASS_CUTOFF_ARRAY[MAX_NUM_CLASSES]
Definition: cutoffs.h:26
void ReadNewCutoffs(TFile *fp, CLASS_CUTOFF_ARRAY Cutoffs)
Definition: cutoffs.cpp:46
#define MAX_NUM_CLASSES
Definition: matchdefs.h:32