Result of clang tidy on recent merge

This commit is contained in:
Ray Smith 2016-11-07 10:46:33 -08:00
parent 8972c0e916
commit 2c837dffc3
139 changed files with 2488 additions and 2947 deletions

View File

@ -17,5 +17,5 @@ in this distribution is now licensed under the Apache License:
Other Dependencies and Licenses: Other Dependencies and Licenses:
================================ ================================
Tesseract uses Leptonica library (http://leptonica.com/) with a very weakly Tesseract uses Leptonica library (http://leptonica.com/) which essentially
restricted copyright license (http://leptonica.com/about-the-license.html) uses a BSD 2-clause license. (http://leptonica.com/about-the-license.html)

View File

@ -4,7 +4,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := tesseract-$(APP_ABI) LOCAL_MODULE := tesseract-$(APP_ABI)
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
mobile_base \ base \
leptonica-$(APP_ABI) leptonica-$(APP_ABI)
LOCAL_C_INCLUDES := $(APP_C_INCLUDES) LOCAL_C_INCLUDES := $(APP_C_INCLUDES)
@ -51,7 +51,6 @@ LOCAL_CFLAGS := -DANDROID_BUILD -DNO_CUBE_BUILD -DGRAPHICS_DISABLED
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
$(call import-module,mobile/base) $(call import-module,base/port)
$(call import-module,mobile/base)
$(call import-module,mobile/util/hash) $(call import-module,mobile/util/hash)
$(call import-module,third_party/leptonica/android/jni) $(call import-module,third_party/leptonica/android/jni)

View File

@ -809,9 +809,7 @@ int CubeAPITest(Boxa* boxa_blocks, Pixa* pixa_blocks,
* has not been subjected to a call of Init, SetImage, Recognize, Clear, End * has not been subjected to a call of Init, SetImage, Recognize, Clear, End
* DetectOS, or anything else that changes the internal PAGE_RES. * DetectOS, or anything else that changes the internal PAGE_RES.
*/ */
PageIterator* TessBaseAPI::AnalyseLayout() { PageIterator* TessBaseAPI::AnalyseLayout() { return AnalyseLayout(false); }
return AnalyseLayout(false);
}
PageIterator* TessBaseAPI::AnalyseLayout(bool merge_similar_words) { PageIterator* TessBaseAPI::AnalyseLayout(bool merge_similar_words) {
if (FindLines() == 0) { if (FindLines() == 0) {
@ -1379,8 +1377,9 @@ static void AddBaselineCoordsTohOCR(const PageIterator *it,
hocr_str->add_str_double(" ", round(p0 * 1000.0) / 1000.0); hocr_str->add_str_double(" ", round(p0 * 1000.0) / 1000.0);
} }
static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, int num2) { static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1,
const unsigned long BUFSIZE = 64; int num2) {
const size_t BUFSIZE = 64;
char id_buffer[BUFSIZE]; char id_buffer[BUFSIZE];
if (num2 >= 0) { if (num2 >= 0) {
snprintf(id_buffer, BUFSIZE - 1, "%s_%d_%d", base.c_str(), num1, num2); snprintf(id_buffer, BUFSIZE - 1, "%s_%d_%d", base.c_str(), num1, num2);
@ -1393,8 +1392,7 @@ static void AddIdTohOCR(STRING* hocr_str, const std::string base, int num1, int
*hocr_str += "'"; *hocr_str += "'";
} }
static void AddBoxTohOCR(const ResultIterator *it, static void AddBoxTohOCR(const ResultIterator* it, PageIteratorLevel level,
PageIteratorLevel level,
STRING* hocr_str) { STRING* hocr_str) {
int left, top, right, bottom; int left, top, right, bottom;
it->BoundingBox(level, &left, &top, &right, &bottom); it->BoundingBox(level, &left, &top, &right, &bottom);
@ -1410,7 +1408,7 @@ static void AddBoxTohOCR(const ResultIterator *it,
// add custom height measures // add custom height measures
float row_height, descenders, ascenders; // row attributes float row_height, descenders, ascenders; // row attributes
it->RowAttributes(&row_height, &descenders, &ascenders); it->RowAttributes(&row_height, &descenders, &ascenders);
// TODO: Do we want to limit these to a single decimal place? // TODO(rays): Do we want to limit these to a single decimal place?
hocr_str->add_str_double("; x_size ", row_height); hocr_str->add_str_double("; x_size ", row_height);
hocr_str->add_str_double("; x_descenders ", descenders * -1); hocr_str->add_str_double("; x_descenders ", descenders * -1);
hocr_str->add_str_double("; x_ascenders ", ascenders); hocr_str->add_str_double("; x_ascenders ", ascenders);
@ -1418,9 +1416,8 @@ static void AddBoxTohOCR(const ResultIterator *it,
*hocr_str += "\">"; *hocr_str += "\">";
} }
static void AddBoxToTSV(const PageIterator *it, static void AddBoxToTSV(const PageIterator* it, PageIteratorLevel level,
PageIteratorLevel level, STRING* hocr_str) {
STRING* hocr_str) {
int left, top, right, bottom; int left, top, right, bottom;
it->BoundingBox(level, &left, &top, &right, &bottom); it->BoundingBox(level, &left, &top, &right, &bottom);
hocr_str->add_str_int("\t", left); hocr_str->add_str_int("\t", left);
@ -1429,8 +1426,6 @@ static void AddBoxToTSV(const PageIterator *it,
hocr_str->add_str_int("\t", bottom - top); hocr_str->add_str_int("\t", bottom - top);
} }
/** /**
* Make a HTML-formatted string with hOCR markup from the internal * Make a HTML-formatted string with hOCR markup from the internal
* data structures. * data structures.
@ -1440,7 +1435,7 @@ static void AddBoxToTSV(const PageIterator *it,
* STL removed from original patch submission and refactored by rays. * STL removed from original patch submission and refactored by rays.
*/ */
char* TessBaseAPI::GetHOCRText(int page_number) { char* TessBaseAPI::GetHOCRText(int page_number) {
return GetHOCRText(NULL,page_number); return GetHOCRText(NULL, page_number);
} }
/** /**
@ -1452,13 +1447,12 @@ char* TessBaseAPI::GetHOCRText(int page_number) {
* STL removed from original patch submission and refactored by rays. * STL removed from original patch submission and refactored by rays.
*/ */
char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) { char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
if (tesseract_ == NULL || if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0))
(page_res_ == NULL && Recognize(monitor) < 0))
return NULL; return NULL;
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1; int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
int page_id = page_number + 1; // hOCR uses 1-based page numbers. int page_id = page_number + 1; // hOCR uses 1-based page numbers.
bool para_is_ltr = true; // Default direction is LTR bool para_is_ltr = true; // Default direction is LTR
const char* paragraph_lang = NULL; const char* paragraph_lang = NULL;
bool font_info = false; bool font_info = false;
GetBoolVariable("hocr_font_info", &font_info); GetBoolVariable("hocr_font_info", &font_info);
@ -1470,13 +1464,13 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
#ifdef _WIN32 #ifdef _WIN32
// convert input name from ANSI encoding to utf-8 // convert input name from ANSI encoding to utf-8
int str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1, int str16_len =
NULL, 0); MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1, NULL, 0);
wchar_t *uni16_str = new WCHAR[str16_len]; wchar_t *uni16_str = new WCHAR[str16_len];
str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1, str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1,
uni16_str, str16_len); uni16_str, str16_len);
int utf8_len = WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, NULL, int utf8_len = WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, NULL, 0,
0, NULL, NULL); NULL, NULL);
char *utf8_str = new char[utf8_len]; char *utf8_str = new char[utf8_len];
WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, utf8_str, WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, utf8_str,
utf8_len, NULL, NULL); utf8_len, NULL, NULL);
@ -1509,7 +1503,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
// Open any new block/paragraph/textline. // Open any new block/paragraph/textline.
if (res_it->IsAtBeginningOf(RIL_BLOCK)) { if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
para_is_ltr = true; // reset to default direction para_is_ltr = true; // reset to default direction
hocr_str += " <div class='ocr_carea'"; hocr_str += " <div class='ocr_carea'";
AddIdTohOCR(&hocr_str, "block", page_id, bcnt); AddIdTohOCR(&hocr_str, "block", page_id, bcnt);
AddBoxTohOCR(res_it, RIL_BLOCK, &hocr_str); AddBoxTohOCR(res_it, RIL_BLOCK, &hocr_str);
@ -1523,9 +1517,9 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
AddIdTohOCR(&hocr_str, "par", page_id, pcnt); AddIdTohOCR(&hocr_str, "par", page_id, pcnt);
paragraph_lang = res_it->WordRecognitionLanguage(); paragraph_lang = res_it->WordRecognitionLanguage();
if (paragraph_lang) { if (paragraph_lang) {
hocr_str += " lang='"; hocr_str += " lang='";
hocr_str += paragraph_lang; hocr_str += paragraph_lang;
hocr_str += "'"; hocr_str += "'";
} }
AddBoxTohOCR(res_it, RIL_PARA, &hocr_str); AddBoxTohOCR(res_it, RIL_PARA, &hocr_str);
} }
@ -1567,8 +1561,12 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
} }
switch (res_it->WordDirection()) { switch (res_it->WordDirection()) {
// Only emit direction if different from current paragraph direction // Only emit direction if different from current paragraph direction
case DIR_LEFT_TO_RIGHT: if (!para_is_ltr) hocr_str += " dir='ltr'"; break; case DIR_LEFT_TO_RIGHT:
case DIR_RIGHT_TO_LEFT: if (para_is_ltr) hocr_str += " dir='rtl'"; break; if (!para_is_ltr) hocr_str += " dir='ltr'";
break;
case DIR_RIGHT_TO_LEFT:
if (para_is_ltr) hocr_str += " dir='rtl'";
break;
case DIR_MIX: case DIR_MIX:
case DIR_NEUTRAL: case DIR_NEUTRAL:
default: // Do nothing. default: // Do nothing.
@ -1600,7 +1598,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
if (last_word_in_para) { if (last_word_in_para) {
hocr_str += "\n </p>\n"; hocr_str += "\n </p>\n";
pcnt++; pcnt++;
para_is_ltr = true; // back to default direction para_is_ltr = true; // back to default direction
} }
if (last_word_in_block) { if (last_word_in_block) {
hocr_str += " </div>\n"; hocr_str += " </div>\n";
@ -1620,8 +1618,7 @@ char* TessBaseAPI::GetHOCRText(ETEXT_DESC* monitor, int page_number) {
* page_number is 0-based but will appear in the output as 1-based. * page_number is 0-based but will appear in the output as 1-based.
*/ */
char* TessBaseAPI::GetTSVText(int page_number) { char* TessBaseAPI::GetTSVText(int page_number) {
if (tesseract_ == NULL || if (tesseract_ == NULL || (page_res_ == NULL && Recognize(NULL) < 0))
(page_res_ == NULL && Recognize(NULL) < 0))
return NULL; return NULL;
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1; int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
@ -1629,9 +1626,10 @@ char* TessBaseAPI::GetTSVText(int page_number) {
STRING tsv_str(""); STRING tsv_str("");
int page_num = page_id, block_num = 0, par_num = 0, line_num = 0, word_num = 0; int page_num = page_id, block_num = 0, par_num = 0, line_num = 0,
word_num = 0;
tsv_str.add_str_int("1\t", page_num); // level 1 - page tsv_str.add_str_int("1\t", page_num); // level 1 - page
tsv_str.add_str_int("\t", block_num); tsv_str.add_str_int("\t", block_num);
tsv_str.add_str_int("\t", par_num); tsv_str.add_str_int("\t", par_num);
tsv_str.add_str_int("\t", line_num); tsv_str.add_str_int("\t", line_num);
@ -1642,7 +1640,7 @@ char* TessBaseAPI::GetTSVText(int page_number) {
tsv_str.add_str_int("\t", rect_height_); tsv_str.add_str_int("\t", rect_height_);
tsv_str += "\t-1\t\n"; tsv_str += "\t-1\t\n";
ResultIterator *res_it = GetIterator(); ResultIterator* res_it = GetIterator();
while (!res_it->Empty(RIL_BLOCK)) { while (!res_it->Empty(RIL_BLOCK)) {
if (res_it->Empty(RIL_WORD)) { if (res_it->Empty(RIL_WORD)) {
res_it->Next(RIL_WORD); res_it->Next(RIL_WORD);
@ -1652,46 +1650,46 @@ char* TessBaseAPI::GetTSVText(int page_number) {
// Add rows for any new block/paragraph/textline. // Add rows for any new block/paragraph/textline.
if (res_it->IsAtBeginningOf(RIL_BLOCK)) { if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
block_num++, par_num = 0, line_num = 0, word_num = 0; block_num++, par_num = 0, line_num = 0, word_num = 0;
tsv_str.add_str_int("2\t", page_num); // level 2 - block tsv_str.add_str_int("2\t", page_num); // level 2 - block
tsv_str.add_str_int("\t", block_num); tsv_str.add_str_int("\t", block_num);
tsv_str.add_str_int("\t", par_num); tsv_str.add_str_int("\t", par_num);
tsv_str.add_str_int("\t", line_num); tsv_str.add_str_int("\t", line_num);
tsv_str.add_str_int("\t", word_num); tsv_str.add_str_int("\t", word_num);
AddBoxToTSV(res_it, RIL_BLOCK, &tsv_str); AddBoxToTSV(res_it, RIL_BLOCK, &tsv_str);
tsv_str += "\t-1\t\n"; // end of row for block tsv_str += "\t-1\t\n"; // end of row for block
} }
if (res_it->IsAtBeginningOf(RIL_PARA)) { if (res_it->IsAtBeginningOf(RIL_PARA)) {
par_num++, line_num = 0, word_num = 0; par_num++, line_num = 0, word_num = 0;
tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph
tsv_str.add_str_int("\t", block_num); tsv_str.add_str_int("\t", block_num);
tsv_str.add_str_int("\t", par_num); tsv_str.add_str_int("\t", par_num);
tsv_str.add_str_int("\t", line_num); tsv_str.add_str_int("\t", line_num);
tsv_str.add_str_int("\t", word_num); tsv_str.add_str_int("\t", word_num);
AddBoxToTSV(res_it, RIL_PARA, &tsv_str); AddBoxToTSV(res_it, RIL_PARA, &tsv_str);
tsv_str += "\t-1\t\n"; // end of row for para tsv_str += "\t-1\t\n"; // end of row for para
} }
if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) { if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
line_num++, word_num = 0; line_num++, word_num = 0;
tsv_str.add_str_int("4\t", page_num); // level 4 - line tsv_str.add_str_int("4\t", page_num); // level 4 - line
tsv_str.add_str_int("\t", block_num); tsv_str.add_str_int("\t", block_num);
tsv_str.add_str_int("\t", par_num); tsv_str.add_str_int("\t", par_num);
tsv_str.add_str_int("\t", line_num); tsv_str.add_str_int("\t", line_num);
tsv_str.add_str_int("\t", word_num); tsv_str.add_str_int("\t", word_num);
AddBoxToTSV(res_it, RIL_TEXTLINE, &tsv_str); AddBoxToTSV(res_it, RIL_TEXTLINE, &tsv_str);
tsv_str += "\t-1\t\n"; // end of row for line tsv_str += "\t-1\t\n"; // end of row for line
} }
// Now, process the word... // Now, process the word...
int left, top, right, bottom; int left, top, right, bottom;
bool bold, italic, underlined, monospace, serif, smallcaps; bool bold, italic, underlined, monospace, serif, smallcaps;
int pointsize, font_id; int pointsize, font_id;
const char *font_name; const char* font_name;
res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom); res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom);
font_name = res_it->WordFontAttributes(&bold, &italic, &underlined, font_name =
&monospace, &serif, &smallcaps, res_it->WordFontAttributes(&bold, &italic, &underlined, &monospace,
&pointsize, &font_id); &serif, &smallcaps, &pointsize, &font_id);
word_num++; word_num++;
tsv_str.add_str_int("5\t", page_num); // level 5 - word tsv_str.add_str_int("5\t", page_num); // level 5 - word
tsv_str.add_str_int("\t", block_num); tsv_str.add_str_int("\t", block_num);
tsv_str.add_str_int("\t", par_num); tsv_str.add_str_int("\t", par_num);
tsv_str.add_str_int("\t", line_num); tsv_str.add_str_int("\t", line_num);
@ -1712,11 +1710,11 @@ char* TessBaseAPI::GetTSVText(int page_number) {
tsv_str += res_it->GetUTF8Text(RIL_SYMBOL); tsv_str += res_it->GetUTF8Text(RIL_SYMBOL);
res_it->Next(RIL_SYMBOL); res_it->Next(RIL_SYMBOL);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD)); } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
tsv_str += "\n"; // end of row tsv_str += "\n"; // end of row
wcnt++; wcnt++;
} }
char *ret = new char[tsv_str.length() + 1]; char* ret = new char[tsv_str.length() + 1];
strcpy(ret, tsv_str.string()); strcpy(ret, tsv_str.string());
delete res_it; delete res_it;
return ret; return ret;
@ -1760,7 +1758,7 @@ char* TessBaseAPI::GetBoxText(int page_number) {
int total_length = blob_count * kBytesPerBoxFileLine + utf8_length + int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
kMaxBytesPerLine; kMaxBytesPerLine;
char* result = new char[total_length]; char* result = new char[total_length];
strcpy(result, "\0"); result[0] = '\0';
int output_length = 0; int output_length = 0;
LTRResultIterator* it = GetLTRIterator(); LTRResultIterator* it = GetLTRIterator();
do { do {
@ -1907,17 +1905,17 @@ char* TessBaseAPI::GetUNLVText() {
return result; return result;
} }
/** /**
* The recognized text is returned as a char* which is coded * The recognized text is returned as a char* which is coded
* as UTF8 and must be freed with the delete [] operator. * as UTF8 and must be freed with the delete [] operator.
* page_number is a 0-based page index that will appear in the osd file. * page_number is a 0-based page index that will appear in the osd file.
*/ */
char* TessBaseAPI::GetOsdText(int page_number) { char* TessBaseAPI::GetOsdText(int page_number) {
OSResults osr; OSResults osr;
bool osd = DetectOS(&osr); bool osd = DetectOS(&osr);
if (!osd) { if (!osd) {
return NULL; return NULL;
} }
int orient_id = osr.best_result.orientation_id; int orient_id = osr.best_result.orientation_id;
@ -1931,19 +1929,19 @@ char* TessBaseAPI::GetOsdText(int page_number) {
int orient_deg = orient_id * 90; int orient_deg = orient_id * 90;
// clockwise rotation needed to make the page upright // clockwise rotation needed to make the page upright
int rotate = OrientationIdToValue(orient_id); int rotate = OrientationIdToValue(orient_id);
char* osd_buf = new char[255]; const int kOsdBufsize = 255;
snprintf(osd_buf, 255, char* osd_buf = new char[kOsdBufsize];
"Page number: %d\n" snprintf(osd_buf, kOsdBufsize,
"Orientation in degrees: %d\n" "Page number: %d\n"
"Rotate: %d\n" "Orientation in degrees: %d\n"
"Orientation confidence: %.2f\n" "Rotate: %d\n"
"Script: %s\n" "Orientation confidence: %.2f\n"
"Script confidence: %.2f\n", "Script: %s\n"
page_number, "Script confidence: %.2f\n",
orient_deg, rotate, orient_conf, page_number, orient_deg, rotate, orient_conf, script_name,
script_name, script_conf); script_conf);
return osd_buf; return osd_buf;
} }
@ -2063,7 +2061,7 @@ void TessBaseAPI::Clear() {
if (thresholder_ != NULL) if (thresholder_ != NULL)
thresholder_->Clear(); thresholder_->Clear();
ClearResults(); ClearResults();
SetInputImage(NULL); if (tesseract_ != NULL) SetInputImage(NULL);
} }
/** /**
@ -2767,7 +2765,7 @@ void TessBaseAPI::GetFeaturesForBlob(TBLOB* blob,
INT_FX_RESULT_STRUCT fx_info; INT_FX_RESULT_STRUCT fx_info;
tesseract_->ExtractFeatures(*blob, false, &bl_features, tesseract_->ExtractFeatures(*blob, false, &bl_features,
&cn_features, &fx_info, &outline_counts); &cn_features, &fx_info, &outline_counts);
if (cn_features.size() == 0 || cn_features.size() > MAX_NUM_INT_FEATURES) { if (cn_features.empty() || cn_features.size() > MAX_NUM_INT_FEATURES) {
*num_features = 0; *num_features = 0;
return; // Feature extraction failed. return; // Feature extraction failed.
} }

View File

@ -588,8 +588,8 @@ class TESS_API TessBaseAPI {
* data structures. * data structures.
* page_number is 0-based but will appear in the output as 1-based. * page_number is 0-based but will appear in the output as 1-based.
* monitor can be used to * monitor can be used to
* cancel the recognition * cancel the recognition
* receive progress callbacks * receive progress callbacks
*/ */
char* GetHOCRText(ETEXT_DESC* monitor, int page_number); char* GetHOCRText(ETEXT_DESC* monitor, int page_number);
@ -750,13 +750,9 @@ class TESS_API TessBaseAPI {
*/ */
static void NormalizeTBLOB(TBLOB *tblob, ROW *row, bool numeric_mode); static void NormalizeTBLOB(TBLOB *tblob, ROW *row, bool numeric_mode);
Tesseract* tesseract() const { Tesseract* tesseract() const { return tesseract_; }
return tesseract_;
}
OcrEngineMode oem() const { OcrEngineMode oem() const { return last_oem_requested_; }
return last_oem_requested_;
}
void InitTruthCallback(TruthCallback *cb) { truth_cb_ = cb; } void InitTruthCallback(TruthCallback *cb) { truth_cb_ = cb; }
@ -898,7 +894,7 @@ class TESS_API TessBaseAPI {
const char* retry_config, int timeout_millisec, const char* retry_config, int timeout_millisec,
TessResultRenderer* renderer, TessResultRenderer* renderer,
int tessedit_page_number); int tessedit_page_number);
// TIFF supports multipage so gets special consideration // TIFF supports multipage so gets special consideration.
bool ProcessPagesMultipageTiff(const unsigned char *data, bool ProcessPagesMultipageTiff(const unsigned char *data,
size_t size, size_t size,
const char* filename, const char* filename,

View File

@ -20,12 +20,12 @@
#include "config_auto.h" #include "config_auto.h"
#endif #endif
#include "allheaders.h"
#include "baseapi.h" #include "baseapi.h"
#include "renderer.h"
#include "math.h" #include "math.h"
#include "renderer.h"
#include "strngs.h" #include "strngs.h"
#include "tprintf.h" #include "tprintf.h"
#include "allheaders.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include "mathfix.h" #include "mathfix.h"
@ -441,8 +441,8 @@ char* TessPDFRenderer::GetPDFTextObjects(TessBaseAPI* api,
int code = unicodes[i]; int code = unicodes[i];
// Convert to UTF-16BE https://en.wikipedia.org/wiki/UTF-16 // Convert to UTF-16BE https://en.wikipedia.org/wiki/UTF-16
if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) { if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) {
tprintf("Dropping invalid codepoint %d\n", code); tprintf("Dropping invalid codepoint %d\n", code);
continue; continue;
} }
if (code < 0x10000) { if (code < 0x10000) {
snprintf(utf16, sizeof(utf16), "<%04X>", code); snprintf(utf16, sizeof(utf16), "<%04X>", code);
@ -567,7 +567,8 @@ bool TessPDFRenderer::BeginDocumentHandler() {
"<<\n" "<<\n"
" /Length %lu /Filter /FlateDecode\n" " /Length %lu /Filter /FlateDecode\n"
">>\n" ">>\n"
"stream\n", (unsigned long)len); "stream\n",
(unsigned long)len);
if (n >= sizeof(buf)) { if (n >= sizeof(buf)) {
lept_free(comp); lept_free(comp);
return false; return false;

View File

@ -155,11 +155,11 @@ TessHOcrRenderer::TessHOcrRenderer(const char *outputbase, bool font_info)
bool TessHOcrRenderer::BeginDocumentHandler() { bool TessHOcrRenderer::BeginDocumentHandler() {
AppendString( AppendString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" " "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" "
"lang=\"en\">\n <head>\n <title>"); "lang=\"en\">\n <head>\n <title>");
AppendString(title()); AppendString(title());
AppendString( AppendString(
"</title>\n" "</title>\n"
@ -198,25 +198,25 @@ bool TessHOcrRenderer::AddImageHandler(TessBaseAPI* api) {
/********************************************************************** /**********************************************************************
* TSV Text Renderer interface implementation * TSV Text Renderer interface implementation
**********************************************************************/ **********************************************************************/
TessTsvRenderer::TessTsvRenderer(const char *outputbase) TessTsvRenderer::TessTsvRenderer(const char* outputbase)
: TessResultRenderer(outputbase, "tsv") { : TessResultRenderer(outputbase, "tsv") {
font_info_ = false; font_info_ = false;
} }
TessTsvRenderer::TessTsvRenderer(const char *outputbase, bool font_info) TessTsvRenderer::TessTsvRenderer(const char* outputbase, bool font_info)
: TessResultRenderer(outputbase, "tsv") { : TessResultRenderer(outputbase, "tsv") {
font_info_ = font_info; font_info_ = font_info;
} }
bool TessTsvRenderer::BeginDocumentHandler() { bool TessTsvRenderer::BeginDocumentHandler() {
// Output TSV column headings // Output TSV column headings
AppendString("level\tpage_num\tblock_num\tpar_num\tline_num\tword_num\tleft\ttop\twidth\theight\tconf\ttext\n"); AppendString(
"level\tpage_num\tblock_num\tpar_num\tline_num\tword_"
"num\tleft\ttop\twidth\theight\tconf\ttext\n");
return true; return true;
} }
bool TessTsvRenderer::EndDocumentHandler() { bool TessTsvRenderer::EndDocumentHandler() { return true; }
return true;
}
bool TessTsvRenderer::AddImageHandler(TessBaseAPI* api) { bool TessTsvRenderer::AddImageHandler(TessBaseAPI* api) {
char* tsv = api->GetTSVText(imagenum()); char* tsv = api->GetTSVText(imagenum());
@ -266,8 +266,7 @@ bool TessBoxTextRenderer::AddImageHandler(TessBaseAPI* api) {
* Osd Text Renderer interface implementation * Osd Text Renderer interface implementation
**********************************************************************/ **********************************************************************/
TessOsdRenderer::TessOsdRenderer(const char* outputbase) TessOsdRenderer::TessOsdRenderer(const char* outputbase)
: TessResultRenderer(outputbase, "osd") { : TessResultRenderer(outputbase, "osd") {}
}
bool TessOsdRenderer::AddImageHandler(TessBaseAPI* api) { bool TessOsdRenderer::AddImageHandler(TessBaseAPI* api) {
char* osd = api->GetOsdText(imagenum()); char* osd = api->GetOsdText(imagenum());

View File

@ -153,13 +153,13 @@ class TESS_API TessHOcrRenderer : public TessResultRenderer {
explicit TessHOcrRenderer(const char *outputbase, bool font_info); explicit TessHOcrRenderer(const char *outputbase, bool font_info);
explicit TessHOcrRenderer(const char *outputbase); explicit TessHOcrRenderer(const char *outputbase);
protected: protected:
virtual bool BeginDocumentHandler(); virtual bool BeginDocumentHandler();
virtual bool AddImageHandler(TessBaseAPI* api); virtual bool AddImageHandler(TessBaseAPI* api);
virtual bool EndDocumentHandler(); virtual bool EndDocumentHandler();
private: private:
bool font_info_; // whether to print font information bool font_info_; // whether to print font information
}; };
/** /**
@ -167,15 +167,15 @@ private:
*/ */
class TESS_API TessTsvRenderer : public TessResultRenderer { class TESS_API TessTsvRenderer : public TessResultRenderer {
public: public:
explicit TessTsvRenderer(const char *outputbase, bool font_info); explicit TessTsvRenderer(const char* outputbase, bool font_info);
explicit TessTsvRenderer(const char *outputbase); explicit TessTsvRenderer(const char* outputbase);
protected: protected:
virtual bool BeginDocumentHandler(); virtual bool BeginDocumentHandler();
virtual bool AddImageHandler(TessBaseAPI* api); virtual bool AddImageHandler(TessBaseAPI* api);
virtual bool EndDocumentHandler(); virtual bool EndDocumentHandler();
private: private:
bool font_info_; // whether to print font information bool font_info_; // whether to print font information
}; };
@ -188,12 +188,12 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
// we load a custom PDF font from this location. // we load a custom PDF font from this location.
TessPDFRenderer(const char *outputbase, const char *datadir); TessPDFRenderer(const char *outputbase, const char *datadir);
protected: protected:
virtual bool BeginDocumentHandler(); virtual bool BeginDocumentHandler();
virtual bool AddImageHandler(TessBaseAPI* api); virtual bool AddImageHandler(TessBaseAPI* api);
virtual bool EndDocumentHandler(); virtual bool EndDocumentHandler();
private: private:
// We don't want to have every image in memory at once, // We don't want to have every image in memory at once,
// so we store some metadata as we go along producing // so we store some metadata as we go along producing
// PDFs one page at a time. At the end that metadata is // PDFs one page at a time. At the end that metadata is

View File

@ -40,28 +40,28 @@
static void Win32WarningHandler(const char* module, const char* fmt, static void Win32WarningHandler(const char* module, const char* fmt,
va_list ap) { va_list ap) {
if (module != NULL) { if (module != NULL) {
fprintf(stderr, "%s: ", module); fprintf(stderr, "%s: ", module);
} }
fprintf(stderr, "Warning, "); fprintf(stderr, "Warning, ");
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n"); fprintf(stderr, ".\n");
} }
#endif /* HAVE_TIFFIO_H && _WIN32 */ #endif /* HAVE_TIFFIO_H && _WIN32 */
void PrintVersionInfo() { void PrintVersionInfo() {
char *versionStrP; char* versionStrP;
printf("tesseract %s\n", tesseract::TessBaseAPI::Version()); printf("tesseract %s\n", tesseract::TessBaseAPI::Version());
versionStrP = getLeptonicaVersion(); versionStrP = getLeptonicaVersion();
printf(" %s\n", versionStrP); printf(" %s\n", versionStrP);
lept_free(versionStrP); lept_free(versionStrP);
versionStrP = getImagelibVersions(); versionStrP = getImagelibVersions();
printf(" %s\n", versionStrP); printf(" %s\n", versionStrP);
lept_free(versionStrP); lept_free(versionStrP);
#ifdef USE_OPENCL #ifdef USE_OPENCL
cl_platform_id platform; cl_platform_id platform;
@ -82,7 +82,7 @@ void PrintVersionInfo() {
printf(" Found %d devices.\n", num_devices); printf(" Found %d devices.\n", num_devices);
for (i = 0; i < num_devices; ++i) { for (i = 0; i < num_devices; ++i) {
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0); clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0);
printf(" Device %d name: %s.\n", i+1, info); printf(" Device %d name: %s.\n", i + 1, info);
} }
#endif #endif
} }
@ -100,27 +100,22 @@ void PrintUsage(const char* program) {
void PrintHelpForPSM() { void PrintHelpForPSM() {
const char* msg = const char* msg =
"Page segmentation modes:\n" "Page segmentation modes:\n"
" 0 Orientation and script detection (OSD) only.\n" " 0 Orientation and script detection (OSD) only.\n"
" 1 Automatic page segmentation with OSD.\n" " 1 Automatic page segmentation with OSD.\n"
" 2 Automatic page segmentation, but no OSD, or OCR.\n" " 2 Automatic page segmentation, but no OSD, or OCR.\n"
" 3 Fully automatic page segmentation, but no OSD. (Default)\n" " 3 Fully automatic page segmentation, but no OSD. (Default)\n"
" 4 Assume a single column of text of variable sizes.\n" " 4 Assume a single column of text of variable sizes.\n"
" 5 Assume a single uniform block of vertically aligned text.\n" " 5 Assume a single uniform block of vertically aligned text.\n"
" 6 Assume a single uniform block of text.\n" " 6 Assume a single uniform block of text.\n"
" 7 Treat the image as a single text line.\n" " 7 Treat the image as a single text line.\n"
" 8 Treat the image as a single word.\n" " 8 Treat the image as a single word.\n"
" 9 Treat the image as a single word in a circle.\n" " 9 Treat the image as a single word in a circle.\n"
" 10 Treat the image as a single character.\n" " 10 Treat the image as a single character.\n"
" 11 Sparse text. Find as much text as possible in no"
//TODO: Consider publishing these modes. " particular order.\n"
#if 0 " 12 Sparse text with OSD.\n"
" 11 Sparse text. Find as much text as possible in no" " 13 Raw line. Treat the image as a single text line,\n"
" particular order.\n" "\t\t\tbypassing hacks that are Tesseract-specific.\n";
" 12 Sparse text with OSD.\n"
" 13 Raw line. Treat the image as a single text line,\n"
"\t\t\tbypassing hacks that are Tesseract-specific.\n"
#endif
;
printf("%s", msg); printf("%s", msg);
} }
@ -137,31 +132,30 @@ void PrintHelpMessage(const char* program) {
" -c VAR=VALUE Set value for config variables.\n" " -c VAR=VALUE Set value for config variables.\n"
" Multiple -c arguments are allowed.\n" " Multiple -c arguments are allowed.\n"
" -psm NUM Specify page segmentation mode.\n" " -psm NUM Specify page segmentation mode.\n"
"NOTE: These options must occur before any configfile.\n" "NOTE: These options must occur before any configfile.\n";
;
printf("\n%s\n", ocr_options); printf("\n%s\n", ocr_options);
PrintHelpForPSM(); PrintHelpForPSM();
const char *single_options = const char* single_options =
"Single options:\n" "Single options:\n"
" -h, --help Show this help message.\n" " -h, --help Show this help message.\n"
" --help-psm Show page segmentation modes.\n" " --help-psm Show page segmentation modes.\n"
" -v, --version Show version information.\n" " -v, --version Show version information.\n"
" --list-langs List available languages for tesseract engine.\n" " --list-langs List available languages for tesseract engine.\n"
" --print-parameters Print tesseract parameters to stdout.\n" " --print-parameters Print tesseract parameters to stdout.\n";
;
printf("\n%s", single_options); printf("\n%s", single_options);
} }
void SetVariablesFromCLArgs(tesseract::TessBaseAPI* api, int argc, char** argv) { void SetVariablesFromCLArgs(tesseract::TessBaseAPI* api, int argc,
char** argv) {
char opt1[256], opt2[255]; char opt1[256], opt2[255];
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "-c") == 0 && i + 1 < argc) { if (strcmp(argv[i], "-c") == 0 && i + 1 < argc) {
strncpy(opt1, argv[i + 1], 255); strncpy(opt1, argv[i + 1], 255);
opt1[255] = '\0'; opt1[255] = '\0';
char *p = strchr(opt1, '='); char* p = strchr(opt1, '=');
if (!p) { if (!p) {
fprintf(stderr, "Missing = in configvar assignment\n"); fprintf(stderr, "Missing = in configvar assignment\n");
exit(1); exit(1);
@ -190,8 +184,8 @@ void PrintLangsList(tesseract::TessBaseAPI* api) {
} }
void PrintBanner() { void PrintBanner() {
tprintf("Tesseract Open Source OCR Engine v%s with Leptonica\n", tprintf("Tesseract Open Source OCR Engine v%s with Leptonica\n",
tesseract::TessBaseAPI::Version()); tesseract::TessBaseAPI::Version());
} }
/** /**
@ -209,31 +203,25 @@ void PrintBanner() {
* but that doesn't work. * but that doesn't work.
*/ */
void FixPageSegMode(tesseract::TessBaseAPI* api, void FixPageSegMode(tesseract::TessBaseAPI* api,
tesseract::PageSegMode pagesegmode) { tesseract::PageSegMode pagesegmode) {
if (api->GetPageSegMode() == tesseract::PSM_SINGLE_BLOCK) if (api->GetPageSegMode() == tesseract::PSM_SINGLE_BLOCK)
api->SetPageSegMode(pagesegmode); api->SetPageSegMode(pagesegmode);
} }
// NOTE: arg_i is used here to avoid ugly *i so many times in this function // NOTE: arg_i is used here to avoid ugly *i so many times in this function
void ParseArgs(const int argc, char** argv, void ParseArgs(const int argc, char** argv, const char** lang,
const char** lang, const char** image, const char** outputbase,
const char** image, const char** datapath, bool* list_langs, bool* print_parameters,
const char** outputbase, GenericVector<STRING>* vars_vec,
const char** datapath, GenericVector<STRING>* vars_values, int* arg_i,
bool* list_langs, tesseract::PageSegMode* pagesegmode) {
bool* print_parameters,
GenericVector<STRING>* vars_vec,
GenericVector<STRING>* vars_values,
int* arg_i,
tesseract::PageSegMode* pagesegmode) {
if (argc == 1) { if (argc == 1) {
PrintHelpMessage(argv[0]); PrintHelpMessage(argv[0]);
exit(0); exit(0);
} }
if (argc == 2) { if (argc == 2) {
if ((strcmp(argv[1], "-h") == 0) || if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
(strcmp(argv[1], "--help") == 0)) {
PrintHelpMessage(argv[0]); PrintHelpMessage(argv[0]);
exit(0); exit(0);
} }
@ -241,8 +229,7 @@ void ParseArgs(const int argc, char** argv,
PrintHelpForPSM(); PrintHelpForPSM();
exit(0); exit(0);
} }
if ((strcmp(argv[1], "-v") == 0) || if ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "--version") == 0)) {
(strcmp(argv[1], "--version") == 0)) {
PrintVersionInfo(); PrintVersionInfo();
exit(0); exit(0);
} }
@ -298,10 +285,10 @@ void ParseArgs(const int argc, char** argv,
} }
} }
void PreloadRenderers(tesseract::TessBaseAPI* api, void PreloadRenderers(
tesseract::PointerVector<tesseract::TessResultRenderer>* renderers, tesseract::TessBaseAPI* api,
tesseract::PageSegMode pagesegmode, tesseract::PointerVector<tesseract::TessResultRenderer>* renderers,
const char* outputbase) { tesseract::PageSegMode pagesegmode, const char* outputbase) {
if (pagesegmode == tesseract::PSM_OSD_ONLY) { if (pagesegmode == tesseract::PSM_OSD_ONLY) {
renderers->push_back(new tesseract::TessOsdRenderer(outputbase)); renderers->push_back(new tesseract::TessOsdRenderer(outputbase));
} else { } else {
@ -311,7 +298,7 @@ void PreloadRenderers(tesseract::TessBaseAPI* api,
bool font_info; bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info); api->GetBoolVariable("hocr_font_info", &font_info);
renderers->push_back( renderers->push_back(
new tesseract::TessHOcrRenderer(outputbase, font_info)); new tesseract::TessHOcrRenderer(outputbase, font_info));
} }
api->GetBoolVariable("tessedit_create_tsv", &b); api->GetBoolVariable("tessedit_create_tsv", &b);
@ -324,8 +311,8 @@ void PreloadRenderers(tesseract::TessBaseAPI* api,
api->GetBoolVariable("tessedit_create_pdf", &b); api->GetBoolVariable("tessedit_create_pdf", &b);
if (b) { if (b) {
renderers->push_back(new tesseract::TessPDFRenderer(outputbase, renderers->push_back(
api->GetDatapath())); new tesseract::TessPDFRenderer(outputbase, api->GetDatapath()));
} }
api->GetBoolVariable("tessedit_write_unlv", &b); api->GetBoolVariable("tessedit_write_unlv", &b);
@ -359,8 +346,7 @@ void PreloadRenderers(tesseract::TessBaseAPI* api,
* *
**********************************************************************/ **********************************************************************/
int main(int argc, char** argv) {
int main(int argc, char **argv) {
const char* lang = "eng"; const char* lang = "eng";
const char* image = NULL; const char* image = NULL;
const char* outputbase = NULL; const char* outputbase = NULL;
@ -380,10 +366,8 @@ int main(int argc, char **argv) {
TIFFSetWarningHandler(Win32WarningHandler); TIFFSetWarningHandler(Win32WarningHandler);
#endif /* HAVE_TIFFIO_H && _WIN32 */ #endif /* HAVE_TIFFIO_H && _WIN32 */
ParseArgs(argc, argv, ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &list_langs,
&lang, &image, &outputbase, &datapath, &print_parameters, &vars_vec, &vars_values, &arg_i, &pagesegmode);
&list_langs, &print_parameters,
&vars_vec, &vars_values, &arg_i, &pagesegmode);
bool banner = false; bool banner = false;
if (outputbase != NULL && strcmp(outputbase, "-") && if (outputbase != NULL && strcmp(outputbase, "-") &&
@ -396,8 +380,9 @@ int main(int argc, char **argv) {
api.SetOutputName(outputbase); api.SetOutputName(outputbase);
int init_failed = api.Init(datapath, lang, tesseract::OEM_DEFAULT, int init_failed =
&(argv[arg_i]), argc - arg_i, &vars_vec, &vars_values, false); api.Init(datapath, lang, tesseract::OEM_DEFAULT, &(argv[arg_i]),
argc - arg_i, &vars_vec, &vars_values, false);
if (init_failed) { if (init_failed) {
fprintf(stderr, "Could not initialize tesseract.\n"); fprintf(stderr, "Could not initialize tesseract.\n");
exit(1); exit(1);
@ -406,8 +391,8 @@ int main(int argc, char **argv) {
SetVariablesFromCLArgs(&api, argc, argv); SetVariablesFromCLArgs(&api, argc, argv);
if (list_langs) { if (list_langs) {
PrintLangsList(&api); PrintLangsList(&api);
exit(0); exit(0);
} }
if (print_parameters) { if (print_parameters) {
@ -436,12 +421,13 @@ int main(int argc, char **argv) {
tesseract::TextlineOrder order; tesseract::TextlineOrder order;
float deskew_angle; float deskew_angle;
tesseract::PageIterator* it = api.AnalyseLayout(); tesseract::PageIterator* it = api.AnalyseLayout();
if (it) { if (it) {
it->Orientation(&orientation, &direction, &order, &deskew_angle); it->Orientation(&orientation, &direction, &order, &deskew_angle);
tprintf("Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n" \ tprintf(
"Deskew angle: %.4f\n", "Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n"
orientation, direction, order, deskew_angle); "Deskew angle: %.4f\n",
orientation, direction, order, deskew_angle);
} else { } else {
ret_val = 1; ret_val = 1;
} }
@ -456,14 +442,12 @@ int main(int argc, char **argv) {
// ambigs.train, box.train, box.train.stderr, linebox, rebox // ambigs.train, box.train, box.train.stderr, linebox, rebox
bool b = false; bool b = false;
bool in_training_mode = bool in_training_mode =
(api.GetBoolVariable("tessedit_ambigs_training", &b) && b) || (api.GetBoolVariable("tessedit_ambigs_training", &b) && b) ||
(api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) || (api.GetBoolVariable("tessedit_resegment_from_boxes", &b) && b) ||
(api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b); (api.GetBoolVariable("tessedit_make_boxes_from_boxes", &b) && b);
tesseract::PointerVector<tesseract::TessResultRenderer> renderers; tesseract::PointerVector<tesseract::TessResultRenderer> renderers;
if (in_training_mode) { if (in_training_mode) {
renderers.push_back(NULL); renderers.push_back(NULL);
} else { } else {

View File

@ -1,8 +1,8 @@
/****************************************************************** /******************************************************************
* File: control.cpp (Formerly control.c) * File: control.cpp (Formerly control.c)
* Description: Module-independent matcher controller. * Description: Module-independent matcher controller.
* Author: Ray Smith * Author: Ray Smith
* Created: Thu Apr 23 11:09:58 BST 1992 * Created: Thu Apr 23 11:09:58 BST 1992
* ReHacked: Tue Sep 22 08:42:49 BST 1992 Phil Cheatle * ReHacked: Tue Sep 22 08:42:49 BST 1992 Phil Cheatle
* *
* (C) Copyright 1992, Hewlett-Packard Ltd. * (C) Copyright 1992, Hewlett-Packard Ltd.
@ -73,7 +73,6 @@ void Tesseract::recog_pseudo_word(PAGE_RES* page_res,
} }
} }
/** /**
* Recognize a single word in interactive mode. * Recognize a single word in interactive mode.
* *
@ -539,7 +538,7 @@ void Tesseract::bigram_correction_pass(PAGE_RES *page_res) {
} }
} }
} }
if (overrides_word1.size() >= 1) { if (!overrides_word1.empty()) {
// Excellent, we have some bigram matches. // Excellent, we have some bigram matches.
if (EqualIgnoringCaseAndTerminalPunct(*w_prev->best_choice, if (EqualIgnoringCaseAndTerminalPunct(*w_prev->best_choice,
*overrides_word1[best_idx]) && *overrides_word1[best_idx]) &&

View File

@ -1,8 +1,8 @@
/****************************************************************** /******************************************************************
* File: docqual.cpp (Formerly docqual.c) * File: docqual.cpp (Formerly docqual.c)
* Description: Document Quality Metrics * Description: Document Quality Metrics
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Mon May 9 11:27:28 BST 1994 * Created: Mon May 9 11:27:28 BST 1994
* *
* (C) Copyright 1994, Hewlett-Packard Ltd. * (C) Copyright 1994, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -98,8 +98,8 @@ void Tesseract::word_char_quality(WERD_RES *word,
ROW *row, ROW *row,
inT16 *match_count, inT16 *match_count,
inT16 *accepted_match_count) { inT16 *accepted_match_count) {
if (word->bln_boxes == NULL || if (word->bln_boxes == NULL || word->rebuild_word == NULL ||
word->rebuild_word == NULL || word->rebuild_word->blobs.empty()) { word->rebuild_word->blobs.empty()) {
*match_count = 0; *match_count = 0;
*accepted_match_count = 0; *accepted_match_count = 0;
return; return;
@ -132,7 +132,7 @@ inT16 Tesseract::count_outline_errs(char c, inT16 outline_count) {
int expected_outline_count; int expected_outline_count;
if (STRING (outlines_odd).contains (c)) if (STRING (outlines_odd).contains (c))
return 0; //Don't use this char return 0; // Don't use this char
else if (STRING (outlines_2).contains (c)) else if (STRING (outlines_2).contains (c))
expected_outline_count = 2; expected_outline_count = 2;
else else
@ -151,17 +151,16 @@ void Tesseract::quality_based_rejection(PAGE_RES_IT &page_res_it,
} }
} }
/************************************************************************* /*************************************************************************
* unrej_good_quality_words() * unrej_good_quality_words()
* Accept potential rejects in words which pass the following checks: * Accept potential rejects in words which pass the following checks:
* - Contains a potential reject * - Contains a potential reject
* - Word looks like a sensible alpha word. * - Word looks like a sensible alpha word.
* - Word segmentation is the same as the original image * - Word segmentation is the same as the original image
* - All characters have the expected number of outlines * - All characters have the expected number of outlines
* NOTE - the rejection counts are recalculated after unrejection * NOTE - the rejection counts are recalculated after unrejection
* - CAN'T do it in a single pass without a bit of fiddling * - CAN'T do it in a single pass without a bit of fiddling
* - keep it simple but inefficient * - keep it simple but inefficient
*************************************************************************/ *************************************************************************/
void Tesseract::unrej_good_quality_words( //unreject potential void Tesseract::unrej_good_quality_words( //unreject potential
PAGE_RES_IT &page_res_it) { PAGE_RES_IT &page_res_it) {
@ -403,7 +402,6 @@ void Tesseract::doc_and_block_rejection( //reject big chunks
} // namespace tesseract } // namespace tesseract
/************************************************************************* /*************************************************************************
* reject_whole_page() * reject_whole_page()
* Don't believe any of it - set the reject map to 00..00 in all words * Don't believe any of it - set the reject map to 00..00 in all words

View File

@ -3,8 +3,8 @@
* Description: Implements a pass over the page res, exploring the alternative * Description: Implements a pass over the page res, exploring the alternative
* spacing possibilities, trying to use context to improve the * spacing possibilities, trying to use context to improve the
* word spacing * word spacing
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Thu Oct 21 11:38:43 BST 1993 * Created: Thu Oct 21 11:38:43 BST 1993
* *
* (C) Copyright 1993, Hewlett-Packard Ltd. * (C) Copyright 1993, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -211,7 +211,6 @@ void Tesseract::match_current_words(WERD_RES_LIST &words, ROW *row,
} }
} }
/** /**
* @name eval_word_spacing() * @name eval_word_spacing()
* The basic measure is the number of characters in contextually confirmed * The basic measure is the number of characters in contextually confirmed

View File

@ -145,13 +145,12 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const {
return 0.0f; return 0.0f;
} }
void LTRResultIterator::RowAttributes(float* row_height, void LTRResultIterator::RowAttributes(float* row_height, float* descenders,
float* descenders,
float* ascenders) const { float* ascenders) const {
*row_height = it_->row()->row->x_height() + it_->row()-> row->ascenders() *row_height = it_->row()->row->x_height() + it_->row()->row->ascenders() -
- it_->row()->row->descenders(); it_->row()->row->descenders();
*descenders = it_->row()->row->descenders(); *descenders = it_->row()->row->descenders();
*ascenders = it_->row()->row->ascenders(); *ascenders = it_->row()->row->ascenders();
} }
// Returns the font attributes of the current word. If iterating at a higher // Returns the font attributes of the current word. If iterating at a higher

View File

@ -92,8 +92,7 @@ class TESS_API LTRResultIterator : public PageIterator {
float Confidence(PageIteratorLevel level) const; float Confidence(PageIteratorLevel level) const;
// Returns the attributes of the current row. // Returns the attributes of the current row.
void RowAttributes(float* row_height, void RowAttributes(float* row_height, float* descenders,
float* descenders,
float* ascenders) const; float* ascenders) const;
// ============= Functions that refer to words only ============. // ============= Functions that refer to words only ============.

View File

@ -1,8 +1,8 @@
/****************************************************************** /******************************************************************
* File: output.cpp (Formerly output.c) * File: output.cpp (Formerly output.c)
* Description: Output pass * Description: Output pass
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Thu Aug 4 10:56:08 BST 1994 * Created: Thu Aug 4 10:56:08 BST 1994
* *
* (C) Copyright 1994, Hewlett-Packard Ltd. * (C) Copyright 1994, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -78,18 +78,16 @@ void Tesseract::output_pass( //Tess output pass //send to api
while (page_res_it.word () != NULL) { while (page_res_it.word () != NULL) {
check_debug_pt (page_res_it.word (), 120); check_debug_pt (page_res_it.word (), 120);
if (target_word_box) if (target_word_box) {
{ TBOX current_word_box = page_res_it.word()->word->bounding_box();
FCOORD center_pt(
TBOX current_word_box=page_res_it.word ()->word->bounding_box(); (current_word_box.right() + current_word_box.left()) / 2,
FCOORD center_pt((current_word_box.right()+current_word_box.left())/2,(current_word_box.bottom()+current_word_box.top())/2); (current_word_box.bottom() + current_word_box.top()) / 2);
if (!target_word_box->contains(center_pt)) if (!target_word_box->contains(center_pt)) {
{ page_res_it.forward();
page_res_it.forward (); continue;
continue; }
} }
}
if (tessedit_write_block_separators && if (tessedit_write_block_separators &&
block_of_last_word != page_res_it.block ()) { block_of_last_word != page_res_it.block ()) {
block_of_last_word = page_res_it.block (); block_of_last_word = page_res_it.block ();
@ -337,7 +335,7 @@ void Tesseract::set_unlv_suspects(WERD_RES *word_res) {
rating_per_ch = word.rating() / word_res->reject_map.length(); rating_per_ch = word.rating() / word_res->reject_map.length();
if (rating_per_ch >= suspect_rating_per_ch) if (rating_per_ch >= suspect_rating_per_ch)
return; //Don't touch bad ratings return; // Don't touch bad ratings
if ((word_res->tess_accepted) || (rating_per_ch < suspect_accept_rating)) { if ((word_res->tess_accepted) || (rating_per_ch < suspect_accept_rating)) {
/* Unreject any Tess Acceptable word - but NOT tess reject chs*/ /* Unreject any Tess Acceptable word - but NOT tess reject chs*/

View File

@ -412,9 +412,10 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation(
"Don't rotate.\n", osd_margin); "Don't rotate.\n", osd_margin);
osd_orientation = 0; osd_orientation = 0;
} else { } else {
tprintf("OSD: Weak margin (%.2f) for %d blob text block, " tprintf(
"but using orientation anyway: %d\n", "OSD: Weak margin (%.2f) for %d blob text block, "
osd_margin, osd_blobs.length(), osd_orientation); "but using orientation anyway: %d\n",
osd_margin, osd_blobs.length(), osd_orientation);
} }
} }
} }

View File

@ -2052,7 +2052,7 @@ void ConvertHypothesizedModelRunsToParagraphs(
bool single_line_paragraph = false; bool single_line_paragraph = false;
SetOfModels models; SetOfModels models;
rows[start].NonNullHypotheses(&models); rows[start].NonNullHypotheses(&models);
if (models.size() > 0) { if (!models.empty()) {
model = models[0]; model = models[0];
if (rows[start].GetLineType(model) != LT_BODY) if (rows[start].GetLineType(model) != LT_BODY)
single_line_paragraph = true; single_line_paragraph = true;
@ -2190,17 +2190,17 @@ void LeftoverSegments(const GenericVector<RowScratchRegisters> &rows,
SetOfModels models_w_crowns; SetOfModels models_w_crowns;
rows[i].StrongHypotheses(&models); rows[i].StrongHypotheses(&models);
rows[i].NonNullHypotheses(&models_w_crowns); rows[i].NonNullHypotheses(&models_w_crowns);
if (models.empty() && models_w_crowns.size() > 0) { if (models.empty() && !models_w_crowns.empty()) {
// Crown paragraph. Is it followed by a modeled line? // Crown paragraph. Is it followed by a modeled line?
for (int end = i + 1; end < rows.size(); end++) { for (int end = i + 1; end < rows.size(); end++) {
SetOfModels end_models; SetOfModels end_models;
SetOfModels strong_end_models; SetOfModels strong_end_models;
rows[end].NonNullHypotheses(&end_models); rows[end].NonNullHypotheses(&end_models);
rows[end].StrongHypotheses(&strong_end_models); rows[end].StrongHypotheses(&strong_end_models);
if (end_models.size() == 0) { if (end_models.empty()) {
needs_fixing = true; needs_fixing = true;
break; break;
} else if (strong_end_models.size() > 0) { } else if (!strong_end_models.empty()) {
needs_fixing = false; needs_fixing = false;
break; break;
} }
@ -2485,7 +2485,7 @@ void InitializeRowInfo(bool after_recognition,
info->ltr = ltr >= rtl; info->ltr = ltr >= rtl;
info->has_leaders = num_leaders > 3; info->has_leaders = num_leaders > 3;
info->num_words = werds.size(); info->num_words = werds.size();
if (werds.size() > 0) { if (!werds.empty()) {
WERD_RES *lword = werds[0], *rword = werds[werds.size() - 1]; WERD_RES *lword = werds[0], *rword = werds[werds.size() - 1];
info->lword_text = lword->best_choice->unichar_string().string(); info->lword_text = lword->best_choice->unichar_string().string();
info->rword_text = rword->best_choice->unichar_string().string(); info->rword_text = rword->best_choice->unichar_string().string();
@ -2538,7 +2538,7 @@ void DetectParagraphs(int debug_level,
// If we're called before text recognition, we might not have // If we're called before text recognition, we might not have
// tight block bounding boxes, so trim by the minimum on each side. // tight block bounding boxes, so trim by the minimum on each side.
if (row_infos.size() > 0) { if (!row_infos.empty()) {
int min_lmargin = row_infos[0].pix_ldistance; int min_lmargin = row_infos[0].pix_ldistance;
int min_rmargin = row_infos[0].pix_rdistance; int min_rmargin = row_infos[0].pix_rdistance;
for (int i = 1; i < row_infos.size(); i++) { for (int i = 1; i < row_infos.size(); i++) {

View File

@ -329,13 +329,19 @@ void ParamsEditor::WriteParams(char *filename,
fclose(fp); fclose(fp);
sprintf (msg_str, "Overwrite file " "%s" "? (Y/N)", filename); sprintf (msg_str, "Overwrite file " "%s" "? (Y/N)", filename);
int a = sv_window_->ShowYesNoDialog(msg_str); int a = sv_window_->ShowYesNoDialog(msg_str);
if (a == 'n') { return; } // don't write if (a == 'n') {
return;
} // don't write
} }
fp = fopen (filename, "wb"); // can we write to it? fp = fopen (filename, "wb"); // can we write to it?
if (fp == NULL) { if (fp == NULL) {
sv_window_->AddMessage("Can't write to file " "%s" "", filename); sv_window_->AddMessage(
"Can't write to file "
"%s"
"",
filename);
return; return;
} }

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: reject.cpp (Formerly reject.c) * File: reject.cpp (Formerly reject.c)
* Description: Rejection functions used in tessedit * Description: Rejection functions used in tessedit
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Wed Sep 23 16:50:21 BST 1992 * Created: Wed Sep 23 16:50:21 BST 1992
* *
* (C) Copyright 1992, Hewlett-Packard Ltd. * (C) Copyright 1992, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -44,7 +44,7 @@
#include "params.h" #include "params.h"
#define VARDIR "configs/" /*variables files */ #define VARDIR "configs/" /*variables files */
//config under api // config under api
#define API_CONFIG "configs/api_config" #define API_CONFIG "configs/api_config"
ETEXT_DESC *global_monitor = NULL; // progress monitor ETEXT_DESC *global_monitor = NULL; // progress monitor

View File

@ -398,8 +398,8 @@ Tesseract::Tesseract()
"Don't suspect dict wds longer than this", this->params()), "Don't suspect dict wds longer than this", this->params()),
BOOL_MEMBER(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected", BOOL_MEMBER(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected",
this->params()), this->params()),
double_MEMBER(suspect_rating_per_ch, 999.9, "Don't touch bad rating limit", double_MEMBER(suspect_rating_per_ch, 999.9,
this->params()), "Don't touch bad rating limit", this->params()),
double_MEMBER(suspect_accept_rating, -999.9, "Accept good rating limit", double_MEMBER(suspect_accept_rating, -999.9, "Accept good rating limit",
this->params()), this->params()),
BOOL_MEMBER(tessedit_minimal_rejection, false, BOOL_MEMBER(tessedit_minimal_rejection, false,
@ -512,7 +512,6 @@ Tesseract::Tesseract()
"Page separator (default is form feed control character)", "Page separator (default is form feed control character)",
this->params()), this->params()),
// The following parameters were deprecated and removed from their // The following parameters were deprecated and removed from their
// original // original
// locations. The parameters are temporarily kept here to give Tesseract // locations. The parameters are temporarily kept here to give Tesseract

View File

@ -38,7 +38,6 @@
class BLOB_CHOICE_LIST_CLIST; class BLOB_CHOICE_LIST_CLIST;
class BLOCK_LIST; class BLOCK_LIST;
class CharSamp;
struct OSResults; struct OSResults;
class PAGE_RES; class PAGE_RES;
class PAGE_RES_IT; class PAGE_RES_IT;
@ -98,6 +97,7 @@ namespace tesseract {
class ColumnFinder; class ColumnFinder;
#ifndef NO_CUBE_BUILD #ifndef NO_CUBE_BUILD
class CharSamp;
class CubeLineObject; class CubeLineObject;
class CubeObject; class CubeObject;
class CubeRecoContext; class CubeRecoContext;
@ -1010,8 +1010,7 @@ class Tesseract : public Wordrec {
INT_VAR_H(suspect_level, 99, "Suspect marker level"); INT_VAR_H(suspect_level, 99, "Suspect marker level");
INT_VAR_H(suspect_space_level, 100, INT_VAR_H(suspect_space_level, 100,
"Min suspect level for rejecting spaces"); "Min suspect level for rejecting spaces");
INT_VAR_H(suspect_short_words, 2, INT_VAR_H(suspect_short_words, 2, "Don't Suspect dict wds longer than this");
"Don't Suspect dict wds longer than this");
BOOL_VAR_H(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected"); BOOL_VAR_H(suspect_constrain_1Il, false, "UNLV keep 1Il chars rejected");
double_VAR_H(suspect_rating_per_ch, 999.9, "Don't touch bad rating limit"); double_VAR_H(suspect_rating_per_ch, 999.9, "Don't touch bad rating limit");
double_VAR_H(suspect_accept_rating, -999.9, "Accept good rating limit"); double_VAR_H(suspect_accept_rating, -999.9, "Accept good rating limit");

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: blobbox.cpp (Formerly blobnbox.c) * File: blobbox.cpp (Formerly blobnbox.c)
* Description: Code for the textord blob class. * Description: Code for the textord blob class.
* Author: Ray Smith * Author: Ray Smith
* Created: Thu Jul 30 09:08:51 BST 1992 * Created: Thu Jul 30 09:08:51 BST 1992
* *
* (C) Copyright 1992, Hewlett-Packard Ltd. * (C) Copyright 1992, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -31,7 +31,9 @@
#define PROJECTION_MARGIN 10 //arbitrary #define PROJECTION_MARGIN 10 //arbitrary
#define EXTERN #define EXTERN
ELISTIZE (BLOBNBOX) ELIST2IZE (TO_ROW) ELISTIZE (TO_BLOCK) ELISTIZE(BLOBNBOX)
ELIST2IZE(TO_ROW)
ELISTIZE(TO_BLOCK)
// Up to 30 degrees is allowed for rotations of diacritic blobs. // Up to 30 degrees is allowed for rotations of diacritic blobs.
const double kCosSmallAngle = 0.866; const double kCosSmallAngle = 0.866;
@ -176,7 +178,7 @@ void BLOBNBOX::NeighbourGaps(int gaps[BND_COUNT]) const {
gaps[dir] = MAX_INT16; gaps[dir] = MAX_INT16;
BLOBNBOX* neighbour = neighbours_[dir]; BLOBNBOX* neighbour = neighbours_[dir];
if (neighbour != NULL) { if (neighbour != NULL) {
TBOX n_box = neighbour->bounding_box(); const TBOX& n_box = neighbour->bounding_box();
if (dir == BND_LEFT || dir == BND_RIGHT) { if (dir == BND_LEFT || dir == BND_RIGHT) {
gaps[dir] = box.x_gap(n_box); gaps[dir] = box.x_gap(n_box);
} else { } else {

View File

@ -34,8 +34,7 @@ FILE* OpenBoxFile(const STRING& fname) {
STRING filename = BoxFileName(fname); STRING filename = BoxFileName(fname);
FILE* box_file = NULL; FILE* box_file = NULL;
if (!(box_file = fopen(filename.string(), "rb"))) { if (!(box_file = fopen(filename.string(), "rb"))) {
CANTOPENFILE.error("read_next_box", TESSEXIT, CANTOPENFILE.error("read_next_box", TESSEXIT, "Can't open box file %s",
"Can't open box file %s",
filename.string()); filename.string());
} }
return box_file; return box_file;

View File

@ -82,9 +82,7 @@ class BoxWord {
const TBOX& bounding_box() const { const TBOX& bounding_box() const {
return bbox_; return bbox_;
} }
int length() const { int length() const { return length_; }
return length_;
}
const TBOX& BlobBox(int index) const { const TBOX& BlobBox(int index) const {
return boxes_[index]; return boxes_[index];
} }

View File

@ -48,9 +48,9 @@ ICOORD C_OUTLINE::step_coords[4] = {
* @param length length of loop * @param length length of loop
*/ */
C_OUTLINE::C_OUTLINE (CRACKEDGE * startpt, ICOORD bot_left, C_OUTLINE::C_OUTLINE(CRACKEDGE* startpt, ICOORD bot_left, ICOORD top_right,
ICOORD top_right, inT16 length) inT16 length)
: box (bot_left, top_right), start (startpt->pos), offsets(NULL) { : box(bot_left, top_right), start(startpt->pos), offsets(NULL) {
inT16 stepindex; //index to step inT16 stepindex; //index to step
CRACKEDGE *edgept; //current point CRACKEDGE *edgept; //current point
@ -71,7 +71,6 @@ C_OUTLINE::C_OUTLINE (CRACKEDGE * startpt, ICOORD bot_left,
} }
} }
/** /**
* @name C_OUTLINE::C_OUTLINE * @name C_OUTLINE::C_OUTLINE
* *
@ -139,7 +138,7 @@ inT16 length //length of loop
* @param rotation rotate to coord * @param rotation rotate to coord
*/ */
C_OUTLINE::C_OUTLINE(C_OUTLINE *srcline, FCOORD rotation) : offsets(NULL) { C_OUTLINE::C_OUTLINE(C_OUTLINE* srcline, FCOORD rotation) : offsets(NULL) {
TBOX new_box; //easy bounding TBOX new_box; //easy bounding
inT16 stepindex; //index to step inT16 stepindex; //index to step
inT16 dirdiff; //direction change inT16 dirdiff; //direction change
@ -300,7 +299,6 @@ inT32 C_OUTLINE::perimeter() const {
return total_steps; return total_steps;
} }
/** /**
* @name C_OUTLINE::outer_area * @name C_OUTLINE::outer_area
* *
@ -332,7 +330,6 @@ inT32 C_OUTLINE::outer_area() const {
return total; return total;
} }
/** /**
* @name C_OUTLINE::count_transitions * @name C_OUTLINE::count_transitions
* *
@ -459,7 +456,6 @@ inT32 C_OUTLINE::count_transitions(inT32 threshold) {
return total; return total;
} }
/** /**
* @name C_OUTLINE::operator< * @name C_OUTLINE::operator<
* *
@ -468,8 +464,7 @@ inT32 C_OUTLINE::count_transitions(inT32 threshold) {
*/ */
BOOL8 BOOL8
C_OUTLINE::operator< (const C_OUTLINE & other) const C_OUTLINE::operator<(const C_OUTLINE& other) const {
{
inT16 count = 0; //winding count inT16 count = 0; //winding count
ICOORD pos; //position of point ICOORD pos; //position of point
inT32 stepindex; //index to cstep inT32 stepindex; //index to cstep
@ -495,7 +490,6 @@ C_OUTLINE::operator< (const C_OUTLINE & other) const
return count != 0; return count != 0;
} }
/** /**
* @name C_OUTLINE::winding_number * @name C_OUTLINE::winding_number
* *
@ -534,7 +528,6 @@ inT16 C_OUTLINE::winding_number(ICOORD point) const {
return count; //winding number return count; //winding number
} }
/** /**
* C_OUTLINE::turn_direction * C_OUTLINE::turn_direction
* *
@ -563,7 +556,6 @@ inT16 C_OUTLINE::turn_direction() const { //winding number
return count; //winding number return count; //winding number
} }
/** /**
* @name C_OUTLINE::reverse * @name C_OUTLINE::reverse
* *
@ -586,7 +578,6 @@ void C_OUTLINE::reverse() { //reverse drection
} }
} }
/** /**
* @name C_OUTLINE::move * @name C_OUTLINE::move
* *
@ -661,14 +652,27 @@ static void ComputeGradient(const l_uint32* data, int wpl,
int x, int y, int width, int height, int x, int y, int width, int height,
ICOORD* gradient) { ICOORD* gradient) {
const l_uint32* line = data + y * wpl; const l_uint32* line = data + y * wpl;
int pix_x_y = x < width && y < height ? int pix_x_y =
GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line)), x) : 255; x < width && y < height
int pix_x_prevy = x < width && y > 0 ? ? GET_DATA_BYTE(
GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line - wpl)), x) : 255; const_cast<void*>(reinterpret_cast<const void*>(line)), x)
int pix_prevx_prevy = x > 0 && y > 0 ? : 255;
GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<void const*>(line - wpl)), x - 1) : 255; int pix_x_prevy =
int pix_prevx_y = x > 0 && y < height ? x < width && y > 0
GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line)), x - 1) : 255; ? GET_DATA_BYTE(
const_cast<void*>(reinterpret_cast<const void*>(line - wpl)), x)
: 255;
int pix_prevx_prevy =
x > 0 && y > 0
? GET_DATA_BYTE(
const_cast<void*>(reinterpret_cast<void const*>(line - wpl)),
x - 1)
: 255;
int pix_prevx_y =
x > 0 && y < height
? GET_DATA_BYTE(
const_cast<void*>(reinterpret_cast<const void*>(line)), x - 1)
: 255;
gradient->set_x(pix_x_y + pix_x_prevy - (pix_prevx_y + pix_prevx_prevy)); gradient->set_x(pix_x_y + pix_x_prevy - (pix_prevx_y + pix_prevx_prevy));
gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y)); gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y));
} }
@ -684,8 +688,10 @@ static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
if (y <= 0 || y >= height) if (y <= 0 || y >= height)
return false; return false;
const l_uint32* line = data + y * wpl; const l_uint32* line = data + y * wpl;
int pixel1 = GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line - wpl)), x); int pixel1 = GET_DATA_BYTE(
int pixel2 = GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line)), x); const_cast<void*>(reinterpret_cast<const void*>(line - wpl)), x);
int pixel2 =
GET_DATA_BYTE(const_cast<void*>(reinterpret_cast<const void*>(line)), x);
int diff = (pixel2 - pixel1) * diff_sign; int diff = (pixel2 - pixel1) * diff_sign;
if (diff > *best_diff) { if (diff > *best_diff) {
*best_diff = diff; *best_diff = diff;
@ -705,8 +711,10 @@ static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
int* best_diff, int* best_sum, int* best_x) { int* best_diff, int* best_sum, int* best_x) {
if (x <= 0 || x >= width) if (x <= 0 || x >= width)
return false; return false;
int pixel1 = GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line)), x - 1); int pixel1 = GET_DATA_BYTE(
int pixel2 = GET_DATA_BYTE(const_cast<void*> (reinterpret_cast<const void *>(line)), x); const_cast<void*>(reinterpret_cast<const void*>(line)), x - 1);
int pixel2 =
GET_DATA_BYTE(const_cast<void*>(reinterpret_cast<const void*>(line)), x);
int diff = (pixel2 - pixel1) * diff_sign; int diff = (pixel2 - pixel1) * diff_sign;
if (diff > *best_diff) { if (diff > *best_diff) {
*best_diff = diff; *best_diff = diff;
@ -954,8 +962,7 @@ void C_OUTLINE::render_outline(int left, int top, Pix* pix) const {
*/ */
#ifndef GRAPHICS_DISABLED #ifndef GRAPHICS_DISABLED
void C_OUTLINE::plot(ScrollView* window, void C_OUTLINE::plot(ScrollView* window, ScrollView::Color colour) const {
ScrollView::Color colour) const {
inT16 stepindex; // index to cstep inT16 stepindex; // index to cstep
ICOORD pos; // current position ICOORD pos; // current position
DIR128 stepdir; // direction of step DIR128 stepdir; // direction of step
@ -1016,7 +1023,6 @@ void C_OUTLINE::plot_normed(const DENORM& denorm, ScrollView::Color colour,
} }
#endif #endif
/** /**
* @name C_OUTLINE::operator= * @name C_OUTLINE::operator=
* *
@ -1024,7 +1030,7 @@ void C_OUTLINE::plot_normed(const DENORM& denorm, ScrollView::Color colour,
* @param source assign from this * @param source assign from this
*/ */
C_OUTLINE & C_OUTLINE::operator= (const C_OUTLINE & source) { C_OUTLINE& C_OUTLINE::operator=(const C_OUTLINE& source) {
box = source.box; box = source.box;
start = source.start; start = source.start;
if (steps != NULL) if (steps != NULL)

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: mod128.c (Formerly dir128.c) * File: mod128.c (Formerly dir128.c)
* Description: Code to convert a DIR128 to an ICOORD. * Description: Code to convert a DIR128 to an ICOORD.
* Author: Ray Smith * Author: Ray Smith
* Created: Tue Oct 22 11:56:09 BST 1991 * Created: Tue Oct 22 11:56:09 BST 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -86,16 +86,3 @@ DIR128::DIR128( //from fcoord
while (high - low > 1); while (high - low > 1);
dir = low; dir = low;
} }
/**********************************************************************
* dir_to_gradient
*
* Convert a direction to a vector.
**********************************************************************/
#if 0 // code is buggy for negative dir and unused
ICOORD DIR128::vector() const { //convert to vector
return dirtab[dir]; //easy really
}
#endif

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: mod128.h (Formerly dir128.h) * File: mod128.h (Formerly dir128.h)
* Description: Header for class which implements modulo arithmetic. * Description: Header for class which implements modulo arithmetic.
* Author: Ray Smith * Author: Ray Smith
* Created: Tue Mar 26 17:48:13 GMT 1991 * Created: Tue Mar 26 17:48:13 GMT 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -77,7 +77,6 @@ class DLLSYM DIR128
inT8 get_dir() const { //access function inT8 get_dir() const { //access function
return dir; return dir;
} }
ICOORD vector() const; //turn to vector
private: private:
inT8 dir; //a direction inT8 dir; //a direction

View File

@ -51,23 +51,16 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
// only use opencl if compiled w/ OpenCL and selected device is opencl // only use opencl if compiled w/ OpenCL and selected device is opencl
#ifdef USE_OPENCL #ifdef USE_OPENCL
// all of channel 0 then all of channel 1... // all of channel 0 then all of channel 1...
int *histogramAllChannels = new int[kHistogramSize * num_channels]; int* histogramAllChannels = new int[kHistogramSize * num_channels];
// Calculate Histogram on GPU // Calculate Histogram on GPU
OpenclDevice od; OpenclDevice od;
if (od.selectedDeviceIsOpenCL() && if (od.selectedDeviceIsOpenCL() && (num_channels == 1 || num_channels == 4) &&
(num_channels == 1 || num_channels == 4) && top == 0 && left == 0 ) { top == 0 && left == 0) {
od.HistogramRectOCL( od.HistogramRectOCL((const unsigned char*)pixGetData(src_pix), num_channels,
(const unsigned char*)pixGetData(src_pix), pixGetWpl(src_pix) * 4, left, top, width, height,
num_channels, kHistogramSize, histogramAllChannels);
pixGetWpl(src_pix) * 4,
left,
top,
width,
height,
kHistogramSize,
histogramAllChannels);
// Calculate Threshold from Histogram on cpu // Calculate Threshold from Histogram on cpu
for (int ch = 0; ch < num_channels; ++ch) { for (int ch = 0; ch < num_channels; ++ch) {
@ -143,7 +136,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
delete[] histogramAllChannels; delete[] histogramAllChannels;
#endif // USE_OPENCL #endif // USE_OPENCL
if (!any_good_hivalue) { if (!any_good_hivalue) {
// Use the best of the ones that were not good enough. // Use the best of the ones that were not good enough.
(*hi_values)[best_hi_index] = best_hi_value; (*hi_values)[best_hi_index] = best_hi_value;

View File

@ -1,7 +1,7 @@
/********************************************************************** /**********************************************************************
* File: pageres.h (Formerly page_res.h) * File: pageres.h (Formerly page_res.h)
* Description: Results classes used by control.c * Description: Results classes used by control.c
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Tue Sep 22 08:42:49 BST 1992 * Created: Tue Sep 22 08:42:49 BST 1992
* *
* (C) Copyright 1992, Hewlett-Packard Ltd. * (C) Copyright 1992, Hewlett-Packard Ltd.
@ -327,7 +327,7 @@ class WERD_RES : public ELIST_LINK {
} }
// Deep copies everything except the ratings MATRIX. // Deep copies everything except the ratings MATRIX.
// To get that use deep_copy below. // To get that use deep_copy below.
WERD_RES(const WERD_RES &source) : ELIST_LINK(source) { WERD_RES(const WERD_RES& source) : ELIST_LINK(source) {
InitPointers(); InitPointers();
*this = source; // see operator= *this = source; // see operator=
} }
@ -630,7 +630,7 @@ class WERD_RES : public ELIST_LINK {
static WERD_RES* deep_copy(const WERD_RES* src) { static WERD_RES* deep_copy(const WERD_RES* src) {
WERD_RES* result = new WERD_RES(*src); WERD_RES* result = new WERD_RES(*src);
// That didn't copy the ratings, but we want a copy if there is one to // That didn't copy the ratings, but we want a copy if there is one to
// begin width. // begin with.
if (src->ratings != NULL) if (src->ratings != NULL)
result->ratings = src->ratings->DeepCopy(); result->ratings = src->ratings->DeepCopy();
return result; return result;

View File

@ -29,90 +29,76 @@ struct Pix;
CLISTIZEH (PDBLK) CLISTIZEH (PDBLK)
///page block ///page block
class PDBLK class PDBLK {
{
friend class BLOCK_RECT_IT; //< block iterator friend class BLOCK_RECT_IT; //< block iterator
public: public:
///empty constructor /// empty constructor
PDBLK() { PDBLK() {
hand_poly = NULL; hand_poly = NULL;
index_ = 0; index_ = 0;
} }
///simple constructor /// simple constructor
PDBLK(inT16 xmin, //< bottom left PDBLK(inT16 xmin, //< bottom left
inT16 ymin, inT16 ymin,
inT16 xmax, //< top right inT16 xmax, //< top right
inT16 ymax); inT16 ymax);
///set vertex lists /// set vertex lists
///@param left list of left vertices ///@param left list of left vertices
///@param right list of right vertices ///@param right list of right vertices
void set_sides(ICOORDELT_LIST *left, void set_sides(ICOORDELT_LIST *left, ICOORDELT_LIST *right);
ICOORDELT_LIST *right);
///destructor /// destructor
~PDBLK () { ~PDBLK() {
if (hand_poly) delete hand_poly; if (hand_poly) delete hand_poly;
} }
POLY_BLOCK *poly_block() const { POLY_BLOCK *poly_block() const { return hand_poly; }
return hand_poly; /// set the poly block
} void set_poly_block(POLY_BLOCK *blk) { hand_poly = blk; }
///set the poly block /// get box
void set_poly_block(POLY_BLOCK *blk) { void bounding_box(ICOORD &bottom_left, // bottom left
hand_poly = blk; ICOORD &top_right) const { // topright
} bottom_left = box.botleft();
///get box top_right = box.topright();
void bounding_box(ICOORD &bottom_left, //bottom left }
ICOORD &top_right) const { //topright /// get real box
bottom_left = box.botleft (); const TBOX &bounding_box() const { return box; }
top_right = box.topright ();
}
///get real box
const TBOX &bounding_box() const {
return box;
}
int index() const { int index() const { return index_; }
return index_; void set_index(int value) { index_ = value; }
}
void set_index(int value) {
index_ = value;
}
///is pt inside block /// is pt inside block
BOOL8 contains(ICOORD pt); BOOL8 contains(ICOORD pt);
/// reposition block /// reposition block
void move(const ICOORD vec); // by vector void move(const ICOORD vec); // by vector
// Returns a binary Pix mask with a 1 pixel for every pixel within the // Returns a binary Pix mask with a 1 pixel for every pixel within the
// block. Rotates the coordinate system by rerotation prior to rendering. // block. Rotates the coordinate system by rerotation prior to rendering.
// If not NULL, mask_box is filled with the position box of the returned // If not NULL, mask_box is filled with the position box of the returned
// mask image. // mask image.
Pix *render_mask(const FCOORD &rerotation, TBOX *mask_box); Pix *render_mask(const FCOORD &rerotation, TBOX *mask_box);
#ifndef GRAPHICS_DISABLED #ifndef GRAPHICS_DISABLED
///draw histogram /// draw histogram
///@param window window to draw in ///@param window window to draw in
///@param serial serial number ///@param serial serial number
///@param colour colour to draw in ///@param colour colour to draw in
void plot(ScrollView* window, void plot(ScrollView *window, inT32 serial, ScrollView::Color colour);
inT32 serial, #endif // GRAPHICS_DISABLED
ScrollView::Color colour);
#endif // GRAPHICS_DISABLED
///assignment /// assignment
///@param source from this ///@param source from this
PDBLK & operator= (const PDBLK & source); PDBLK &operator=(const PDBLK &source);
protected: protected:
POLY_BLOCK *hand_poly; //< weird as well POLY_BLOCK *hand_poly; //< weird as well
ICOORDELT_LIST leftside; //< left side vertices ICOORDELT_LIST leftside; //< left side vertices
ICOORDELT_LIST rightside; //< right side vertices ICOORDELT_LIST rightside; //< right side vertices
TBOX box; //< bounding box TBOX box; //< bounding box
int index_; //< Serial number of this block. int index_; //< Serial number of this block.
}; };
class DLLSYM BLOCK_RECT_IT //rectangle iterator class DLLSYM BLOCK_RECT_IT //rectangle iterator

View File

@ -214,7 +214,7 @@ EDGEPT edgepts[] //output is array
void fix2( //polygonal approx void fix2( //polygonal approx
EDGEPT *start, /*loop to approimate */ EDGEPT *start, /*loop to approimate */
int area) { int area) {
EDGEPT *edgept; /*current point */ EDGEPT *edgept; /*current point */
EDGEPT *edgept1; EDGEPT *edgept1;
EDGEPT *loopstart; /*modified start of loop */ EDGEPT *loopstart; /*modified start of loop */
EDGEPT *linestart; /*start of line segment */ EDGEPT *linestart; /*start of line segment */

View File

@ -1,7 +1,7 @@
/********************************************************************** /**********************************************************************
* File: polyblk.c (Formerly poly_block.c) * File: polyblk.c (Formerly poly_block.c)
* Description: Polygonal blocks * Description: Polygonal blocks
* Author: Sheelagh Lloyd? * Author: Sheelagh Lloyd?
* Created: * Created:
* *
* (C) Copyright 1993, Hewlett-Packard Ltd. * (C) Copyright 1993, Hewlett-Packard Ltd.

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: quspline.cpp (Formerly qspline.c) * File: quspline.cpp (Formerly qspline.c)
* Description: Code for the QSPLINE class. * Description: Code for the QSPLINE class.
* Author: Ray Smith * Author: Ray Smith
* Created: Tue Oct 08 17:16:12 BST 1991 * Created: Tue Oct 08 17:16:12 BST 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -288,7 +288,8 @@ class WERD_CHOICE : public ELIST_LINK {
src_certainty, src_permuter); src_certainty, src_permuter);
} }
WERD_CHOICE(const char *src_string, const UNICHARSET &unicharset); WERD_CHOICE(const char *src_string, const UNICHARSET &unicharset);
WERD_CHOICE(const WERD_CHOICE &word) : ELIST_LINK(word), unicharset_(word.unicharset_) { WERD_CHOICE(const WERD_CHOICE &word)
: ELIST_LINK(word), unicharset_(word.unicharset_) {
this->init(word.length()); this->init(word.length());
this->operator=(word); this->operator=(word);
} }

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: rect.c (Formerly box.c) * File: rect.c (Formerly box.c)
* Description: Bounding box class definition. * Description: Bounding box class definition.
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Wed Oct 16 15:18:45 BST 1991 * Created: Wed Oct 16 15:18:45 BST 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -29,10 +29,10 @@
* *
**********************************************************************/ **********************************************************************/
TBOX::TBOX( //constructor TBOX::TBOX( // constructor
const ICOORD pt1, //one corner const ICOORD pt1, // one corner
const ICOORD pt2 //the other corner const ICOORD pt2 // the other corner
) { ) {
if (pt1.x () <= pt2.x ()) { if (pt1.x () <= pt2.x ()) {
if (pt1.y () <= pt2.y ()) { if (pt1.y () <= pt2.y ()) {
bot_left = pt1; bot_left = pt1;

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: rect.h (Formerly box.h) * File: rect.h (Formerly box.h)
* Description: Bounding box class definition. * Description: Bounding box class definition.
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Wed Oct 16 15:18:45 BST 1991 * Created: Wed Oct 16 15:18:45 BST 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -307,9 +307,9 @@ class DLLSYM TBOX { // bounding box
* *
**********************************************************************/ **********************************************************************/
inline TBOX::TBOX( // constructor inline TBOX::TBOX( // constructor
const FCOORD pt // floating centre const FCOORD pt // floating centre
) { ) {
bot_left = ICOORD ((inT16) floor (pt.x ()), (inT16) floor (pt.y ())); bot_left = ICOORD ((inT16) floor (pt.x ()), (inT16) floor (pt.y ()));
top_right = ICOORD ((inT16) ceil (pt.x ()), (inT16) ceil (pt.y ())); top_right = ICOORD ((inT16) ceil (pt.x ()), (inT16) ceil (pt.y ()));
} }

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: rejctmap.h (Formerly rejmap.h) * File: rejctmap.h (Formerly rejmap.h)
* Description: REJ and REJMAP class functions. * Description: REJ and REJMAP class functions.
* Author: Phil Cheatle * Author: Phil Cheatle
* Created: Thu Jun 9 13:46:38 BST 1994 * Created: Thu Jun 9 13:46:38 BST 1994
* *
* (C) Copyright 1994, Hewlett-Packard Ltd. * (C) Copyright 1994, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -48,46 +48,45 @@ OF THIS IMPLIED TEMPORAL ORDERING OF THE FLAGS!!!!
#include "bits16.h" #include "bits16.h"
#include "params.h" #include "params.h"
enum REJ_FLAGS enum REJ_FLAGS {
{
/* Reject modes which are NEVER overridden */ /* Reject modes which are NEVER overridden */
R_TESS_FAILURE, // PERM Tess didn't classify R_TESS_FAILURE, // PERM Tess didn't classify
R_SMALL_XHT, // PERM Xht too small R_SMALL_XHT, // PERM Xht too small
R_EDGE_CHAR, // PERM Too close to edge of image R_EDGE_CHAR, // PERM Too close to edge of image
R_1IL_CONFLICT, // PERM 1Il confusion R_1IL_CONFLICT, // PERM 1Il confusion
R_POSTNN_1IL, // PERM 1Il unrejected by NN R_POSTNN_1IL, // PERM 1Il unrejected by NN
R_REJ_CBLOB, // PERM Odd blob R_REJ_CBLOB, // PERM Odd blob
R_MM_REJECT, // PERM Matrix match rejection (m's) R_MM_REJECT, // PERM Matrix match rejection (m's)
R_BAD_REPETITION, // TEMP Repeated char which doesn't match trend R_BAD_REPETITION, // TEMP Repeated char which doesn't match trend
/* Initial reject modes (pre NN_ACCEPT) */ /* Initial reject modes (pre NN_ACCEPT) */
R_POOR_MATCH, // TEMP Ray's original heuristic (Not used) R_POOR_MATCH, // TEMP Ray's original heuristic (Not used)
R_NOT_TESS_ACCEPTED, // TEMP Tess didn't accept WERD R_NOT_TESS_ACCEPTED, // TEMP Tess didn't accept WERD
R_CONTAINS_BLANKS, // TEMP Tess failed on other chs in WERD R_CONTAINS_BLANKS, // TEMP Tess failed on other chs in WERD
R_BAD_PERMUTER, // POTENTIAL Bad permuter for WERD R_BAD_PERMUTER, // POTENTIAL Bad permuter for WERD
/* Reject modes generated after NN_ACCEPT but before MM_ACCEPT */ /* Reject modes generated after NN_ACCEPT but before MM_ACCEPT */
R_HYPHEN, // TEMP Post NN dodgy hyphen or full stop R_HYPHEN, // TEMP Post NN dodgy hyphen or full stop
R_DUBIOUS, // TEMP Post NN dodgy chars R_DUBIOUS, // TEMP Post NN dodgy chars
R_NO_ALPHANUMS, // TEMP No alphanumerics in word after NN R_NO_ALPHANUMS, // TEMP No alphanumerics in word after NN
R_MOSTLY_REJ, // TEMP Most of word rejected so rej the rest R_MOSTLY_REJ, // TEMP Most of word rejected so rej the rest
R_XHT_FIXUP, // TEMP Xht tests unsure R_XHT_FIXUP, // TEMP Xht tests unsure
/* Reject modes generated after MM_ACCEPT but before QUALITY_ACCEPT */ /* Reject modes generated after MM_ACCEPT but before QUALITY_ACCEPT */
R_BAD_QUALITY, // TEMP Quality metrics bad for WERD R_BAD_QUALITY, // TEMP Quality metrics bad for WERD
/* Reject modes generated after QUALITY_ACCEPT but before MINIMAL_REJ accep*/ /* Reject modes generated after QUALITY_ACCEPT but before MINIMAL_REJ accep*/
R_DOC_REJ, // TEMP Document rejection R_DOC_REJ, // TEMP Document rejection
R_BLOCK_REJ, // TEMP Block rejection R_BLOCK_REJ, // TEMP Block rejection
R_ROW_REJ, // TEMP Row rejection R_ROW_REJ, // TEMP Row rejection
R_UNLV_REJ, // TEMP ~ turned to - or ^ turned to space R_UNLV_REJ, // TEMP ~ turned to - or ^ turned to space
/* Accept modes which occur between the above rejection groups */ /* Accept modes which occur between the above rejection groups */
R_NN_ACCEPT, //NN acceptance R_NN_ACCEPT, // NN acceptance
R_HYPHEN_ACCEPT, //Hyphen acceptance R_HYPHEN_ACCEPT, // Hyphen acceptance
R_MM_ACCEPT, //Matrix match acceptance R_MM_ACCEPT, // Matrix match acceptance
R_QUALITY_ACCEPT, //Accept word in good quality doc R_QUALITY_ACCEPT, // Accept word in good quality doc
R_MINIMAL_REJ_ACCEPT //Accept EVERYTHING except tess failures R_MINIMAL_REJ_ACCEPT // Accept EVERYTHING except tess failures
}; };
/* REJECT MAP VALUES */ /* REJECT MAP VALUES */

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: statistc.c (Formerly stats.c) * File: statistc.c (Formerly stats.c)
* Description: Simple statistical package for integer values. * Description: Simple statistical package for integer values.
* Author: Ray Smith * Author: Ray Smith
* Created: Mon Feb 04 16:56:05 GMT 1991 * Created: Mon Feb 04 16:56:05 GMT 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -215,7 +215,6 @@ inT32 STATS::min_bucket() const { // Find min
return rangemin_ + min; return rangemin_ + min;
} }
/********************************************************************** /**********************************************************************
* STATS::max_bucket * STATS::max_bucket
* *

View File

@ -26,7 +26,7 @@
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* CLIST::internal_deep_clear * CLIST::internal_deep_clear
* *
* Used by the "deep_clear" member function of derived list * Used by the "deep_clear" member function of derived list
* classes to destroy all the elements on the list. * classes to destroy all the elements on the list.
@ -56,9 +56,8 @@ void (*zapper) (void *)) { //ptr to zapper functn
} }
} }
/*********************************************************************** /***********************************************************************
* CLIST::shallow_clear * CLIST::shallow_clear
* *
* Used by the destructor and the "shallow_clear" member function of derived * Used by the destructor and the "shallow_clear" member function of derived
* list classes to destroy the list. * list classes to destroy the list.
@ -83,7 +82,7 @@ void CLIST::shallow_clear() { //destroy all links
} }
/*********************************************************************** /***********************************************************************
* CLIST::assign_to_sublist * CLIST::assign_to_sublist
* *
* The list is set to a sublist of another list. "This" list must be empty * The list is set to a sublist of another list. "This" list must be empty
* before this function is invoked. The two iterators passed must refer to * before this function is invoked. The two iterators passed must refer to
@ -107,9 +106,8 @@ void CLIST::assign_to_sublist( //to this list
last = start_it->extract_sublist (end_it); last = start_it->extract_sublist (end_it);
} }
/*********************************************************************** /***********************************************************************
* CLIST::length * CLIST::length
* *
* Return count of elements on list * Return count of elements on list
**********************************************************************/ **********************************************************************/
@ -123,9 +121,8 @@ inT32 CLIST::length() const { //count elements
return count; return count;
} }
/*********************************************************************** /***********************************************************************
* CLIST::sort * CLIST::sort
* *
* Sort elements on list * Sort elements on list
**********************************************************************/ **********************************************************************/
@ -239,7 +236,7 @@ void CLIST::set_subtract(int comparator(const void*, const void*),
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::forward * CLIST_ITERATOR::forward
* *
* Move the iterator to the next element of the list. * Move the iterator to the next element of the list.
* REMEMBER: ALL LISTS ARE CIRCULAR. * REMEMBER: ALL LISTS ARE CIRCULAR.
@ -276,9 +273,8 @@ void *CLIST_ITERATOR::forward() {
return current->data; return current->data;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::data_relative * CLIST_ITERATOR::data_relative
* *
* Return the data pointer to the element "offset" elements from current. * Return the data pointer to the element "offset" elements from current.
* "offset" must not be less than -1. * "offset" must not be less than -1.
@ -312,9 +308,8 @@ void *CLIST_ITERATOR::data_relative( //get data + or - ...
return ptr->data; return ptr->data;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::move_to_last() * CLIST_ITERATOR::move_to_last()
* *
* Move current so that it is set to the end of the list. * Move current so that it is set to the end of the list.
* Return data just in case anyone wants it. * Return data just in case anyone wants it.
@ -336,9 +331,8 @@ void *CLIST_ITERATOR::move_to_last() {
return current->data; return current->data;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::exchange() * CLIST_ITERATOR::exchange()
* *
* Given another iterator, whose current element is a different element on * Given another iterator, whose current element is a different element on
* the same list list OR an element of another list, exchange the two current * the same list list OR an element of another list, exchange the two current
@ -434,9 +428,8 @@ void CLIST_ITERATOR::exchange( //positions of 2 link
other_it->current = old_current; other_it->current = old_current;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::extract_sublist() * CLIST_ITERATOR::extract_sublist()
* *
* This is a private member, used only by CLIST::assign_to_sublist. * This is a private member, used only by CLIST::assign_to_sublist.
* Given another iterator for the same list, extract the links from THIS to * Given another iterator for the same list, extract the links from THIS to
@ -478,7 +471,7 @@ CLIST_LINK *CLIST_ITERATOR::extract_sublist( //from
temp_it.mark_cycle_pt (); temp_it.mark_cycle_pt ();
do { //walk sublist do { //walk sublist
if (temp_it.cycled_list ()) //can't find end pt if (temp_it.cycled_list()) // can't find end pt
BAD_SUBLIST.error ("CLIST_ITERATOR.extract_sublist", ABORT, NULL); BAD_SUBLIST.error ("CLIST_ITERATOR.extract_sublist", ABORT, NULL);
if (temp_it.at_last ()) { if (temp_it.at_last ()) {

View File

@ -28,9 +28,9 @@
class CLIST_ITERATOR; class CLIST_ITERATOR;
/********************************************************************** /**********************************************************************
* CLASS - CLIST_LINK * CLASS - CLIST_LINK
* *
* Generic link class for singly linked CONS cell lists * Generic link class for singly linked CONS cell lists
* *
* Note: No destructor - elements are assumed to be destroyed EITHER after * Note: No destructor - elements are assumed to be destroyed EITHER after
* they have been extracted from a list OR by the CLIST destructor which * they have been extracted from a list OR by the CLIST destructor which
@ -50,13 +50,13 @@ class DLLSYM CLIST_LINK
data = next = NULL; data = next = NULL;
} }
CLIST_LINK( //copy constructor CLIST_LINK( // copy constructor
const CLIST_LINK &) { //don't copy link const CLIST_LINK &) { // don't copy link
data = next = NULL; data = next = NULL;
} }
void operator= ( //don't copy links void operator=( // don't copy links
const CLIST_LINK &) { const CLIST_LINK &) {
data = next = NULL; data = next = NULL;
} }
}; };
@ -89,8 +89,8 @@ class DLLSYM CLIST
void internal_deep_clear ( //destroy all links void internal_deep_clear ( //destroy all links
void (*zapper) (void *)); //ptr to zapper functn void (*zapper) (void *)); //ptr to zapper functn
void shallow_clear(); //clear list but don't void shallow_clear(); // clear list but don't
//delete data elements // delete data elements
bool empty() const { //is list empty? bool empty() const { //is list empty?
return !last; return !last;
@ -136,9 +136,10 @@ class DLLSYM CLIST
}; };
/*********************************************************************** /***********************************************************************
* CLASS - CLIST_ITERATOR * CLASS - CLIST_ITERATOR
* *
* Generic iterator class for singly linked lists with embedded links * Generic iterator class for singly linked lists with embedded
*links
**********************************************************************/ **********************************************************************/
class DLLSYM CLIST_ITERATOR class DLLSYM CLIST_ITERATOR
@ -231,8 +232,8 @@ class DLLSYM CLIST_ITERATOR
BOOL8 cycled_list(); //Completed a cycle? BOOL8 cycled_list(); //Completed a cycle?
void add_to_end( //add at end & void add_to_end( // add at end &
void *new_data); //don't move void *new_data); // don't move
void exchange( //positions of 2 links void exchange( //positions of 2 links
CLIST_ITERATOR *other_it); //other iterator CLIST_ITERATOR *other_it); //other iterator
@ -246,7 +247,7 @@ class DLLSYM CLIST_ITERATOR
}; };
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::set_to_list * CLIST_ITERATOR::set_to_list
* *
* (Re-)initialise the iterator to point to the start of the list_to_iterate * (Re-)initialise the iterator to point to the start of the list_to_iterate
* over. * over.
@ -270,9 +271,8 @@ inline void CLIST_ITERATOR::set_to_list( //change list
ex_current_was_cycle_pt = FALSE; ex_current_was_cycle_pt = FALSE;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::CLIST_ITERATOR * CLIST_ITERATOR::CLIST_ITERATOR
* *
* CONSTRUCTOR - set iterator to specified list; * CONSTRUCTOR - set iterator to specified list;
**********************************************************************/ **********************************************************************/
@ -281,9 +281,8 @@ inline CLIST_ITERATOR::CLIST_ITERATOR(CLIST *list_to_iterate) {
set_to_list(list_to_iterate); set_to_list(list_to_iterate);
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_after_then_move * CLIST_ITERATOR::add_after_then_move
* *
* Add a new element to the list after the current element and move the * Add a new element to the list after the current element and move the
* iterator to the new element. * iterator to the new element.
@ -329,9 +328,8 @@ inline void CLIST_ITERATOR::add_after_then_move( // element to add
current = new_element; current = new_element;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_after_stay_put * CLIST_ITERATOR::add_after_stay_put
* *
* Add a new element to the list after the current element but do not move * Add a new element to the list after the current element but do not move
* the iterator to the new element. * the iterator to the new element.
@ -380,9 +378,8 @@ inline void CLIST_ITERATOR::add_after_stay_put( // element to add
} }
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_before_then_move * CLIST_ITERATOR::add_before_then_move
* *
* Add a new element to the list before the current element and move the * Add a new element to the list before the current element and move the
* iterator to the new element. * iterator to the new element.
@ -425,9 +422,8 @@ inline void CLIST_ITERATOR::add_before_then_move( // element to add
current = new_element; current = new_element;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_before_stay_put * CLIST_ITERATOR::add_before_stay_put
* *
* Add a new element to the list before the current element but don't move the * Add a new element to the list before the current element but don't move the
* iterator to the new element. * iterator to the new element.
@ -471,11 +467,11 @@ inline void CLIST_ITERATOR::add_before_stay_put( // element to add
} }
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_list_after * CLIST_ITERATOR::add_list_after
* *
* Insert another list to this list after the current element but don't move the * Insert another list to this list after the current element but don't move
*the
* iterator. * iterator.
**********************************************************************/ **********************************************************************/
@ -518,9 +514,8 @@ inline void CLIST_ITERATOR::add_list_after(CLIST *list_to_add) {
} }
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_list_before * CLIST_ITERATOR::add_list_before
* *
* Insert another list to this list before the current element. Move the * Insert another list to this list before the current element. Move the
* iterator to the start of the inserted elements * iterator to the start of the inserted elements
@ -563,9 +558,8 @@ inline void CLIST_ITERATOR::add_list_before(CLIST *list_to_add) {
} }
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::extract * CLIST_ITERATOR::extract
* *
* Do extraction by removing current from the list, deleting the cons cell * Do extraction by removing current from the list, deleting the cons cell
* and returning the data to the caller, but NOT updating the iterator. (So * and returning the data to the caller, but NOT updating the iterator. (So
@ -606,9 +600,8 @@ inline void *CLIST_ITERATOR::extract() {
return extracted_data; return extracted_data;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::move_to_first() * CLIST_ITERATOR::move_to_first()
* *
* Move current so that it is set to the start of the list. * Move current so that it is set to the start of the list.
* Return data just in case anyone wants it. * Return data just in case anyone wants it.
@ -626,9 +619,8 @@ inline void *CLIST_ITERATOR::move_to_first() {
return current != NULL ? current->data : NULL; return current != NULL ? current->data : NULL;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::mark_cycle_pt() * CLIST_ITERATOR::mark_cycle_pt()
* *
* Remember the current location so that we can tell whether we've returned * Remember the current location so that we can tell whether we've returned
* to this point later. * to this point later.
@ -651,9 +643,8 @@ inline void CLIST_ITERATOR::mark_cycle_pt() {
started_cycling = FALSE; started_cycling = FALSE;
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::at_first() * CLIST_ITERATOR::at_first()
* *
* Are we at the start of the list? * Are we at the start of the list?
* *
@ -671,9 +662,8 @@ inline BOOL8 CLIST_ITERATOR::at_first() {
!ex_current_was_last)); //first and last !ex_current_was_last)); //first and last
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::at_last() * CLIST_ITERATOR::at_last()
* *
* Are we at the end of the list? * Are we at the end of the list?
* *
@ -691,9 +681,8 @@ inline BOOL8 CLIST_ITERATOR::at_last() {
ex_current_was_last)); //first and last ex_current_was_last)); //first and last
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::cycled_list() * CLIST_ITERATOR::cycled_list()
* *
* Have we returned to the cycle_pt since it was set? * Have we returned to the cycle_pt since it was set?
* *
@ -709,9 +698,8 @@ inline BOOL8 CLIST_ITERATOR::cycled_list() {
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::length() * CLIST_ITERATOR::length()
* *
* Return the length of the list * Return the length of the list
* *
@ -726,9 +714,8 @@ inline inT32 CLIST_ITERATOR::length() {
return list->length (); return list->length ();
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::sort() * CLIST_ITERATOR::sort()
* *
* Sort the elements of the list, then reposition at the start. * Sort the elements of the list, then reposition at the start.
* *
@ -747,9 +734,8 @@ const void *, const void *)) {
move_to_first(); move_to_first();
} }
/*********************************************************************** /***********************************************************************
* CLIST_ITERATOR::add_to_end * CLIST_ITERATOR::add_to_end
* *
* Add a new element to the end of the list without moving the iterator. * Add a new element to the end of the list without moving the iterator.
* This is provided because a single linked list cannot move to the last as * This is provided because a single linked list cannot move to the last as
@ -811,7 +797,7 @@ The macro generates:
- An element deletion function: CLASSNAME##_c1_zapper - An element deletion function: CLASSNAME##_c1_zapper
- An element copier function: - An element copier function:
CLASSNAME##_c1_copier CLASSNAME##_c1_copier
- A CLIST subclass: CLASSNAME##_CLIST - A CLIST subclass: CLASSNAME##_CLIST
- A CLIST_ITERATOR subclass: - A CLIST_ITERATOR subclass:
CLASSNAME##_C_IT CLASSNAME##_C_IT
@ -830,114 +816,116 @@ CLISTIZEH is a concatenation of 3 fragments CLISTIZEH_A, CLISTIZEH_B and
CLISTIZEH_C. CLISTIZEH_C.
***********************************************************************/ ***********************************************************************/
#define CLISTIZEH_A( CLASSNAME ) \ #define CLISTIZEH_A(CLASSNAME) \
\ \
extern DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \ extern DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \
void* link); /*link to delete*/ \ void *link); /*link to delete*/ \
\ \
extern DLLSYM void* CLASSNAME##_c1_copier( /*deep copy a link*/ \ extern DLLSYM void \
void* old_element); /*source link */ *CLASSNAME##_c1_copier( /*deep copy a link*/ \
void *old_element); /*source link */
#define CLISTIZEH_B( CLASSNAME ) \ #define CLISTIZEH_B(CLASSNAME) \
\ \
/*********************************************************************** \ /*********************************************************************** \
* CLASS - CLASSNAME##_CLIST \ * CLASS - \
* \ *CLASSNAME##_CLIST \
* List class for class CLASSNAME \ * \
* \ * List class for class \
**********************************************************************/ \ *CLASSNAME \
\ * \
class DLLSYM CLASSNAME##_CLIST : public CLIST \ **********************************************************************/ \
{ \ \
public: \ class DLLSYM CLASSNAME##_CLIST : public CLIST { \
CLASSNAME##_CLIST():CLIST() {} \ public: \
/* constructor */ \ CLASSNAME##_CLIST() : CLIST() {} \
\ /* constructor */ \
CLASSNAME##_CLIST( /* don't construct */ \ \
const CLASSNAME##_CLIST&) /*by initial assign*/ \ CLASSNAME##_CLIST( /* don't construct */ \
{ DONT_CONSTRUCT_LIST_BY_COPY.error( QUOTE_IT( CLASSNAME##_CLIST ), \ const CLASSNAME##_CLIST &) /*by initial assign*/ \
ABORT, NULL ); } \ { \
\ DONT_CONSTRUCT_LIST_BY_COPY.error(QUOTE_IT(CLASSNAME##_CLIST), ABORT, \
void deep_clear() /* delete elements */ \ NULL); \
{ CLIST::internal_deep_clear( &CLASSNAME##_c1_zapper ); } \ } \
\ \
void operator=( /* prevent assign */ \ void deep_clear() /* delete elements */ \
const CLASSNAME##_CLIST&) \ { \
{ DONT_ASSIGN_LISTS.error( QUOTE_IT( CLASSNAME##_CLIST ), \ CLIST::internal_deep_clear(&CLASSNAME##_c1_zapper); \
ABORT, NULL ); } } \
\
void operator=(/* prevent assign */ \
const CLASSNAME##_CLIST &) { \
DONT_ASSIGN_LISTS.error(QUOTE_IT(CLASSNAME##_CLIST), ABORT, NULL); \
}
#define CLISTIZEH_C( CLASSNAME ) \ #define CLISTIZEH_C(CLASSNAME) \
\ } \
}; \ ; \
\ \
\ /*********************************************************************** \
\ * CLASS - CLASSNAME##_C_IT \
/*********************************************************************** \ * \
* CLASS - CLASSNAME##_C_IT \ * Iterator class for class CLASSNAME##_CLIST \
* \ * \
* Iterator class for class CLASSNAME##_CLIST \ * Note: We don't need to coerce pointers to member functions input \
* \ * parameters as these are automatically converted to the type of the base \
* Note: We don't need to coerce pointers to member functions input \ * type. ("A ptr to a class may be converted to a pointer to a public base \
* parameters as these are automatically converted to the type of the base \ * class of that class") \
* type. ("A ptr to a class may be converted to a pointer to a public base \ **********************************************************************/ \
* class of that class") \ \
**********************************************************************/ \ class DLLSYM CLASSNAME##_C_IT : public CLIST_ITERATOR { \
\ public: \
class DLLSYM CLASSNAME##_C_IT : public CLIST_ITERATOR \ CLASSNAME##_C_IT() : CLIST_ITERATOR() {} \
{ \ \
public: \ CLASSNAME##_C_IT(CLASSNAME##_CLIST *list) : CLIST_ITERATOR(list) {} \
CLASSNAME##_C_IT():CLIST_ITERATOR(){} \ \
\ CLASSNAME *data() { return (CLASSNAME *)CLIST_ITERATOR::data(); } \
CLASSNAME##_C_IT( \ \
CLASSNAME##_CLIST* list):CLIST_ITERATOR(list){} \ CLASSNAME *data_relative(inT8 offset) { \
\ return (CLASSNAME *)CLIST_ITERATOR::data_relative(offset); \
CLASSNAME* data() \ } \
{ return (CLASSNAME*) CLIST_ITERATOR::data(); } \ \
\ CLASSNAME *forward() { return (CLASSNAME *)CLIST_ITERATOR::forward(); } \
CLASSNAME* data_relative( \ \
inT8 offset) \ CLASSNAME *extract() { return (CLASSNAME *)CLIST_ITERATOR::extract(); } \
{ return (CLASSNAME*) CLIST_ITERATOR::data_relative( offset ); } \ \
\ CLASSNAME *move_to_first() { \
CLASSNAME* forward() \ return (CLASSNAME *)CLIST_ITERATOR::move_to_first(); \
{ return (CLASSNAME*) CLIST_ITERATOR::forward(); } \ } \
\ \
CLASSNAME* extract() \ CLASSNAME *move_to_last() { \
{ return (CLASSNAME*) CLIST_ITERATOR::extract(); } \ return (CLASSNAME *)CLIST_ITERATOR::move_to_last(); \
\ } \
CLASSNAME* move_to_first() \ };
{ return (CLASSNAME*) CLIST_ITERATOR::move_to_first(); } \
\
CLASSNAME* move_to_last() \
{ return (CLASSNAME*) CLIST_ITERATOR::move_to_last(); } \
};
#define CLISTIZEH( CLASSNAME ) \ #define CLISTIZEH(CLASSNAME) \
\ \
CLISTIZEH_A( CLASSNAME ) \ CLISTIZEH_A(CLASSNAME) \
\ \
CLISTIZEH_B( CLASSNAME ) \ CLISTIZEH_B(CLASSNAME) \
\ \
CLISTIZEH_C( CLASSNAME ) CLISTIZEH_C(CLASSNAME)
/*********************************************************************** /***********************************************************************
CLISTIZE( CLASSNAME ) MACRO CLISTIZE( CLASSNAME ) MACRO
***********************************************************************/ ***********************************************************************/
#define CLISTIZE( CLASSNAME ) \ #define CLISTIZE(CLASSNAME) \
\ \
/*********************************************************************** \ /*********************************************************************** \
* CLASSNAME##_c1_zapper \ * CLASSNAME##_c1_zapper \
* \ * \
* A function which can delete a CLASSNAME element. This is passed to the \ * A function which can delete a CLASSNAME element. This is passed to the \
* generic deep_clear list member function so that when a list is cleared the \ * generic deep_clear list member function so that when a list is cleared \
* elements on the list are properly destroyed from the base class, even \ *the \
* though we don't use a virtual destructor function. \ * elements on the list are properly destroyed from the base class, even \
**********************************************************************/ \ * though we don't use a virtual destructor function. \
\ **********************************************************************/ \
DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \ \
void* link) /*link to delete*/ \ DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \
{ \ void *link) /*link to delete*/ \
delete (CLASSNAME *) link; \ { \
} \ delete (CLASSNAME *)link; \
}
#endif #endif

View File

@ -26,7 +26,7 @@
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* ELIST::internal_clear * ELIST::internal_clear
* *
* Used by the destructor and the "clear" member function of derived list * Used by the destructor and the "clear" member function of derived list
* classes to destroy all the elements on the list. * classes to destroy all the elements on the list.
@ -57,7 +57,7 @@ void (*zapper) (ELIST_LINK *)) {
} }
/*********************************************************************** /***********************************************************************
* ELIST::assign_to_sublist * ELIST::assign_to_sublist
* *
* The list is set to a sublist of another list. "This" list must be empty * The list is set to a sublist of another list. "This" list must be empty
* before this function is invoked. The two iterators passed must refer to * before this function is invoked. The two iterators passed must refer to
@ -81,9 +81,8 @@ void ELIST::assign_to_sublist( //to this list
last = start_it->extract_sublist (end_it); last = start_it->extract_sublist (end_it);
} }
/*********************************************************************** /***********************************************************************
* ELIST::length * ELIST::length
* *
* Return count of elements on list * Return count of elements on list
**********************************************************************/ **********************************************************************/
@ -97,9 +96,8 @@ inT32 ELIST::length() const { // count elements
return count; return count;
} }
/*********************************************************************** /***********************************************************************
* ELIST::sort * ELIST::sort
* *
* Sort elements on list * Sort elements on list
* NB If you don't like the const declarations in the comparator, coerce yours: * NB If you don't like the const declarations in the comparator, coerce yours:
@ -187,7 +185,7 @@ ELIST_LINK *ELIST::add_sorted_and_find(
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::forward * ELIST_ITERATOR::forward
* *
* Move the iterator to the next element of the list. * Move the iterator to the next element of the list.
* REMEMBER: ALL LISTS ARE CIRCULAR. * REMEMBER: ALL LISTS ARE CIRCULAR.
@ -224,9 +222,8 @@ ELIST_LINK *ELIST_ITERATOR::forward() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::data_relative * ELIST_ITERATOR::data_relative
* *
* Return the data pointer to the element "offset" elements from current. * Return the data pointer to the element "offset" elements from current.
* "offset" must not be less than -1. * "offset" must not be less than -1.
@ -260,9 +257,8 @@ ELIST_LINK *ELIST_ITERATOR::data_relative( //get data + or - ...
return ptr; return ptr;
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::move_to_last() * ELIST_ITERATOR::move_to_last()
* *
* Move current so that it is set to the end of the list. * Move current so that it is set to the end of the list.
* Return data just in case anyone wants it. * Return data just in case anyone wants it.
@ -281,9 +277,8 @@ ELIST_LINK *ELIST_ITERATOR::move_to_last() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::exchange() * ELIST_ITERATOR::exchange()
* *
* Given another iterator, whose current element is a different element on * Given another iterator, whose current element is a different element on
* the same list list OR an element of another list, exchange the two current * the same list list OR an element of another list, exchange the two current
@ -379,9 +374,8 @@ void ELIST_ITERATOR::exchange( //positions of 2 link
other_it->current = old_current; other_it->current = old_current;
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::extract_sublist() * ELIST_ITERATOR::extract_sublist()
* *
* This is a private member, used only by ELIST::assign_to_sublist. * This is a private member, used only by ELIST::assign_to_sublist.
* Given another iterator for the same list, extract the links from THIS to * Given another iterator for the same list, extract the links from THIS to
@ -425,7 +419,7 @@ ELIST_LINK *ELIST_ITERATOR::extract_sublist( //from
temp_it.mark_cycle_pt (); temp_it.mark_cycle_pt ();
do { //walk sublist do { //walk sublist
if (temp_it.cycled_list ()) //can't find end pt if (temp_it.cycled_list()) // can't find end pt
BAD_SUBLIST.error ("ELIST_ITERATOR.extract_sublist", ABORT, NULL); BAD_SUBLIST.error ("ELIST_ITERATOR.extract_sublist", ABORT, NULL);
if (temp_it.at_last ()) { if (temp_it.at_last ()) {

View File

@ -98,8 +98,8 @@ class DLLSYM ELIST_LINK
next = NULL; next = NULL;
} }
void operator= ( //don't copy links void operator=( // don't copy links
const ELIST_LINK &) { const ELIST_LINK &) {
next = NULL; next = NULL;
} }
}; };
@ -273,8 +273,8 @@ class DLLSYM ELIST_ITERATOR
bool cycled_list(); //Completed a cycle? bool cycled_list(); //Completed a cycle?
void add_to_end( //add at end & void add_to_end( // add at end &
ELIST_LINK *new_link); //don't move ELIST_LINK *new_link); // don't move
void exchange( //positions of 2 links void exchange( //positions of 2 links
ELIST_ITERATOR *other_it); //other iterator ELIST_ITERATOR *other_it); //other iterator
@ -458,7 +458,6 @@ inline void ELIST_ITERATOR::add_before_then_move( // element to add
current = new_element; current = new_element;
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::add_before_stay_put * ELIST_ITERATOR::add_before_stay_put
* *
@ -501,11 +500,11 @@ inline void ELIST_ITERATOR::add_before_stay_put( // element to add
} }
} }
/*********************************************************************** /***********************************************************************
* ELIST_ITERATOR::add_list_after * ELIST_ITERATOR::add_list_after
* *
* Insert another list to this list after the current element but don't move the * Insert another list to this list after the current element but don't move
*the
* iterator. * iterator.
**********************************************************************/ **********************************************************************/
@ -959,30 +958,29 @@ ELISTIZEH_C( CLASSNAME )
ELISTIZE( CLASSNAME ) MACRO ELISTIZE( CLASSNAME ) MACRO
***********************************************************************/ ***********************************************************************/
#define ELISTIZE(CLASSNAME) \ #define ELISTIZE(CLASSNAME) \
\ \
/*********************************************************************** \ /*********************************************************************** \
* CLASSNAME##_zapper \ * CLASSNAME##_zapper \
* \ * \
* A function which can delete a CLASSNAME element. This is passed to the \ * A function which can delete a CLASSNAME element. This is passed to the \
* generic clear list member function so that when a list is cleared the \ * generic clear list member function so that when a list is cleared the \
* elements on the list are properly destroyed from the base class, even \ * elements on the list are properly destroyed from the base class, even \
* though we don't use a virtual destructor function. \ * though we don't use a virtual destructor function. \
**********************************************************************/ \ **********************************************************************/ \
\ \
DLLSYM void CLASSNAME##_zapper(ELIST_LINK* link) { \ DLLSYM void CLASSNAME##_zapper(ELIST_LINK *link) { \
delete reinterpret_cast<CLASSNAME*>(link); \ delete reinterpret_cast<CLASSNAME *>(link); \
} \ } \
\ \
/* Become a deep copy of src_list*/ \ /* Become a deep copy of src_list*/ \
void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST* src_list, \ void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST *src_list, \
CLASSNAME* (*copier)(const CLASSNAME*)) { \ CLASSNAME *(*copier)(const CLASSNAME *)) { \
\ CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST *>(src_list)); \
CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST*>(src_list)); \ CLASSNAME##_IT to_it(this); \
CLASSNAME##_IT to_it(this); \ \
\ for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \
for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \ to_it.add_after_then_move((*copier)(from_it.data())); \
to_it.add_after_then_move((*copier)(from_it.data())); \ }
}
#endif #endif

View File

@ -27,7 +27,7 @@
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* ELIST2::internal_clear * ELIST2::internal_clear
* *
* Used by the destructor and the "clear" member function of derived list * Used by the destructor and the "clear" member function of derived list
* classes to destroy all the elements on the list. * classes to destroy all the elements on the list.
@ -58,7 +58,7 @@ void (*zapper) (ELIST2_LINK *)) {
} }
/*********************************************************************** /***********************************************************************
* ELIST2::assign_to_sublist * ELIST2::assign_to_sublist
* *
* The list is set to a sublist of another list. "This" list must be empty * The list is set to a sublist of another list. "This" list must be empty
* before this function is invoked. The two iterators passed must refer to * before this function is invoked. The two iterators passed must refer to
@ -82,9 +82,8 @@ void ELIST2::assign_to_sublist( //to this list
last = start_it->extract_sublist (end_it); last = start_it->extract_sublist (end_it);
} }
/*********************************************************************** /***********************************************************************
* ELIST2::length * ELIST2::length
* *
* Return count of elements on list * Return count of elements on list
**********************************************************************/ **********************************************************************/
@ -98,9 +97,8 @@ inT32 ELIST2::length() const { // count elements
return count; return count;
} }
/*********************************************************************** /***********************************************************************
* ELIST2::sort * ELIST2::sort
* *
* Sort elements on list * Sort elements on list
* NB If you don't like the const declarations in the comparator, coerce yours: * NB If you don't like the const declarations in the comparator, coerce yours:
@ -180,7 +178,7 @@ void ELIST2::add_sorted(int comparator(const void*, const void*),
**********************************************************************/ **********************************************************************/
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::forward * ELIST2_ITERATOR::forward
* *
* Move the iterator to the next element of the list. * Move the iterator to the next element of the list.
* REMEMBER: ALL LISTS ARE CIRCULAR. * REMEMBER: ALL LISTS ARE CIRCULAR.
@ -218,9 +216,8 @@ ELIST2_LINK *ELIST2_ITERATOR::forward() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::backward * ELIST2_ITERATOR::backward
* *
* Move the iterator to the previous element of the list. * Move the iterator to the previous element of the list.
* REMEMBER: ALL LISTS ARE CIRCULAR. * REMEMBER: ALL LISTS ARE CIRCULAR.
@ -257,9 +254,8 @@ ELIST2_LINK *ELIST2_ITERATOR::backward() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::data_relative * ELIST2_ITERATOR::data_relative
* *
* Return the data pointer to the element "offset" elements from current. * Return the data pointer to the element "offset" elements from current.
* (This function can't be INLINEd because it contains a loop) * (This function can't be INLINEd because it contains a loop)
@ -289,9 +285,8 @@ ELIST2_LINK *ELIST2_ITERATOR::data_relative( //get data + or - ..
return ptr; return ptr;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::exchange() * ELIST2_ITERATOR::exchange()
* *
* Given another iterator, whose current element is a different element on * Given another iterator, whose current element is a different element on
* the same list list OR an element of another list, exchange the two current * the same list list OR an element of another list, exchange the two current
@ -399,9 +394,8 @@ void ELIST2_ITERATOR::exchange( //positions of 2 li
other_it->current = old_current; other_it->current = old_current;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::extract_sublist() * ELIST2_ITERATOR::extract_sublist()
* *
* This is a private member, used only by ELIST2::assign_to_sublist. * This is a private member, used only by ELIST2::assign_to_sublist.
* Given another iterator for the same list, extract the links from THIS to * Given another iterator for the same list, extract the links from THIS to
@ -445,7 +439,7 @@ ELIST2_LINK *ELIST2_ITERATOR::extract_sublist( //fr
temp_it.mark_cycle_pt (); temp_it.mark_cycle_pt ();
do { //walk sublist do { //walk sublist
if (temp_it.cycled_list ()) //can't find end pt if (temp_it.cycled_list()) // can't find end pt
BAD_SUBLIST.error ("ELIST2_ITERATOR.extract_sublist", ABORT, NULL); BAD_SUBLIST.error ("ELIST2_ITERATOR.extract_sublist", ABORT, NULL);
if (temp_it.at_last ()) { if (temp_it.at_last ()) {

View File

@ -46,9 +46,9 @@ i) The duplication in source does not affect the run time code size - the
**********************************************************************/ **********************************************************************/
/********************************************************************** /**********************************************************************
* CLASS - ELIST2_LINK * CLASS - ELIST2_LINK
* *
* Generic link class for doubly linked lists with embedded links * Generic link class for doubly linked lists with embedded links
* *
* Note: No destructor - elements are assumed to be destroyed EITHER after * Note: No destructor - elements are assumed to be destroyed EITHER after
* they have been extracted from a list OR by the ELIST2 destructor which * they have been extracted from a list OR by the ELIST2 destructor which
@ -68,13 +68,13 @@ class DLLSYM ELIST2_LINK
prev = next = NULL; prev = next = NULL;
} }
ELIST2_LINK( //copy constructor ELIST2_LINK( // copy constructor
const ELIST2_LINK &) { //don't copy link const ELIST2_LINK &) { // don't copy link
prev = next = NULL; prev = next = NULL;
} }
void operator= ( //don't copy links void operator=( // don't copy links
const ELIST2_LINK &) { const ELIST2_LINK &) {
prev = next = NULL; prev = next = NULL;
} }
}; };
@ -142,9 +142,10 @@ class DLLSYM ELIST2
}; };
/*********************************************************************** /***********************************************************************
* CLASS - ELIST2_ITERATOR * CLASS - ELIST2_ITERATOR
* *
* Generic iterator class for doubly linked lists with embedded links * Generic iterator class for doubly linked lists with embedded
*links
**********************************************************************/ **********************************************************************/
class DLLSYM ELIST2_ITERATOR class DLLSYM ELIST2_ITERATOR
@ -240,8 +241,8 @@ class DLLSYM ELIST2_ITERATOR
BOOL8 cycled_list(); //Completed a cycle? BOOL8 cycled_list(); //Completed a cycle?
void add_to_end( //add at end & void add_to_end( // add at end &
ELIST2_LINK *new_link); //don't move ELIST2_LINK *new_link); // don't move
void exchange( //positions of 2 links void exchange( //positions of 2 links
ELIST2_ITERATOR *other_it); //other iterator ELIST2_ITERATOR *other_it); //other iterator
@ -255,7 +256,7 @@ class DLLSYM ELIST2_ITERATOR
}; };
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::set_to_list * ELIST2_ITERATOR::set_to_list
* *
* (Re-)initialise the iterator to point to the start of the list_to_iterate * (Re-)initialise the iterator to point to the start of the list_to_iterate
* over. * over.
@ -279,9 +280,8 @@ inline void ELIST2_ITERATOR::set_to_list( //change list
ex_current_was_cycle_pt = FALSE; ex_current_was_cycle_pt = FALSE;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::ELIST2_ITERATOR * ELIST2_ITERATOR::ELIST2_ITERATOR
* *
* CONSTRUCTOR - set iterator to specified list; * CONSTRUCTOR - set iterator to specified list;
**********************************************************************/ **********************************************************************/
@ -290,9 +290,8 @@ inline ELIST2_ITERATOR::ELIST2_ITERATOR(ELIST2 *list_to_iterate) {
set_to_list(list_to_iterate); set_to_list(list_to_iterate);
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_after_then_move * ELIST2_ITERATOR::add_after_then_move
* *
* Add a new element to the list after the current element and move the * Add a new element to the list after the current element and move the
* iterator to the new element. * iterator to the new element.
@ -339,9 +338,8 @@ inline void ELIST2_ITERATOR::add_after_then_move( // element to add
current = new_element; current = new_element;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_after_stay_put * ELIST2_ITERATOR::add_after_stay_put
* *
* Add a new element to the list after the current element but do not move * Add a new element to the list after the current element but do not move
* the iterator to the new element. * the iterator to the new element.
@ -391,9 +389,8 @@ inline void ELIST2_ITERATOR::add_after_stay_put( // element to add
} }
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_before_then_move * ELIST2_ITERATOR::add_before_then_move
* *
* Add a new element to the list before the current element and move the * Add a new element to the list before the current element and move the
* iterator to the new element. * iterator to the new element.
@ -438,9 +435,8 @@ inline void ELIST2_ITERATOR::add_before_then_move( // element to add
current = new_element; current = new_element;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_before_stay_put * ELIST2_ITERATOR::add_before_stay_put
* *
* Add a new element to the list before the current element but don't move the * Add a new element to the list before the current element but don't move the
* iterator to the new element. * iterator to the new element.
@ -486,11 +482,11 @@ inline void ELIST2_ITERATOR::add_before_stay_put( // element to add
} }
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_list_after * ELIST2_ITERATOR::add_list_after
* *
* Insert another list to this list after the current element but don't move the * Insert another list to this list after the current element but don't move
*the
* iterator. * iterator.
**********************************************************************/ **********************************************************************/
@ -537,9 +533,8 @@ inline void ELIST2_ITERATOR::add_list_after(ELIST2 *list_to_add) {
} }
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_list_before * ELIST2_ITERATOR::add_list_before
* *
* Insert another list to this list before the current element. Move the * Insert another list to this list before the current element. Move the
* iterator to the start of the inserted elements * iterator to the start of the inserted elements
@ -586,9 +581,8 @@ inline void ELIST2_ITERATOR::add_list_before(ELIST2 *list_to_add) {
} }
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::extract * ELIST2_ITERATOR::extract
* *
* Do extraction by removing current from the list, returning it to the * Do extraction by removing current from the list, returning it to the
* caller, but NOT updating the iterator. (So that any calling loop can do * caller, but NOT updating the iterator. (So that any calling loop can do
@ -631,9 +625,8 @@ inline ELIST2_LINK *ELIST2_ITERATOR::extract() {
return extracted_link; return extracted_link;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::move_to_first() * ELIST2_ITERATOR::move_to_first()
* *
* Move current so that it is set to the start of the list. * Move current so that it is set to the start of the list.
* Return data just in case anyone wants it. * Return data just in case anyone wants it.
@ -651,9 +644,8 @@ inline ELIST2_LINK *ELIST2_ITERATOR::move_to_first() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::move_to_last() * ELIST2_ITERATOR::move_to_last()
* *
* Move current so that it is set to the end of the list. * Move current so that it is set to the end of the list.
* Return data just in case anyone wants it. * Return data just in case anyone wants it.
@ -671,9 +663,8 @@ inline ELIST2_LINK *ELIST2_ITERATOR::move_to_last() {
return current; return current;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::mark_cycle_pt() * ELIST2_ITERATOR::mark_cycle_pt()
* *
* Remember the current location so that we can tell whether we've returned * Remember the current location so that we can tell whether we've returned
* to this point later. * to this point later.
@ -696,9 +687,8 @@ inline void ELIST2_ITERATOR::mark_cycle_pt() {
started_cycling = FALSE; started_cycling = FALSE;
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::at_first() * ELIST2_ITERATOR::at_first()
* *
* Are we at the start of the list? * Are we at the start of the list?
* *
@ -716,9 +706,8 @@ inline BOOL8 ELIST2_ITERATOR::at_first() {
!ex_current_was_last)); //first and last !ex_current_was_last)); //first and last
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::at_last() * ELIST2_ITERATOR::at_last()
* *
* Are we at the end of the list? * Are we at the end of the list?
* *
@ -736,9 +725,8 @@ inline BOOL8 ELIST2_ITERATOR::at_last() {
ex_current_was_last)); //first and last ex_current_was_last)); //first and last
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::cycled_list() * ELIST2_ITERATOR::cycled_list()
* *
* Have we returned to the cycle_pt since it was set? * Have we returned to the cycle_pt since it was set?
* *
@ -754,9 +742,8 @@ inline BOOL8 ELIST2_ITERATOR::cycled_list() {
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::length() * ELIST2_ITERATOR::length()
* *
* Return the length of the list * Return the length of the list
* *
@ -771,9 +758,8 @@ inline inT32 ELIST2_ITERATOR::length() {
return list->length (); return list->length ();
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::sort() * ELIST2_ITERATOR::sort()
* *
* Sort the elements of the list, then reposition at the start. * Sort the elements of the list, then reposition at the start.
* *
@ -792,9 +778,8 @@ const void *, const void *)) {
move_to_first(); move_to_first();
} }
/*********************************************************************** /***********************************************************************
* ELIST2_ITERATOR::add_to_end * ELIST2_ITERATOR::add_to_end
* *
* Add a new element to the end of the list without moving the iterator. * Add a new element to the end of the list without moving the iterator.
* This is provided because a single linked list cannot move to the last as * This is provided because a single linked list cannot move to the last as
@ -854,7 +839,7 @@ will NOT work correctly for classes derived from this.
The macro generates: The macro generates:
- An element deletion function: CLASSNAME##_zapper - An element deletion function: CLASSNAME##_zapper
- An E_LIST2 subclass: CLASSNAME##_LIST - An E_LIST2 subclass: CLASSNAME##_LIST
- An E_LIST2_ITERATOR subclass: - An E_LIST2_ITERATOR subclass:
CLASSNAME##_IT CLASSNAME##_IT
@ -873,132 +858,132 @@ ELIST2IZEH is a concatenation of 3 fragments ELIST2IZEH_A, ELIST2IZEH_B and
ELIST2IZEH_C. ELIST2IZEH_C.
***********************************************************************/ ***********************************************************************/
#define ELIST2IZEH_A( CLASSNAME ) \ #define ELIST2IZEH_A(CLASSNAME) \
\ \
extern DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \ extern DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \
ELIST2_LINK* link); /*link to delete*/ ELIST2_LINK *link); /*link to delete*/
#define ELIST2IZEH_B( CLASSNAME ) \ #define ELIST2IZEH_B(CLASSNAME) \
\ \
/*********************************************************************** \ /*********************************************************************** \
* CLASS - CLASSNAME##_LIST \ * CLASS - \
* \ *CLASSNAME##_LIST \
* List class for class CLASSNAME \ * \
* \ * List class for class \
**********************************************************************/ \ *CLASSNAME \
\ * \
class DLLSYM CLASSNAME##_LIST : public ELIST2 \ **********************************************************************/ \
{ \ \
public: \ class DLLSYM CLASSNAME##_LIST : public ELIST2 { \
CLASSNAME##_LIST():ELIST2() {} \ public: \
/* constructor */ \ CLASSNAME##_LIST() : ELIST2() {} \
\ /* constructor */ \
CLASSNAME##_LIST( /* don't construct */ \ \
const CLASSNAME##_LIST&) /*by initial assign*/\ CLASSNAME##_LIST( /* don't construct */ \
{ DONT_CONSTRUCT_LIST_BY_COPY.error( QUOTE_IT( CLASSNAME##_LIST ), \ const CLASSNAME##_LIST &) /*by initial assign*/ \
ABORT, NULL ); } \ { \
\ DONT_CONSTRUCT_LIST_BY_COPY.error(QUOTE_IT(CLASSNAME##_LIST), ABORT, \
void clear() /* delete elements */\ NULL); \
{ ELIST2::internal_clear( &CLASSNAME##_zapper ); } \ } \
\ \
~CLASSNAME##_LIST() /* destructor */ \ void clear() /* delete elements */ \
{ clear(); } \ { \
\ ELIST2::internal_clear(&CLASSNAME##_zapper); \
/* Become a deep copy of src_list*/ \ } \
void deep_copy(const CLASSNAME##_LIST* src_list, \ \
CLASSNAME* (*copier)(const CLASSNAME*)); \ ~CLASSNAME##_LIST() /* destructor */ \
\ { \
void operator=( /* prevent assign */ \ clear(); \
const CLASSNAME##_LIST&) \ } \
{ DONT_ASSIGN_LISTS.error( QUOTE_IT( CLASSNAME##_LIST ), \ \
ABORT, NULL ); } /* Become a deep copy of src_list*/ \
void deep_copy(const CLASSNAME##_LIST *src_list, \
CLASSNAME *(*copier)(const CLASSNAME *)); \
\
void operator=(/* prevent assign */ \
const CLASSNAME##_LIST &) { \
DONT_ASSIGN_LISTS.error(QUOTE_IT(CLASSNAME##_LIST), ABORT, NULL); \
}
#define ELIST2IZEH_C( CLASSNAME ) \ #define ELIST2IZEH_C(CLASSNAME) \
}; \ } \
\ ; \
\ \
\ /*********************************************************************** \
/*********************************************************************** \ * CLASS - CLASSNAME##_IT \
* CLASS - CLASSNAME##_IT \ * \
* \ * Iterator class for class CLASSNAME##_LIST \
* Iterator class for class CLASSNAME##_LIST \ * \
* \ * Note: We don't need to coerce pointers to member functions input \
* Note: We don't need to coerce pointers to member functions input \ * parameters as these are automatically converted to the type of the base \
* parameters as these are automatically converted to the type of the base \ * type. ("A ptr to a class may be converted to a pointer to a public base \
* type. ("A ptr to a class may be converted to a pointer to a public base \ * class of that class") \
* class of that class") \ **********************************************************************/ \
**********************************************************************/ \ \
\ class DLLSYM CLASSNAME##_IT : public ELIST2_ITERATOR { \
class DLLSYM CLASSNAME##_IT : public ELIST2_ITERATOR \ public: \
{ \ CLASSNAME##_IT() : ELIST2_ITERATOR() {} \
public: \ \
CLASSNAME##_IT():ELIST2_ITERATOR(){} \ CLASSNAME##_IT(CLASSNAME##_LIST *list) : ELIST2_ITERATOR(list) {} \
\ \
CLASSNAME##_IT( \ CLASSNAME *data() { return (CLASSNAME *)ELIST2_ITERATOR::data(); } \
CLASSNAME##_LIST* list):ELIST2_ITERATOR(list){} \ \
\ CLASSNAME *data_relative(inT8 offset) { \
CLASSNAME* data() \ return (CLASSNAME *)ELIST2_ITERATOR::data_relative(offset); \
{ return (CLASSNAME*) ELIST2_ITERATOR::data(); } \ } \
\ \
CLASSNAME* data_relative( \ CLASSNAME *forward() { return (CLASSNAME *)ELIST2_ITERATOR::forward(); } \
inT8 offset) \ \
{ return (CLASSNAME*) ELIST2_ITERATOR::data_relative( offset ); } \ CLASSNAME *backward() { return (CLASSNAME *)ELIST2_ITERATOR::backward(); } \
\ \
CLASSNAME* forward() \ CLASSNAME *extract() { return (CLASSNAME *)ELIST2_ITERATOR::extract(); } \
{ return (CLASSNAME*) ELIST2_ITERATOR::forward(); } \ \
\ CLASSNAME *move_to_first() { \
CLASSNAME* backward() \ return (CLASSNAME *)ELIST2_ITERATOR::move_to_first(); \
{ return (CLASSNAME*) ELIST2_ITERATOR::backward(); } \ } \
\ \
CLASSNAME* extract() \ CLASSNAME *move_to_last() { \
{ return (CLASSNAME*) ELIST2_ITERATOR::extract(); } \ return (CLASSNAME *)ELIST2_ITERATOR::move_to_last(); \
\ } \
CLASSNAME* move_to_first() \ };
{ return (CLASSNAME*) ELIST2_ITERATOR::move_to_first(); } \
\
CLASSNAME* move_to_last() \
{ return (CLASSNAME*) ELIST2_ITERATOR::move_to_last(); } \
};
#define ELIST2IZEH( CLASSNAME ) \
\
ELIST2IZEH_A( CLASSNAME ) \
\
ELIST2IZEH_B( CLASSNAME ) \
\
ELIST2IZEH_C( CLASSNAME )
#define ELIST2IZEH(CLASSNAME) \
\
ELIST2IZEH_A(CLASSNAME) \
\
ELIST2IZEH_B(CLASSNAME) \
\
ELIST2IZEH_C(CLASSNAME)
/*********************************************************************** /***********************************************************************
ELIST2IZE( CLASSNAME ) MACRO ELIST2IZE( CLASSNAME ) MACRO
***********************************************************************/ ***********************************************************************/
#define ELIST2IZE( CLASSNAME ) \ #define ELIST2IZE(CLASSNAME) \
\ \
/*********************************************************************** \ /*********************************************************************** \
* CLASSNAME##_zapper \ * CLASSNAME##_zapper \
* \ * \
* A function which can delete a CLASSNAME element. This is passed to the \ * A function which can delete a CLASSNAME element. This is passed to the \
* generic clear list member function so that when a list is cleared the \ * generic clear list member function so that when a list is cleared the \
* elements on the list are properly destroyed from the base class, even \ * elements on the list are properly destroyed from the base class, even \
* though we don't use a virtual destructor function. \ * though we don't use a virtual destructor function. \
**********************************************************************/ \ **********************************************************************/ \
\ \
DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \ DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \
ELIST2_LINK* link) /*link to delete*/ \ ELIST2_LINK *link) /*link to delete*/ \
{ \ { \
delete (CLASSNAME *) link; \ delete (CLASSNAME *)link; \
} \ } \
\ \
/* Become a deep copy of src_list*/ \ /* Become a deep copy of src_list*/ \
void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST* src_list, \ void CLASSNAME##_LIST::deep_copy(const CLASSNAME##_LIST *src_list, \
CLASSNAME* (*copier)(const CLASSNAME*)) { \ CLASSNAME *(*copier)(const CLASSNAME *)) { \
\ CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST *>(src_list)); \
CLASSNAME##_IT from_it(const_cast<CLASSNAME##_LIST*>(src_list)); \ CLASSNAME##_IT to_it(this); \
CLASSNAME##_IT to_it(this); \ \
\ for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \
for (from_it.mark_cycle_pt(); !from_it.cycled_list(); from_it.forward()) \ to_it.add_after_then_move((*copier)(from_it.data())); \
to_it.add_after_then_move((*copier)(from_it.data())); \ }
}
#endif #endif

View File

@ -87,11 +87,10 @@ const ERRCODE ASSERT_FAILED = "Assert failed";
__FILE__, __LINE__); \ __FILE__, __LINE__); \
} }
#define ASSERT_HOST_MSG(x, ...) if (!(x)) \ #define ASSERT_HOST_MSG(x, ...) \
{ \ if (!(x)) { \
tprintf(__VA_ARGS__); \ tprintf(__VA_ARGS__); \
ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", \ ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__); \
__FILE__, __LINE__); \
} }
void signal_exit(int signal_code); void signal_exit(int signal_code);

View File

@ -73,7 +73,7 @@ class TRand {
// Remove newline (if any) at the end of the string. // Remove newline (if any) at the end of the string.
inline void chomp_string(char *str) { inline void chomp_string(char *str) {
int last_index = (int)strlen(str) - 1; int last_index = static_cast<int>(strlen(str)) - 1;
while (last_index >= 0 && while (last_index >= 0 &&
(str[last_index] == '\n' || str[last_index] == '\r')) { (str[last_index] == '\n' || str[last_index] == '\r')) {
str[last_index--] = '\0'; str[last_index--] = '\0';

View File

@ -59,6 +59,7 @@
** of the computer and/or operating system. ** of the computer and/or operating system.
******************************************************************************/ ******************************************************************************/
#include <limits>
#include "platform.h" #include "platform.h"
/* _WIN32 */ /* _WIN32 */
#ifdef _WIN32 #ifdef _WIN32
@ -121,15 +122,16 @@ typedef unsigned char BOOL8;
#define MAX_UINT8 0xff #define MAX_UINT8 0xff
#define MAX_UINT16 0xffff #define MAX_UINT16 0xffff
#define MAX_UINT32 0xffffffff #define MAX_UINT32 0xffffffff
#define MAX_FLOAT32 ((float)3.40282347e+38) #define MAX_FLOAT32 std::numeric_limits<float>::max()
#define MIN_INT8 0x80 #define MIN_INT8 static_cast<inT8>(0x80)
#define MIN_INT16 0x8000 #define MIN_INT16 static_cast<inT16>(0x8000)
#define MIN_INT32 static_cast<int>(0x80000000) #define MIN_INT32 static_cast<inT32>(0x80000000)
#define MIN_UINT8 0x00 #define MIN_UINT8 0x00
#define MIN_UINT16 0x0000 #define MIN_UINT16 0x0000
#define MIN_UINT32 0x00000000 #define MIN_UINT32 0x00000000
#define MIN_FLOAT32 ((float)1.17549435e-38) // Minimum positive value ie 1e-37ish.
#define MIN_FLOAT32 std::numeric_limits<float>::min()
// Defines // Defines
#ifndef TRUE #ifndef TRUE

View File

@ -38,6 +38,6 @@ const ERRCODE NULL_PREV = "Previous element on the list is NULL";
const ERRCODE EMPTY_LIST = "List is empty"; const ERRCODE EMPTY_LIST = "List is empty";
const ERRCODE BAD_PARAMETER = "List parameter error"; const ERRCODE BAD_PARAMETER = "List parameter error";
const ERRCODE STILL_LINKED = const ERRCODE STILL_LINKED =
"Attempting to add an element with non NULL links, to a list"; "Attempting to add an element with non NULL links, to a list";
#endif #endif
#endif #endif

View File

@ -74,7 +74,7 @@ void CCUtil::main_setup(const char *argv0, const char *basename) {
#endif /* _WIN32 */ #endif /* _WIN32 */
#if defined(TESSDATA_PREFIX) #if defined(TESSDATA_PREFIX)
} else { } else {
/* Use tessdata prefix which was compiled in. */ /* Use tessdata prefix which was compiled in. */
#define _STR(a) #a #define _STR(a) #a
#define _XSTR(a) _STR(a) #define _XSTR(a) _STR(a)
datadir = _XSTR(TESSDATA_PREFIX); datadir = _XSTR(TESSDATA_PREFIX);

View File

@ -1,7 +1,7 @@
/********************************************************************** /**********************************************************************
* File: ocrclass.h * File: ocrclass.h
* Description: Class definitions and constants for the OCR API. * Description: Class definitions and constants for the OCR API.
* Author: Hewlett-Packard Co * Author: Hewlett-Packard Co
* *
* (C) Copyright 1996, Hewlett-Packard Co. * (C) Copyright 1996, Hewlett-Packard Co.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
@ -110,28 +110,35 @@ typedef struct { /*single character */
* user words found. If it returns true then operation is cancelled. * user words found. If it returns true then operation is cancelled.
**********************************************************************/ **********************************************************************/
typedef bool (*CANCEL_FUNC)(void* cancel_this, int words); typedef bool (*CANCEL_FUNC)(void* cancel_this, int words);
typedef bool (*PROGRESS_FUNC)(int progress, typedef bool (*PROGRESS_FUNC)(int progress, int left, int right, int top,
int left, int right, int top, int bottom); int bottom);
class ETEXT_DESC { // output header class ETEXT_DESC { // output header
public: public:
inT16 count; /// chars in this buffer(0) inT16 count; /// chars in this buffer(0)
inT16 progress; /// percent complete increasing (0-100) inT16 progress; /// percent complete increasing (0-100)
/** Progress monitor covers word recognition and it does not cover layout /** Progress monitor covers word recognition and it does not cover layout
* analysis. * analysis.
* See Ray comment in https://github.com/tesseract-ocr/tesseract/pull/27 */ * See Ray comment in https://github.com/tesseract-ocr/tesseract/pull/27 */
inT8 more_to_come; /// true if not last inT8 more_to_come; /// true if not last
volatile inT8 ocr_alive; /// ocr sets to 1, HP 0 volatile inT8 ocr_alive; /// ocr sets to 1, HP 0
inT8 err_code; /// for errcode use inT8 err_code; /// for errcode use
CANCEL_FUNC cancel; /// returns true to cancel CANCEL_FUNC cancel; /// returns true to cancel
PROGRESS_FUNC progress_callback; /// called whenever progress increases PROGRESS_FUNC progress_callback; /// called whenever progress increases
void* cancel_this; /// this or other data for cancel void* cancel_this; /// this or other data for cancel
struct timeval end_time; /** time to stop. expected to be set only by call struct timeval end_time; /// Time to stop. Expected to be set only
* to set_deadline_msecs() */ /// by call to set_deadline_msecs().
EANYCODE_CHAR text[1]; /// character data EANYCODE_CHAR text[1]; /// character data
ETEXT_DESC() : count(0), progress(0), more_to_come(0), ocr_alive(0), ETEXT_DESC()
err_code(0), cancel(NULL), cancel_this(NULL) { : count(0),
progress(0),
more_to_come(0),
ocr_alive(0),
err_code(0),
cancel(NULL),
progress_callback(NULL),
cancel_this(NULL) {
end_time.tv_sec = 0; end_time.tv_sec = 0;
end_time.tv_usec = 0; end_time.tv_usec = 0;
} }

View File

@ -31,8 +31,7 @@
#define EQUAL '=' #define EQUAL '='
tesseract::ParamsVectors *GlobalParams() { tesseract::ParamsVectors *GlobalParams() {
static tesseract::ParamsVectors global_params = static tesseract::ParamsVectors global_params = tesseract::ParamsVectors();
tesseract::ParamsVectors();
return &global_params; return &global_params;
} }

View File

@ -1,8 +1,8 @@
/********************************************************************** /**********************************************************************
* File: strngs.c (Formerly strings.c) * File: strngs.c (Formerly strings.c)
* Description: STRING class functions. * Description: STRING class functions.
* Author: Ray Smith * Author: Ray Smith
* Created: Fri Feb 15 09:13:30 GMT 1991 * Created: Fri Feb 15 09:13:30 GMT 1991
* *
* (C) Copyright 1991, Hewlett-Packard Ltd. * (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -181,8 +181,7 @@ class UNICHARSET {
// Return the UNICHAR_ID of a given unichar representation within the // Return the UNICHAR_ID of a given unichar representation within the
// UNICHARSET. Only the first length characters from unichar_repr are used. // UNICHARSET. Only the first length characters from unichar_repr are used.
UNICHAR_ID unichar_to_id(const char* const unichar_repr, UNICHAR_ID unichar_to_id(const char* const unichar_repr, int length) const;
int length) const;
// Return the minimum number of bytes that matches a legal UNICHAR_ID, // Return the minimum number of bytes that matches a legal UNICHAR_ID,
// while leaving the rest of the string encodable. Returns 0 if the // while leaving the rest of the string encodable. Returns 0 if the

View File

@ -908,8 +908,7 @@ void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
NumFeatures = GetAdaptiveFeatures(Blob, IntFeatures, &FloatFeatures); NumFeatures = GetAdaptiveFeatures(Blob, IntFeatures, &FloatFeatures);
if (NumFeatures <= 0) { if (NumFeatures <= 0) {
FreeFeatureSet(FloatFeatures); return; // Features already freed by GetAdaptiveFeatures.
return;
} }
// Only match configs with the matching font. // Only match configs with the matching font.
@ -1008,8 +1007,6 @@ void Classify::DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class) {
#endif #endif
} }
/** /**
* This routine adds the result of a classification into * This routine adds the result of a classification into
* Results. If the new rating is much worse than the current * Results. If the new rating is much worse than the current

View File

@ -151,8 +151,8 @@ Classify::Classify()
INT_MEMBER(classify_integer_matcher_multiplier, 10, INT_MEMBER(classify_integer_matcher_multiplier, 10,
"Integer Matcher Multiplier 0-255: ", this->params()), "Integer Matcher Multiplier 0-255: ", this->params()),
EnableLearning(true), EnableLearning(true),
INT_MEMBER(il1_adaption_test, 0, "Don't adapt to i/I at beginning of word", INT_MEMBER(il1_adaption_test, 0,
this->params()), "Don't adapt to i/I at beginning of word", this->params()),
BOOL_MEMBER(classify_bln_numeric_mode, 0, BOOL_MEMBER(classify_bln_numeric_mode, 0,
"Assume the input is numbers [0-9].", this->params()), "Assume the input is numbers [0-9].", this->params()),
double_MEMBER(speckle_large_max_size, 0.30, "Max large speckle size", double_MEMBER(speckle_large_max_size, 0.30, "Max large speckle size",

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: clustertool.c ** Filename: clustertool.c
** Purpose: Misc. tools for use with the clustering routines ** Purpose: Misc. tools for use with the clustering routines
** Author: Dan Johnson ** Author: Dan Johnson
** History: 6/6/89, DSJ, Created. ** History: 6/6/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -26,9 +26,10 @@
#include <math.h> #include <math.h>
//---------------Global Data Definitions and Declarations-------------------- //---------------Global Data Definitions and Declarations--------------------
#define TOKENSIZE 80 //< max size of tokens read from an input file #define TOKENSIZE 80 //< max size of tokens read from an input file
#define MAXSAMPLESIZE 65535 //< max num of dimensions in feature space #define MAXSAMPLESIZE 65535 //< max num of dimensions in feature space
//#define MAXBLOCKSIZE 65535 //< max num of samples in a character (block size) //#define MAXBLOCKSIZE 65535 //< max num of samples in a character (block
// size)
/** /**
* This routine reads a single integer from the specified * This routine reads a single integer from the specified
@ -37,7 +38,7 @@
* @param File open text file to read sample size from * @param File open text file to read sample size from
* @return Sample size * @return Sample size
* @note Globals: None * @note Globals: None
* @note Exceptions: ILLEGALSAMPLESIZE illegal format or range * @note Exceptions: ILLEGALSAMPLESIZE illegal format or range
* @note History: 6/6/89, DSJ, Created. * @note History: 6/6/89, DSJ, Created.
*/ */
uinT16 ReadSampleSize(FILE *File) { uinT16 ReadSampleSize(FILE *File) {
@ -293,7 +294,7 @@ FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
if (NumFloatsRead != 1) { if (NumFloatsRead != 1) {
if ((NumFloatsRead == EOF) && (i == 0)) { if ((NumFloatsRead == EOF) && (i == 0)) {
if (needs_free) { if (needs_free) {
Efree(Buffer); Efree(Buffer);
} }
return NULL; return NULL;
} else { } else {
@ -315,8 +316,7 @@ FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
* @note Exceptions: None * @note Exceptions: None
* @note History: 6/6/89, DSJ, Created. * @note History: 6/6/89, DSJ, Created.
*/ */
void void WriteParamDesc(FILE *File, uinT16 N, const PARAM_DESC ParamDesc[]) {
WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]) {
int i; int i;
for (i = 0; i < N; i++) { for (i = 0; i < N; i++) {
@ -446,15 +446,10 @@ void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
* @note History: 6/12/89, DSJ, Created. * @note History: 6/12/89, DSJ, Created.
*/ */
void WriteProtoList( void WriteProtoList(FILE *File, uinT16 N, PARAM_DESC ParamDesc[],
FILE *File, LIST ProtoList, BOOL8 WriteSigProtos,
uinT16 N, BOOL8 WriteInsigProtos) {
PARAM_DESC ParamDesc[], PROTOTYPE *Proto;
LIST ProtoList,
BOOL8 WriteSigProtos,
BOOL8 WriteInsigProtos)
{
PROTOTYPE *Proto;
/* write file header */ /* write file header */
fprintf(File,"%0d\n",N); fprintf(File,"%0d\n",N);
@ -464,8 +459,8 @@ void WriteProtoList(
iterate(ProtoList) iterate(ProtoList)
{ {
Proto = (PROTOTYPE *) first_node ( ProtoList ); Proto = (PROTOTYPE *) first_node ( ProtoList );
if (( Proto->Significant && WriteSigProtos ) || if ((Proto->Significant && WriteSigProtos) ||
( ! Proto->Significant && WriteInsigProtos ) ) (!Proto->Significant && WriteInsigProtos))
WritePrototype( File, N, Proto ); WritePrototype(File, N, Proto);
} }
} }

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: clusttool.h ** Filename: clusttool.h
** Purpose: Definition of clustering utility tools ** Purpose: Definition of clustering utility tools
** Author: Dan Johnson ** Author: Dan Johnson
** History: 6/6/89, DSJ, Created. ** History: 6/6/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -36,7 +36,7 @@ PROTOSTYLE ReadProtoStyle(FILE *File);
FLOAT32 *ReadNFloats (FILE * File, uinT16 N, FLOAT32 Buffer[]); FLOAT32 *ReadNFloats (FILE * File, uinT16 N, FLOAT32 Buffer[]);
void WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]); void WriteParamDesc(FILE *File, uinT16 N, const PARAM_DESC ParamDesc[]);
void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto); void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto);
@ -44,13 +44,9 @@ void WriteNFloats (FILE * File, uinT16 N, FLOAT32 Array[]);
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle); void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle);
void WriteProtoList( void WriteProtoList(FILE *File, uinT16 N, PARAM_DESC ParamDesc[],
FILE *File, LIST ProtoList, BOOL8 WriteSigProtos,
uinT16 N, BOOL8 WriteInsigProtos);
PARAM_DESC ParamDesc[],
LIST ProtoList,
BOOL8 WriteSigProtos,
BOOL8 WriteInsigProtos);
//--------------Global Data Definitions and Declarations--------------------- //--------------Global Data Definitions and Declarations---------------------
// define errors that can be trapped // define errors that can be trapped

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: cutoffs.c ** Filename: cutoffs.c
** Purpose: Routines to manipulate an array of class cutoffs. ** Purpose: Routines to manipulate an array of class cutoffs.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Wed Feb 20 09:28:51 1991, DSJ, Created. ** History: Wed Feb 20 09:28:51 1991, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: featdefs.c ** Filename: featdefs.c
** Purpose: Definitions of currently defined feature types. ** Purpose: Definitions of currently defined feature types.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Mon May 21 10:26:21 1990, DSJ, Created. ** History: Mon May 21 10:26:21 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -289,13 +289,13 @@ CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
* the feature type for the feature with the specified short * the feature type for the feature with the specified short
* name. Trap an error if the specified name is not found. * name. Trap an error if the specified name is not found.
* *
* Globals: * Globals:
* - none * - none
* *
* @param FeatureDefs definitions of feature types/extractors * @param FeatureDefs definitions of feature types/extractors
* @param ShortName short name of a feature type * @param ShortName short name of a feature type
* @return Feature type which corresponds to ShortName. * @return Feature type which corresponds to ShortName.
* @note Exceptions: * @note Exceptions:
* - ILLEGAL_SHORT_NAME * - ILLEGAL_SHORT_NAME
* @note History: Wed May 23 15:36:05 1990, DSJ, Created. * @note History: Wed May 23 15:36:05 1990, DSJ, Created.
*/ */

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: fpoint.c ** Filename: fpoint.c
** Purpose: Abstract data type for a 2D point (floating point coords) ** Purpose: Abstract data type for a 2D point (floating point coords)
** Author: Dan Johnson ** Author: Dan Johnson
** History: Thu Apr 12 10:44:15 1990, DSJ, Created. ** History: Thu Apr 12 10:44:15 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -58,5 +58,4 @@ FLOAT32 NormalizedAngleFrom(FPOINT *Point1,
if (Angle < 0.0 || Angle >= FullScale) if (Angle < 0.0 || Angle >= FullScale)
Angle = 0.0; Angle = 0.0;
return (Angle); return (Angle);
} }

View File

@ -520,7 +520,7 @@ bool ExtractIntFeat(const TBLOB& blob,
tesseract::Classify::ExtractFeatures(blob, nonlinear_norm, tesseract::Classify::ExtractFeatures(blob, nonlinear_norm,
&bl_features, &cn_features, results, &bl_features, &cn_features, results,
NULL); NULL);
if (bl_features.size() == 0 || cn_features.size() == 0 || if (bl_features.empty() || cn_features.empty() ||
bl_features.size() > MAX_NUM_INT_FEATURES || bl_features.size() > MAX_NUM_INT_FEATURES ||
cn_features.size() > MAX_NUM_INT_FEATURES) { cn_features.size() > MAX_NUM_INT_FEATURES) {
return false; // Feature extraction failed. return false; // Feature extraction failed.

View File

@ -295,7 +295,8 @@ class ClassPruner {
HeapSort(num_classes_, sort_key_, sort_index_); HeapSort(num_classes_, sort_key_, sort_index_);
} }
/** Prints debug info on the class pruner matches for the pruned classes only. */ /** Prints debug info on the class pruner matches for the pruned classes only.
*/
void DebugMatch(const Classify& classify, void DebugMatch(const Classify& classify,
const INT_TEMPLATES_STRUCT* int_templates, const INT_TEMPLATES_STRUCT* int_templates,
const INT_FEATURE_STRUCT* features) const { const INT_FEATURE_STRUCT* features) const {
@ -370,8 +371,9 @@ class ClassPruner {
private: private:
/** Array[rounded_classes_] of initial counts for each class. */ /** Array[rounded_classes_] of initial counts for each class. */
int *class_count_; int *class_count_;
/// Array[rounded_classes_] of modified counts for each class after normalizing /// Array[rounded_classes_] of modified counts for each class after
/// for expected number of features, disabled classes, fragments, and xheights. /// normalizing for expected number of features, disabled classes, fragments,
/// and xheights.
int *norm_count_; int *norm_count_;
/** Array[rounded_classes_ +1] of pruned counts that gets sorted */ /** Array[rounded_classes_ +1] of pruned counts that gets sorted */
int *sort_key_; int *sort_key_;
@ -402,8 +404,9 @@ class ClassPruner {
* normalization process (by CLASS_INDEX) * normalization process (by CLASS_INDEX)
* @param expected_num_features Array of expected number of features * @param expected_num_features Array of expected number of features
* for each class (by CLASS_INDEX) * for each class (by CLASS_INDEX)
* @param results Sorted Array of pruned classes. Must be an array * @param results Sorted Array of pruned classes. Must be an
* of size at least int_templates->NumClasses. * array of size at least
* int_templates->NumClasses.
* @param keep_this * @param keep_this
*/ */
int Classify::PruneClasses(const INT_TEMPLATES_STRUCT* int_templates, int Classify::PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
@ -606,7 +609,6 @@ int IntegerMatcher::FindGoodProtos(
return NumGoodProtos; return NumGoodProtos;
} }
/** /**
* FindBadFeatures finds all features with maximum feature-evidence < * FindBadFeatures finds all features with maximum feature-evidence <
* AdaptFeatureThresh. The list is ordered by increasing feature number. * AdaptFeatureThresh. The list is ordered by increasing feature number.
@ -701,7 +703,6 @@ void IntegerMatcher::Init(tesseract::IntParam *classify_debug_level) {
evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1); evidence_mult_mask_ = ((1 << kIntEvidenceTruncBits) - 1);
} }
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
Private Code Private Code
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
@ -717,8 +718,6 @@ void ScratchEvidence::ClearFeatureEvidence(const INT_CLASS class_template) {
class_template->NumConfigs * sizeof(feature_evidence_[0])); class_template->NumConfigs * sizeof(feature_evidence_[0]));
} }
/** /**
* Print debugging information for Configuations * Print debugging information for Configuations
* @return none * @return none
@ -742,7 +741,6 @@ void IMDebugConfiguration(int FeatureNum,
cprintf ("\n"); cprintf ("\n");
} }
/** /**
* Print debugging information for Configuations * Print debugging information for Configuations
* @return none * @return none
@ -795,10 +793,10 @@ int IntegerMatcher::UpdateTablesForFeature(
uinT32 XFeatureAddress; uinT32 XFeatureAddress;
uinT32 YFeatureAddress; uinT32 YFeatureAddress;
uinT32 ThetaFeatureAddress; uinT32 ThetaFeatureAddress;
uinT8 *UINT8Pointer; uinT8* UINT8Pointer;
int ProtoIndex; int ProtoIndex;
uinT8 Temp; uinT8 Temp;
int *IntPointer; int* IntPointer;
int ConfigNum; int ConfigNum;
inT32 M3; inT32 M3;
inT32 A3; inT32 A3;
@ -916,7 +914,6 @@ int IntegerMatcher::UpdateTablesForFeature(
return SumOverConfigs; return SumOverConfigs;
} }
/** /**
* Print debugging information for Configuations * Print debugging information for Configuations
* @return none * @return none
@ -1165,8 +1162,6 @@ void ScratchEvidence::UpdateSumOfProtoEvidences(
} }
} }
/** /**
* Normalize Sum of Proto and Feature Evidence by dividing by the sum of * Normalize Sum of Proto and Feature Evidence by dividing by the sum of
* the Feature Lengths and the Proto Lengths for each configuration. * the Feature Lengths and the Proto Lengths for each configuration.
@ -1180,7 +1175,6 @@ void ScratchEvidence::NormalizeSums(
} }
} }
/** /**
* Find the best match for the current class and update the Result * Find the best match for the current class and update the Result
* with the configuration and match rating. * with the configuration and match rating.

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: intmatcher.h ** Filename: intmatcher.h
** Purpose: Interface to high level generic classifier routines. ** Purpose: Interface to high level generic classifier routines.
** Author: Robert Moss ** Author: Robert Moss
** History: Wed Feb 13 15:24:15 MST 1991, RWM, Created. ** History: Wed Feb 13 15:24:15 MST 1991, RWM, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -46,9 +46,7 @@
#include "config_auto.h" #include "config_auto.h"
#endif #endif
using tesseract::FontInfo;
using tesseract::FontSet; using tesseract::FontSet;
using tesseract::FontSpacingInfo;
/* match debug display constants*/ /* match debug display constants*/
#define PROTO_PRUNER_SCALE (4.0) #define PROTO_PRUNER_SCALE (4.0)
@ -326,10 +324,8 @@ int AddIntProto(INT_CLASS Class) {
Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0); Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);
return (Index); return (Index);
} }
/** /**
* This routine adds Proto to the class pruning tables * This routine adds Proto to the class pruning tables
* for the specified class in Templates. * for the specified class in Templates.
@ -372,7 +368,6 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
} }
} /* AddProtoToClassPruner */ } /* AddProtoToClassPruner */
/** /**
* This routine updates the proto pruner lookup tables * This routine updates the proto pruner lookup tables
* for Class to include a new proto identified by ProtoId * for Class to include a new proto identified by ProtoId
@ -432,7 +427,6 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug); FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);
} /* AddProtoToProtoPruner */ } /* AddProtoToProtoPruner */
/** /**
* Returns a quantized bucket for the given param shifted by offset, * Returns a quantized bucket for the given param shifted by offset,
* notionally (param + offset) * num_buckets, but clipped and casted to the * notionally (param + offset) * num_buckets, but clipped and casted to the
@ -550,7 +544,6 @@ void Classify::ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) {
P->A, P->B, P->C, Class->ProtoLengths[ProtoId]); P->A, P->B, P->C, Class->ProtoLengths[ProtoId]);
} /* ConvertProto */ } /* ConvertProto */
/** /**
* This routine converts from the old floating point format * This routine converts from the old floating point format
* to the new integer format. * to the new integer format.
@ -627,7 +620,7 @@ INT_TEMPLATES Classify::CreateIntTemplates(CLASSES FloatProtos,
* @note Exceptions: none * @note Exceptions: none
* @note History: Thu Mar 21 14:45:04 1991, DSJ, Created. * @note History: Thu Mar 21 14:45:04 1991, DSJ, Created.
*/ */
void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence) { void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence) {
ScrollView::Color color = GetMatchColorFor(Evidence); ScrollView::Color color = GetMatchColorFor(Evidence);
RenderIntFeature(IntMatchWindow, Feature, color); RenderIntFeature(IntMatchWindow, Feature, color);
if (FeatureDisplayWindow) { if (FeatureDisplayWindow) {
@ -635,7 +628,6 @@ void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence) {
} }
} /* DisplayIntFeature */ } /* DisplayIntFeature */
/** /**
* This routine renders the specified proto into a * This routine renders the specified proto into a
* global display list. * global display list.
@ -720,7 +712,6 @@ void free_int_class(INT_CLASS int_class) {
Efree(int_class); Efree(int_class);
} }
/** /**
* This routine allocates a new set of integer templates * This routine allocates a new set of integer templates
* initialized to hold 0 classes. * initialized to hold 0 classes.
@ -1218,7 +1209,6 @@ FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) {
} /* BucketStart */ } /* BucketStart */
/** /**
* This routine returns the parameter value which * This routine returns the parameter value which
* corresponds to the end of the specified bucket. * corresponds to the end of the specified bucket.
@ -1236,7 +1226,6 @@ FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) {
return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset); return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
} /* BucketEnd */ } /* BucketEnd */
/** /**
* This routine fills in the section of a class pruner * This routine fills in the section of a class pruner
* corresponding to a single x value for a single proto of * corresponding to a single x value for a single proto of
@ -1284,7 +1273,6 @@ void DoFill(FILL_SPEC *FillSpec,
} }
} /* DoFill */ } /* DoFill */
/** /**
* Return TRUE if the specified table filler is done, i.e. * Return TRUE if the specified table filler is done, i.e.
* if it has no more lines to fill. * if it has no more lines to fill.
@ -1306,7 +1294,6 @@ BOOL8 FillerDone(TABLE_FILLER *Filler) {
} /* FillerDone */ } /* FillerDone */
/** /**
* This routine sets Bit in each bit vector whose * This routine sets Bit in each bit vector whose
* bucket lies within the range Center +- Spread. The fill * bucket lies within the range Center +- Spread. The fill
@ -1349,7 +1336,6 @@ void FillPPCircularBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
} /* FillPPCircularBits */ } /* FillPPCircularBits */
/** /**
* This routine sets Bit in each bit vector whose * This routine sets Bit in each bit vector whose
* bucket lies within the range Center +- Spread. The fill * bucket lies within the range Center +- Spread. The fill
@ -1516,7 +1502,6 @@ void GetCPPadsForLevel(int Level,
} /* GetCPPadsForLevel */ } /* GetCPPadsForLevel */
/** /**
* @param Evidence evidence value to return color for * @param Evidence evidence value to return color for
* @return Color which corresponds to specified Evidence value. * @return Color which corresponds to specified Evidence value.
@ -1538,7 +1523,6 @@ ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) {
return ScrollView::BLUE; return ScrollView::BLUE;
} /* GetMatchColorFor */ } /* GetMatchColorFor */
/** /**
* This routine returns (in Fill) the specification of * This routine returns (in Fill) the specification of
* the next line to be filled from Filler. FillerDone() should * the next line to be filled from Filler. FillerDone() should
@ -1589,7 +1573,6 @@ void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
} /* GetNextFill */ } /* GetNextFill */
/** /**
* This routine computes a data structure (Filler) * This routine computes a data structure (Filler)
* which can be used to fill in a rectangle surrounding * which can be used to fill in a rectangle surrounding
@ -1723,8 +1706,10 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
/* translate into bucket positions and deltas */ /* translate into bucket positions and deltas */
Filler->X = Bucket8For(Start.x, XS, NB); Filler->X = Bucket8For(Start.x, XS, NB);
Filler->StartDelta = -(inT16) ((Sin / Cos) * 256); Filler->StartDelta = static_cast<inT16>(ClipToRange<int>(
Filler->EndDelta = (inT16) ((Cos / Sin) * 256); -IntCastRounded((Sin / Cos) * 256), MIN_INT16, MAX_INT16));
Filler->EndDelta = static_cast<inT16>(ClipToRange<int>(
IntCastRounded((Cos / Sin) * 256), MIN_INT16, MAX_INT16));
XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x; XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
YAdjust = XAdjust * Sin / Cos; YAdjust = XAdjust * Sin / Cos;
@ -1787,7 +1772,6 @@ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
window->DrawTo(X + Dx, Y + Dy); window->DrawTo(X + Dx, Y + Dy);
} /* RenderIntFeature */ } /* RenderIntFeature */
/** /**
* This routine extracts the parameters of the specified * This routine extracts the parameters of the specified
* proto from the class description and adds a rendering of * proto from the class description and adds a rendering of

View File

@ -52,7 +52,7 @@ class FCOORD;
#define NUM_CP_BUCKETS 24 #define NUM_CP_BUCKETS 24
#define CLASSES_PER_CP 32 #define CLASSES_PER_CP 32
#define NUM_BITS_PER_CLASS 2 #define NUM_BITS_PER_CLASS 2
#define CLASS_PRUNER_CLASS_MASK (~(~0 << NUM_BITS_PER_CLASS)) #define CLASS_PRUNER_CLASS_MASK (~(~0u << NUM_BITS_PER_CLASS))
#define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS) #define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
#define PROTOS_PER_PP_WERD BITS_PER_WERD #define PROTOS_PER_PP_WERD BITS_PER_WERD
#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS) #define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)

View File

@ -70,11 +70,11 @@ class MinK {
const Element* elements() { return elements_; } const Element* elements() { return elements_; }
private: private:
const Key max_key_; //< the maximum possible Key const Key max_key_; //< the maximum possible Key
Element* elements_; //< unsorted array of elements Element *elements_; //< unsorted array of elements
int elements_count_; //< the number of results collected so far int elements_count_; //< the number of results collected so far
int k_; //< the number of results we want from the search int k_; //< the number of results we want from the search
int max_index_; //< the index of the result with the largest key int max_index_; //< the index of the result with the largest key
}; };
template<typename Key, typename Value> template<typename Key, typename Value>
@ -117,7 +117,8 @@ bool MinK<Key, Value>::insert(Key key, Value value) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Helper class for searching for the k closest points to query_point in tree. */ /** Helper class for searching for the k closest points to query_point in tree.
*/
class KDTreeSearch { class KDTreeSearch {
public: public:
KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest); KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest);
@ -241,14 +242,13 @@ void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data) {
*PtrToNode = MakeKDNode(Tree, Key, (void *) Data, Level); *PtrToNode = MakeKDNode(Tree, Key, (void *) Data, Level);
} /* KDStore */ } /* KDStore */
/** /**
* This routine deletes a node from Tree. The node to be * This routine deletes a node from Tree. The node to be
* deleted is specified by the Key for the node and the Data * deleted is specified by the Key for the node and the Data
* contents of the node. These two pointers must be identical * contents of the node. These two pointers must be identical
* to the pointers that were used for the node when it was * to the pointers that were used for the node when it was
* originally stored in the tree. A node will be deleted from * originally stored in the tree. A node will be deleted from
* the tree only if its key and data pointers are identical * the tree only if its key and data pointers are identical
* to Key and Data respectively. The tree is re-formed by removing * to Key and Data respectively. The tree is re-formed by removing
* the affected subtree and inserting all elements but the root. * the affected subtree and inserting all elements but the root.
* *
@ -298,7 +298,6 @@ KDDelete (KDTREE * Tree, FLOAT32 Key[], void *Data) {
} }
} /* KDDelete */ } /* KDDelete */
/** /**
* This routine searches the K-D tree specified by Tree and * This routine searches the K-D tree specified by Tree and
* finds the QuerySize nearest neighbors of Query. All neighbors * finds the QuerySize nearest neighbors of Query. All neighbors
@ -442,7 +441,7 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
*Returns the Euclidean distance squared between p1 and p2 for all essential *Returns the Euclidean distance squared between p1 and p2 for all essential
* dimensions. * dimensions.
* @param k keys are in k-space * @param k keys are in k-space
@ -541,7 +540,6 @@ void Walk(KDTREE *tree, void_proc action, void *context,
Walk(tree, action, context, sub_tree->Right, NextLevel(tree, level)); Walk(tree, action, context, sub_tree->Right, NextLevel(tree, level));
} }
/** Given a subtree nodes, insert all of its elements into tree. */ /** Given a subtree nodes, insert all of its elements into tree. */
void InsertNodes(KDTREE *tree, KDNODE *nodes) { void InsertNodes(KDTREE *tree, KDNODE *nodes) {
if (nodes == NULL) if (nodes == NULL)

View File

@ -362,9 +362,11 @@ bool MasterTrainer::LoadFontInfo(const char* filename) {
fontinfo.name = font_name; fontinfo.name = font_name;
fontinfo.properties = 0; fontinfo.properties = 0;
fontinfo.universal_id = 0; fontinfo.universal_id = 0;
if (tfscanf(fp, "%1024s %i %i %i %i %i\n", font_name, if (tfscanf(fp, "%1024s %i %i %i %i %i\n", font_name, &italic, &bold,
&italic, &bold, &fixed, &serif, &fraktur) != 6) &fixed, &serif, &fraktur) != 6) {
delete[] font_name;
continue; continue;
}
fontinfo.properties = fontinfo.properties =
(italic << 0) + (italic << 0) +
(bold << 1) + (bold << 1) +
@ -373,6 +375,8 @@ bool MasterTrainer::LoadFontInfo(const char* filename) {
(fraktur << 4); (fraktur << 4);
if (!fontinfo_table_.contains(fontinfo)) { if (!fontinfo_table_.contains(fontinfo)) {
fontinfo_table_.push_back(fontinfo); fontinfo_table_.push_back(fontinfo);
} else {
delete[] font_name;
} }
} }
fclose(fp); fclose(fp);

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: mf.c ** Filename: mf.c
** Purpose: Micro-feature interface to flexible feature extractor. ** Purpose: Micro-feature interface to flexible feature extractor.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Thu May 24 09:08:38 1990, DSJ, Created. ** History: Thu May 24 09:08:38 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -36,7 +36,7 @@
* Call the old micro-feature extractor and then copy * Call the old micro-feature extractor and then copy
* the features into the new format. Then deallocate the * the features into the new format. Then deallocate the
* old micro-features. * old micro-features.
* @param Blob blob to extract micro-features from * @param Blob blob to extract micro-features from
* @param cn_denorm control parameter to feature extractor. * @param cn_denorm control parameter to feature extractor.
* @return Micro-features for Blob. * @return Micro-features for Blob.
* @note Exceptions: none * @note Exceptions: none

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: mfdefs.c ** Filename: mfdefs.c
** Purpose: Basic routines for manipulating micro-features ** Purpose: Basic routines for manipulating micro-features
** Author: Dan Johnson ** Author: Dan Johnson
** History: Mon Jan 22 08:48:58 1990, DSJ, Created. ** History: Mon Jan 22 08:48:58 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -32,7 +32,7 @@
* @return New MICROFEATURE * @return New MICROFEATURE
* @note History: 7/27/89, DSJ, Created. * @note History: 7/27/89, DSJ, Created.
*/ */
MICROFEATURE NewMicroFeature() { MICROFEATURE NewMicroFeature() {
return ((MICROFEATURE) Emalloc (sizeof (MFBLOCK))); return ((MICROFEATURE) Emalloc (sizeof (MFBLOCK)));
} /* NewMicroFeature */ } /* NewMicroFeature */
@ -41,10 +41,10 @@ MICROFEATURE NewMicroFeature() {
/** /**
* This routine deallocates all of the memory consumed by * This routine deallocates all of the memory consumed by
* a list of micro-features. * a list of micro-features.
* @param MicroFeatures list of micro-features to be freed * @param MicroFeatures list of micro-features to be freed
* @return none * @return none
* @note History: 7/27/89, DSJ, Created. * @note History: 7/27/89, DSJ, Created.
*/ */
void FreeMicroFeatures(MICROFEATURES MicroFeatures) { void FreeMicroFeatures(MICROFEATURES MicroFeatures) {
destroy_nodes(MicroFeatures, Efree); destroy_nodes(MicroFeatures, Efree);
} /* FreeMicroFeatures */ } /* FreeMicroFeatures */

View File

@ -35,7 +35,8 @@
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** Convert a blob into a list of MFOUTLINEs (float-based microfeature format). */ /** Convert a blob into a list of MFOUTLINEs (float-based microfeature format).
*/
LIST ConvertBlob(TBLOB *blob) { LIST ConvertBlob(TBLOB *blob) {
LIST outlines = NIL_LIST; LIST outlines = NIL_LIST;
return (blob == NULL) return (blob == NULL)
@ -344,7 +345,6 @@ void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction) {
} /* ChangeDirection */ } /* ChangeDirection */
/** /**
* This routine normalizes each point in Outline by * This routine normalizes each point in Outline by
* translating it to the specified center and scaling it * translating it to the specified center and scaling it
@ -378,7 +378,6 @@ void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm) {
} /* CharNormalizeOutline */ } /* CharNormalizeOutline */
/** /**
* This routine computes the slope from Start to Finish and * This routine computes the slope from Start to Finish and
* and then computes the approximate direction of the line * and then computes the approximate direction of the line

View File

@ -128,7 +128,6 @@ FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) {
return (Orientation); return (Orientation);
} /* ComputeOrientation */ } /* ComputeOrientation */
/** /**
* Convert Outline to MicroFeatures * Convert Outline to MicroFeatures
* @param Outline outline to extract micro-features from * @param Outline outline to extract micro-features from
@ -164,7 +163,6 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline,
return (MicroFeatures); return (MicroFeatures);
} /* ConvertToMicroFeatures */ } /* ConvertToMicroFeatures */
/** /**
* This routine computes the feature parameters which describe * This routine computes the feature parameters which describe
* the micro-feature that starts and Start and ends at End. * the micro-feature that starts and Start and ends at End.
@ -178,7 +176,7 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline,
* @return New micro-feature or NULL if the feature was rejected. * @return New micro-feature or NULL if the feature was rejected.
* @note Globals: none * @note Globals: none
* @note Exceptions: none * @note Exceptions: none
* @note History: * @note History:
* - 7/26/89, DSJ, Created. * - 7/26/89, DSJ, Created.
* - 11/17/89, DSJ, Added handling for Start and End same point. * - 11/17/89, DSJ, Added handling for Start and End same point.
*/ */

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: mfx.h ** Filename: mfx.h
** Purpose: Definition of micro-feature extraction routines ** Purpose: Definition of micro-feature extraction routines
** Author: Dan Johnson ** Author: Dan Johnson
** History: 5/29/89, DSJ, Created. ** History: 5/29/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: normfeat.c ** Filename: normfeat.c
** Purpose: Definition of char normalization features. ** Purpose: Definition of char normalization features.
** Author: Dan Johnson ** Author: Dan Johnson
** History: 12/14/90, DSJ, Created. ** History: 12/14/90, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -33,7 +33,6 @@ FLOAT32 ActualOutlineLength(FEATURE Feature) {
return (Feature->Params[CharNormLength] * LENGTH_COMPRESSION); return (Feature->Params[CharNormLength] * LENGTH_COMPRESSION);
} }
/** /**
* Return the character normalization feature for a blob. * Return the character normalization feature for a blob.
* *

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: normmatch.c ** Filename: normmatch.c
** Purpose: Simple matcher based on character normalization features. ** Purpose: Simple matcher based on character normalization features.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Wed Dec 19 16:18:06 1990, DSJ, Created. ** History: Wed Dec 19 16:18:06 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -197,10 +197,10 @@ double NormEvidenceOf(register double NormAdj) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**
* This routine dumps out detailed normalization match info. * This routine dumps out detailed normalization match info.
* @param File open text file to dump match debug info to * @param File open text file to dump match debug info to
* @param NumParams # of parameters in proto and feature * @param NumParams # of parameters in proto and feature
* @param Proto[] array of prototype parameters * @param Proto[] array of prototype parameters
* @param Feature[] array of feature parameters * @param Feature[] array of feature parameters
* Globals: none * Globals: none
* @return none * @return none
* @note Exceptions: none * @note Exceptions: none

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: features.c ** Filename: features.c
** Purpose: Generic definition of a feature. ** Purpose: Generic definition of a feature.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Mon May 21 10:49:04 1990, DSJ, Created. ** History: Mon May 21 10:49:04 1990, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -66,12 +66,11 @@ void FreeFeature(FEATURE Feature) {
} /* FreeFeature */ } /* FreeFeature */
/** /**
* Release the memory consumed by the specified feature * Release the memory consumed by the specified feature
* set. This routine also frees the memory consumed by the * set. This routine also frees the memory consumed by the
* features contained in the set. * features contained in the set.
* @param FeatureSet set of features to be freed * @param FeatureSet set of features to be freed
* @return none * @return none
* @note History: Mon May 21 13:59:46 1990, DSJ, Created. * @note History: Mon May 21 13:59:46 1990, DSJ, Created.
*/ */
@ -85,11 +84,10 @@ void FreeFeatureSet(FEATURE_SET FeatureSet) {
} }
} /* FreeFeatureSet */ } /* FreeFeatureSet */
/** /**
* Allocate and return a new feature of the specified * Allocate and return a new feature of the specified
* type. * type.
* @param FeatureDesc description of feature to be created. * @param FeatureDesc description of feature to be created.
* @return New #FEATURE. * @return New #FEATURE.
* @note History: Mon May 21 14:06:42 1990, DSJ, Created. * @note History: Mon May 21 14:06:42 1990, DSJ, Created.
*/ */
@ -105,11 +103,10 @@ FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) {
} /* NewFeature */ } /* NewFeature */
/** /**
* Allocate and return a new feature set large enough to * Allocate and return a new feature set large enough to
* hold the specified number of features. * hold the specified number of features.
* @param NumFeatures maximum # of features to be put in feature set * @param NumFeatures maximum # of features to be put in feature set
* @return New #FEATURE_SET. * @return New #FEATURE_SET.
* @note History: Mon May 21 14:22:40 1990, DSJ, Created. * @note History: Mon May 21 14:22:40 1990, DSJ, Created.
*/ */
@ -124,7 +121,6 @@ FEATURE_SET NewFeatureSet(int NumFeatures) {
} /* NewFeatureSet */ } /* NewFeatureSet */
/** /**
* Create a new feature of the specified type and read in * Create a new feature of the specified type and read in
* the value of its parameters from File. The extra penalty * the value of its parameters from File. The extra penalty
@ -135,10 +131,11 @@ FEATURE_SET NewFeatureSet(int NumFeatures) {
* @param File open text file to read feature from * @param File open text file to read feature from
* @param FeatureDesc specifies type of feature to read from File * @param FeatureDesc specifies type of feature to read from File
* @return New #FEATURE read from File. * @return New #FEATURE read from File.
* @note Exceptions: #ILLEGAL_FEATURE_PARAM if text file doesn't match expected format * @note Exceptions: #ILLEGAL_FEATURE_PARAM if text file doesn't match expected
* format
* @note History: Wed May 23 08:53:16 1990, DSJ, Created. * @note History: Wed May 23 08:53:16 1990, DSJ, Created.
*/ */
FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) { FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
FEATURE Feature; FEATURE Feature;
int i; int i;
@ -153,7 +150,6 @@ FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) {
return (Feature); return (Feature);
} /* ReadFeature */ } /* ReadFeature */
/** /**
* Create a new feature set of the specified type and read in * Create a new feature set of the specified type and read in
* the features from File. The correct text representation * the features from File. The correct text representation
@ -165,7 +161,7 @@ FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) {
* @return New feature set read from File. * @return New feature set read from File.
* @note History: Wed May 23 09:17:31 1990, DSJ, Created. * @note History: Wed May 23 09:17:31 1990, DSJ, Created.
*/ */
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) { FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
FEATURE_SET FeatureSet; FEATURE_SET FeatureSet;
int NumFeatures; int NumFeatures;
int i; int i;
@ -180,7 +176,6 @@ FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) {
return (FeatureSet); return (FeatureSet);
} /* ReadFeatureSet */ } /* ReadFeatureSet */
/** /**
* Appends a textual representation of Feature to str. * Appends a textual representation of Feature to str.
* This representation is simply a list of the N parameters * This representation is simply a list of the N parameters
@ -203,7 +198,6 @@ void WriteFeature(FEATURE Feature, STRING* str) {
*str += "\n"; *str += "\n";
} /* WriteFeature */ } /* WriteFeature */
/** /**
* Write a textual representation of FeatureSet to File. * Write a textual representation of FeatureSet to File.
* This representation is an integer specifying the number of * This representation is an integer specifying the number of
@ -224,7 +218,6 @@ void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str) {
} }
} /* WriteFeatureSet */ } /* WriteFeatureSet */
/** /**
* Write a textual representation of FeatureDesc to File * Write a textual representation of FeatureDesc to File
* in the old format (i.e. the format used by the clusterer). * in the old format (i.e. the format used by the clusterer).
@ -240,7 +233,7 @@ void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str) {
* @return none * @return none
* @note History: Fri May 25 15:27:18 1990, DSJ, Created. * @note History: Fri May 25 15:27:18 1990, DSJ, Created.
*/ */
void WriteOldParamDesc(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) { void WriteOldParamDesc(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
int i; int i;
fprintf (File, "%d\n", FeatureDesc->NumParams); fprintf (File, "%d\n", FeatureDesc->NumParams);

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: outfeat.c ** Filename: outfeat.c
** Purpose: Definition of outline-features. ** Purpose: Definition of outline-features.
** Author: Dan Johnson ** Author: Dan Johnson
** History: 11/13/90, DSJ, Created. ** History: 11/13/90, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -40,7 +40,7 @@ namespace tesseract {
* @return Outline-features for Blob. * @return Outline-features for Blob.
* @note Globals: none * @note Globals: none
* @note Exceptions: none * @note Exceptions: none
* @note History: * @note History:
* - 11/13/90, DSJ, Created. * - 11/13/90, DSJ, Created.
* - 05/24/91, DSJ, Updated for either char or baseline normalize. * - 05/24/91, DSJ, Updated for either char or baseline normalize.
*/ */
@ -115,7 +115,7 @@ void AddOutlineFeatureToSet(FPOINT *Start,
* @return none (results are returned in FeatureSet) * @return none (results are returned in FeatureSet)
* @note Globals: none * @note Globals: none
* @note Exceptions: none * @note Exceptions: none
* @note History: * @note History:
* - 11/13/90, DSJ, Created. * - 11/13/90, DSJ, Created.
* - 5/24/91, DSJ, Added hidden edge capability. * - 5/24/91, DSJ, Added hidden edge capability.
*/ */

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: picofeat.c ** Filename: picofeat.c
** Purpose: Definition of pico-features. ** Purpose: Definition of pico-features.
** Author: Dan Johnson ** Author: Dan Johnson
** History: 9/4/90, DSJ, Created. ** History: 9/4/90, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -98,7 +98,7 @@ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
* nearest whole number of pico-features. The pico-features * nearest whole number of pico-features. The pico-features
* are spaced evenly over the entire segment. * are spaced evenly over the entire segment.
* Globals: * Globals:
* - classify_pico_feature_length length of a single pico-feature * - classify_pico_feature_length length of a single pico-feature
* @param Start starting point of pico-feature * @param Start starting point of pico-feature
* @param End ending point of pico-feature * @param End ending point of pico-feature
* @param FeatureSet set to add pico-feature to * @param FeatureSet set to add pico-feature to

View File

@ -176,7 +176,7 @@ void ShapeClassifier::UnicharPrintResults(
for (int i = 0; i < results.size(); ++i) { for (int i = 0; i < results.size(); ++i) {
tprintf("%g: c_id=%d=%s", results[i].rating, results[i].unichar_id, tprintf("%g: c_id=%d=%s", results[i].rating, results[i].unichar_id,
GetUnicharset().id_to_unichar(results[i].unichar_id)); GetUnicharset().id_to_unichar(results[i].unichar_id));
if (results[i].fonts.size() != 0) { if (!results[i].fonts.empty()) {
tprintf(" Font Vector:"); tprintf(" Font Vector:");
for (int f = 0; f < results[i].fonts.size(); ++f) { for (int f = 0; f < results[i].fonts.size(); ++f) {
tprintf(" %d", results[i].fonts[f].fontinfo_id); tprintf(" %d", results[i].fonts[f].fontinfo_id);

View File

@ -400,7 +400,7 @@ bool CubeSearchObject::ComputeSpaceCosts() {
float prob = 0.0; float prob = 0.0;
// gap is too small => no space // gap is too small => no space
if (gap < min_spc_gap_) { if (gap < min_spc_gap_ || max_spc_gap_ == min_spc_gap_) {
prob = 0.0; prob = 0.0;
} else if (gap > max_spc_gap_) { } else if (gap > max_spc_gap_) {
// gap is too big => definite space // gap is too big => definite space

View File

@ -330,7 +330,7 @@ bool HybridNeuralNetCharClassifier::LoadNets(const string &data_file_path,
// split into lines // split into lines
vector<string> str_vec; vector<string> str_vec;
CubeUtils::SplitStringUsing(str, "\r\n", &str_vec); CubeUtils::SplitStringUsing(str, "\r\n", &str_vec);
if (str_vec.size() <= 0) { if (str_vec.empty()) {
return false; return false;
} }

View File

@ -163,7 +163,7 @@ int WordUnigrams::Cost(const char_32 *key_str32,
CubeUtils::SplitStringUsing(key_str, " \t", &words); CubeUtils::SplitStringUsing(key_str, " \t", &words);
// no words => no cost // no words => no cost
if (words.size() <= 0) { if (words.empty()) {
return 0; return 0;
} }

View File

@ -30,29 +30,29 @@ typedef uinT32 *BIT_VECTOR;
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
Public Function Prototypes Public Function Prototypes
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#define zero_all_bits(array,length) \ #define zero_all_bits(array, length) \
{\ { \
int index; /*temporary index*/\ int index; /*temporary index*/ \
\ \
for (index=0;index<length;index++)\ for (index = 0; index < length; index++) \
array[index]=0; /*zero all bits*/\ array[index] = 0; /*zero all bits*/ \
} }
#define set_all_bits(array,length) \ #define set_all_bits(array, length) \
{\ { \
int index; /*temporary index*/\ int index; /*temporary index*/ \
\ \
for (index=0;index<length;index++)\ for (index = 0; index < length; index++) \
array[index]= ~0; /*set all bits*/\ array[index] = ~0; /*set all bits*/ \
} }
#define copy_all_bits(source,dest,length) \ #define copy_all_bits(source, dest, length) \
{\ { \
int index; /*temporary index*/\ int index; /*temporary index*/ \
\ \
for (index=0;index<length;index++)\ for (index = 0; index < length; index++) \
dest[index]=source[index]; /*copy all bits*/\ dest[index] = source[index]; /*copy all bits*/ \
} }
#define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1))) #define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1)))

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: danerror.c ** Filename: danerror.c
** Purpose: Routines for managing error trapping ** Purpose: Routines for managing error trapping
** Author: Dan Johnson ** Author: Dan Johnson
** History: 3/17/89, DSJ, Created. ** History: 3/17/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: efio.c ** Filename: efio.c
** Purpose: Utility I/O routines ** Purpose: Utility I/O routines
** Author: Dan Johnson ** Author: Dan Johnson
** History: 5/21/89, DSJ, Created. ** History: 5/21/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -40,7 +40,7 @@
* @note Exceptions: #FOPENERROR unable to open specified file * @note Exceptions: #FOPENERROR unable to open specified file
* @note History: 5/21/89, DSJ, Created. * @note History: 5/21/89, DSJ, Created.
*/ */
FILE *Efopen(const char *Name, const char *Mode) { FILE *Efopen(const char *Name, const char *Mode) {
FILE *File; FILE *File;
char ErrorMessage[MAXERRORMESSAGE]; char ErrorMessage[MAXERRORMESSAGE];

View File

@ -10,7 +10,7 @@
** History: ** History:
4/3/89, DSJ, Created. 4/3/89, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -206,8 +206,8 @@ void destroy_nodes(LIST list, void_dest destructor) {
destructor = memfree; destructor = memfree;
while (list != NIL_LIST) { while (list != NIL_LIST) {
(*destructor) (first_node (list)); if (first_node(list) != NULL) (*destructor)(first_node(list));
list = pop (list); list = pop(list);
} }
} }

View File

@ -32,28 +32,22 @@ namespace tesseract {
static const int kMinAbsoluteGarbageWordLength = 10; static const int kMinAbsoluteGarbageWordLength = 10;
static const float kMinAbsoluteGarbageAlphanumFrac = 0.5f; static const float kMinAbsoluteGarbageAlphanumFrac = 0.5f;
const int case_state_table[6][4] = { { const int case_state_table[6][4] = {
/* 0. Beginning of word */ {/* 0. Beginning of word */
/* P U L D */ /* P U L D */
/* -1. Error on case */ /* -1. Error on case */
0, 1, 5, 4 0, 1, 5, 4},
}, {/* 1. After initial capital */
{ /* 1. After initial capital */ 0, 3, 2, 4},
0, 3, 2, 4 {/* 2. After lower case */
}, 0, -1, 2, -1},
{ /* 2. After lower case */ {/* 3. After upper case */
0, -1, 2, -1 0, 3, -1, 4},
}, {/* 4. After a digit */
{ /* 3. After upper case */ 0, -1, -1, 4},
0, 3, -1, 4 {/* 5. After initial lower case */
}, 5, -1, 2, -1},
{ /* 4. After a digit */ };
0, -1, -1, 4
},
{ /* 5. After initial lower case */
5, -1, 2, -1
},
};
int Dict::case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset) { int Dict::case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset) {
int state = 0; int state = 0;

View File

@ -30,13 +30,12 @@ namespace tesseract {
class Image; class Image;
Dict::Dict(CCUtil* ccutil) Dict::Dict(CCUtil *ccutil)
: letter_is_okay_(&tesseract::Dict::def_letter_is_okay), : letter_is_okay_(&tesseract::Dict::def_letter_is_okay),
probability_in_context_(&tesseract::Dict::def_probability_in_context), probability_in_context_(&tesseract::Dict::def_probability_in_context),
params_model_classify_(NULL), params_model_classify_(NULL),
ccutil_(ccutil), ccutil_(ccutil),
STRING_MEMBER(user_words_file, "", STRING_MEMBER(user_words_file, "", "A filename of user-provided words.",
"A filename of user-provided words.",
getCCUtil()->params()), getCCUtil()->params()),
STRING_INIT_MEMBER(user_words_suffix, "", STRING_INIT_MEMBER(user_words_suffix, "",
"A suffix of user-provided words located in tessdata.", "A suffix of user-provided words located in tessdata.",
@ -54,33 +53,41 @@ Dict::Dict(CCUtil* ccutil)
getCCUtil()->params()), getCCUtil()->params()),
BOOL_INIT_MEMBER(load_unambig_dawg, true, "Load unambiguous word dawg.", BOOL_INIT_MEMBER(load_unambig_dawg, true, "Load unambiguous word dawg.",
getCCUtil()->params()), getCCUtil()->params()),
BOOL_INIT_MEMBER(load_punc_dawg, true, "Load dawg with punctuation" BOOL_INIT_MEMBER(load_punc_dawg, true,
" patterns.", getCCUtil()->params()), "Load dawg with punctuation"
BOOL_INIT_MEMBER(load_number_dawg, true, "Load dawg with number" " patterns.",
" patterns.", getCCUtil()->params()), getCCUtil()->params()),
BOOL_INIT_MEMBER(load_bigram_dawg, true, "Load dawg with special word " BOOL_INIT_MEMBER(load_number_dawg, true,
"bigrams.", getCCUtil()->params()), "Load dawg with number"
" patterns.",
getCCUtil()->params()),
BOOL_INIT_MEMBER(load_bigram_dawg, true,
"Load dawg with special word "
"bigrams.",
getCCUtil()->params()),
double_MEMBER(xheight_penalty_subscripts, 0.125, double_MEMBER(xheight_penalty_subscripts, 0.125,
"Score penalty (0.1 = 10%) added if there are subscripts " "Score penalty (0.1 = 10%) added if there are subscripts "
"or superscripts in a word, but it is otherwise OK.", "or superscripts in a word, but it is otherwise OK.",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(xheight_penalty_inconsistent, 0.25, double_MEMBER(xheight_penalty_inconsistent, 0.25,
"Score penalty (0.1 = 10%) added if an xheight is " "Score penalty (0.1 = 10%) added if an xheight is "
"inconsistent.", getCCUtil()->params()), "inconsistent.",
getCCUtil()->params()),
double_MEMBER(segment_penalty_dict_frequent_word, 1.0, double_MEMBER(segment_penalty_dict_frequent_word, 1.0,
"Score multiplier for word matches which have good case and" "Score multiplier for word matches which have good case and"
"are frequent in the given language (lower is better).", "are frequent in the given language (lower is better).",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(segment_penalty_dict_case_ok, 1.1, double_MEMBER(segment_penalty_dict_case_ok, 1.1,
"Score multiplier for word matches that have good case " "Score multiplier for word matches that have good case "
"(lower is better).", getCCUtil()->params()), "(lower is better).",
getCCUtil()->params()),
double_MEMBER(segment_penalty_dict_case_bad, 1.3125, double_MEMBER(segment_penalty_dict_case_bad, 1.3125,
"Default score multiplier for word matches, which may have " "Default score multiplier for word matches, which may have "
"case issues (lower is better).", "case issues (lower is better).",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(segment_penalty_ngram_best_choice, 1.24, double_MEMBER(segment_penalty_ngram_best_choice, 1.24,
"Multipler to for the best choice from the ngram model.", "Multipler to for the best choice from the ngram model.",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(segment_penalty_dict_nonword, 1.25, double_MEMBER(segment_penalty_dict_nonword, 1.25,
"Score multiplier for glyph fragment segmentations which " "Score multiplier for glyph fragment segmentations which "
"do not match a dictionary word (lower is better).", "do not match a dictionary word (lower is better).",
@ -88,11 +95,13 @@ Dict::Dict(CCUtil* ccutil)
double_MEMBER(segment_penalty_garbage, 1.50, double_MEMBER(segment_penalty_garbage, 1.50,
"Score multiplier for poorly cased strings that are not in" "Score multiplier for poorly cased strings that are not in"
" the dictionary and generally look like garbage (lower is" " the dictionary and generally look like garbage (lower is"
" better).", getCCUtil()->params()), " better).",
getCCUtil()->params()),
STRING_MEMBER(output_ambig_words_file, "", STRING_MEMBER(output_ambig_words_file, "",
"Output file for ambiguities found in the dictionary", "Output file for ambiguities found in the dictionary",
getCCUtil()->params()), getCCUtil()->params()),
INT_MEMBER(dawg_debug_level, 0, "Set to 1 for general debug info" INT_MEMBER(dawg_debug_level, 0,
"Set to 1 for general debug info"
", to 2 for more details, to 3 to see all the debug messages", ", to 2 for more details, to 3 to see all the debug messages",
getCCUtil()->params()), getCCUtil()->params()),
INT_MEMBER(hyphen_debug_level, 0, "Debug level for hyphenated words.", INT_MEMBER(hyphen_debug_level, 0, "Debug level for hyphenated words.",
@ -109,12 +118,12 @@ Dict::Dict(CCUtil* ccutil)
"Certainty threshold for non-dict words", "Certainty threshold for non-dict words",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(stopper_phase2_certainty_rejection_offset, 1.0, double_MEMBER(stopper_phase2_certainty_rejection_offset, 1.0,
"Reject certainty offset", "Reject certainty offset", getCCUtil()->params()),
getCCUtil()->params()),
INT_MEMBER(stopper_smallword_size, 2, INT_MEMBER(stopper_smallword_size, 2,
"Size of dict word to be treated as non-dict word", "Size of dict word to be treated as non-dict word",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(stopper_certainty_per_char, -0.50, "Certainty to add" double_MEMBER(stopper_certainty_per_char, -0.50,
"Certainty to add"
" for each dict char above small word size.", " for each dict char above small word size.",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(stopper_allowable_character_badness, 3.0, double_MEMBER(stopper_allowable_character_badness, 3.0,
@ -130,9 +139,9 @@ Dict::Dict(CCUtil* ccutil)
"Deprecated- backward compatibility only", "Deprecated- backward compatibility only",
getCCUtil()->params()), getCCUtil()->params()),
INT_MEMBER(tessedit_truncate_wordchoice_log, 10, INT_MEMBER(tessedit_truncate_wordchoice_log, 10,
"Max words to keep in list", "Max words to keep in list", getCCUtil()->params()),
getCCUtil()->params()), STRING_MEMBER(word_to_debug, "",
STRING_MEMBER(word_to_debug, "", "Word for which stopper debug" "Word for which stopper debug"
" information should be printed to stdout", " information should be printed to stdout",
getCCUtil()->params()), getCCUtil()->params()),
STRING_MEMBER(word_to_debug_lengths, "", STRING_MEMBER(word_to_debug_lengths, "",
@ -141,10 +150,10 @@ Dict::Dict(CCUtil* ccutil)
INT_MEMBER(fragments_debug, 0, "Debug character fragments", INT_MEMBER(fragments_debug, 0, "Debug character fragments",
getCCUtil()->params()), getCCUtil()->params()),
BOOL_MEMBER(segment_nonalphabetic_script, false, BOOL_MEMBER(segment_nonalphabetic_script, false,
"Don't use any alphabetic-specific tricks." "Don't use any alphabetic-specific tricks."
"Set to true in the traineddata config file for" "Set to true in the traineddata config file for"
" scripts that are cursive or inherently fixed-pitch", " scripts that are cursive or inherently fixed-pitch",
getCCUtil()->params()), getCCUtil()->params()),
BOOL_MEMBER(save_doc_words, 0, "Save Document Words", BOOL_MEMBER(save_doc_words, 0, "Save Document Words",
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(doc_dict_pending_threshold, 0.0, double_MEMBER(doc_dict_pending_threshold, 0.0,
@ -152,8 +161,10 @@ Dict::Dict(CCUtil* ccutil)
getCCUtil()->params()), getCCUtil()->params()),
double_MEMBER(doc_dict_certainty_threshold, -2.25, double_MEMBER(doc_dict_certainty_threshold, -2.25,
"Worst certainty for words that can be inserted into the" "Worst certainty for words that can be inserted into the"
"document dictionary", getCCUtil()->params()), "document dictionary",
INT_MEMBER(max_permuter_attempts, 10000, "Maximum number of different" getCCUtil()->params()),
INT_MEMBER(max_permuter_attempts, 10000,
"Maximum number of different"
" character choices to consider during permutation." " character choices to consider during permutation."
" This limit is especially useful when user patterns" " This limit is especially useful when user patterns"
" are specified, since overly generic patterns can result in" " are specified, since overly generic patterns can result in"
@ -179,6 +190,7 @@ Dict::Dict(CCUtil* ccutil)
} }
Dict::~Dict() { Dict::~Dict() {
End();
if (hyphen_word_ != NULL) delete hyphen_word_; if (hyphen_word_ != NULL) delete hyphen_word_;
if (output_ambig_words_file_ != NULL) fclose(output_ambig_words_file_); if (output_ambig_words_file_ != NULL) fclose(output_ambig_words_file_);
} }

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: stopper.c ** Filename: stopper.c
** Purpose: Stopping criteria for word classifier. ** Purpose: Stopping criteria for word classifier.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Mon Apr 29 14:56:49 1991, DSJ, Created. ** History: Mon Apr 29 14:56:49 1991, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at
@ -41,7 +41,6 @@
#pragma warning(disable:4800) // int/bool warnings #pragma warning(disable:4800) // int/bool warnings
#endif #endif
using tesseract::ScriptPos;
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
Private Code Private Code
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/

View File

@ -1,10 +1,10 @@
/****************************************************************************** /******************************************************************************
** Filename: stopper.h ** Filename: stopper.h
** Purpose: Stopping criteria for word classifier. ** Purpose: Stopping criteria for word classifier.
** Author: Dan Johnson ** Author: Dan Johnson
** History: Wed May 1 09:42:57 1991, DSJ, Created. ** History: Wed May 1 09:42:57 1991, DSJ, Created.
** **
** (c) Copyright Hewlett-Packard Company, 1988. ** (c) Copyright Hewlett-Packard Company, 1988.
** Licensed under the Apache License, Version 2.0 (the "License"); ** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License. ** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at ** You may obtain a copy of the License at

View File

@ -1092,7 +1092,8 @@ void kernel_ThresholdRectToPix(
for ( int c = 0; c < NUM_CHANNELS; c++) { for ( int c = 0; c < NUM_CHANNELS; c++) {
unsigned char pixChan = pixels.s[p*NUM_CHANNELS + c]; unsigned char pixChan = pixels.s[p*NUM_CHANNELS + c];
if (pHi_Values[c] >= 0 && (pixChan > pThresholds[c]) == (pHi_Values[c] == 0)) { if (pHi_Values[c] >= 0 && (pixChan > pThresholds[c]) == (pHi_Values[c] == 0)) {
word |= (((uint)0x80000000) >> ((b*PIXELS_PER_BURST+p)&31)); const uint kTopBit = 0x80000000;
word |= (kTopBit >> ((b*PIXELS_PER_BURST+p)&31));
} }
} }
} }
@ -1157,7 +1158,8 @@ void kernel_ThresholdRectToPix_OneChan(
\n#endif\n \n#endif\n
unsigned char pixChan = pixels.s[idx]; unsigned char pixChan = pixels.s[idx];
if (pHi_Values[0] >= 0 && (pixChan > pThresholds[0]) == (pHi_Values[0] == 0)) { if (pHi_Values[0] >= 0 && (pixChan > pThresholds[0]) == (pHi_Values[0] == 0)) {
word |= (0x80000000 >> ((b*PIXELS_PER_BURST+p)&31)); const uint kTopBit = 0x80000000;
word |= (kTopBit >> ((b*PIXELS_PER_BURST+p)&31));
} }
} }
} }

View File

@ -63,8 +63,10 @@ static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
if (profile->devices!=NULL && sr!=NULL) { if (profile->devices!=NULL && sr!=NULL) {
unsigned int i; unsigned int i;
for (i = 0; i < profile->numDevices; i++) { for (i = 0; i < profile->numDevices; i++) {
if (profile->devices[i].oclDeviceName) free(profile->devices[i].oclDeviceName); if (profile->devices[i].oclDeviceName)
if (profile->devices[i].oclDriverVersion) free(profile->devices[i].oclDriverVersion); free(profile->devices[i].oclDeviceName);
if (profile->devices[i].oclDriverVersion)
free(profile->devices[i].oclDriverVersion);
status = sr(profile->devices[i].score); status = sr(profile->devices[i].score);
if (status != DS_SUCCESS) if (status != DS_SUCCESS)
break; break;

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,8 @@
// including CL/cl.h doesn't occur until USE_OPENCL defined below // including CL/cl.h doesn't occur until USE_OPENCL defined below
// platform preprocessor commands // platform preprocessor commands
#if defined( WIN32 ) || defined( __WIN32__ ) || defined( _WIN32 ) || defined( __CYGWIN__ ) || defined( __MINGW32__ ) #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || \
defined(__CYGWIN__) || defined(__MINGW32__)
#define ON_WINDOWS 1 #define ON_WINDOWS 1
#define ON_LINUX 0 #define ON_LINUX 0
#define ON_APPLE 0 #define ON_APPLE 0
@ -80,21 +81,23 @@
time_sub_start = time_funct_start; \ time_sub_start = time_funct_start; \
time_sub_end = time_funct_start; time_sub_end = time_funct_start;
#define PERF_COUNT_END \ #define PERF_COUNT_END \
QueryPerformanceCounter(&time_funct_end); \ QueryPerformanceCounter(&time_funct_end); \
elapsed_time_sec = (time_funct_end.QuadPart-time_funct_start.QuadPart)/(double)(freq.QuadPart); \ elapsed_time_sec = (time_funct_end.QuadPart - time_funct_start.QuadPart) / \
printf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec); (double)(freq.QuadPart); \
printf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec);
#else #else
#define PERF_COUNT_START(FUNCT_NAME) #define PERF_COUNT_START(FUNCT_NAME)
#define PERF_COUNT_END #define PERF_COUNT_END
#endif #endif
#if PERF_COUNT_VERBOSE >= 3 #if PERF_COUNT_VERBOSE >= 3
#define PERF_COUNT_SUB(SUB) \ #define PERF_COUNT_SUB(SUB) \
QueryPerformanceCounter(&time_sub_end); \ QueryPerformanceCounter(&time_sub_end); \
elapsed_time_sec = (time_sub_end.QuadPart-time_sub_start.QuadPart)/(double)(freq.QuadPart); \ elapsed_time_sec = (time_sub_end.QuadPart - time_sub_start.QuadPart) / \
printf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \ (double)(freq.QuadPart); \
time_sub_start = time_sub_end; printf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \
time_sub_start = time_sub_end;
#else #else
#define PERF_COUNT_SUB(SUB) #define PERF_COUNT_SUB(SUB)
#endif #endif
@ -112,21 +115,25 @@
time_sub_start = time_funct_start; \ time_sub_start = time_funct_start; \
time_sub_end = time_funct_start; time_sub_end = time_funct_start;
#define PERF_COUNT_END \ #define PERF_COUNT_END \
clock_gettime( CLOCK_MONOTONIC, &time_funct_end ); \ clock_gettime(CLOCK_MONOTONIC, &time_funct_end); \
elapsed_time_sec = (time_funct_end.tv_sec - time_funct_start.tv_sec)*1.0 + (time_funct_end.tv_nsec - time_funct_start.tv_nsec)/1000000000.0; \ elapsed_time_sec = \
printf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec); (time_funct_end.tv_sec - time_funct_start.tv_sec) * 1.0 + \
(time_funct_end.tv_nsec - time_funct_start.tv_nsec) / 1000000000.0; \
printf(PERF_COUNT_REPORT_STR, funct_name, "total", elapsed_time_sec);
#else #else
#define PERF_COUNT_START(FUNCT_NAME) #define PERF_COUNT_START(FUNCT_NAME)
#define PERF_COUNT_END #define PERF_COUNT_END
#endif #endif
#if PERF_COUNT_VERBOSE >= 3 #if PERF_COUNT_VERBOSE >= 3
#define PERF_COUNT_SUB(SUB) \ #define PERF_COUNT_SUB(SUB) \
clock_gettime( CLOCK_MONOTONIC, &time_sub_end ); \ clock_gettime(CLOCK_MONOTONIC, &time_sub_end); \
elapsed_time_sec = (time_sub_end.tv_sec - time_sub_start.tv_sec)*1.0 + (time_sub_end.tv_nsec - time_sub_start.tv_nsec)/1000000000.0; \ elapsed_time_sec = \
printf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \ (time_sub_end.tv_sec - time_sub_start.tv_sec) * 1.0 + \
time_sub_start = time_sub_end; (time_sub_end.tv_nsec - time_sub_start.tv_nsec) / 1000000000.0; \
printf(PERF_COUNT_REPORT_STR, funct_name, SUB, elapsed_time_sec); \
time_sub_start = time_sub_end;
#else #else
#define PERF_COUNT_SUB(SUB) #define PERF_COUNT_SUB(SUB)
#endif #endif
@ -253,12 +260,12 @@ public:
// OpenCL implementation of Morphology (Hollow = Closed - Open) // OpenCL implementation of Morphology (Hollow = Closed - Open)
static PIX* pixHollowCL(PIX *pixd, PIX *pixs, l_int32 close_hsize, l_int32 close_vsize, l_int32 open_hsize, l_int32 open_vsize, bool reqDataCopy); static PIX* pixHollowCL(PIX *pixd, PIX *pixs, l_int32 close_hsize, l_int32 close_vsize, l_int32 open_hsize, l_int32 open_vsize, bool reqDataCopy);
static void pixGetLinesCL(PIX *pixd, PIX *pixs, static void pixGetLinesCL(PIX *pixd, PIX *pixs, PIX **pix_vline,
PIX** pix_vline, PIX** pix_hline, PIX **pix_hline, PIX **pixClosed,
PIX** pixClosed, bool getpixClosed, bool getpixClosed, l_int32 close_hsize,
l_int32 close_hsize, l_int32 close_vsize, l_int32 close_vsize, l_int32 open_hsize,
l_int32 open_hsize, l_int32 open_vsize, l_int32 open_vsize, l_int32 line_hsize,
l_int32 line_hsize, l_int32 line_vsize); l_int32 line_vsize);
//int InitOpenclAttr( OpenCLEnv * env ); //int InitOpenclAttr( OpenCLEnv * env );
//int ReleaseKernel( KernelEnv * env ); //int ReleaseKernel( KernelEnv * env );
@ -279,34 +286,24 @@ public:
static void FreeOpenclDll(); static void FreeOpenclDll();
#endif #endif
inline static int AddKernelConfig( int kCount, const char *kName ); inline static int AddKernelConfig( int kCount, const char *kName );
/* for binarization */ /* for binarization */
static int HistogramRectOCL( static int HistogramRectOCL(const unsigned char *imagedata,
const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line,
int bytes_per_pixel, int left, int top, int width, int height,
int bytes_per_line, int kHistogramSize, int *histogramAllChannels);
int left,
int top,
int width,
int height,
int kHistogramSize,
int *histogramAllChannels);
static int ThresholdRectToPixOCL( static int ThresholdRectToPixOCL(const unsigned char *imagedata,
const unsigned char* imagedata, int bytes_per_pixel, int bytes_per_line,
int bytes_per_pixel, const int *thresholds,
int bytes_per_line, const int *hi_values, Pix **pix,
const int* thresholds, int rect_height, int rect_width,
const int* hi_values, int rect_top, int rect_left);
Pix** pix,
int rect_height,
int rect_width,
int rect_top,
int rect_left);
static Pix * pixConvertRGBToGrayOCL( Pix *pix, float weightRed = 0.3, float weightGreen = 0.5, float weightBlue = 0.2 ); static Pix *pixConvertRGBToGrayOCL(Pix *pix, float weightRed = 0.3,
float weightGreen = 0.5,
float weightBlue = 0.2);
static ds_device getDeviceSelection(); static ds_device getDeviceSelection();
static ds_device selectedDevice; static ds_device selectedDevice;

View File

@ -1,7 +1,7 @@
file_type .bl file_type .bl
#tessedit_use_nn F #tessedit_use_nn F
textord_fast_pitch_test T textord_fast_pitch_test T
tessedit_single_match 0 tessedit_single_match 0
tessedit_zero_rejection T tessedit_zero_rejection T
tessedit_minimal_rejection F tessedit_minimal_rejection F
tessedit_write_rep_codes F tessedit_write_rep_codes F

View File

@ -188,7 +188,7 @@ ScrollView* AlignedBlob::DisplayTabs(const char* window_name,
gsearch.StartFullSearch(); gsearch.StartFullSearch();
BLOBNBOX* bbox; BLOBNBOX* bbox;
while ((bbox = gsearch.NextFullSearch()) != NULL) { while ((bbox = gsearch.NextFullSearch()) != NULL) {
TBOX box = bbox->bounding_box(); const TBOX& box = bbox->bounding_box();
int left_x = box.left(); int left_x = box.left();
int right_x = box.right(); int right_x = box.right();
int top_y = box.top(); int top_y = box.top();

View File

@ -231,7 +231,7 @@ Pix* GridReducedPix(const TBOX& box, int gridsize,
// Note that the Pix is used upside-down, with (0, 0) being the bottom-left. // Note that the Pix is used upside-down, with (0, 0) being the bottom-left.
Pix* TraceOutlineOnReducedPix(C_OUTLINE* outline, int gridsize, Pix* TraceOutlineOnReducedPix(C_OUTLINE* outline, int gridsize,
ICOORD bleft, int* left, int* bottom) { ICOORD bleft, int* left, int* bottom) {
TBOX box = outline->bounding_box(); const TBOX& box = outline->bounding_box();
Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom); Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
int wpl = pixGetWpl(pix); int wpl = pixGetWpl(pix);
l_uint32* data = pixGetData(pix); l_uint32* data = pixGetData(pix);
@ -257,7 +257,7 @@ Pix* TraceOutlineOnReducedPix(C_OUTLINE* outline, int gridsize,
// As TraceOutlineOnReducedPix above, but on a BLOCK instead of a C_OUTLINE. // As TraceOutlineOnReducedPix above, but on a BLOCK instead of a C_OUTLINE.
Pix* TraceBlockOnReducedPix(BLOCK* block, int gridsize, Pix* TraceBlockOnReducedPix(BLOCK* block, int gridsize,
ICOORD bleft, int* left, int* bottom) { ICOORD bleft, int* left, int* bottom) {
TBOX box = block->bounding_box(); const TBOX& box = block->bounding_box();
Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom); Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
int wpl = pixGetWpl(pix); int wpl = pixGetWpl(pix);
l_uint32* data = pixGetData(pix); l_uint32* data = pixGetData(pix);

View File

@ -623,7 +623,7 @@ void BBGrid<BBC, BBC_CLIST, BBC_C_IT>::DisplayBoxes(ScrollView* tab_win) {
gsearch.StartFullSearch(); gsearch.StartFullSearch();
BBC* bbox; BBC* bbox;
while ((bbox = gsearch.NextFullSearch()) != NULL) { while ((bbox = gsearch.NextFullSearch()) != NULL) {
TBOX box = bbox->bounding_box(); const TBOX& box = bbox->bounding_box();
int left_x = box.left(); int left_x = box.left();
int right_x = box.right(); int right_x = box.right();
int top_y = box.top(); int top_y = box.top();

View File

@ -72,12 +72,12 @@ ELISTIZEH (REGION_OCC)
Adapted from the following procedure so that it can be used in the bands Adapted from the following procedure so that it can be used in the bands
class in an include file... class in an include file...
BOOL8 range_in_band[ BOOL8 range_in_band[
range within band? range within band?
inT16 band_max, inT16 band_max,
inT16 band_min, inT16 band_min,
inT16 range_max, inT16 range_max,
inT16 range_min] inT16 range_min]
{ {
if ( (range_min >= band_min) && (range_max < band_max) ) if ( (range_min >= band_min) && (range_max < band_max) )
return TRUE; return TRUE;
@ -91,12 +91,12 @@ inT16 range_min]
Adapted from the following procedure so that it can be used in the bands Adapted from the following procedure so that it can be used in the bands
class in an include file... class in an include file...
BOOL8 range_overlaps_band[ BOOL8 range_overlaps_band[
range crosses band? range crosses band?
inT16 band_max, inT16 band_max,
inT16 band_min, inT16 band_min,
inT16 range_max, inT16 range_max,
inT16 range_min] inT16 range_min]
{ {
if ( (range_max >= band_min) && (range_min < band_max) ) if ( (range_max >= band_min) && (range_min < band_max) )
return TRUE; return TRUE;

Some files were not shown because too many files have changed in this diff Show More