diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index c4abc249..e6d5c52b 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -2622,9 +2622,9 @@ void TessBaseAPI::NormalizeTBLOB(TBLOB *tblob, ROW *row, bool numeric_mode) { * Return a TBLOB * from the whole pix. * To be freed later with delete. */ -TBLOB *make_tesseract_blob(float baseline, float xheight, - float descender, float ascender, - bool numeric_mode, Pix* pix) { +static TBLOB *make_tesseract_blob(float baseline, float xheight, + float descender, float ascender, + bool numeric_mode, Pix* pix) { TBLOB *tblob = TessBaseAPI::MakeTBLOB(pix); // Normalize TBLOB diff --git a/src/api/pdfrenderer.cpp b/src/api/pdfrenderer.cpp index 73bd200c..9937c856 100644 --- a/src/api/pdfrenderer.cpp +++ b/src/api/pdfrenderer.cpp @@ -202,7 +202,7 @@ void TessPDFRenderer::AppendPDFObject(const char *data) { // Helper function to prevent us from accidentally writing // scientific notation to an HOCR or PDF file. Besides, three // decimal points are all you really need. -double prec(double x) { +static double prec(double x) { double kPrecision = 1000.0; double a = round(x * kPrecision) / kPrecision; if (a == -0) @@ -210,7 +210,7 @@ double prec(double x) { return a; } -long dist2(int x1, int y1, int x2, int y2) { +static long dist2(int x1, int y1, int x2, int y2) { return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); } @@ -222,10 +222,10 @@ long dist2(int x1, int y1, int x2, int y2) { // left-to-right no matter what the reading order is. We need the // word baseline in reading order, so we do that conversion here. Returns // the word's baseline origin and length. -void GetWordBaseline(int writing_direction, int ppi, int height, - int word_x1, int word_y1, int word_x2, int word_y2, - int line_x1, int line_y1, int line_x2, int line_y2, - double *x0, double *y0, double *length) { +static void GetWordBaseline(int writing_direction, int ppi, int height, + int word_x1, int word_y1, int word_x2, int word_y2, + int line_x1, int line_y1, int line_x2, int line_y2, + double *x0, double *y0, double *length) { if (writing_direction == WRITING_DIRECTION_RIGHT_TO_LEFT) { Swap(&word_x1, &word_x2); Swap(&word_y1, &word_y2); @@ -264,9 +264,9 @@ void GetWordBaseline(int writing_direction, int ppi, int height, // RTL // [ x' ] = [ a b ][ x ] = [-1 0 ] [ cos sin ][ x ] // [ y' ] [ c d ][ y ] [ 0 1 ] [-sin cos ][ y ] -void AffineMatrix(int writing_direction, - int line_x1, int line_y1, int line_x2, int line_y2, - double *a, double *b, double *c, double *d) { +static void AffineMatrix(int writing_direction, + int line_x1, int line_y1, int line_x2, int line_y2, + double *a, double *b, double *c, double *d) { double theta = atan2(static_cast(line_y1 - line_y2), static_cast(line_x2 - line_x1)); *a = cos(theta); diff --git a/src/ccmain/osdetect.cpp b/src/ccmain/osdetect.cpp index 853b2fc1..6096e9fb 100644 --- a/src/ccmain/osdetect.cpp +++ b/src/ccmain/osdetect.cpp @@ -156,8 +156,9 @@ void OSResults::accumulate(const OSResults& osr) { // Detect and erase horizontal/vertical lines and picture regions from the // image, so that non-text blobs are removed from consideration. -void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *blocks, - TO_BLOCK_LIST *to_blocks) { +static void remove_nontext_regions(tesseract::Tesseract *tess, + BLOCK_LIST *blocks, + TO_BLOCK_LIST *to_blocks) { Pix *pix = tess->pix_binary(); ASSERT_HOST(pix != nullptr); int vertical_x = 0; diff --git a/src/ccmain/output.cpp b/src/ccmain/output.cpp index 440ff2b8..a010c528 100644 --- a/src/ccmain/output.cpp +++ b/src/ccmain/output.cpp @@ -42,23 +42,6 @@ #define CTRL_NEWLINE '\012' //newline #define CTRL_HARDLINE '\015' //cr -/********************************************************************** - * pixels_to_pts - * - * Convert an integer number of pixels to the nearest integer - * number of points. - **********************************************************************/ - -int32_t pixels_to_pts( //convert coords - int32_t pixels, - int32_t pix_res //resolution - ) { - float pts; //converted value - - pts = pixels * 72.0 / pix_res; - return (int32_t) (pts + 0.5); //round it -} - namespace tesseract { void Tesseract::output_pass( //Tess output pass //send to api PAGE_RES_IT &page_res_it, diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp index 43d3f9a3..5b211f1c 100644 --- a/src/ccmain/paragraphs.cpp +++ b/src/ccmain/paragraphs.cpp @@ -56,6 +56,11 @@ const ParagraphModel *kCrownLeft const ParagraphModel *kCrownRight = reinterpret_cast(0xDEAD888F); +// Do the text and geometry of two rows support a paragraph break between them? +static bool LikelyParagraphStart(const RowScratchRegisters &before, + const RowScratchRegisters &after, + tesseract::ParagraphJustification j); + // Given the width of a typical space between words, what is the threshold // by which by which we think left and right alignments for paragraphs // can vary and still be aligned. @@ -128,7 +133,7 @@ static void PrintTable(const GenericVector > &rows, } } -STRING RtlEmbed(const STRING &word, bool rtlify) { +static STRING RtlEmbed(const STRING &word, bool rtlify) { if (rtlify) return STRING(kRLE) + word + STRING(kPDF); return word; @@ -200,34 +205,34 @@ static void PrintRowRange(const GenericVector &rows, // ============= Brain Dead Language Model (ASCII Version) =================== -bool IsLatinLetter(int ch) { +static bool IsLatinLetter(int ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); } -bool IsDigitLike(int ch) { +static bool IsDigitLike(int ch) { return ch == 'o' || ch == 'O' || ch == 'l' || ch == 'I'; } -bool IsOpeningPunct(int ch) { +static bool IsOpeningPunct(int ch) { return strchr("'\"({[", ch) != nullptr; } -bool IsTerminalPunct(int ch) { +static bool IsTerminalPunct(int ch) { return strchr(":'\".?!]})", ch) != nullptr; } // Return a pointer after consuming as much text as qualifies as roman numeral. -const char *SkipChars(const char *str, const char *toskip) { +static const char *SkipChars(const char *str, const char *toskip) { while (*str != '\0' && strchr(toskip, *str)) { str++; } return str; } -const char *SkipChars(const char *str, bool (*skip)(int)) { +static const char *SkipChars(const char *str, bool (*skip)(int)) { while (*str != '\0' && skip(*str)) { str++; } return str; } -const char *SkipOne(const char *str, const char *toskip) { +static const char *SkipOne(const char *str, const char *toskip) { if (*str != '\0' && strchr(toskip, *str)) return str + 1; return str; } @@ -235,7 +240,7 @@ const char *SkipOne(const char *str, const char *toskip) { // Return whether it is very likely that this is a numeral marker that could // start a list item. Some examples include: // A I iii. VI (2) 3.5. [C-4] -bool LikelyListNumeral(const STRING &word) { +static bool LikelyListNumeral(const STRING &word) { const char *kRomans = "ivxlmdIVXLMD"; const char *kDigits = "012345789"; const char *kOpen = "[{("; @@ -269,7 +274,7 @@ bool LikelyListNumeral(const STRING &word) { return *pos == '\0'; } -bool LikelyListMark(const STRING &word) { +static bool LikelyListMark(const STRING &word) { const char *kListMarks = "0Oo*.,+."; return word.size() == 1 && strchr(kListMarks, word[0]) != nullptr; } @@ -335,7 +340,7 @@ int UnicodeSpanSkipper::SkipAlpha(int pos) { return pos; } -bool LikelyListMarkUnicode(int ch) { +static bool LikelyListMarkUnicode(int ch) { if (ch < 0x80) { STRING single_ch; single_ch += ch; @@ -364,7 +369,7 @@ bool LikelyListMarkUnicode(int ch) { // Return whether it is very likely that this is a numeral marker that could // start a list item. Some examples include: // A I iii. VI (2) 3.5. [C-4] -bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd) { +static bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd) { if (werd->length() == 1 && LikelyListMarkUnicode(UnicodeFor(u, werd, 0))) return true; @@ -672,7 +677,7 @@ class SimpleClusterer { }; // Return the index of the cluster closest to value. -int ClosestCluster(const GenericVector &clusters, int value) { +static int ClosestCluster(const GenericVector &clusters, int value) { int best_index = 0; for (int i = 0; i < clusters.size(); i++) { if (abs(value - clusters[i].center) < @@ -698,11 +703,10 @@ void SimpleClusterer::GetClusters(GenericVector *clusters) { // Calculate left- and right-indent tab stop values seen in // rows[row_start, row_end) given a tolerance of tolerance. -void CalculateTabStops(GenericVector *rows, - int row_start, int row_end, - int tolerance, - GenericVector *left_tabs, - GenericVector *right_tabs) { +static void CalculateTabStops(GenericVector *rows, + int row_start, int row_end, int tolerance, + GenericVector *left_tabs, + GenericVector *right_tabs) { if (!AcceptableRowArgs(0, 1, __func__, rows, row_start, row_end)) return; // First pass: toss all left and right indents into clusterers. @@ -814,11 +818,10 @@ void CalculateTabStops(GenericVector *rows, // Case 2b: Fully Justified. (eop_threshold > 0) // We mark a line as short (end of paragraph) if the offside indent // is greater than eop_threshold. -void MarkRowsWithModel(GenericVector *rows, - int row_start, int row_end, - const ParagraphModel *model, - bool ltr, - int eop_threshold) { +static void MarkRowsWithModel(GenericVector *rows, + int row_start, int row_end, + const ParagraphModel *model, + bool ltr, int eop_threshold) { if (!AcceptableRowArgs(0, 0, __func__, rows, row_start, row_end)) return; for (int row = row_start; row < row_end; row++) { @@ -992,7 +995,7 @@ struct GeometricClassifierState { // [script direction: first indent, body indent] // (A1) LtR: 2,0 RtL: 0,0 (B1) LtR: 0,0 RtL: 2,0 // (A2) LtR: 2,0 RtL: CrR (B2) LtR: CrL RtL: 2,0 -void GeometricClassifyThreeTabStopTextBlock( +static void GeometricClassifyThreeTabStopTextBlock( int debug_level, GeometricClassifierState &s, ParagraphTheory *theory) { @@ -1084,10 +1087,10 @@ void GeometricClassifyThreeTabStopTextBlock( // have capital letters to go on (e.g. Hebrew, Arabic, Hindi, Chinese), // it's worth guessing that (A1b) is the correct interpretation if there are // far more "full" lines than "short" lines. -void GeometricClassify(int debug_level, - GenericVector *rows, - int row_start, int row_end, - ParagraphTheory *theory) { +static void GeometricClassify(int debug_level, + GenericVector *rows, + int row_start, int row_end, + ParagraphTheory *theory) { if (!AcceptableRowArgs(debug_level, 4, __func__, rows, row_start, row_end)) return; if (debug_level > 1) { @@ -1462,8 +1465,8 @@ void ParagraphModelSmearer::Smear() { // Find out what ParagraphModels are actually used, and discard any // that are not. -void DiscardUnusedModels(const GenericVector &rows, - ParagraphTheory *theory) { +static void DiscardUnusedModels(const GenericVector &rows, + ParagraphTheory *theory) { SetOfModels used_models; for (int i = 0; i < rows.size(); i++) { rows[i].StrongHypotheses(&used_models); @@ -1495,9 +1498,8 @@ void DiscardUnusedModels(const GenericVector &rows, // Comb backwards through the row scratch registers, and turn any // sequences of body lines of equivalent type abutted against the beginning // or a body or start line of a different type into a crown paragraph. -void DowngradeWeakestToCrowns(int debug_level, - ParagraphTheory *theory, - GenericVector *rows) { +static void DowngradeWeakestToCrowns(int debug_level, ParagraphTheory *theory, + GenericVector *rows) { int start; for (int end = rows->size(); end > 0; end = start) { // Search back for a body line of a unique type. @@ -1668,8 +1670,8 @@ bool FirstWordWouldHaveFit(const RowScratchRegisters &before, return after.ri_->rword_box.width() < available_space; } -bool TextSupportsBreak(const RowScratchRegisters &before, - const RowScratchRegisters &after) { +static bool TextSupportsBreak(const RowScratchRegisters &before, + const RowScratchRegisters &after) { if (before.ri_->ltr) { return before.ri_->rword_likely_ends_idea && after.ri_->lword_likely_starts_idea; @@ -1679,16 +1681,9 @@ bool TextSupportsBreak(const RowScratchRegisters &before, } } -bool LikelyParagraphStart(const RowScratchRegisters &before, - const RowScratchRegisters &after) { - return before.ri_->num_words == 0 || - (FirstWordWouldHaveFit(before, after) && - TextSupportsBreak(before, after)); -} - -bool LikelyParagraphStart(const RowScratchRegisters &before, - const RowScratchRegisters &after, - tesseract::ParagraphJustification j) { +static bool LikelyParagraphStart(const RowScratchRegisters &before, + const RowScratchRegisters &after, + tesseract::ParagraphJustification j) { return before.ri_->num_words == 0 || (FirstWordWouldHaveFit(before, after, j) && TextSupportsBreak(before, after)); @@ -1699,7 +1694,7 @@ bool LikelyParagraphStart(const RowScratchRegisters &before, // If we can't produce a unique model justification_ = JUSTIFICATION_UNKNOWN. // If the rows given could be a consistent start to a paragraph, set *consistent // true. -ParagraphModel InternalParagraphModelByOutline( +static ParagraphModel InternalParagraphModelByOutline( const GenericVector *rows, int start, int end, int tolerance, bool *consistent) { int ltr_line_count = 0; @@ -1800,7 +1795,7 @@ ParagraphModel InternalParagraphModelByOutline( // would fit them as a single paragraph. If nothing fits, // justification_ = JUSTIFICATION_UNKNOWN and print the paragraph to debug // output if we're debugging. -ParagraphModel ParagraphModelByOutline( +static ParagraphModel ParagraphModelByOutline( int debug_level, const GenericVector *rows, int start, int end, int tolerance) { @@ -1837,8 +1832,8 @@ bool RowsFitModel(const GenericVector *rows, // We only take the very strongest signals, as we don't want to get // confused and marking up centered text, poetry, or source code as // clearly part of a typical paragraph. -void MarkStrongEvidence(GenericVector *rows, - int row_start, int row_end) { +static void MarkStrongEvidence(GenericVector *rows, + int row_start, int row_end) { // Record patently obvious body text. for (int i = row_start + 1; i < row_end; i++) { const RowScratchRegisters &prev = (*rows)[i - 1]; @@ -1907,11 +1902,11 @@ void MarkStrongEvidence(GenericVector *rows, // Look for sequences of a start line followed by some body lines in // rows[row_start, row_end) and create ParagraphModels for them if // they seem coherent. -void ModelStrongEvidence(int debug_level, - GenericVector *rows, - int row_start, int row_end, - bool allow_flush_models, - ParagraphTheory *theory) { +static void ModelStrongEvidence(int debug_level, + GenericVector *rows, + int row_start, int row_end, + bool allow_flush_models, + ParagraphTheory *theory) { if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end)) return; @@ -2002,10 +1997,10 @@ void ModelStrongEvidence(int debug_level, // clues. // (3) Form models for any sequence of start + continuation lines. // (4) Smear the paragraph models to cover surrounding text. -void StrongEvidenceClassify(int debug_level, - GenericVector *rows, - int row_start, int row_end, - ParagraphTheory *theory) { +static void StrongEvidenceClassify(int debug_level, + GenericVector *rows, + int row_start, int row_end, + ParagraphTheory *theory) { if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end)) return; @@ -2032,9 +2027,9 @@ void StrongEvidenceClassify(int debug_level, smearer.Smear(); } -void SeparateSimpleLeaderLines(GenericVector *rows, - int row_start, int row_end, - ParagraphTheory *theory) { +static void SeparateSimpleLeaderLines(GenericVector *rows, + int row_start, int row_end, + ParagraphTheory *theory) { for (int i = row_start + 1; i < row_end - 1; i++) { if ((*rows)[i - 1].ri_->has_leaders && (*rows)[i].ri_->has_leaders && @@ -2048,7 +2043,7 @@ void SeparateSimpleLeaderLines(GenericVector *rows, // Collect sequences of unique hypotheses in row registers and create proper // paragraphs for them, referencing the paragraphs in row_owners. -void ConvertHypothesizedModelRunsToParagraphs( +static void ConvertHypothesizedModelRunsToParagraphs( int debug_level, const GenericVector &rows, GenericVector *row_owners, @@ -2147,7 +2142,8 @@ struct Interval { // (1) If a line is surrounded by lines of unknown type, it's weak. // (2) If two lines in a row are start lines for a given paragraph type, but // after that the same paragraph type does not continue, they're weak. -bool RowIsStranded(const GenericVector &rows, int row) { +static bool RowIsStranded(const GenericVector &rows, + int row) { SetOfModels row_models; rows[row].StrongHypotheses(&row_models); @@ -2189,9 +2185,9 @@ bool RowIsStranded(const GenericVector &rows, int row) { // + Crown paragraphs not immediately followed by a strongly modeled line. // + Single line paragraphs surrounded by text that doesn't match the // model. -void LeftoverSegments(const GenericVector &rows, - GenericVector *to_fix, - int row_start, int row_end) { +static void LeftoverSegments(const GenericVector &rows, + GenericVector *to_fix, + int row_start, int row_end) { to_fix->clear(); for (int i = row_start; i < row_end; i++) { bool needs_fixing = false; @@ -2367,8 +2363,8 @@ void DetectParagraphs(int debug_level, // ============ Code interfacing with the rest of Tesseract ================== -void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, - RowInfo *info) { +static void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, + RowInfo *info) { // Set up text, lword_text, and rword_text (mostly for debug printing). STRING fake_text; PageIterator pit(static_cast(it)); @@ -2419,9 +2415,8 @@ void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, // Given a Tesseract Iterator pointing to a text line, fill in the paragraph // detector RowInfo with all relevant information from the row. -void InitializeRowInfo(bool after_recognition, - const MutableIterator &it, - RowInfo *info) { +static void InitializeRowInfo(bool after_recognition, + const MutableIterator &it, RowInfo *info) { if (it.PageResIt()->row() != nullptr) { ROW *row = it.PageResIt()->row()->row; info->pix_ldistance = row->lmargin(); diff --git a/src/ccmain/paragraphs_internal.h b/src/ccmain/paragraphs_internal.h index ccf5334e..f8fe136e 100644 --- a/src/ccmain/paragraphs_internal.h +++ b/src/ccmain/paragraphs_internal.h @@ -291,11 +291,6 @@ bool FirstWordWouldHaveFit(const RowScratchRegisters &before, bool RowsFitModel(const GenericVector *rows, int start, int end, const ParagraphModel *model); -// Do the text and geometry of two rows support a paragraph break between them? -bool LikelyParagraphStart(const RowScratchRegisters &before, - const RowScratchRegisters &after, - tesseract::ParagraphJustification j); - // Given a set of row_owners pointing to PARAs or nullptr (no paragraph known), // normalize each row_owner to point to an actual PARA, and output the // paragraphs in order onto paragraphs. diff --git a/src/ccmain/pgedit.cpp b/src/ccmain/pgedit.cpp index 440efbdb..10cb0490 100644 --- a/src/ccmain/pgedit.cpp +++ b/src/ccmain/pgedit.cpp @@ -203,12 +203,9 @@ void build_image_window(int width, int height) { * Display normalized baseline, x-height, ascender limit and descender limit */ -void display_bln_lines(ScrollView* window, - ScrollView::Color colour, - float scale_factor, - float y_offset, - float minx, - float maxx) { +static void display_bln_lines(ScrollView* window, ScrollView::Color colour, + float scale_factor, float y_offset, + float minx, float maxx) { window->Pen(colour); window->Line(minx, y_offset + scale_factor * DESC_HEIGHT, maxx, y_offset + scale_factor * DESC_HEIGHT); diff --git a/src/ccmain/recogtraining.cpp b/src/ccmain/recogtraining.cpp index a9a7f267..13318057 100644 --- a/src/ccmain/recogtraining.cpp +++ b/src/ccmain/recogtraining.cpp @@ -53,7 +53,7 @@ FILE *Tesseract::init_recog_training(const STRING &fname) { } // Copies the bounding box from page_res_it->word() to the given TBOX. -bool read_t(PAGE_RES_IT *page_res_it, TBOX *tbox) { +static bool read_t(PAGE_RES_IT *page_res_it, TBOX *tbox) { while (page_res_it->block() != nullptr && page_res_it->word() == nullptr) page_res_it->forward(); diff --git a/src/ccmain/superscript.cpp b/src/ccmain/superscript.cpp index 518b21e6..61f54629 100644 --- a/src/ccmain/superscript.cpp +++ b/src/ccmain/superscript.cpp @@ -43,10 +43,11 @@ namespace tesseract { * or superscript letter based only on y position. Also do this for the * right side. */ -void YOutlierPieces(WERD_RES *word, int rebuilt_blob_index, - int super_y_bottom, int sub_y_top, - ScriptPos *leading_pos, int *num_leading_outliers, - ScriptPos *trailing_pos, int *num_trailing_outliers) { +static void YOutlierPieces(WERD_RES *word, int rebuilt_blob_index, + int super_y_bottom, int sub_y_top, + ScriptPos *leading_pos, int *num_leading_outliers, + ScriptPos *trailing_pos, + int *num_trailing_outliers) { ScriptPos sp_unused1, sp_unused2; int unused1, unused2; if (!leading_pos) leading_pos = &sp_unused1; diff --git a/src/ccstruct/ocrblock.cpp b/src/ccstruct/ocrblock.cpp index 7dfdd79e..7c8d03e3 100644 --- a/src/ccstruct/ocrblock.cpp +++ b/src/ccstruct/ocrblock.cpp @@ -252,7 +252,7 @@ const BLOCK & source //from this // margin - return value, the distance from x,y to the left margin of the // block containing it. // If all segments were to the right of x, we return false and 0. -bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin) { +static bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin) { bool found = false; *margin = 0; if (segments->empty()) @@ -282,7 +282,7 @@ bool LeftMargin(ICOORDELT_LIST *segments, int x, int *margin) { // margin - return value, the distance from x,y to the right margin of the // block containing it. // If all segments were to the left of x, we return false and 0. -bool RightMargin(ICOORDELT_LIST *segments, int x, int *margin) { +static bool RightMargin(ICOORDELT_LIST *segments, int x, int *margin) { bool found = false; *margin = 0; if (segments->empty()) diff --git a/src/ccstruct/stepblob.cpp b/src/ccstruct/stepblob.cpp index f711ea86..664aa4a3 100644 --- a/src/ccstruct/stepblob.cpp +++ b/src/ccstruct/stepblob.cpp @@ -359,7 +359,8 @@ void C_BLOB::move( // reposition blob } // Static helper for C_BLOB::rotate to allow recursion of child outlines. -void RotateOutlineList(const FCOORD& rotation, C_OUTLINE_LIST* outlines) { +static void RotateOutlineList(const FCOORD& rotation, + C_OUTLINE_LIST* outlines) { C_OUTLINE_LIST new_outlines; C_OUTLINE_IT src_it(outlines); C_OUTLINE_IT dest_it(&new_outlines); diff --git a/src/ccutil/globaloc.cpp b/src/ccutil/globaloc.cpp index 62e92db4..0510be1c 100644 --- a/src/ccutil/globaloc.cpp +++ b/src/ccutil/globaloc.cpp @@ -17,14 +17,15 @@ * **********************************************************************/ -#include +#include "globaloc.h" +#include #ifdef __linux__ -#include // For SYS_gettid. -#include // For syscall itself. +#include // For SYS_gettid. +#include // For syscall itself. #endif -#include "allheaders.h" -#include "errcode.h" -#include "tprintf.h" +#include "allheaders.h" +#include "errcode.h" +#include "tprintf.h" // Size of thread-id array of pixes to keep in case of crash. const int kMaxNumThreadPixes = 32768; @@ -75,20 +76,17 @@ void err_exit() { ASSERT_HOST("Fatal error encountered!" == nullptr); } - +// TODO: remove empty function? void set_global_loc_code(int loc_code) { // global_loc_code = loc_code; - } - +// TODO: remove empty function? void set_global_subloc_code(int loc_code) { // global_subloc_code = loc_code; - } - +// TODO: remove empty function? void set_global_subsubloc_code(int loc_code) { // global_subsubloc_code = loc_code; - } diff --git a/src/ccutil/scanutils.cpp b/src/ccutil/scanutils.cpp index c64e0ba5..5dbcc4a0 100644 --- a/src/ccutil/scanutils.cpp +++ b/src/ccutil/scanutils.cpp @@ -103,7 +103,7 @@ static inline int DigitValue(int ch, int base) { } // IO (re-)implementations ----------------------------------------------------- -uintmax_t streamtoumax(FILE* s, int base) { +static uintmax_t streamtoumax(FILE* s, int base) { int minus = 0; uintmax_t v = 0; int d, c = 0; @@ -144,7 +144,7 @@ uintmax_t streamtoumax(FILE* s, int base) { return minus ? -v : v; } -double streamtofloat(FILE* s) { +static double streamtofloat(FILE* s) { int minus = 0; int v = 0; int d, c = 0; @@ -191,39 +191,6 @@ double streamtofloat(FILE* s) { return minus ? -f : f; } -double strtofloat(const char* s) { - int minus = 0; - int v = 0; - int d; - int k = 1; - int w = 0; - - while(*s && isspace(static_cast(*s))) s++; - - // Single optional + or - - if (*s == '-' || *s == '+') { - minus = (*s == '-'); - s++; - } - - // Actual number parsing - for (; *s && (d = DigitValue(*s, 10)) >= 0; s++) - v = v*10 + d; - if (*s == '.') { - for (++s; *s && (d = DigitValue(*s, 10)) >= 0; s++) { - w = w*10 + d; - k *= 10; - } - } - if (*s == 'e' || *s == 'E') - tprintf("WARNING: Scientific Notation not supported!"); - - double f = static_cast(v) - + static_cast(w) / static_cast(k); - - return minus ? -f : f; -} - static int tvfscanf(FILE* stream, const char *format, va_list ap); int tfscanf(FILE* stream, const char *format, ...) { diff --git a/src/classify/adaptive.cpp b/src/classify/adaptive.cpp index f1ac33f6..8d2a6389 100644 --- a/src/classify/adaptive.cpp +++ b/src/classify/adaptive.cpp @@ -87,7 +87,7 @@ void FreeTempProto(void *arg) { free(proto); } -void FreePermConfig(PERM_CONFIG Config) { +static void FreePermConfig(PERM_CONFIG Config) { assert(Config != nullptr); delete [] Config->Ambigs; free(Config); @@ -475,7 +475,7 @@ void Classify::WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) { /** * This routine writes a binary representation of a * permanent configuration to File. - * + * * @param File open file to write Config to * @param Config permanent config to write to File * diff --git a/src/classify/intfx.cpp b/src/classify/intfx.cpp index 8437eab6..93311819 100644 --- a/src/classify/intfx.cpp +++ b/src/classify/intfx.cpp @@ -166,8 +166,9 @@ void Classify::SetupBLCNDenorms(const TBLOB& blob, bool nonlinear_norm, // Helper normalizes the direction, assuming that it is at the given // unnormed_pos, using the given denorm, starting at the root_denorm. -uint8_t NormalizeDirection(uint8_t dir, const FCOORD& unnormed_pos, - const DENORM& denorm, const DENORM* root_denorm) { +static uint8_t NormalizeDirection(uint8_t dir, const FCOORD& unnormed_pos, + const DENORM& denorm, + const DENORM* root_denorm) { // Convert direction to a vector. FCOORD unnormed_end; unnormed_end.from_direction(dir); diff --git a/src/classify/intmatcher.cpp b/src/classify/intmatcher.cpp index 2f5be942..d13a890d 100644 --- a/src/classify/intmatcher.cpp +++ b/src/classify/intmatcher.cpp @@ -713,11 +713,9 @@ void ScratchEvidence::ClearFeatureEvidence(const INT_CLASS class_template) { * Print debugging information for Configurations * @return none */ -void IMDebugConfiguration(int FeatureNum, - uint16_t ActualProtoNum, - uint8_t Evidence, - BIT_VECTOR ConfigMask, - uint32_t ConfigWord) { +static void IMDebugConfiguration(int FeatureNum, uint16_t ActualProtoNum, + uint8_t Evidence, BIT_VECTOR ConfigMask, + uint32_t ConfigWord) { cprintf ("F = %3d, P = %3d, E = %3d, Configs = ", FeatureNum, (int) ActualProtoNum, (int) Evidence); while (ConfigWord) { @@ -734,9 +732,8 @@ void IMDebugConfiguration(int FeatureNum, * Print debugging information for Configurations * @return none */ -void IMDebugConfigurationSum(int FeatureNum, - uint8_t *FeatureEvidence, - int32_t ConfigCount) { +static void IMDebugConfigurationSum(int FeatureNum, uint8_t *FeatureEvidence, + int32_t ConfigCount) { cprintf("F=%3d, C=", FeatureNum); for (int ConfigNum = 0; ConfigNum < ConfigCount; ConfigNum++) { cprintf("%4d", FeatureEvidence[ConfigNum]); diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp index 5837b4e6..c8067e00 100644 --- a/src/classify/intproto.cpp +++ b/src/classify/intproto.cpp @@ -674,8 +674,7 @@ INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs) { } /* NewIntClass */ - -void free_int_class(INT_CLASS int_class) { +static void free_int_class(INT_CLASS int_class) { int i; for (i = 0; i < int_class->NumProtoSets; i++) { diff --git a/src/classify/mfx.cpp b/src/classify/mfx.cpp index 50fd08c8..7771ebe4 100644 --- a/src/classify/mfx.cpp +++ b/src/classify/mfx.cpp @@ -2,7 +2,6 @@ ** Filename: mfx.c ** Purpose: Micro feature extraction routines ** Author: Dan Johnson - ** History: 7/21/89, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +17,7 @@ /*---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------*/ +#include "mfx.h" #include "mfdefs.h" #include "mfoutline.h" #include "clusttool.h" //NEEDED @@ -93,7 +93,6 @@ MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) { return MicroFeatures; } /* BlobMicroFeatures */ - /*--------------------------------------------------------------------------- Private Code ---------------------------------------------------------------------------*/ diff --git a/src/classify/mfx.h b/src/classify/mfx.h index 5ed006dc..9778a547 100644 --- a/src/classify/mfx.h +++ b/src/classify/mfx.h @@ -2,7 +2,6 @@ ** Filename: mfx.h ** Purpose: Definition of micro-feature extraction routines ** Author: Dan Johnson - ** History: 5/29/89, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +14,19 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ******************************************************************************/ -#ifndef MFX_H -#define MFX_H + +#ifndef MFX_H +#define MFX_H /*---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------**/ #include "mfdefs.h" #include "params.h" + +class DENORM; +struct TBLOB; + /*---------------------------------------------------------------------------- Variables ----------------------------------------------------------------------------**/ diff --git a/src/classify/ocrfeatures.cpp b/src/classify/ocrfeatures.cpp index a8e75d06..9579e606 100644 --- a/src/classify/ocrfeatures.cpp +++ b/src/classify/ocrfeatures.cpp @@ -191,37 +191,3 @@ void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str) { } } } /* WriteFeatureSet */ - -/** - * Write a textual representation of FeatureDesc to File - * in the old format (i.e. the format used by the clusterer). - * - * This format is: - * @verbatim - * Number of Params - * Description of Param 1 - * ... - * @endverbatim - * @param File open text file to write FeatureDesc to - * @param FeatureDesc feature descriptor to write to File - * @return none - */ -void WriteOldParamDesc(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) { - int i; - - fprintf (File, "%d\n", FeatureDesc->NumParams); - for (i = 0; i < FeatureDesc->NumParams; i++) { - if (FeatureDesc->ParamDesc[i].Circular) - fprintf (File, "circular "); - else - fprintf (File, "linear "); - - if (FeatureDesc->ParamDesc[i].NonEssential) - fprintf (File, "non-essential "); - else - fprintf (File, "essential "); - - fprintf (File, "%f %f\n", - FeatureDesc->ParamDesc[i].Min, FeatureDesc->ParamDesc[i].Max); - } -} /* WriteOldParamDesc */ diff --git a/src/dict/dawg.cpp b/src/dict/dawg.cpp index 07de6cca..27a28bf7 100644 --- a/src/dict/dawg.cpp +++ b/src/dict/dawg.cpp @@ -109,7 +109,8 @@ void Dawg::iterate_words(const UNICHARSET &unicharset, iterate_words_rec(word, 0, cb); } -void CallWithUTF8(TessCallback1 *cb, const WERD_CHOICE *wc) { +static void CallWithUTF8(TessCallback1 *cb, + const WERD_CHOICE *wc) { STRING s; wc->string_and_lengths(&s, nullptr); cb->Run(s.string()); diff --git a/src/textord/bbgrid.cpp b/src/textord/bbgrid.cpp index fb65e27c..55146b0b 100644 --- a/src/textord/bbgrid.cpp +++ b/src/textord/bbgrid.cpp @@ -201,8 +201,8 @@ Pix* IntGrid::ThresholdToPix(int threshold) const { } // Make a Pix of the correct scaled size for the TraceOutline functions. -Pix* GridReducedPix(const TBOX& box, int gridsize, - ICOORD bleft, int* left, int* bottom) { +static Pix* GridReducedPix(const TBOX& box, int gridsize, + ICOORD bleft, int* left, int* bottom) { // Compute grid bounds of the outline and pad all round by 1. int grid_left = (box.left() - bleft.x()) / gridsize - 1; int grid_bottom = (box.bottom() - bleft.y()) / gridsize - 1; diff --git a/src/textord/makerow.cpp b/src/textord/makerow.cpp index ebfa3581..535d724d 100644 --- a/src/textord/makerow.cpp +++ b/src/textord/makerow.cpp @@ -133,7 +133,8 @@ static float MakeRowFromBlobs(float line_size, // Helper to make a row using the children of a single blob. // Returns the mean size of the blobs created. -float MakeRowFromSubBlobs(TO_BLOCK* block, C_BLOB* blob, TO_ROW_IT* row_it) { +static float MakeRowFromSubBlobs(TO_BLOCK* block, C_BLOB* blob, + TO_ROW_IT* row_it) { // The blobs made from the children will go in the small_blobs list. BLOBNBOX_IT bb_it(&block->small_blobs); C_OUTLINE_IT ol_it(blob->out_list()); diff --git a/src/training/commandlineflags.cpp b/src/training/commandlineflags.cpp index c1700f98..fa17b4a5 100644 --- a/src/training/commandlineflags.cpp +++ b/src/training/commandlineflags.cpp @@ -15,7 +15,7 @@ #ifndef GOOGLE_TESSERACT namespace tesseract { -bool IntFlagExists(const char* flag_name, int32_t* value) { +static bool IntFlagExists(const char* flag_name, int32_t* value) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -26,7 +26,7 @@ bool IntFlagExists(const char* flag_name, int32_t* value) { return true; } -bool DoubleFlagExists(const char* flag_name, double* value) { +static bool DoubleFlagExists(const char* flag_name, double* value) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -37,7 +37,7 @@ bool DoubleFlagExists(const char* flag_name, double* value) { return true; } -bool BoolFlagExists(const char* flag_name, bool* value) { +static bool BoolFlagExists(const char* flag_name, bool* value) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -48,7 +48,7 @@ bool BoolFlagExists(const char* flag_name, bool* value) { return true; } -bool StringFlagExists(const char* flag_name, const char** value) { +static bool StringFlagExists(const char* flag_name, const char** value) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -58,7 +58,7 @@ bool StringFlagExists(const char* flag_name, const char** value) { return p != nullptr; } -void SetIntFlagValue(const char* flag_name, const int32_t new_val) { +static void SetIntFlagValue(const char* flag_name, const int32_t new_val) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -68,7 +68,7 @@ void SetIntFlagValue(const char* flag_name, const int32_t new_val) { p->set_value(new_val); } -void SetDoubleFlagValue(const char* flag_name, const double new_val) { +static void SetDoubleFlagValue(const char* flag_name, const double new_val) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -78,7 +78,7 @@ void SetDoubleFlagValue(const char* flag_name, const double new_val) { p->set_value(new_val); } -void SetBoolFlagValue(const char* flag_name, const bool new_val) { +static void SetBoolFlagValue(const char* flag_name, const bool new_val) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -88,7 +88,7 @@ void SetBoolFlagValue(const char* flag_name, const bool new_val) { p->set_value(new_val); } -void SetStringFlagValue(const char* flag_name, const char* new_val) { +static void SetStringFlagValue(const char* flag_name, const char* new_val) { STRING full_flag_name("FLAGS_"); full_flag_name += flag_name; GenericVector empty; @@ -98,19 +98,19 @@ void SetStringFlagValue(const char* flag_name, const char* new_val) { p->set_value(STRING(new_val)); } -bool SafeAtoi(const char* str, int* val) { +static bool SafeAtoi(const char* str, int* val) { char* endptr = nullptr; *val = strtol(str, &endptr, 10); return endptr != nullptr && *endptr == '\0'; } -bool SafeAtod(const char* str, double* val) { +static bool SafeAtod(const char* str, double* val) { char* endptr = nullptr; *val = strtod(str, &endptr); return endptr != nullptr && *endptr == '\0'; } -void PrintCommandLineFlags() { +static void PrintCommandLineFlags() { const char* kFlagNamePrefix = "FLAGS_"; const int kFlagNamePrefixLen = strlen(kFlagNamePrefix); for (int i = 0; i < GlobalParams()->int_params.size(); ++i) { diff --git a/src/training/dawg2wordlist.cpp b/src/training/dawg2wordlist.cpp index ca8612c7..def4d784 100644 --- a/src/training/dawg2wordlist.cpp +++ b/src/training/dawg2wordlist.cpp @@ -25,8 +25,8 @@ #include "trie.h" #include "unicharset.h" -tesseract::Dawg *LoadSquishedDawg(const UNICHARSET &unicharset, - const char *filename) { +static tesseract::Dawg *LoadSquishedDawg(const UNICHARSET &unicharset, + const char *filename) { const int kDictDebugLevel = 1; tesseract::TFile dawg_file; if (!dawg_file.Open(filename, nullptr)) { @@ -54,9 +54,9 @@ class WordOutputter { }; // returns 0 if successful. -int WriteDawgAsWordlist(const UNICHARSET &unicharset, - const tesseract::Dawg *dawg, - const char *outfile_name) { +static int WriteDawgAsWordlist(const UNICHARSET &unicharset, + const tesseract::Dawg *dawg, + const char *outfile_name) { FILE *out = fopen(outfile_name, "wb"); if (out == nullptr) { tprintf("Could not open %s for writing.\n", outfile_name); diff --git a/src/training/normstrngs.cpp b/src/training/normstrngs.cpp index efa6a7be..759284b2 100644 --- a/src/training/normstrngs.cpp +++ b/src/training/normstrngs.cpp @@ -35,7 +35,7 @@ namespace tesseract { -bool is_hyphen_punc(const char32 ch) { +static bool is_hyphen_punc(const char32 ch) { static const int kNumHyphenPuncUnicodes = 13; static const char32 kHyphenPuncUnicodes[kNumHyphenPuncUnicodes] = { '-', 0x2010, 0x2011, 0x2012, @@ -53,7 +53,7 @@ bool is_hyphen_punc(const char32 ch) { return false; } -bool is_single_quote(const char32 ch) { +static bool is_single_quote(const char32 ch) { static const int kNumSingleQuoteUnicodes = 8; static const char32 kSingleQuoteUnicodes[kNumSingleQuoteUnicodes] = { '\'', '`', @@ -71,7 +71,7 @@ bool is_single_quote(const char32 ch) { return false; } -bool is_double_quote(const char32 ch) { +static bool is_double_quote(const char32 ch) { static const int kNumDoubleQuoteUnicodes = 8; static const char32 kDoubleQuoteUnicodes[kNumDoubleQuoteUnicodes] = { '"', diff --git a/src/training/stringrenderer.cpp b/src/training/stringrenderer.cpp index 5719c1c4..24b162d5 100644 --- a/src/training/stringrenderer.cpp +++ b/src/training/stringrenderer.cpp @@ -68,7 +68,7 @@ static bool RandBool(const double prob, TRand* rand) { } /* static */ -Pix* CairoARGB32ToPixFormat(cairo_surface_t *surface) { +static Pix* CairoARGB32ToPixFormat(cairo_surface_t *surface) { if (cairo_image_surface_get_format(surface) != CAIRO_FORMAT_ARGB32) { printf("Unexpected surface format %d\n", cairo_image_surface_get_format(surface)); diff --git a/src/training/text2image.cpp b/src/training/text2image.cpp index 273d37bb..580df723 100644 --- a/src/training/text2image.cpp +++ b/src/training/text2image.cpp @@ -208,9 +208,9 @@ static std::string StringReplace(const std::string& in, // with "T", such that "AT" has spacing of -5, the entry/line for unichar "A" // in .fontinfo file will be: // A 0 -1 T -5 V -7 -void ExtractFontProperties(const std::string &utf8_text, - StringRenderer *render, - const std::string &output_base) { +static void ExtractFontProperties(const std::string &utf8_text, + StringRenderer *render, + const std::string &output_base) { std::map spacing_map; std::map::iterator spacing_map_it0; std::map::iterator spacing_map_it1; @@ -308,9 +308,8 @@ void ExtractFontProperties(const std::string &utf8_text, File::WriteStringToFileOrDie(output_string, output_base + ".fontinfo"); } -bool MakeIndividualGlyphs(Pix* pix, - const std::vector& vbox, - const int input_tiff_page) { +static bool MakeIndividualGlyphs(Pix* pix, const std::vector& vbox, + const int input_tiff_page) { // If checks fail, return false without exiting text2image if (!pix) { tprintf("ERROR: MakeIndividualGlyphs(): Input Pix* is nullptr\n"); diff --git a/src/training/validator.cpp b/src/training/validator.cpp index bcdd844e..d764c3da 100644 --- a/src/training/validator.cpp +++ b/src/training/validator.cpp @@ -123,8 +123,8 @@ void Validator::MoveResultsToDest(GraphemeNormMode g_mode, } } -bool CmpPairSecond(const std::pair& p1, - const std::pair& p2) { +static bool CmpPairSecond(const std::pair& p1, + const std::pair& p2) { return p1.second < p2.second; }