|
tesseract 3.04.01
|
00001 /****************************************************************************** 00002 ** Filename: cutoffs.c 00003 ** Purpose: Routines to manipulate an array of class cutoffs. 00004 ** Author: Dan Johnson 00005 ** History: Wed Feb 20 09:28:51 1991, DSJ, Created. 00006 ** 00007 ** (c) Copyright Hewlett-Packard Company, 1988. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 ******************************************************************************/ 00018 /*---------------------------------------------------------------------------- 00019 Include Files and Type Defines 00020 ----------------------------------------------------------------------------*/ 00021 #include "cutoffs.h" 00022 00023 #include <stdio.h> 00024 00025 #include "classify.h" 00026 #include "efio.h" 00027 #include "globals.h" 00028 #include "helpers.h" 00029 #include "scanutils.h" 00030 #include "serialis.h" 00031 #include "unichar.h" 00032 00033 #define REALLY_QUOTE_IT(x) QUOTE_IT(x) 00034 00035 #define MAX_CUTOFF 1000 00036 00037 namespace tesseract { 00052 void Classify::ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset, 00053 CLASS_CUTOFF_ARRAY Cutoffs) { 00054 char Class[UNICHAR_LEN + 1]; 00055 CLASS_ID ClassId; 00056 int Cutoff; 00057 int i; 00058 00059 if (shape_table_ != NULL) { 00060 if (!shapetable_cutoffs_.DeSerialize(swap, CutoffFile)) { 00061 tprintf("Error during read of shapetable pffmtable!\n"); 00062 } 00063 } 00064 for (i = 0; i < MAX_NUM_CLASSES; i++) 00065 Cutoffs[i] = MAX_CUTOFF; 00066 00067 while ((end_offset < 0 || ftell(CutoffFile) < end_offset) && 00068 tfscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d", 00069 Class, &Cutoff) == 2) { 00070 if (strcmp(Class, "NULL") == 0) { 00071 ClassId = unicharset.unichar_to_id(" "); 00072 } else { 00073 ClassId = unicharset.unichar_to_id(Class); 00074 } 00075 Cutoffs[ClassId] = Cutoff; 00076 SkipNewline(CutoffFile); 00077 } 00078 } 00079 00080 } // namespace tesseract