-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some issues which were reported by Codacy #4266
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,10 @@ int16_t Tesseract::word_blob_quality(WERD_RES *word) { | |
} | ||
|
||
int16_t Tesseract::word_outline_errs(WERD_RES *word) { | ||
int16_t i = 0; | ||
int16_t err_count = 0; | ||
|
||
if (word->rebuild_word != nullptr) { | ||
int16_t i = 0; | ||
for (unsigned b = 0; b < word->rebuild_word->NumBlobs(); ++b) { | ||
TBLOB *blob = word->rebuild_word->blobs[b]; | ||
err_count += count_outline_errs(word->best_choice->unichar_string()[i], blob->NumOutlines()); | ||
|
@@ -209,13 +209,8 @@ void Tesseract::unrej_good_quality_words( // unreject potential | |
|
||
void Tesseract::doc_and_block_rejection( // reject big chunks | ||
PAGE_RES_IT &page_res_it, bool good_quality_doc) { | ||
int16_t block_no = 0; | ||
int16_t row_no = 0; | ||
BLOCK_RES *current_block; | ||
ROW_RES *current_row; | ||
|
||
bool rej_word; | ||
bool prev_word_rejected; | ||
int16_t char_quality = 0; | ||
int16_t accepted_char_quality; | ||
|
||
|
@@ -238,16 +233,17 @@ void Tesseract::doc_and_block_rejection( // reject big chunks | |
WERD_RES *word; | ||
while ((word = page_res_it.word()) != nullptr) { | ||
current_block = page_res_it.block(); | ||
block_no = current_block->block->pdblk.index(); | ||
int16_t block_no = current_block->block->pdblk.index(); | ||
if (current_block->char_count > 0 && | ||
(current_block->rej_count * 100.0 / current_block->char_count) > | ||
tessedit_reject_block_percent) { | ||
if (tessedit_debug_block_rejection) { | ||
tprintf("REJECTING BLOCK %d #chars: %d; #Rejects: %d\n", block_no, | ||
current_block->char_count, current_block->rej_count); | ||
} | ||
prev_word_rejected = false; | ||
bool prev_word_rejected = false; | ||
while ((word = page_res_it.word()) != nullptr && (page_res_it.block() == current_block)) { | ||
bool rej_word; | ||
if (tessedit_preserve_blk_rej_perfect_wds) { | ||
rej_word = word->reject_map.reject_count() > 0 || | ||
word->reject_map.length() < tessedit_preserve_min_wd_len; | ||
|
@@ -284,9 +280,9 @@ void Tesseract::doc_and_block_rejection( // reject big chunks | |
} | ||
|
||
/* Walk rows in block testing for row rejection */ | ||
row_no = 0; | ||
int16_t row_no = 0; | ||
while (page_res_it.word() != nullptr && page_res_it.block() == current_block) { | ||
current_row = page_res_it.row(); | ||
ROW_RES *current_row = page_res_it.row(); | ||
row_no++; | ||
/* Reject whole row if: | ||
fraction of chars on row which are rejected exceed a limit AND | ||
|
@@ -302,9 +298,10 @@ void Tesseract::doc_and_block_rejection( // reject big chunks | |
tprintf("REJECTING ROW %d #chars: %d; #Rejects: %d\n", row_no, | ||
current_row->char_count, current_row->rej_count); | ||
} | ||
prev_word_rejected = false; | ||
bool prev_word_rejected = false; | ||
while ((word = page_res_it.word()) != nullptr && page_res_it.row() == current_row) { | ||
/* Preserve words on good docs unless they are mostly rejected*/ | ||
bool rej_word; | ||
if (!tessedit_row_rej_good_docs && good_quality_doc) { | ||
rej_word = word->reject_map.reject_count() / | ||
static_cast<float>(word->reject_map.length()) > | ||
|
@@ -448,20 +445,18 @@ void Tesseract::tilde_crunch(PAGE_RES_IT &page_res_it) { | |
} | ||
|
||
bool Tesseract::terrible_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_level) { | ||
float rating_per_ch; | ||
int adjusted_len; | ||
int crunch_mode = 0; | ||
|
||
if (word->best_choice->unichar_string().empty() || | ||
(strspn(word->best_choice->unichar_string().c_str(), " ") == | ||
word->best_choice->unichar_string().size())) { | ||
crunch_mode = 1; | ||
} else { | ||
adjusted_len = word->reject_map.length(); | ||
int adjusted_len = word->reject_map.length(); | ||
if (adjusted_len > crunch_rating_max) { | ||
adjusted_len = crunch_rating_max; | ||
} | ||
rating_per_ch = word->best_choice->rating() / adjusted_len; | ||
float rating_per_ch = word->best_choice->rating() / adjusted_len; | ||
|
||
if (rating_per_ch > crunch_terrible_rating) { | ||
crunch_mode = 2; | ||
|
@@ -528,7 +523,6 @@ bool Tesseract::potential_word_crunch(WERD_RES *word, GARBAGE_LEVEL garbage_leve | |
} | ||
|
||
void Tesseract::tilde_delete(PAGE_RES_IT &page_res_it) { | ||
WERD_RES *word; | ||
PAGE_RES_IT copy_it; | ||
bool deleting_from_bol = false; | ||
bool marked_delete_point = false; | ||
|
@@ -539,7 +533,7 @@ void Tesseract::tilde_delete(PAGE_RES_IT &page_res_it) { | |
|
||
page_res_it.restart_page(); | ||
while (page_res_it.word() != nullptr) { | ||
word = page_res_it.word(); | ||
WERD_RES *word = page_res_it.word(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto? |
||
|
||
delete_mode = word_deletable(word, debug_delete_mode); | ||
if (delete_mode != CR_NONE) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,7 +171,6 @@ void Tesseract::fix_fuzzy_spaces(ETEXT_DESC *monitor, int32_t word_count, PAGE_R | |
void Tesseract::fix_fuzzy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK *block) { | ||
int16_t best_score; | ||
WERD_RES_LIST current_perm; | ||
int16_t current_score; | ||
bool improved = false; | ||
|
||
best_score = eval_word_spacing(best_perm); // default score | ||
|
@@ -183,7 +182,7 @@ void Tesseract::fix_fuzzy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK * | |
|
||
while ((best_score != PERFECT_WERDS) && !current_perm.empty()) { | ||
match_current_words(current_perm, row, block); | ||
current_score = eval_word_spacing(current_perm); | ||
int16_t current_score = eval_word_spacing(current_perm); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto? |
||
dump_words(current_perm, current_score, 2, improved); | ||
if (current_score > best_score) { | ||
best_perm.clear(); | ||
|
@@ -201,11 +200,10 @@ void Tesseract::fix_fuzzy_space_list(WERD_RES_LIST &best_perm, ROW *row, BLOCK * | |
void initialise_search(WERD_RES_LIST &src_list, WERD_RES_LIST &new_list) { | ||
WERD_RES_IT src_it(&src_list); | ||
WERD_RES_IT new_it(&new_list); | ||
WERD_RES *src_wd; | ||
WERD_RES *new_wd; | ||
|
||
for (src_it.mark_cycle_pt(); !src_it.cycled_list(); src_it.forward()) { | ||
src_wd = src_it.data(); | ||
WERD_RES *src_wd = src_it.data(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto? |
||
if (!src_wd->combination) { | ||
new_wd = WERD_RES::deep_copy(src_wd); | ||
new_wd->combination = false; | ||
|
@@ -393,8 +391,6 @@ void transform_to_next_perm(WERD_RES_LIST &words) { | |
WERD_RES_IT prev_word_it(&words); | ||
WERD_RES *word; | ||
WERD_RES *prev_word; | ||
WERD_RES *combo; | ||
WERD *copy_word; | ||
int16_t prev_right = -INT16_MAX; | ||
TBOX box; | ||
int16_t gap; | ||
|
@@ -425,12 +421,13 @@ void transform_to_next_perm(WERD_RES_LIST &words) { | |
gap = box.left() - prev_right; | ||
if (gap <= min_gap) { | ||
prev_word = prev_word_it.data(); | ||
WERD_RES *combo; | ||
if (prev_word->combination) { | ||
combo = prev_word; | ||
} else { | ||
/* Make a new combination and insert before | ||
* the first word being joined. */ | ||
copy_word = new WERD; | ||
auto *copy_word = new WERD; | ||
*copy_word = *(prev_word->word); | ||
// deep copy | ||
combo = new WERD_RES(copy_word); | ||
|
@@ -546,7 +543,6 @@ void Tesseract::fix_sp_fp_word(WERD_RES_IT &word_res_it, ROW *row, BLOCK *block) | |
WERD_RES *word_res; | ||
WERD_RES_LIST sub_word_list; | ||
WERD_RES_IT sub_word_list_it(&sub_word_list); | ||
int16_t blob_index; | ||
int16_t new_length; | ||
float junk; | ||
|
||
|
@@ -556,7 +552,7 @@ void Tesseract::fix_sp_fp_word(WERD_RES_IT &word_res_it, ROW *row, BLOCK *block) | |
return; | ||
} | ||
|
||
blob_index = worst_noise_blob(word_res, &junk); | ||
auto blob_index = worst_noise_blob(word_res, &junk); | ||
if (blob_index < 0) { | ||
return; | ||
} | ||
|
@@ -623,7 +619,6 @@ void Tesseract::break_noisiest_blob_word(WERD_RES_LIST &words) { | |
WERD_RES_IT worst_word_it; | ||
float worst_noise_score = 9999; | ||
int worst_blob_index = -1; // Noisiest blob of noisiest wd | ||
int blob_index; // of wds noisiest blob | ||
float noise_score; // of wds noisiest blob | ||
WERD_RES *word_res; | ||
C_BLOB_IT blob_it; | ||
|
@@ -636,7 +631,7 @@ void Tesseract::break_noisiest_blob_word(WERD_RES_LIST &words) { | |
int16_t i; | ||
|
||
for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) { | ||
blob_index = worst_noise_blob(word_it.data(), &noise_score); | ||
auto blob_index = worst_noise_blob(word_it.data(), &noise_score); | ||
if (blob_index > -1 && worst_noise_score > noise_score) { | ||
worst_noise_score = noise_score; | ||
worst_blob_index = blob_index; | ||
|
@@ -806,7 +801,6 @@ float Tesseract::blob_noise_score(TBLOB *blob) { | |
void fixspace_dbg(WERD_RES *word) { | ||
TBOX box = word->word->bounding_box(); | ||
const bool show_map_detail = false; | ||
int16_t i; | ||
|
||
box.print(); | ||
tprintf(" \"%s\" ", word->best_choice->unichar_string().c_str()); | ||
|
@@ -816,7 +810,7 @@ void fixspace_dbg(WERD_RES *word) { | |
tprintf("\n"); | ||
if (show_map_detail) { | ||
tprintf("\"%s\"\n", word->best_choice->unichar_string().c_str()); | ||
for (i = 0; word->best_choice->unichar_string()[i] != '\0'; i++) { | ||
for (unsigned i = 0; word->best_choice->unichar_string()[i] != '\0'; i++) { | ||
tprintf("**** \"%c\" ****\n", word->best_choice->unichar_string()[i]); | ||
word->reject_map[i].full_print(debug_fp); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto?