All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <stdio.h>
24 
25 #include "classify.h"
26 #include "efio.h"
27 #include "globals.h"
28 #include "helpers.h"
29 #include "scanutils.h"
30 #include "serialis.h"
31 #include "unichar.h"
32 
33 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
34 
35 #define MAX_CUTOFF 1000
36 
37 namespace tesseract {
52 void Classify::ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset,
53  CLASS_CUTOFF_ARRAY Cutoffs) {
54  char Class[UNICHAR_LEN + 1];
55  CLASS_ID ClassId;
56  int Cutoff;
57  int i;
58 
59  if (shape_table_ != NULL) {
60  if (!shapetable_cutoffs_.DeSerialize(swap, CutoffFile)) {
61  tprintf("Error during read of shapetable pffmtable!\n");
62  }
63  }
64  for (i = 0; i < MAX_NUM_CLASSES; i++)
65  Cutoffs[i] = MAX_CUTOFF;
66 
67  while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
68  tfscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d",
69  Class, &Cutoff) == 2) {
70  if (strcmp(Class, "NULL") == 0) {
71  ClassId = unicharset.unichar_to_id(" ");
72  } else {
73  ClassId = unicharset.unichar_to_id(Class);
74  }
75  Cutoffs[ClassId] = Cutoff;
76  SkipNewline(CutoffFile);
77  }
78 }
79 
80 } // namespace tesseract
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
void ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset, CLASS_CUTOFF_ARRAY Cutoffs)
Definition: cutoffs.cpp:52
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
#define tprintf(...)
Definition: tprintf.h:31
UNICHARSET unicharset
Definition: ccutil.h:72
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:229
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:35
#define REALLY_QUOTE_IT(x)
Definition: cutoffs.cpp:33
ShapeTable * shape_table_
Definition: classify.h:512
bool DeSerialize(bool swap, FILE *fp)
void SkipNewline(FILE *file)
Definition: helpers.h:84
#define MAX_CUTOFF
Definition: cutoffs.cpp:35
#define NULL
Definition: host.h:144
#define UNICHAR_LEN
Definition: unichar.h:30
uinT16 CLASS_CUTOFF_ARRAY[MAX_NUM_CLASSES]
Definition: cutoffs.h:26
long long int inT64
Definition: host.h:108