From 5b4ce2431d10fa766766494354a494f7c204dd5c Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Dec 2016 17:19:35 +0100 Subject: [PATCH] ccmain: Replace NULL by nullptr Signed-off-by: Stefan Weil --- ccmain/adaptions.cpp | 4 +- ccmain/applybox.cpp | 52 +++++------ ccmain/control.cpp | 176 +++++++++++++++++------------------ ccmain/docqual.cpp | 48 +++++----- ccmain/equationdetect.cpp | 120 ++++++++++++------------ ccmain/equationdetect.h | 2 +- ccmain/fixspace.cpp | 22 ++--- ccmain/linerec.cpp | 28 +++--- ccmain/ltrresultiterator.cpp | 82 ++++++++-------- ccmain/ltrresultiterator.h | 6 +- ccmain/osdetect.cpp | 28 +++--- ccmain/osdetect.h | 2 +- ccmain/output.cpp | 16 ++-- ccmain/pageiterator.cpp | 82 ++++++++-------- ccmain/pageiterator.h | 8 +- ccmain/pagesegmain.cpp | 42 ++++----- ccmain/pagewalk.cpp | 2 +- ccmain/par_control.cpp | 10 +- ccmain/paragraphs.cpp | 66 ++++++------- ccmain/paragraphs_internal.h | 12 +-- ccmain/paramsd.cpp | 14 +-- ccmain/paramsd.h | 2 +- ccmain/pgedit.cpp | 54 +++++------ ccmain/recogtraining.cpp | 16 ++-- ccmain/reject.cpp | 6 +- ccmain/resultiterator.cpp | 22 ++--- ccmain/resultiterator.h | 2 +- ccmain/superscript.cpp | 22 ++--- ccmain/tessbox.cpp | 2 +- ccmain/tessedit.cpp | 18 ++-- ccmain/tesseractclass.cpp | 18 ++-- ccmain/tesseractclass.h | 18 ++-- ccmain/tfacepp.cpp | 22 ++--- ccmain/thresholder.cpp | 14 +-- ccmain/thresholder.h | 2 +- ccmain/werdit.cpp | 8 +- 36 files changed, 524 insertions(+), 524 deletions(-) diff --git a/ccmain/adaptions.cpp b/ccmain/adaptions.cpp index 6a0250aebd..5623eb68a2 100644 --- a/ccmain/adaptions.cpp +++ b/ccmain/adaptions.cpp @@ -47,7 +47,7 @@ BOOL8 Tesseract::word_adaptable( //should we adapt? uint16_t mode) { if (tessedit_adaption_debug) { tprintf("Running word_adaptable() for %s rating %.4f certainty %.4f\n", - word->best_choice == NULL ? "" : + word->best_choice == nullptr ? "" : word->best_choice->unichar_string().string(), word->best_choice->rating(), word->best_choice->certainty()); } @@ -106,7 +106,7 @@ BOOL8 Tesseract::word_adaptable( //should we adapt? } if (flags.bit (CHECK_SPACES) && - (strchr(word->best_choice->unichar_string().string(), ' ') != NULL)) { + (strchr(word->best_choice->unichar_string().string(), ' ') != nullptr)) { if (tessedit_adaption_debug) tprintf("word contains spaces\n"); return FALSE; } diff --git a/ccmain/applybox.cpp b/ccmain/applybox.cpp index 3316bc4bba..70e56d3e55 100644 --- a/ccmain/applybox.cpp +++ b/ccmain/applybox.cpp @@ -120,8 +120,8 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname, GenericVector boxes; GenericVector texts, full_texts; if (!ReadAllBoxes(applybox_page, true, fname, &boxes, &texts, &full_texts, - NULL)) { - return NULL; // Can't do it. + nullptr)) { + return nullptr; // Can't do it. } int box_count = boxes.size(); @@ -134,14 +134,14 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname, // In word mode, we use the boxes to make a word for each box, but // in blob mode we use the existing words and maximally chop them first. PAGE_RES* page_res = find_segmentation ? - NULL : SetupApplyBoxes(boxes, block_list); + nullptr : SetupApplyBoxes(boxes, block_list); clear_any_old_text(block_list); for (int i = 0; i < boxes.size() - 1; i++) { bool foundit = false; - if (page_res != NULL) { + if (page_res != nullptr) { if (i == 0) { - foundit = ResegmentCharBox(page_res, NULL, boxes[i], boxes[i + 1], + foundit = ResegmentCharBox(page_res, nullptr, boxes[i], boxes[i + 1], full_texts[i].string()); } else { foundit = ResegmentCharBox(page_res, &boxes[i-1], boxes[i], @@ -158,7 +158,7 @@ PAGE_RES* Tesseract::ApplyBoxes(const STRING& fname, } } - if (page_res == NULL) { + if (page_res == nullptr) { // In word/line mode, we now maximally chop all the words and resegment // them with the classifier. page_res = SetupApplyBoxes(boxes, block_list); @@ -236,10 +236,10 @@ PAGE_RES* Tesseract::SetupApplyBoxes(const GenericVector& boxes, } } } - PAGE_RES* page_res = new PAGE_RES(false, block_list, NULL); + PAGE_RES* page_res = new PAGE_RES(false, block_list, nullptr); PAGE_RES_IT pr_it(page_res); WERD_RES* word_res; - while ((word_res = pr_it.word()) != NULL) { + while ((word_res = pr_it.word()) != nullptr) { MaximallyChopWord(boxes, pr_it.block()->block, pr_it.row()->row, word_res); pr_it.forward(); @@ -254,7 +254,7 @@ void Tesseract::MaximallyChopWord(const GenericVector& boxes, BLOCK* block, ROW* row, WERD_RES* word_res) { if (!word_res->SetupForRecognition(unicharset, this, BestPix(), - tessedit_ocr_engine_mode, NULL, + tessedit_ocr_engine_mode, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, @@ -288,9 +288,9 @@ void Tesseract::MaximallyChopWord(const GenericVector& boxes, int right_chop_index = 0; if (!assume_fixed_pitch_char_segment) { // We only chop if the language is not fixed pitch like CJK. - SEAM* seam = NULL; + SEAM* seam = nullptr; while ((seam = chop_one_blob(boxes, blob_choices, word_res, - &blob_number)) != NULL) { + &blob_number)) != nullptr) { word_res->InsertSeam(blob_number, seam); BLOB_CHOICE* left_choice = blob_choices[blob_number]; rating = left_choice->rating() / e; @@ -345,7 +345,7 @@ bool Tesseract::ResegmentCharBox(PAGE_RES* page_res, const TBOX *prev_box, } PAGE_RES_IT page_res_it(page_res); WERD_RES* word_res; - for (word_res = page_res_it.word(); word_res != NULL; + for (word_res = page_res_it.word(); word_res != nullptr; word_res = page_res_it.forward()) { if (!word_res->box_word->bounding_box().major_overlap(box)) continue; @@ -381,7 +381,7 @@ bool Tesseract::ResegmentCharBox(PAGE_RES* page_res, const TBOX *prev_box, } if (!char_box.almost_equal(box, 3) && (box.x_gap(next_box) < -3 || - (prev_box != NULL && prev_box->x_gap(box) < -3))) { + (prev_box != nullptr && prev_box->x_gap(box) < -3))) { return false; } // We refine just the box_word, best_state and correct_text here. @@ -441,7 +441,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, if (applybox_debug > 1) { tprintf("\nAPPLY_BOX: in ResegmentWordBox() for %s\n", correct_text); } - WERD* new_word = NULL; + WERD* new_word = nullptr; BLOCK_IT b_it(block_list); for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) { BLOCK* block = b_it.data(); @@ -459,7 +459,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, tprintf("Checking word:"); word->bounding_box().print(); } - if (word->text() != NULL && word->text()[0] != '\0') + if (word->text() != nullptr && word->text()[0] != '\0') continue; // Ignore words that are already done. if (!box.major_overlap(word->bounding_box())) continue; @@ -488,7 +488,7 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, tprintf("With next box:"); next_box.print(); } - if (new_word == NULL) { + if (new_word == nullptr) { // Make a new word with a single blob. new_word = word->shallow_copy(); new_word->set_text(correct_text); @@ -500,8 +500,8 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, } } } - if (new_word == NULL && applybox_debug > 0) tprintf("FAIL!\n"); - return new_word != NULL; + if (new_word == nullptr && applybox_debug > 0) tprintf("FAIL!\n"); + return new_word != nullptr; } /// Resegments the words by running the classifier in an attempt to find the @@ -509,9 +509,9 @@ bool Tesseract::ResegmentWordBox(BLOCK_LIST *block_list, void Tesseract::ReSegmentByClassification(PAGE_RES* page_res) { PAGE_RES_IT pr_it(page_res); WERD_RES* word_res; - for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) { + for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) { WERD* word = word_res->word; - if (word->text() == NULL || word->text()[0] == '\0') + if (word->text() == nullptr || word->text()[0] == '\0') continue; // Ignore words that have no text. // Convert the correct text to a vector of UNICHAR_ID GenericVector target_text; @@ -536,7 +536,7 @@ bool Tesseract::ConvertStringToUnichars(const char* utf8, GenericVector* class_ids) { for (int step = 0; *utf8 != '\0'; utf8 += step) { const char* next_space = strchr(utf8, ' '); - if (next_space == NULL) + if (next_space == nullptr) next_space = utf8 + strlen(utf8); step = next_space - utf8; UNICHAR_ID class_id = unicharset.unichar_to_id(utf8, step); @@ -648,7 +648,7 @@ void Tesseract::SearchForText(const GenericVector* choices, break; } // Search ambigs table. - if (class_id < table.size() && table[class_id] != NULL) { + if (class_id < table.size() && table[class_id] != nullptr) { AmbigSpec_IT spec_it(table[class_id]); for (spec_it.mark_cycle_pt(); !spec_it.cycled_list(); spec_it.forward()) { @@ -710,7 +710,7 @@ void Tesseract::TidyUp(PAGE_RES* page_res) { int unlabelled_words = 0; PAGE_RES_IT pr_it(page_res); WERD_RES* word_res; - for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) { + for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) { int ok_in_word = 0; int blob_count = word_res->correct_text.size(); WERD_CHOICE* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count); @@ -742,7 +742,7 @@ void Tesseract::TidyUp(PAGE_RES* page_res) { } } pr_it.restart_page(); - for (; (word_res = pr_it.word()) != NULL; pr_it.forward()) { + for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) { // Denormalize back to a BoxWord. word_res->RebuildBestState(); word_res->SetupBoxWord(); @@ -771,7 +771,7 @@ void Tesseract::ReportFailedBox(int boxfile_lineno, TBOX box, /** Creates a fake best_choice entry in each WERD_RES with the correct text.*/ void Tesseract::CorrectClassifyWords(PAGE_RES* page_res) { PAGE_RES_IT pr_it(page_res); - for (WERD_RES *word_res = pr_it.word(); word_res != NULL; + for (WERD_RES *word_res = pr_it.word(); word_res != nullptr; word_res = pr_it.forward()) { WERD_CHOICE* choice = new WERD_CHOICE(word_res->uch_set, word_res->correct_text.size()); @@ -796,7 +796,7 @@ void Tesseract::CorrectClassifyWords(PAGE_RES* page_res) { void Tesseract::ApplyBoxTraining(const STRING& fontname, PAGE_RES* page_res) { PAGE_RES_IT pr_it(page_res); int word_count = 0; - for (WERD_RES *word_res = pr_it.word(); word_res != NULL; + for (WERD_RES *word_res = pr_it.word(); word_res != nullptr; word_res = pr_it.forward()) { LearnWord(fontname.string(), word_res); ++word_count; diff --git a/ccmain/control.cpp b/ccmain/control.cpp index 2f01366e6b..c05d7c622f 100644 --- a/ccmain/control.cpp +++ b/ccmain/control.cpp @@ -67,7 +67,7 @@ namespace tesseract { void Tesseract::recog_pseudo_word(PAGE_RES* page_res, TBOX &selection_box) { PAGE_RES_IT* it = make_pseudo_word(page_res, selection_box); - if (it != NULL) { + if (it != nullptr) { recog_interactive(it); it->DeleteCurrentWord(); delete it; @@ -86,7 +86,7 @@ BOOL8 Tesseract::recog_interactive(PAGE_RES_IT* pr_it) { WordData word_data(*pr_it); SetupWordPassN(2, &word_data); // LSTM doesn't run on pass2, but we want to run pass2 for tesseract. - if (lstm_recognizer_ == NULL) { + if (lstm_recognizer_ == nullptr) { classify_word_and_language(2, pr_it, &word_data); } else { classify_word_and_language(1, pr_it, &word_data); @@ -122,9 +122,9 @@ bool Tesseract::ProcessTargetWord(const TBOX& word_box, const TBOX& target_word_box, const char* word_config, int pass) { - if (word_config != NULL) { + if (word_config != nullptr) { if (word_box.major_overlap(target_word_box)) { - if (backup_config_file_ == NULL) { + if (backup_config_file_ == nullptr) { backup_config_file_ = kBackUpConfigFile; FILE* config_fp = fopen(backup_config_file_, "wb"); ParamUtils::PrintParams(config_fp, params()); @@ -134,11 +134,11 @@ bool Tesseract::ProcessTargetWord(const TBOX& word_box, params()); } } else { - if (backup_config_file_ != NULL) { + if (backup_config_file_ != nullptr) { ParamUtils::ReadParamsFile(backup_config_file_, SET_PARAM_CONSTRAINT_DEBUG_ONLY, params()); - backup_config_file_ = NULL; + backup_config_file_ = nullptr; } } } else if (pass > 1 && !word_box.major_overlap(target_word_box)) { @@ -155,9 +155,9 @@ void Tesseract::SetupAllWordsPassN(int pass_n, GenericVector* words) { // Prepare all the words. PAGE_RES_IT page_res_it(page_res); - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { - if (target_word_box == NULL || + if (target_word_box == nullptr || ProcessTargetWord(page_res_it.word()->word->bounding_box(), *target_word_box, word_config, 1)) { words->push_back(WordData(page_res_it)); @@ -175,7 +175,7 @@ void Tesseract::SetupWordPassN(int pass_n, WordData* word) { if (pass_n == 1 || !word->word->done) { if (pass_n == 1) { word->word->SetupForRecognition(unicharset, this, BestPix(), - tessedit_ocr_engine_mode, NULL, + tessedit_ocr_engine_mode, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, @@ -197,7 +197,7 @@ void Tesseract::SetupWordPassN(int pass_n, WordData* word) { if (pass_n == 1 || lang_t->tessedit_ocr_engine_mode != OEM_LSTM_ONLY) { word_res->SetupForRecognition( lang_t->unicharset, lang_t, BestPix(), - lang_t->tessedit_ocr_engine_mode, NULL, + lang_t->tessedit_ocr_engine_mode, nullptr, lang_t->classify_bln_numeric_mode, lang_t->textord_use_cjk_fp_model, lang_t->poly_allow_detailed_fx, word->row, word->block); @@ -219,23 +219,23 @@ bool Tesseract::RecogAllWordsPassN(int pass_n, ETEXT_DESC* monitor, for (int w = 0; w < words->size(); ++w) { WordData* word = &(*words)[w]; if (w > 0) word->prev_word = &(*words)[w - 1]; - if (monitor != NULL) { + if (monitor != nullptr) { monitor->ocr_alive = TRUE; if (pass_n == 1) { monitor->progress = 70 * w / words->size(); - if (monitor->progress_callback != NULL) { + if (monitor->progress_callback != nullptr) { TBOX box = pr_it->word()->word->bounding_box(); (*monitor->progress_callback)(monitor->progress, box.left(), box.right(), box.top(), box.bottom()); } } else { monitor->progress = 70 + 30 * w / words->size(); - if (monitor->progress_callback != NULL) { + if (monitor->progress_callback != nullptr) { (*monitor->progress_callback)(monitor->progress, 0, 0, 0, 0); } } if (monitor->deadline_exceeded() || - (monitor->cancel != NULL && (*monitor->cancel)(monitor->cancel_this, + (monitor->cancel != nullptr && (*monitor->cancel)(monitor->cancel_this, words->size()))) { // Timeout. Fake out the rest of the words. for (; w < words->size(); ++w) { @@ -252,9 +252,9 @@ bool Tesseract::RecogAllWordsPassN(int pass_n, ETEXT_DESC* monitor, if (s > word->lang_words.size()) continue; } // Sync pr_it with the wth WordData. - while (pr_it->word() != NULL && pr_it->word() != word->word) + while (pr_it->word() != nullptr && pr_it->word() != word->word) pr_it->forward(); - ASSERT_HOST(pr_it->word() != NULL); + ASSERT_HOST(pr_it->word() != nullptr); bool make_next_word_fuzzy = false; if (!AnyLSTMLang() && ReassignDiacritics(pass_n, pr_it, &make_next_word_fuzzy)) { @@ -269,7 +269,7 @@ bool Tesseract::RecogAllWordsPassN(int pass_n, ETEXT_DESC* monitor, word->word->best_choice->debug_string().string()); } pr_it->forward(); - if (make_next_word_fuzzy && pr_it->word() != NULL) { + if (make_next_word_fuzzy && pr_it->word() != nullptr) { pr_it->MakeCurrentWordFuzzy(); } } @@ -351,7 +351,7 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res, // Run pass 1 word recognition. if (!RecogAllWordsPassN(1, monitor, &page_res_it, &words)) return false; // Pass 1 post-processing. - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { if (page_res_it.word()->word->flag(W_REP_CHAR)) { fix_rep_char(&page_res_it); @@ -364,7 +364,7 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res, // Update misadaption log (we only need to do it on pass 1, since // adaption only happens on this pass). - if (page_res_it.word()->blamer_bundle != NULL && + if (page_res_it.word()->blamer_bundle != nullptr && page_res_it.word()->blamer_bundle->misadaption_debug().length() > 0) { page_res->misadaption_log.push_back( page_res_it.word()->blamer_bundle->misadaption_debug()); @@ -429,19 +429,19 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res, textord_.CleanupSingleRowResult(pageseg_mode, page_res); // Remove empty words, as these mess up the result iterators. - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { WERD_RES* word = page_res_it.word(); - POLY_BLOCK* pb = page_res_it.block()->block != NULL + POLY_BLOCK* pb = page_res_it.block()->block != nullptr ? page_res_it.block()->block->pdblk.poly_block() - : NULL; - if (word->best_choice == NULL || word->best_choice->length() == 0 || - (word->best_choice->IsAllSpaces() && (pb == NULL || pb->IsText()))) { + : nullptr; + if (word->best_choice == nullptr || word->best_choice->length() == 0 || + (word->best_choice->IsAllSpaces() && (pb == nullptr || pb->IsText()))) { page_res_it.DeleteCurrentWord(); } } - if (monitor != NULL) { + if (monitor != nullptr) { monitor->progress = 100; } return true; @@ -450,11 +450,11 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res, void Tesseract::bigram_correction_pass(PAGE_RES *page_res) { PAGE_RES_IT word_it(page_res); - WERD_RES *w_prev = NULL; + WERD_RES *w_prev = nullptr; WERD_RES *w = word_it.word(); while (1) { w_prev = w; - while (word_it.forward() != NULL && + while (word_it.forward() != nullptr && (!word_it.word() || word_it.word()->part_of_combo)) { // advance word_it, skipping over parts of combos } @@ -603,15 +603,15 @@ void Tesseract::rejection_passes(PAGE_RES* page_res, // ****************** Pass 5 ******************* // Gather statistics on rejects. int word_index = 0; - while (!tessedit_test_adaption && page_res_it.word() != NULL) { + while (!tessedit_test_adaption && page_res_it.word() != nullptr) { set_global_loc_code(LOC_MM_ADAPT); WERD_RES* word = page_res_it.word(); word_index++; - if (monitor != NULL) { + if (monitor != nullptr) { monitor->ocr_alive = TRUE; monitor->progress = 95 + 5 * word_index / stats_.word_count; } - if (word->rebuild_word == NULL) { + if (word->rebuild_word == nullptr) { // Word was not processed by tesseract. page_res_it.forward(); continue; @@ -694,7 +694,7 @@ void Tesseract::rejection_passes(PAGE_RES* page_res, void Tesseract::blamer_pass(PAGE_RES* page_res) { if (!wordrec_run_blamer) return; PAGE_RES_IT page_res_it(page_res); - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { WERD_RES *word = page_res_it.word(); BlamerBundle::LastChanceBlame(wordrec_debug_blamer, word); @@ -717,7 +717,7 @@ void Tesseract::blamer_pass(PAGE_RES* page_res) { // Sets script positions and detects smallcaps on all output words. void Tesseract::script_pos_pass(PAGE_RES* page_res) { PAGE_RES_IT page_res_it(page_res); - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { WERD_RES* word = page_res_it.word(); if (word->word->flag(W_REP_CHAR)) { @@ -852,7 +852,7 @@ static int SelectBestWords(double rating_ratio, // New is better. for (int i = start_n; i < end_n; ++i) { out_words.push_back((*new_words)[i]); - (*new_words)[i] = NULL; + (*new_words)[i] = nullptr; ++num_new; } new_better = true; @@ -860,7 +860,7 @@ static int SelectBestWords(double rating_ratio, // Current best is better. for (int i = start_b; i < end_b; ++i) { out_words.push_back((*best_words)[i]); - (*best_words)[i] = NULL; + (*best_words)[i] = nullptr; ++num_best; } } @@ -900,7 +900,7 @@ int Tesseract::RetryWithLanguage(const WordData& word_data, // Transfer input word to new_words, as the classifier must have put // the result back in the input. new_words.push_back(*in_word); - *in_word = NULL; + *in_word = nullptr; } if (debug) { for (int i = 0; i < new_words.size(); ++i) @@ -957,17 +957,17 @@ bool Tesseract::ReassignDiacritics(int pass, PAGE_RES_IT* pr_it, wanted.push_back(word_wanted[i]); wanted_blobs.push_back(target_blobs[i]); wanted_outlines.push_back(outlines[i]); - outlines[i] = NULL; + outlines[i] = nullptr; } } - real_word->AddSelectedOutlines(wanted, wanted_blobs, wanted_outlines, NULL); + real_word->AddSelectedOutlines(wanted, wanted_blobs, wanted_outlines, nullptr); AssignDiacriticsToNewBlobs(outlines, pass, real_word, pr_it, &word_wanted, &target_blobs); int non_overlapped = 0; int non_overlapped_used = 0; for (int i = 0; i < word_wanted.size(); ++i) { if (word_wanted[i]) ++non_overlapped_used; - if (outlines[i] != NULL) ++non_overlapped_used; + if (outlines[i] != nullptr) ++non_overlapped_used; } if (debug_noise_removal) { tprintf("Used %d/%d overlapped %d/%d non-overlaped diacritics on word:", @@ -998,7 +998,7 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs( GenericVector blob_wanted; word_wanted->init_to_size(outlines.size(), false); overlapped_any_blob->init_to_size(outlines.size(), false); - target_blobs->init_to_size(outlines.size(), NULL); + target_blobs->init_to_size(outlines.size(), nullptr); // For each real blob, find the outlines that seriously overlap it. // A single blob could be several merged characters, so there can be quite // a few outlines overlapping, and the full engine needs to be used to chop @@ -1049,15 +1049,15 @@ void Tesseract::AssignDiacriticsToNewBlobs( GenericVector* target_blobs) { GenericVector blob_wanted; word_wanted->init_to_size(outlines.size(), false); - target_blobs->init_to_size(outlines.size(), NULL); + target_blobs->init_to_size(outlines.size(), nullptr); // Check for outlines that need to be turned into stand-alone blobs. for (int i = 0; i < outlines.size(); ++i) { - if (outlines[i] == NULL) continue; + if (outlines[i] == nullptr) continue; // Get a set of adjacent outlines that don't overlap any existing blob. blob_wanted.init_to_size(outlines.size(), false); int num_blob_outlines = 0; TBOX total_ol_box(outlines[i]->bounding_box()); - while (i < outlines.size() && outlines[i] != NULL) { + while (i < outlines.size() && outlines[i] != nullptr) { blob_wanted[i] = true; total_ol_box += outlines[i]->bounding_box(); ++i; @@ -1076,8 +1076,8 @@ void Tesseract::AssignDiacriticsToNewBlobs( tprintf("Num blobless outlines = %d\n", num_blob_outlines); C_BLOB* left_blob = blob_it.data(); TBOX left_box = left_blob->bounding_box(); - C_BLOB* right_blob = blob_it.at_last() ? NULL : blob_it.data_relative(1); - if ((left_box.x_overlap(total_ol_box) || right_blob == NULL || + C_BLOB* right_blob = blob_it.at_last() ? nullptr : blob_it.data_relative(1); + if ((left_box.x_overlap(total_ol_box) || right_blob == nullptr || !right_blob->bounding_box().x_overlap(total_ol_box)) && SelectGoodDiacriticOutlines(pass, noise_cert_disjoint, pr_it, left_blob, outlines, num_blob_outlines, @@ -1089,7 +1089,7 @@ void Tesseract::AssignDiacriticsToNewBlobs( (*target_blobs)[j] = left_blob; } } - } else if (right_blob != NULL && + } else if (right_blob != nullptr && (!left_box.x_overlap(total_ol_box) || right_blob->bounding_box().x_overlap(total_ol_box)) && SelectGoodDiacriticOutlines(pass, noise_cert_disjoint, pr_it, @@ -1102,14 +1102,14 @@ void Tesseract::AssignDiacriticsToNewBlobs( (*target_blobs)[j] = right_blob; } } - } else if (SelectGoodDiacriticOutlines(pass, noise_cert_punc, pr_it, NULL, + } else if (SelectGoodDiacriticOutlines(pass, noise_cert_punc, pr_it, nullptr, outlines, num_blob_outlines, &blob_wanted)) { if (debug_noise_removal) tprintf("Fitted between blobs\n"); for (int j = 0; j < blob_wanted.size(); ++j) { if (blob_wanted[j]) { (*word_wanted)[j] = true; - (*target_blobs)[j] = NULL; + (*target_blobs)[j] = nullptr; } } } @@ -1125,7 +1125,7 @@ bool Tesseract::SelectGoodDiacriticOutlines( GenericVector* ok_outlines) { STRING best_str; float target_cert = certainty_threshold; - if (blob != NULL) { + if (blob != nullptr) { float target_c2; target_cert = ClassifyBlobAsWord(pass, pr_it, blob, &best_str, &target_c2); if (debug_noise_removal) { @@ -1154,7 +1154,7 @@ bool Tesseract::SelectGoodDiacriticOutlines( // we get past the threshold, have zero bits, or fail to improve. int best_index = 0; // To zero out. while (num_outlines > 1 && best_index >= 0 && - (blob == NULL || best_cert < target_cert || blob != NULL)) { + (blob == nullptr || best_cert < target_cert || blob != nullptr)) { // Find the best bit to zero out. best_index = -1; for (int i = 0; i < outlines.size(); ++i) { @@ -1209,8 +1209,8 @@ float Tesseract::ClassifyBlobPlusOutlines( const GenericVector& outlines, int pass_n, PAGE_RES_IT* pr_it, C_BLOB* blob, STRING* best_str) { C_OUTLINE_IT ol_it; - C_OUTLINE* first_to_keep = NULL; - if (blob != NULL) { + C_OUTLINE* first_to_keep = nullptr; + if (blob != nullptr) { // Add the required outlines to the blob. ol_it.set_to_list(blob->out_list()); first_to_keep = ol_it.data(); @@ -1218,7 +1218,7 @@ float Tesseract::ClassifyBlobPlusOutlines( for (int i = 0; i < ok_outlines.size(); ++i) { if (ok_outlines[i]) { // This outline is to be added. - if (blob == NULL) { + if (blob == nullptr) { blob = new C_BLOB(outlines[i]); ol_it.set_to_list(blob->out_list()); } else { @@ -1229,7 +1229,7 @@ float Tesseract::ClassifyBlobPlusOutlines( float c2; float cert = ClassifyBlobAsWord(pass_n, pr_it, blob, best_str, &c2); ol_it.move_to_first(); - if (first_to_keep == NULL) { + if (first_to_keep == nullptr) { // We created blob. Empty its outlines and delete it. for (; !ol_it.empty(); ol_it.forward()) ol_it.extract(); delete blob; @@ -1254,7 +1254,7 @@ float Tesseract::ClassifyBlobAsWord(int pass_n, PAGE_RES_IT* pr_it, WERD_RES* word_res = pr_it->InsertSimpleCloneWord(*pr_it->word(), word); // Get a new iterator that points to the new word. PAGE_RES_IT it(pr_it->page_res); - while (it.word() != word_res && it.word() != NULL) it.forward(); + while (it.word() != word_res && it.word() != nullptr) it.forward(); ASSERT_HOST(it.word() == word_res); WordData wd(it); // Force full initialization. @@ -1341,7 +1341,7 @@ void Tesseract::classify_word_and_language(int pass_n, PAGE_RES_IT* pr_it, word_data->word = best_words.back(); pr_it->ReplaceCurrentWord(&best_words); } - ASSERT_HOST(word_data->word->box_word != NULL); + ASSERT_HOST(word_data->word->box_word != nullptr); } else { tprintf("no best words!!\n"); } @@ -1364,8 +1364,8 @@ void Tesseract::classify_word_pass1(const WordData& word_data, PointerVector* out_words) { ROW* row = word_data.row; BLOCK* block = word_data.block; - prev_word_best_choice_ = word_data.prev_word != NULL - ? word_data.prev_word->word->best_choice : NULL; + prev_word_best_choice_ = word_data.prev_word != nullptr + ? word_data.prev_word->word->best_choice : nullptr; #ifndef ANDROID_BUILD if (tessedit_ocr_engine_mode == OEM_LSTM_ONLY || tessedit_ocr_engine_mode == OEM_TESSERACT_LSTM_COMBINED) { @@ -1381,7 +1381,7 @@ void Tesseract::classify_word_pass1(const WordData& word_data, } // Fall back to tesseract for failed words or odd words. (*in_word)->SetupForRecognition(unicharset, this, BestPix(), - OEM_TESSERACT_ONLY, NULL, + OEM_TESSERACT_ONLY, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, row, block); @@ -1396,9 +1396,9 @@ void Tesseract::classify_word_pass1(const WordData& word_data, if (adapt_ok) { // Send word to adaptive classifier for training. word->BestChoiceToCorrectText(); - LearnWord(NULL, word); + LearnWord(nullptr, word); // Mark misadaptions if running blamer. - if (word->blamer_bundle != NULL) { + if (word->blamer_bundle != nullptr) { word->blamer_bundle->SetMisAdaptionDebug(word->best_choice, wordrec_debug_blamer); } @@ -1470,7 +1470,7 @@ bool Tesseract::TestNewNormalization(int original_misfits, WERD_RES *word, BLOCK* block, ROW *row) { bool accept_new_x_ht = false; WERD_RES new_x_ht_word(word->word); - if (word->blamer_bundle != NULL) { + if (word->blamer_bundle != nullptr) { new_x_ht_word.blamer_bundle = new BlamerBundle(); new_x_ht_word.blamer_bundle->CopyTruth(*(word->blamer_bundle)); } @@ -1478,7 +1478,7 @@ bool Tesseract::TestNewNormalization(int original_misfits, new_x_ht_word.baseline_shift = baseline_shift; new_x_ht_word.caps_height = 0.0; new_x_ht_word.SetupForRecognition( - unicharset, this, BestPix(), tessedit_ocr_engine_mode, NULL, + unicharset, this, BestPix(), tessedit_ocr_engine_mode, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, row, block); match_word_pass_n(2, &new_x_ht_word, row, block); @@ -1526,8 +1526,8 @@ void Tesseract::classify_word_pass2(const WordData& word_data, ROW* row = word_data.row; BLOCK* block = word_data.block; WERD_RES* word = *in_word; - prev_word_best_choice_ = word_data.prev_word != NULL - ? word_data.prev_word->word->best_choice : NULL; + prev_word_best_choice_ = word_data.prev_word != nullptr + ? word_data.prev_word->word->best_choice : nullptr; set_global_subloc_code(SUBLOC_NORM); check_debug_pt(word, 30); @@ -1552,7 +1552,7 @@ void Tesseract::classify_word_pass2(const WordData& word_data, } #ifndef GRAPHICS_DISABLED if (tessedit_display_outwords) { - if (fx_win == NULL) + if (fx_win == nullptr) create_fx_win(); clear_fx_win(); word->rebuild_word->plot(fx_win); @@ -1600,20 +1600,20 @@ void Tesseract::match_word_pass_n(int pass_n, WERD_RES *word, } set_word_fonts(word); - ASSERT_HOST(word->raw_choice != NULL); + ASSERT_HOST(word->raw_choice != nullptr); } // Helper to return the best rated BLOB_CHOICE in the whole word that matches -// the given char_id, or NULL if none can be found. +// the given char_id, or nullptr if none can be found. static BLOB_CHOICE* FindBestMatchingChoice(UNICHAR_ID char_id, WERD_RES* word_res) { // Find the corresponding best BLOB_CHOICE from any position in the word_res. - BLOB_CHOICE* best_choice = NULL; + BLOB_CHOICE* best_choice = nullptr; for (int i = 0; i < word_res->best_choice->length(); ++i) { BLOB_CHOICE* choice = FindMatchingChoice(char_id, word_res->GetBlobChoices(i)); - if (choice != NULL) { - if (best_choice == NULL || choice->rating() < best_choice->rating()) + if (choice != nullptr) { + if (best_choice == nullptr || choice->rating() < best_choice->rating()) best_choice = choice; } } @@ -1629,7 +1629,7 @@ static void CorrectRepcharChoices(BLOB_CHOICE* blob_choice, for (int i = 0; i < word_res->best_choice->length(); ++i) { BLOB_CHOICE* choice = FindMatchingChoice(blob_choice->unichar_id(), word_res->GetBlobChoices(i)); - if (choice == NULL) { + if (choice == nullptr) { BLOB_CHOICE_IT choice_it(word_res->GetBlobChoices(i)); choice_it.add_before_stay_put(new BLOB_CHOICE(*blob_choice)); } @@ -1663,7 +1663,7 @@ void Tesseract::fix_rep_char(PAGE_RES_IT* page_res_it) { int max_count = rep_ch.MaxCount(&maxch_id); // Find the best exemplar of a classifier result for maxch_id. BLOB_CHOICE* best_choice = FindBestMatchingChoice(maxch_id, word_res); - if (best_choice == NULL) { + if (best_choice == nullptr) { tprintf("Failed to find a choice for %s, occurring %d times\n", word_res->uch_set->debug_str(maxch_id).string(), max_count); return; @@ -1851,7 +1851,7 @@ BOOL8 Tesseract::check_debug_pt(WERD_RES *word, int location) { show_map_detail = TRUE; break; } - if (word->best_choice != NULL) { + if (word->best_choice != nullptr) { tprintf(" \"%s\" ", word->best_choice->unichar_string().string()); word->reject_map.print(debug_fp); tprintf("\n"); @@ -1907,8 +1907,8 @@ static void find_modal_font( // good chars in word void Tesseract::set_word_fonts(WERD_RES *word) { // Don't try to set the word fonts for an lstm word, as the configs // will be meaningless. - if (word->chopped_word == NULL) return; - ASSERT_HOST(word->best_choice != NULL); + if (word->chopped_word == nullptr) return; + ASSERT_HOST(word->best_choice != nullptr); int fontinfo_size = get_fontinfo_table().size(); if (fontinfo_size == 0) return; @@ -1924,7 +1924,7 @@ void Tesseract::set_word_fonts(WERD_RES *word) { } for (int b = 0; b < word->best_choice->length(); ++b) { BLOB_CHOICE* choice = word->GetBlobChoice(b); - if (choice == NULL) continue; + if (choice == nullptr) continue; const GenericVector& fonts = choice->fonts(); for (int f = 0; f < fonts.size(); ++f) { int fontinfo_id = fonts[f].fontinfo_id; @@ -1951,8 +1951,8 @@ void Tesseract::set_word_fonts(WERD_RES *word) { font_id2 = f; } } - word->fontinfo = font_id1 >= 0 ? &fontinfo_table_.get(font_id1) : NULL; - word->fontinfo2 = font_id2 >= 0 ? &fontinfo_table_.get(font_id2) : NULL; + word->fontinfo = font_id1 >= 0 ? &fontinfo_table_.get(font_id1) : nullptr; + word->fontinfo2 = font_id2 >= 0 ? &fontinfo_table_.get(font_id2) : nullptr; // Each score has a limit of UINT16_MAX, so divide by that to get the number // of "votes" for that font, ie number of perfect scores. word->fontinfo_id_count = ClipToRange(score1 / UINT16_MAX, 1, INT8_MAX); @@ -1988,13 +1988,13 @@ void Tesseract::font_recognition_pass(PAGE_RES* page_res) { STATS doc_fonts(0, font_table_size_); // font counters // Gather font id statistics. - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { word = page_res_it.word(); - if (word->fontinfo != NULL) { + if (word->fontinfo != nullptr) { doc_fonts.add(word->fontinfo->universal_id, word->fontinfo_id_count); } - if (word->fontinfo2 != NULL) { + if (word->fontinfo2 != nullptr) { doc_fonts.add(word->fontinfo2->universal_id, word->fontinfo_id2_count); } } @@ -2004,23 +2004,23 @@ void Tesseract::font_recognition_pass(PAGE_RES* page_res) { if (doc_font_count == 0) return; // Get the modal font pointer. - const FontInfo* modal_font = NULL; - for (page_res_it.restart_page(); page_res_it.word() != NULL; + const FontInfo* modal_font = nullptr; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { word = page_res_it.word(); - if (word->fontinfo != NULL && word->fontinfo->universal_id == doc_font) { + if (word->fontinfo != nullptr && word->fontinfo->universal_id == doc_font) { modal_font = word->fontinfo; break; } - if (word->fontinfo2 != NULL && word->fontinfo2->universal_id == doc_font) { + if (word->fontinfo2 != nullptr && word->fontinfo2->universal_id == doc_font) { modal_font = word->fontinfo2; break; } } - ASSERT_HOST(modal_font != NULL); + ASSERT_HOST(modal_font != nullptr); // Assign modal font to weak words. - for (page_res_it.restart_page(); page_res_it.word() != NULL; + for (page_res_it.restart_page(); page_res_it.word() != nullptr; page_res_it.forward()) { word = page_res_it.word(); int length = word->best_choice->length(); @@ -2041,7 +2041,7 @@ void Tesseract::font_recognition_pass(PAGE_RES* page_res) { // dictionary. void Tesseract::dictionary_correction_pass(PAGE_RES *page_res) { PAGE_RES_IT word_it(page_res); - for (WERD_RES* word = word_it.word(); word != NULL; + for (WERD_RES* word = word_it.word(); word != nullptr; word = word_it.forward()) { if (word->best_choices.singleton()) continue; // There are no alternates. diff --git a/ccmain/docqual.cpp b/ccmain/docqual.cpp index 12fa19cec9..cfa2a4c646 100644 --- a/ccmain/docqual.cpp +++ b/ccmain/docqual.cpp @@ -63,8 +63,8 @@ struct DocQualCallbacks { * left hand blob edge. *************************************************************************/ int16_t Tesseract::word_blob_quality(WERD_RES *word, ROW *row) { - if (word->bln_boxes == NULL || - word->rebuild_word == NULL || word->rebuild_word->blobs.empty()) + if (word->bln_boxes == nullptr || + word->rebuild_word == nullptr || word->rebuild_word->blobs.empty()) return 0; DocQualCallbacks cb(word); @@ -78,7 +78,7 @@ int16_t Tesseract::word_outline_errs(WERD_RES *word) { int16_t i = 0; int16_t err_count = 0; - if (word->rebuild_word != NULL) { + if (word->rebuild_word != nullptr) { for (int 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], @@ -98,7 +98,7 @@ void Tesseract::word_char_quality(WERD_RES *word, ROW *row, int16_t *match_count, int16_t *accepted_match_count) { - if (word->bln_boxes == NULL || word->rebuild_word == NULL || + if (word->bln_boxes == nullptr || word->rebuild_word == nullptr || word->rebuild_word->blobs.empty()) { *match_count = 0; *accepted_match_count = 0; @@ -118,8 +118,8 @@ void Tesseract::word_char_quality(WERD_RES *word, * Unreject POTENTIAL rejects if the blob passes the blob and outline checks *************************************************************************/ void Tesseract::unrej_good_chs(WERD_RES *word, ROW *row) { - if (word->bln_boxes == NULL || - word->rebuild_word == NULL || word->rebuild_word->blobs.empty()) + if (word->bln_boxes == nullptr || + word->rebuild_word == nullptr || word->rebuild_word->blobs.empty()) return; DocQualCallbacks cb(word); @@ -170,7 +170,7 @@ void Tesseract::unrej_good_quality_words( //unreject potential int i; page_res_it.restart_page (); - while (page_res_it.word () != NULL) { + while (page_res_it.word () != nullptr) { check_debug_pt (page_res_it.word (), 100); if (bland_unrej) { word = page_res_it.word (); @@ -198,7 +198,7 @@ void Tesseract::unrej_good_quality_words( //unreject potential else { /* Skip to end of dodgy row */ current_row = page_res_it.row (); - while ((page_res_it.word () != NULL) && + while ((page_res_it.word () != nullptr) && (page_res_it.row () == current_row)) page_res_it.forward (); } @@ -207,9 +207,9 @@ void Tesseract::unrej_good_quality_words( //unreject potential page_res_it.restart_page (); page_res_it.page_res->char_count = 0; page_res_it.page_res->rej_count = 0; - current_block = NULL; - current_row = NULL; - while (page_res_it.word () != NULL) { + current_block = nullptr; + current_row = nullptr; + while (page_res_it.word () != nullptr) { if (current_block != page_res_it.block ()) { current_block = page_res_it.block (); current_block->char_count = 0; @@ -266,7 +266,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks page_res_it.restart_page(); WERD_RES* word; - while ((word = page_res_it.word()) != NULL) { + while ((word = page_res_it.word()) != nullptr) { current_block = page_res_it.block(); block_no = current_block->block->pdblk.index(); if (current_block->char_count > 0 && @@ -278,7 +278,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks current_block->rej_count); } prev_word_rejected = FALSE; - while ((word = page_res_it.word()) != NULL && + while ((word = page_res_it.word()) != nullptr && (page_res_it.block() == current_block)) { if (tessedit_preserve_blk_rej_perfect_wds) { rej_word = word->reject_map.reject_count() > 0 || @@ -323,7 +323,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks /* Walk rows in block testing for row rejection */ row_no = 0; - while (page_res_it.word() != NULL && + while (page_res_it.word() != nullptr && page_res_it.block() == current_block) { current_row = page_res_it.row(); row_no++; @@ -344,7 +344,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks current_row->rej_count); } prev_word_rejected = FALSE; - while ((word = page_res_it.word()) != NULL && + while ((word = page_res_it.word()) != nullptr && page_res_it.row () == current_row) { /* Preserve words on good docs unless they are mostly rejected*/ if (!tessedit_row_rej_good_docs && good_quality_doc) { @@ -390,7 +390,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks tprintf("NOT REJECTING ROW %d #chars: %d # Rejects: %d; \n", row_no, current_row->char_count, current_row->rej_count); } - while (page_res_it.word() != NULL && + while (page_res_it.word() != nullptr && page_res_it.row() == current_row) page_res_it.forward(); } @@ -410,7 +410,7 @@ void Tesseract::doc_and_block_rejection( //reject big chunks void reject_whole_page(PAGE_RES_IT &page_res_it) { page_res_it.restart_page (); - while (page_res_it.word () != NULL) { + while (page_res_it.word () != nullptr) { page_res_it.word ()->reject_map.rej_word_doc_rej (); page_res_it.forward (); } @@ -428,9 +428,9 @@ void Tesseract::tilde_crunch(PAGE_RES_IT &page_res_it) { BOOL8 ok_dict_word; page_res_it.restart_page(); - while (page_res_it.word() != NULL) { + while (page_res_it.word() != nullptr) { POLY_BLOCK* pb = page_res_it.block()->block->pdblk.poly_block(); - if (pb != NULL && !pb->IsText()) { + if (pb != nullptr && !pb->IsText()) { page_res_it.forward(); continue; } @@ -602,7 +602,7 @@ void Tesseract::tilde_delete(PAGE_RES_IT &page_res_it) { CRUNCH_MODE x_delete_mode; page_res_it.restart_page(); - while (page_res_it.word() != NULL) { + while (page_res_it.word() != nullptr) { word = page_res_it.word(); delete_mode = word_deletable (word, debug_delete_mode); @@ -834,7 +834,7 @@ GARBAGE_LEVEL Tesseract::garbage_word(WERD_RES *word, BOOL8 ok_dict_word) { return G_NEVER_CRUNCH; } if (word->reject_map.length() > 1 && - strpbrk(str, " ") == NULL && + strpbrk(str, " ") == nullptr && (word->best_choice->permuter() == SYSTEM_DAWG_PERM || word->best_choice->permuter() == FREQ_DAWG_PERM || word->best_choice->permuter() == USER_DAWG_PERM || @@ -911,8 +911,8 @@ CRUNCH_MODE Tesseract::word_deletable(WERD_RES *word, int16_t &delete_mode) { return CR_DELETE; } - if (word->rebuild_word != NULL) { - // Cube leaves rebuild_word NULL. + if (word->rebuild_word != nullptr) { + // Cube leaves rebuild_word nullptr. box = word->rebuild_word->bounding_box(); if (box.height () < crunch_del_min_ht * kBlnXHeight) { delete_mode = 4; @@ -988,7 +988,7 @@ BOOL8 Tesseract::noise_outlines(TWERD *word) { for (int b = 0; b < word->NumBlobs(); ++b) { TBLOB* blob = word->blobs[b]; - for (TESSLINE* ol = blob->outlines; ol != NULL; ol = ol->next) { + for (TESSLINE* ol = blob->outlines; ol != nullptr; ol = ol->next) { outline_count++; box = ol->bounding_box(); if (box.height() > box.width()) diff --git a/ccmain/equationdetect.cpp b/ccmain/equationdetect.cpp index 4d9b940645..911da95f65 100644 --- a/ccmain/equationdetect.cpp +++ b/ccmain/equationdetect.cpp @@ -53,7 +53,7 @@ namespace tesseract { static int SortCPByTopReverse(const void* p1, const void* p2) { const ColPartition* cp1 = *static_cast(p1); const ColPartition* cp2 = *static_cast(p2); - ASSERT_HOST(cp1 != NULL && cp2 != NULL); + ASSERT_HOST(cp1 != nullptr && cp2 != nullptr); const TBOX &box1(cp1->bounding_box()), &box2(cp2->bounding_box()); return box2.top() - box1.top(); } @@ -61,7 +61,7 @@ static int SortCPByTopReverse(const void* p1, const void* p2) { static int SortCPByBottom(const void* p1, const void* p2) { const ColPartition* cp1 = *static_cast(p1); const ColPartition* cp2 = *static_cast(p2); - ASSERT_HOST(cp1 != NULL && cp2 != NULL); + ASSERT_HOST(cp1 != nullptr && cp2 != nullptr); const TBOX &box1(cp1->bounding_box()), &box2(cp2->bounding_box()); return box1.bottom() - box2.bottom(); } @@ -69,7 +69,7 @@ static int SortCPByBottom(const void* p1, const void* p2) { static int SortCPByHeight(const void* p1, const void* p2) { const ColPartition* cp1 = *static_cast(p1); const ColPartition* cp2 = *static_cast(p2); - ASSERT_HOST(cp1 != NULL && cp2 != NULL); + ASSERT_HOST(cp1 != nullptr && cp2 != nullptr); const TBOX &box1(cp1->bounding_box()), &box2(cp2->bounding_box()); return box1.height() - box2.height(); } @@ -100,10 +100,10 @@ inline bool IsRightIndented(const EquationDetect::IndentType type) { EquationDetect::EquationDetect(const char* equ_datapath, const char* equ_name) { const char* default_name = "equ"; - if (equ_name == NULL) { + if (equ_name == nullptr) { equ_name = default_name; } - lang_tesseract_ = NULL; + lang_tesseract_ = nullptr; resolution_ = 0; page_count_ = 0; @@ -113,7 +113,7 @@ EquationDetect::EquationDetect(const char* equ_datapath, " but %s failed to load from %s\n", equ_name, equ_datapath); } - cps_super_bbox_ = NULL; + cps_super_bbox_ = nullptr; } EquationDetect::~EquationDetect() { delete (cps_super_bbox_); } @@ -127,8 +127,8 @@ void EquationDetect::SetResolution(const int resolution) { } int EquationDetect::LabelSpecialText(TO_BLOCK* to_block) { - if (to_block == NULL) { - tprintf("Warning: input to_block is NULL!\n"); + if (to_block == nullptr) { + tprintf("Warning: input to_block is nullptr!\n"); return -1; } @@ -148,7 +148,7 @@ int EquationDetect::LabelSpecialText(TO_BLOCK* to_block) { void EquationDetect::IdentifySpecialText( BLOBNBOX *blobnbox, const int height_th) { - ASSERT_HOST(blobnbox != NULL); + ASSERT_HOST(blobnbox != nullptr); if (blobnbox->bounding_box().height() < height_th && height_th > 0) { // For small blob, we simply set to BSTT_NONE. blobnbox->set_special_text_type(BSTT_NONE); @@ -167,9 +167,9 @@ void EquationDetect::IdentifySpecialText( float scaling = static_cast(kBlnXHeight) / box.height(); float x_orig = (box.left() + box.right()) / 2.0f, y_orig = box.bottom(); TBLOB* normed_blob = new TBLOB(*tblob); - normed_blob->Normalize(NULL, NULL, NULL, x_orig, y_orig, scaling, scaling, + normed_blob->Normalize(nullptr, nullptr, nullptr, x_orig, y_orig, scaling, scaling, 0.0f, static_cast(kBlnBaselineOffset), - false, NULL); + false, nullptr); equ_tesseract_.AdaptiveClassifier(normed_blob, &ratings_equ); lang_tesseract_->AdaptiveClassifier(normed_blob, &ratings_lang); delete normed_blob; @@ -178,7 +178,7 @@ void EquationDetect::IdentifySpecialText( // Get the best choice from ratings_lang and rating_equ. As the choice in the // list has already been sorted by the certainty, we simply use the first // choice. - BLOB_CHOICE *lang_choice = NULL, *equ_choice = NULL; + BLOB_CHOICE *lang_choice = nullptr, *equ_choice = nullptr; if (ratings_lang.length() > 0) { BLOB_CHOICE_IT choice_it(&ratings_lang); lang_choice = choice_it.data(); @@ -267,9 +267,9 @@ void EquationDetect::IdentifySpecialText() { lang_tesseract_->classify_integer_matcher_multiplier.set_value(0); ColPartitionGridSearch gsearch(part_grid_); - ColPartition *part = NULL; + ColPartition *part = nullptr; gsearch.StartFullSearch(); - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { if (!IsTextOrEquationType(part->type())) { continue; } @@ -357,11 +357,11 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) { int EquationDetect::FindEquationParts( ColPartitionGrid* part_grid, ColPartitionSet** best_columns) { if (!lang_tesseract_) { - tprintf("Warning: lang_tesseract_ is NULL!\n"); + tprintf("Warning: lang_tesseract_ is nullptr!\n"); return -1; } if (!part_grid || !best_columns) { - tprintf("part_grid/best_columns is NULL!!\n"); + tprintf("part_grid/best_columns is nullptr!!\n"); return -1; } cp_seeds_.clear(); @@ -422,12 +422,12 @@ int EquationDetect::FindEquationParts( void EquationDetect::MergePartsByLocation() { while (true) { - ColPartition* part = NULL; + ColPartition* part = nullptr; // partitions that have been updated. GenericVector parts_updated; ColPartitionGridSearch gsearch(part_grid_); gsearch.StartFullSearch(); - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { if (!IsTextOrEquationType(part->type())) { continue; } @@ -440,8 +440,8 @@ void EquationDetect::MergePartsByLocation() { // Merge parts_to_merge with part, and remove them from part_grid_. part_grid_->RemoveBBox(part); for (int i = 0; i < parts_to_merge.size(); ++i) { - ASSERT_HOST(parts_to_merge[i] != NULL && parts_to_merge[i] != part); - part->Absorb(parts_to_merge[i], NULL); + ASSERT_HOST(parts_to_merge[i] != nullptr && parts_to_merge[i] != part); + part->Absorb(parts_to_merge[i], nullptr); } gsearch.RepositionIterator(); @@ -462,7 +462,7 @@ void EquationDetect::MergePartsByLocation() { void EquationDetect::SearchByOverlap( ColPartition* seed, GenericVector* parts_overlap) { - ASSERT_HOST(seed != NULL && parts_overlap != NULL); + ASSERT_HOST(seed != nullptr && parts_overlap != nullptr); if (!IsTextOrEquationType(seed->type())) { return; } @@ -479,7 +479,7 @@ void EquationDetect::SearchByOverlap( GenericVector parts; const float kLargeOverlapTh = 0.95; const float kEquXOverlap = 0.4, kEquYOverlap = 0.5; - while ((part = search.NextRadSearch()) != NULL) { + while ((part = search.NextRadSearch()) != nullptr) { if (part == seed || !IsTextOrEquationType(part->type())) { continue; } @@ -537,7 +537,7 @@ void EquationDetect::InsertPartAfterAbsorb(ColPartition* part) { void EquationDetect::IdentifySeedParts() { ColPartitionGridSearch gsearch(part_grid_); - ColPartition *part = NULL; + ColPartition *part = nullptr; gsearch.StartFullSearch(); GenericVector seeds1, seeds2; @@ -545,7 +545,7 @@ void EquationDetect::IdentifySeedParts() { GenericVector indented_texts_left; // The foreground density of text partitions. GenericVector texts_foreground_density; - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { if (!IsTextOrEquationType(part->type())) { continue; } @@ -612,7 +612,7 @@ float EquationDetect::ComputeForegroundDensity(const TBOX& tbox) { int pix_height = pixGetHeight(pix_bi); Box* box = boxCreate(tbox.left(), pix_height - tbox.top(), tbox.width(), tbox.height()); - Pix *pix_sub = pixClipRectangle(pix_bi, box, NULL); + Pix *pix_sub = pixClipRectangle(pix_bi, box, nullptr); l_float32 fract; pixForegroundFraction(pix_sub, &fract); pixDestroy(&pix_sub); @@ -788,13 +788,13 @@ void EquationDetect::IdentifyInlineParts() { void EquationDetect::ComputeCPsSuperBBox() { ColPartitionGridSearch gsearch(part_grid_); - ColPartition *part = NULL; + ColPartition *part = nullptr; gsearch.StartFullSearch(); if (cps_super_bbox_) { delete cps_super_bbox_; } cps_super_bbox_ = new TBOX(); - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { (*cps_super_bbox_) += part->bounding_box(); } } @@ -832,9 +832,9 @@ void EquationDetect::IdentifyInlinePartsHorizontal() { new_seeds.push_back(part); continue; } - ColPartition* neighbor = NULL; + ColPartition* neighbor = nullptr; bool side_neighbor_found = false; - while ((neighbor = search.NextSideSearch(right_to_left)) != NULL) { + while ((neighbor = search.NextSideSearch(right_to_left)) != nullptr) { const TBOX& neighbor_box(neighbor->bounding_box()); if (!IsTextOrEquationType(neighbor->type()) || part_box.x_gap(neighbor_box) > kGapTh || @@ -868,14 +868,14 @@ int EquationDetect::EstimateTextPartLineSpacing() { ColPartitionGridSearch gsearch(part_grid_); // Get the y gap between text partitions; - ColPartition *current = NULL, *prev = NULL; + ColPartition *current = nullptr, *prev = nullptr; gsearch.StartFullSearch(); GenericVector ygaps; - while ((current = gsearch.NextFullSearch()) != NULL) { + while ((current = gsearch.NextFullSearch()) != nullptr) { if (!PTIsTextType(current->type())) { continue; } - if (prev != NULL) { + if (prev != nullptr) { const TBOX ¤t_box = current->bounding_box(); const TBOX &prev_box = prev->bounding_box(); // prev and current should be x major overlap and non y overlap. @@ -936,11 +936,11 @@ void EquationDetect::IdentifyInlinePartsVertical( bool EquationDetect::IsInline(const bool search_bottom, const int textparts_linespacing, ColPartition* part) { - ASSERT_HOST(part != NULL); + ASSERT_HOST(part != nullptr); // Look for its nearest vertical neighbor that hardly overlaps in y but // largely overlaps in x. ColPartitionGridSearch search(part_grid_); - ColPartition *neighbor = NULL; + ColPartition *neighbor = nullptr; const TBOX& part_box(part->bounding_box()); const float kYGapRatioTh = 1.0; @@ -952,7 +952,7 @@ bool EquationDetect::IsInline(const bool search_bottom, part_box.top()); } search.SetUniqueMode(true); - while ((neighbor = search.NextVerticalSearch(search_bottom)) != NULL) { + while ((neighbor = search.NextVerticalSearch(search_bottom)) != nullptr) { const TBOX& neighbor_box(neighbor->bounding_box()); if (part_box.y_gap(neighbor_box) > kYGapRatioTh * MIN(part_box.height(), neighbor_box.height())) { @@ -1021,7 +1021,7 @@ EquationDetect::IndentType EquationDetect::IsIndented(ColPartition* part) { ASSERT_HOST(part); ColPartitionGridSearch search(part_grid_); - ColPartition *neighbor = NULL; + ColPartition *neighbor = nullptr; const TBOX& part_box(part->bounding_box()); const int kXGapTh = static_cast(roundf(0.5 * resolution_)); const int kRadiusTh = static_cast(roundf(3.0 * resolution_)); @@ -1034,7 +1034,7 @@ EquationDetect::IndentType EquationDetect::IsIndented(ColPartition* part) { (part_box.top() + part_box.bottom()) / 2, kRadiusTh); search.SetUniqueMode(true); bool left_indented = false, right_indented = false; - while ((neighbor = search.NextRadSearch()) != NULL && + while ((neighbor = search.NextRadSearch()) != nullptr && (!left_indented || !right_indented)) { if (neighbor == part) { continue; @@ -1082,7 +1082,7 @@ EquationDetect::IndentType EquationDetect::IsIndented(ColPartition* part) { } bool EquationDetect::ExpandSeed(ColPartition* seed) { - if (seed == NULL || // This seed has been absorbed by other seeds. + if (seed == nullptr || // This seed has been absorbed by other seeds. seed->IsVerticalType()) { // We skip vertical type right now. return false; } @@ -1106,11 +1106,11 @@ bool EquationDetect::ExpandSeed(ColPartition* seed) { for (int i = 0; i < parts_to_merge.size(); ++i) { ColPartition* part = parts_to_merge[i]; if (part->type() == PT_EQUATION) { - // If part is in cp_seeds_, then we mark it as NULL so that we won't + // If part is in cp_seeds_, then we mark it as nullptr so that we won't // process it again. for (int j = 0; j < cp_seeds_.size(); ++j) { if (part == cp_seeds_[j]) { - cp_seeds_[j] = NULL; + cp_seeds_[j] = nullptr; break; } } @@ -1118,7 +1118,7 @@ bool EquationDetect::ExpandSeed(ColPartition* seed) { // part has already been removed from part_grid_ in function // ExpandSeedHorizontal/ExpandSeedVertical. - seed->Absorb(part, NULL); + seed->Absorb(part, nullptr); } return true; @@ -1128,7 +1128,7 @@ void EquationDetect::ExpandSeedHorizontal( const bool search_left, ColPartition* seed, GenericVector* parts_to_merge) { - ASSERT_HOST(seed != NULL && parts_to_merge != NULL); + ASSERT_HOST(seed != nullptr && parts_to_merge != nullptr); const float kYOverlapTh = 0.6; const int kXGapTh = static_cast(roundf(0.2 * resolution_)); @@ -1139,8 +1139,8 @@ void EquationDetect::ExpandSeedHorizontal( search.SetUniqueMode(true); // Search iteratively. - ColPartition *part = NULL; - while ((part = search.NextSideSearch(search_left)) != NULL) { + ColPartition *part = nullptr; + while ((part = search.NextSideSearch(search_left)) != nullptr) { if (part == seed) { continue; } @@ -1184,8 +1184,8 @@ void EquationDetect::ExpandSeedVertical( const bool search_bottom, ColPartition* seed, GenericVector* parts_to_merge) { - ASSERT_HOST(seed != NULL && parts_to_merge != NULL && - cps_super_bbox_ != NULL); + ASSERT_HOST(seed != nullptr && parts_to_merge != nullptr && + cps_super_bbox_ != nullptr); const float kXOverlapTh = 0.4; const int kYGapTh = static_cast(roundf(0.2 * resolution_)); @@ -1197,10 +1197,10 @@ void EquationDetect::ExpandSeedVertical( search.SetUniqueMode(true); // Search iteratively. - ColPartition *part = NULL; + ColPartition *part = nullptr; GenericVector parts; int skipped_min_top = INT_MAX, skipped_max_bottom = -1; - while ((part = search.NextVerticalSearch(search_bottom)) != NULL) { + while ((part = search.NextVerticalSearch(search_bottom)) != nullptr) { if (part == seed) { continue; } @@ -1309,11 +1309,11 @@ bool EquationDetect::CheckSeedNeighborDensity(const ColPartition* part) const { void EquationDetect::ProcessMathBlockSatelliteParts() { // Iterate over part_grid_, and find all parts that are text type but not // equation type. - ColPartition *part = NULL; + ColPartition *part = nullptr; GenericVector text_parts; ColPartitionGridSearch gsearch(part_grid_); gsearch.StartFullSearch(); - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { if (part->type() == PT_FLOWING_TEXT || part->type() == PT_HEADING_TEXT) { text_parts.push_back(part); } @@ -1349,7 +1349,7 @@ void EquationDetect::ProcessMathBlockSatelliteParts() { text_parts[i]->set_type(PT_EQUATION); for (int j = 0; j < math_blocks.size(); ++j) { part_grid_->RemoveBBox(math_blocks[j]); - text_parts[i]->Absorb(math_blocks[j], NULL); + text_parts[i]->Absorb(math_blocks[j], nullptr); } InsertPartAfterAbsorb(text_parts[i]); } @@ -1357,7 +1357,7 @@ void EquationDetect::ProcessMathBlockSatelliteParts() { bool EquationDetect::IsMathBlockSatellite( ColPartition* part, GenericVector* math_blocks) { - ASSERT_HOST(part != NULL && math_blocks != NULL); + ASSERT_HOST(part != nullptr && math_blocks != nullptr); math_blocks->clear(); const TBOX& part_box(part->bounding_box()); // Find the top/bottom nearest neighbor of part. @@ -1380,7 +1380,7 @@ bool EquationDetect::IsMathBlockSatellite( } if (neighbors[0] == neighbors[1]) { // This happens when part is inside neighbor. - neighbors[1] = NULL; + neighbors[1] = nullptr; y_gaps[1] = INT_MAX; } @@ -1412,7 +1412,7 @@ bool EquationDetect::IsMathBlockSatellite( ColPartition* EquationDetect::SearchNNVertical( const bool search_bottom, const ColPartition* part) { ASSERT_HOST(part); - ColPartition *nearest_neighbor = NULL, *neighbor = NULL; + ColPartition *nearest_neighbor = nullptr, *neighbor = nullptr; const int kYGapTh = static_cast(roundf(resolution_ * 0.5)); ColPartitionGridSearch search(part_grid_); @@ -1421,7 +1421,7 @@ ColPartition* EquationDetect::SearchNNVertical( int y = search_bottom ? part_box.bottom() : part_box.top(); search.StartVerticalSearch(part_box.left(), part_box.right(), y); int min_y_gap = INT_MAX; - while ((neighbor = search.NextVerticalSearch(search_bottom)) != NULL) { + while ((neighbor = search.NextVerticalSearch(search_bottom)) != nullptr) { if (neighbor == part || !IsTextOrEquationType(neighbor->type())) { continue; } @@ -1462,12 +1462,12 @@ void EquationDetect::GetOutputTiffName(const char* name, } void EquationDetect::PaintSpecialTexts(const STRING& outfile) const { - Pix *pix = NULL, *pixBi = lang_tesseract_->pix_binary(); + Pix *pix = nullptr, *pixBi = lang_tesseract_->pix_binary(); pix = pixConvertTo32(pixBi); ColPartitionGridSearch gsearch(part_grid_); - ColPartition* part = NULL; + ColPartition* part = nullptr; gsearch.StartFullSearch(); - while ((part = gsearch.NextFullSearch()) != NULL) { + while ((part = gsearch.NextFullSearch()) != nullptr) { BLOBNBOX_C_IT blob_it(part->boxes()); for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) { RenderSpecialText(pix, blob_it.data()); @@ -1482,8 +1482,8 @@ void EquationDetect::PaintColParts(const STRING& outfile) const { Pix *pix = pixConvertTo32(lang_tesseract_->BestPix()); ColPartitionGridSearch gsearch(part_grid_); gsearch.StartFullSearch(); - ColPartition* part = NULL; - while ((part = gsearch.NextFullSearch()) != NULL) { + ColPartition* part = nullptr; + while ((part = gsearch.NextFullSearch()) != nullptr) { const TBOX& tbox = part->bounding_box(); Box *box = boxCreate(tbox.left(), pixGetHeight(pix) - tbox.top(), tbox.width(), tbox.height()); diff --git a/ccmain/equationdetect.h b/ccmain/equationdetect.h index 9dff5a7681..a0c29b9ebe 100644 --- a/ccmain/equationdetect.h +++ b/ccmain/equationdetect.h @@ -220,7 +220,7 @@ class EquationDetect : public EquationDetectBase { // Search the nearest neighbor of part in one vertical direction as defined in // search_bottom. It returns the neighbor found that major x overlap with it, - // or NULL when not found. + // or nullptr when not found. ColPartition* SearchNNVertical(const bool search_bottom, const ColPartition* part); diff --git a/ccmain/fixspace.cpp b/ccmain/fixspace.cpp index d259c510ab..f3470a7de9 100644 --- a/ccmain/fixspace.cpp +++ b/ccmain/fixspace.cpp @@ -76,11 +76,11 @@ void Tesseract::fix_fuzzy_spaces(ETEXT_DESC *monitor, block_res_it.data()->block); word_res = word_res_it_from.forward(); word_index++; - if (monitor != NULL) { + if (monitor != nullptr) { monitor->ocr_alive = TRUE; monitor->progress = 90 + 5 * word_index / word_count; if (monitor->deadline_exceeded() || - (monitor->cancel != NULL && + (monitor->cancel != nullptr && (*monitor->cancel)(monitor->cancel_this, stats_.dict_words))) return; } @@ -94,11 +94,11 @@ void Tesseract::fix_fuzzy_spaces(ETEXT_DESC *monitor, debug_fix_space_level.set_value(10); word_res_it_to.forward(); word_index++; - if (monitor != NULL) { + if (monitor != nullptr) { monitor->ocr_alive = TRUE; monitor->progress = 90 + 5 * word_index / word_count; if (monitor->deadline_exceeded() || - (monitor->cancel != NULL && + (monitor->cancel != nullptr && (*monitor->cancel)(monitor->cancel_this, stats_.dict_words))) return; } @@ -199,13 +199,13 @@ void Tesseract::match_current_words(WERD_RES_LIST &words, ROW *row, WERD_RES *word; // Since we are not using PAGE_RES to iterate over words, we need to update // prev_word_best_choice_ before calling classify_word_pass2(). - prev_word_best_choice_ = NULL; + prev_word_best_choice_ = nullptr; for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) { word = word_it.data(); - if ((!word->part_of_combo) && (word->box_word == NULL)) { + if ((!word->part_of_combo) && (word->box_word == nullptr)) { WordData word_data(block, row, word); SetupWordPassN(2, &word_data); - classify_word_and_language(2, NULL, &word_data); + classify_word_and_language(2, nullptr, &word_data); } prev_word_best_choice_ = word->best_choice; } @@ -513,7 +513,7 @@ BOOL8 Tesseract::fixspace_thinks_word_done(WERD_RES *word) { (word->tess_accepted || (fixsp_done_mode == 2 && word->reject_map.reject_count() == 0) || fixsp_done_mode == 3) && - (strchr(word->best_choice->unichar_string().string(), ' ') == NULL) && + (strchr(word->best_choice->unichar_string().string(), ' ') == nullptr) && ((word->best_choice->permuter() == SYSTEM_DAWG_PERM) || (word->best_choice->permuter() == FREQ_DAWG_PERM) || (word->best_choice->permuter() == USER_DAWG_PERM) || @@ -688,7 +688,7 @@ int16_t Tesseract::worst_noise_blob(WERD_RES *word_res, float small_limit = kBlnXHeight * fixsp_small_outlines_size; float non_noise_limit = kBlnXHeight * 0.8; - if (word_res->rebuild_word == NULL) + if (word_res->rebuild_word == nullptr) return -1; // Can't handle cube words. // Normalised. @@ -763,7 +763,7 @@ float Tesseract::blob_noise_score(TBLOB *blob) { int16_t max_dimension; int16_t largest_outline_dimension = 0; - for (TESSLINE* ol = blob->outlines; ol != NULL; ol= ol->next) { + for (TESSLINE* ol = blob->outlines; ol != nullptr; ol= ol->next) { outline_count++; box = ol->bounding_box(); if (box.height() > box.width()) { @@ -836,7 +836,7 @@ int16_t Tesseract::fp_eval_word_spacing(WERD_RES_LIST &word_res_list) { for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) { word = word_it.data(); - if (word->rebuild_word == NULL) + if (word->rebuild_word == nullptr) continue; // Can't handle cube words. if (word->done || word->tess_accepted || diff --git a/ccmain/linerec.cpp b/ccmain/linerec.cpp index d4927544b7..e3d7b67c79 100644 --- a/ccmain/linerec.cpp +++ b/ccmain/linerec.cpp @@ -54,15 +54,15 @@ void Tesseract::TrainLineRecognizer(const STRING& input_imagename, GenericVector boxes; GenericVector texts; // Get the boxes for this page, if there are any. - if (!ReadAllBoxes(applybox_page, false, input_imagename, &boxes, &texts, NULL, - NULL) || + if (!ReadAllBoxes(applybox_page, false, input_imagename, &boxes, &texts, nullptr, + nullptr) || boxes.empty()) { tprintf("Failed to read boxes from %s\n", input_imagename.string()); return; } TrainFromBoxes(boxes, texts, block_list, &images); images.Shuffle(); - if (!images.SaveDocument(lstmf_name.string(), NULL)) { + if (!images.SaveDocument(lstmf_name.string(), nullptr)) { tprintf("Failed to write training data to %s!\n", lstmf_name.string()); } } @@ -90,12 +90,12 @@ void Tesseract::TrainFromBoxes(const GenericVector& boxes, line_str += texts[end_box]; } // Find the most overlapping block. - BLOCK* best_block = NULL; + BLOCK* best_block = nullptr; int best_overlap = 0; BLOCK_IT b_it(block_list); for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) { BLOCK* block = b_it.data(); - if (block->pdblk.poly_block() != NULL && !block->pdblk.poly_block()->IsText()) + if (block->pdblk.poly_block() != nullptr && !block->pdblk.poly_block()->IsText()) continue; // Not a text block. TBOX block_box = block->pdblk.bounding_box(); block_box.rotate(block->re_rotation()); @@ -107,14 +107,14 @@ void Tesseract::TrainFromBoxes(const GenericVector& boxes, } } } - ImageData* imagedata = NULL; - if (best_block == NULL) { + ImageData* imagedata = nullptr; + if (best_block == nullptr) { tprintf("No block overlapping textline: %s\n", line_str.string()); } else { imagedata = GetLineData(line_box, boxes, texts, start_box, end_box, *best_block); } - if (imagedata != NULL) + if (imagedata != nullptr) training_data->AddPageToDocument(imagedata); // Don't let \t, which marks newlines in the box file, get into the line // content, as that makes the line unusable in training. @@ -133,7 +133,7 @@ ImageData* Tesseract::GetLineData(const TBOX& line_box, TBOX revised_box; ImageData* image_data = GetRectImage(line_box, block, kImagePadding, &revised_box); - if (image_data == NULL) return NULL; + if (image_data == nullptr) return nullptr; image_data->set_page_number(applybox_page); // Copy the boxes and shift them so they are relative to the image. FCOORD block_rotation(block.re_rotation().x(), -block.re_rotation().y()); @@ -185,11 +185,11 @@ ImageData* Tesseract::GetRectImage(const TBOX& box, const BLOCK& block, TBOX image_box(0, 0, width, height); // Clip to image bounds; *revised_box &= image_box; - if (revised_box->null_box()) return NULL; + if (revised_box->null_box()) return nullptr; Box* clip_box = boxCreate(revised_box->left(), height - revised_box->top(), revised_box->width(), revised_box->height()); - Pix* box_pix = pixClipRectangle(pix, clip_box, NULL); - if (box_pix == NULL) return NULL; + Pix* box_pix = pixClipRectangle(pix, clip_box, nullptr); + if (box_pix == nullptr) return nullptr; boxDestroy(&clip_box); if (num_rotations > 0) { Pix* rot_pix = pixRotateOrth(box_pix, num_rotations); @@ -235,7 +235,7 @@ void Tesseract::LSTMRecognizeWord(const BLOCK& block, ROW *row, WERD_RES *word, word_box.set_top(baseline + row->x_height() + row->ascenders()); } ImageData* im_data = GetRectImage(word_box, block, kImagePadding, &word_box); - if (im_data == NULL) return; + if (im_data == nullptr) return; lstm_recognizer_->RecognizeLine(*im_data, true, classify_debug_level > 0, kWorstDictCertainty / kCertaintyScale, word_box, words); @@ -264,7 +264,7 @@ void Tesseract::SearchWords(PointerVector* words) { } for (int w = 0; w < words->size(); ++w) { WERD_RES* word = (*words)[w]; - if (word->best_choice == NULL) { + if (word->best_choice == nullptr) { // It is a dud. word->SetupFake(lstm_recognizer_->GetUnicharset()); } else { diff --git a/ccmain/ltrresultiterator.cpp b/ccmain/ltrresultiterator.cpp index 528345a51a..6b1b4ad2b1 100644 --- a/ccmain/ltrresultiterator.cpp +++ b/ccmain/ltrresultiterator.cpp @@ -43,11 +43,11 @@ LTRResultIterator::~LTRResultIterator() { // Returns the null terminated UTF-8 encoded text string for the current // object at the given level. Use delete [] to free after use. char* LTRResultIterator::GetUTF8Text(PageIteratorLevel level) const { - if (it_->word() == NULL) return NULL; // Already at the end! + if (it_->word() == nullptr) return nullptr; // Already at the end! STRING text; PAGE_RES_IT res_it(*it_); WERD_CHOICE* best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); if (level == RIL_SYMBOL) { text = res_it.word()->BestUTF8(blob_index_, false); } else if (level == RIL_WORD) { @@ -59,7 +59,7 @@ char* LTRResultIterator::GetUTF8Text(PageIteratorLevel level) const { do { // for each text line in a paragraph do { // for each word in a text line best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); text += best_choice->unichar_string(); text += " "; res_it.forward(); @@ -92,17 +92,17 @@ void LTRResultIterator::SetParagraphSeparator(const char *new_para) { // Returns the mean confidence of the current object at the given level. // The number should be interpreted as a percent probability. (0.0f-100.0f) float LTRResultIterator::Confidence(PageIteratorLevel level) const { - if (it_->word() == NULL) return 0.0f; // Already at the end! + if (it_->word() == nullptr) return 0.0f; // Already at the end! float mean_certainty = 0.0f; int certainty_count = 0; PAGE_RES_IT res_it(*it_); WERD_CHOICE* best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); switch (level) { case RIL_BLOCK: do { best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); mean_certainty += best_choice->certainty(); ++certainty_count; res_it.forward(); @@ -111,7 +111,7 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const { case RIL_PARA: do { best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); mean_certainty += best_choice->certainty(); ++certainty_count; res_it.forward(); @@ -121,7 +121,7 @@ float LTRResultIterator::Confidence(PageIteratorLevel level) const { case RIL_TEXTLINE: do { best_choice = res_it.word()->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); mean_certainty += best_choice->certainty(); ++certainty_count; res_it.forward(); @@ -175,10 +175,10 @@ const char* LTRResultIterator::WordFontAttributes(bool* is_bold, *pointsize = scaled_yres_ > 0 ? static_cast(row_height * kPointsPerInch / scaled_yres_ + 0.5) : 0; - if (it_->word() == NULL) return NULL; // Already at the end! - if (it_->word()->fontinfo == NULL) { + if (it_->word() == nullptr) return nullptr; // Already at the end! + if (it_->word()->fontinfo == nullptr) { *font_id = -1; - return NULL; // No font information. + return nullptr; // No font information. } const FontInfo& font_info = *it_->word()->fontinfo; *font_id = font_info.universal_id; @@ -194,13 +194,13 @@ const char* LTRResultIterator::WordFontAttributes(bool* is_bold, // Returns the name of the language used to recognize this word. const char* LTRResultIterator::WordRecognitionLanguage() const { - if (it_->word() == NULL || it_->word()->tesseract == NULL) return NULL; + if (it_->word() == nullptr || it_->word()->tesseract == nullptr) return nullptr; return it_->word()->tesseract->lang.string(); } // Return the overall directionality of this word. StrongScriptDirection LTRResultIterator::WordDirection() const { - if (it_->word() == NULL) return DIR_NEUTRAL; + if (it_->word() == nullptr) return DIR_NEUTRAL; bool has_rtl = it_->word()->AnyRtlCharsInWord(); bool has_ltr = it_->word()->AnyLtrCharsInWord(); if (has_rtl && !has_ltr) @@ -214,7 +214,7 @@ StrongScriptDirection LTRResultIterator::WordDirection() const { // Returns true if the current word was found in a dictionary. bool LTRResultIterator::WordIsFromDictionary() const { - if (it_->word() == NULL) return false; // Already at the end! + if (it_->word() == nullptr) return false; // Already at the end! int permuter = it_->word()->best_choice->permuter(); return permuter == SYSTEM_DAWG_PERM || permuter == FREQ_DAWG_PERM || permuter == USER_DAWG_PERM; @@ -222,46 +222,46 @@ bool LTRResultIterator::WordIsFromDictionary() const { // Returns the number of blanks before the current word. int LTRResultIterator::BlanksBeforeWord() const { - if (it_->word() == NULL) return 1; + if (it_->word() == nullptr) return 1; return it_->word()->word->space(); } // Returns true if the current word is numeric. bool LTRResultIterator::WordIsNumeric() const { - if (it_->word() == NULL) return false; // Already at the end! + if (it_->word() == nullptr) return false; // Already at the end! int permuter = it_->word()->best_choice->permuter(); return permuter == NUMBER_PERM; } // Returns true if the word contains blamer information. bool LTRResultIterator::HasBlamerInfo() const { - return it_->word() != NULL && it_->word()->blamer_bundle != NULL && + return it_->word() != nullptr && it_->word()->blamer_bundle != nullptr && it_->word()->blamer_bundle->HasDebugInfo(); } // Returns the pointer to ParamsTrainingBundle stored in the BlamerBundle // of the current word. const void *LTRResultIterator::GetParamsTrainingBundle() const { - return (it_->word() != NULL && it_->word()->blamer_bundle != NULL) ? - &(it_->word()->blamer_bundle->params_training_bundle()) : NULL; + return (it_->word() != nullptr && it_->word()->blamer_bundle != nullptr) ? + &(it_->word()->blamer_bundle->params_training_bundle()) : nullptr; } // Returns the pointer to the string with blamer information for this word. -// Assumes that the word's blamer_bundle is not NULL. +// Assumes that the word's blamer_bundle is not nullptr. const char *LTRResultIterator::GetBlamerDebug() const { return it_->word()->blamer_bundle->debug().string(); } // Returns the pointer to the string with misadaption information for this word. -// Assumes that the word's blamer_bundle is not NULL. +// Assumes that the word's blamer_bundle is not nullptr. const char *LTRResultIterator::GetBlamerMisadaptionDebug() const { return it_->word()->blamer_bundle->misadaption_debug().string(); } // Returns true if a truth string was recorded for the current word. bool LTRResultIterator::HasTruthString() const { - if (it_->word() == NULL) return false; // Already at the end! - if (it_->word()->blamer_bundle == NULL || + if (it_->word() == nullptr) return false; // Already at the end! + if (it_->word()->blamer_bundle == nullptr || it_->word()->blamer_bundle->NoTruth()) { return false; // no truth information for this word } @@ -272,7 +272,7 @@ bool LTRResultIterator::HasTruthString() const { // the current word. bool LTRResultIterator::EquivalentToTruth(const char *str) const { if (!HasTruthString()) return false; - ASSERT_HOST(it_->word()->uch_set != NULL); + ASSERT_HOST(it_->word()->uch_set != nullptr); WERD_CHOICE str_wd(str, *(it_->word()->uch_set)); return it_->word()->blamer_bundle->ChoiceIsCorrect(&str_wd); } @@ -280,7 +280,7 @@ bool LTRResultIterator::EquivalentToTruth(const char *str) const { // Returns the null terminated UTF-8 encoded truth string for the current word. // Use delete [] to free after use. char* LTRResultIterator::WordTruthUTF8Text() const { - if (!HasTruthString()) return NULL; + if (!HasTruthString()) return nullptr; STRING truth_text = it_->word()->blamer_bundle->TruthString(); int length = truth_text.length() + 1; char* result = new char[length]; @@ -291,11 +291,11 @@ char* LTRResultIterator::WordTruthUTF8Text() const { // Returns the null terminated UTF-8 encoded normalized OCR string for the // current word. Use delete [] to free after use. char* LTRResultIterator::WordNormedUTF8Text() const { - if (it_->word() == NULL) return NULL; // Already at the end! + if (it_->word() == nullptr) return nullptr; // Already at the end! STRING ocr_text; WERD_CHOICE* best_choice = it_->word()->best_choice; const UNICHARSET *unicharset = it_->word()->uch_set; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); for (int i = 0; i < best_choice->length(); ++i) { ocr_text += unicharset->get_normed_unichar(best_choice->unichar_id(i)); } @@ -308,8 +308,8 @@ char* LTRResultIterator::WordNormedUTF8Text() const { // Returns a pointer to serialized choice lattice. // Fills lattice_size with the number of bytes in lattice data. const char *LTRResultIterator::WordLattice(int *lattice_size) const { - if (it_->word() == NULL) return NULL; // Already at the end! - if (it_->word()->blamer_bundle == NULL) return NULL; + if (it_->word() == nullptr) return nullptr; // Already at the end! + if (it_->word()->blamer_bundle == nullptr) return nullptr; *lattice_size = it_->word()->blamer_bundle->lattice_size(); return it_->word()->blamer_bundle->lattice_data(); } @@ -318,7 +318,7 @@ const char *LTRResultIterator::WordLattice(int *lattice_size) const { // If iterating at a higher level object than symbols, eg words, then // this will return the attributes of the first symbol in that word. bool LTRResultIterator::SymbolIsSuperscript() const { - if (cblob_it_ == NULL && it_->word() != NULL) + if (cblob_it_ == nullptr && it_->word() != nullptr) return it_->word()->best_choice->BlobPosition(blob_index_) == SP_SUPERSCRIPT; return false; @@ -328,7 +328,7 @@ bool LTRResultIterator::SymbolIsSuperscript() const { // If iterating at a higher level object than symbols, eg words, then // this will return the attributes of the first symbol in that word. bool LTRResultIterator::SymbolIsSubscript() const { - if (cblob_it_ == NULL && it_->word() != NULL) + if (cblob_it_ == nullptr && it_->word() != nullptr) return it_->word()->best_choice->BlobPosition(blob_index_) == SP_SUBSCRIPT; return false; } @@ -337,22 +337,22 @@ bool LTRResultIterator::SymbolIsSubscript() const { // If iterating at a higher level object than symbols, eg words, then // this will return the attributes of the first symbol in that word. bool LTRResultIterator::SymbolIsDropcap() const { - if (cblob_it_ == NULL && it_->word() != NULL) + if (cblob_it_ == nullptr && it_->word() != nullptr) return it_->word()->best_choice->BlobPosition(blob_index_) == SP_DROPCAP; return false; } ChoiceIterator::ChoiceIterator(const LTRResultIterator& result_it) { - ASSERT_HOST(result_it.it_->word() != NULL); + ASSERT_HOST(result_it.it_->word() != nullptr); word_res_ = result_it.it_->word(); - BLOB_CHOICE_LIST* choices = NULL; - if (word_res_->ratings != NULL) + BLOB_CHOICE_LIST* choices = nullptr; + if (word_res_->ratings != nullptr) choices = word_res_->GetBlobChoices(result_it.blob_index_); - if (choices != NULL && !choices->empty()) { + if (choices != nullptr && !choices->empty()) { choice_it_ = new BLOB_CHOICE_IT(choices); choice_it_->mark_cycle_pt(); } else { - choice_it_ = NULL; + choice_it_ = nullptr; } } @@ -363,7 +363,7 @@ ChoiceIterator::~ChoiceIterator() { // Moves to the next choice for the symbol and returns false if there // are none left. bool ChoiceIterator::Next() { - if (choice_it_ == NULL) + if (choice_it_ == nullptr) return false; choice_it_->forward(); return !choice_it_->cycled_list(); @@ -372,8 +372,8 @@ bool ChoiceIterator::Next() { // Returns the null terminated UTF-8 encoded text string for the current // choice. Do NOT use delete [] to free after use. const char* ChoiceIterator::GetUTF8Text() const { - if (choice_it_ == NULL) - return NULL; + if (choice_it_ == nullptr) + return nullptr; UNICHAR_ID id = choice_it_->data()->unichar_id(); return word_res_->uch_set->id_to_unichar_ext(id); } @@ -381,7 +381,7 @@ const char* ChoiceIterator::GetUTF8Text() const { // Returns the confidence of the current choice. // The number should be interpreted as a percent probability. (0.0f-100.0f) float ChoiceIterator::Confidence() const { - if (choice_it_ == NULL) + if (choice_it_ == nullptr) return 0.0f; float confidence = 100 + 5 * choice_it_->data()->certainty(); if (confidence < 0.0f) confidence = 0.0f; diff --git a/ccmain/ltrresultiterator.h b/ccmain/ltrresultiterator.h index 95722cae5d..2d54d6d4eb 100644 --- a/ccmain/ltrresultiterator.h +++ b/ccmain/ltrresultiterator.h @@ -115,7 +115,7 @@ class TESS_API LTRResultIterator : public PageIterator { int* font_id) const; // Return the name of the language used to recognize this word. - // On error, NULL. Do not delete this pointer. + // On error, nullptr. Do not delete this pointer. const char* WordRecognitionLanguage() const; // Return the overall directionality of this word. @@ -138,11 +138,11 @@ class TESS_API LTRResultIterator : public PageIterator { const void *GetParamsTrainingBundle() const; // Returns a pointer to the string with blamer information for this word. - // Assumes that the word's blamer_bundle is not NULL. + // Assumes that the word's blamer_bundle is not nullptr. const char *GetBlamerDebug() const; // Returns a pointer to the string with misadaption information for this word. - // Assumes that the word's blamer_bundle is not NULL. + // Assumes that the word's blamer_bundle is not nullptr. const char *GetBlamerMisadaptionDebug() const; // Returns true if a truth string was recorded for the current word. diff --git a/ccmain/osdetect.cpp b/ccmain/osdetect.cpp index 40b9ccf7f3..e5c3b1bfa7 100644 --- a/ccmain/osdetect.cpp +++ b/ccmain/osdetect.cpp @@ -156,7 +156,7 @@ void OSResults::accumulate(const OSResults& osr) { void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks) { Pix *pix = tess->pix_binary(); - ASSERT_HOST(pix != NULL); + ASSERT_HOST(pix != nullptr); int vertical_x = 0; int vertical_y = 1; tesseract::TabVector_LIST v_lines; @@ -172,9 +172,9 @@ void remove_nontext_regions(tesseract::Tesseract *tess, BLOCK_LIST *blocks, tesseract::LineFinder::FindAndRemoveLines(resolution, false, pix, &vertical_x, &vertical_y, - NULL, &v_lines, &h_lines); + nullptr, &v_lines, &h_lines); Pix* im_pix = tesseract::ImageFind::FindImages(pix, nullptr); - if (im_pix != NULL) { + if (im_pix != nullptr) { pixSubtract(pix, pix, im_pix); pixDestroy(&im_pix); } @@ -193,10 +193,10 @@ int orientation_and_script_detection(STRING& filename, TBOX page_box; lastdot = strrchr (name.string (), '.'); - if (lastdot != NULL) + if (lastdot != nullptr) name[lastdot-name.string()] = '\0'; - ASSERT_HOST(tess->pix_binary() != NULL) + ASSERT_HOST(tess->pix_binary() != nullptr) int width = pixGetWidth(tess->pix_binary()); int height = pixGetHeight(tess->pix_binary()); @@ -261,7 +261,7 @@ int os_detect(TO_BLOCK_LIST* port_blocks, OSResults* osr, filtered_it.add_to_end(bbox); } } - return os_detect_blobs(NULL, &filtered_list, osr, tess); + return os_detect_blobs(nullptr, &filtered_list, osr, tess); } // Detect orientation and script from a list of blobs. @@ -274,7 +274,7 @@ int os_detect_blobs(const GenericVector* allowed_scripts, BLOBNBOX_CLIST* blob_list, OSResults* osr, tesseract::Tesseract* tess) { OSResults osr_; - if (osr == NULL) + if (osr == nullptr) osr = &osr_; osr->unicharset = &tess->unicharset; @@ -347,10 +347,10 @@ bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o, x_origin = i == 1 ? box.left() : box.right(); } TBLOB* rotated_blob = new TBLOB(*tblob); - rotated_blob->Normalize(NULL, ¤t_rotation, NULL, + rotated_blob->Normalize(nullptr, ¤t_rotation, nullptr, x_origin, y_origin, scaling, scaling, 0.0f, static_cast(kBlnBaselineOffset), - false, NULL); + false, nullptr); tess->AdaptiveClassifier(rotated_blob, ratings + i); delete rotated_blob; current_rotation.rotate(rotation90); @@ -380,11 +380,11 @@ bool OrientationDetector::detect_blob(BLOB_CHOICE_LIST* scores) { for (int i = 0; i < 4; ++i) { BLOB_CHOICE_IT choice_it(scores + i); if (!choice_it.empty()) { - BLOB_CHOICE* choice = NULL; - if (allowed_scripts_ != NULL && !allowed_scripts_->empty()) { + BLOB_CHOICE* choice = nullptr; + if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) { // Find the top choice in an allowed script. for (choice_it.mark_cycle_pt(); !choice_it.cycled_list() && - choice == NULL; choice_it.forward()) { + choice == nullptr; choice_it.forward()) { int choice_script = choice_it.data()->script_id(); int s = 0; for (s = 0; s < allowed_scripts_->size(); ++s) { @@ -397,7 +397,7 @@ bool OrientationDetector::detect_blob(BLOB_CHOICE_LIST* scores) { } else { choice = choice_it.data(); } - if (choice != NULL) { + if (choice != nullptr) { // The certainty score ranges between [-20,0]. This is converted here to // [0,1], with 1 indicating best match. blob_o_score[i] = 1 + 0.05 * choice->certainty(); @@ -482,7 +482,7 @@ void ScriptDetector::detect_blob(BLOB_CHOICE_LIST* scores) { choice_it.forward()) { BLOB_CHOICE* choice = choice_it.data(); int id = choice->script_id(); - if (allowed_scripts_ != NULL && !allowed_scripts_->empty()) { + if (allowed_scripts_ != nullptr && !allowed_scripts_->empty()) { // Check that the choice is in an allowed script. int s = 0; for (s = 0; s < allowed_scripts_->size(); ++s) { diff --git a/ccmain/osdetect.h b/ccmain/osdetect.h index 34a8f5e7ac..52b00968c9 100644 --- a/ccmain/osdetect.h +++ b/ccmain/osdetect.h @@ -45,7 +45,7 @@ struct OSBestResult { }; struct OSResults { - OSResults() : unicharset(NULL) { + OSResults() : unicharset(nullptr) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < kMaxNumberOfScripts; ++j) scripts_na[i][j] = 0; diff --git a/ccmain/output.cpp b/ccmain/output.cpp index e3e17a677e..f0ef3c93ec 100644 --- a/ccmain/output.cpp +++ b/ccmain/output.cpp @@ -74,8 +74,8 @@ void Tesseract::output_pass( //Tess output pass //send to api WERD *nextword; //next word page_res_it.restart_page (); - block_of_last_word = NULL; - while (page_res_it.word () != NULL) { + block_of_last_word = nullptr; + while (page_res_it.word () != nullptr) { check_debug_pt (page_res_it.word (), 120); if (target_word_box) { @@ -95,16 +95,16 @@ void Tesseract::output_pass( //Tess output pass //send to api force_eol = (tessedit_write_block_separators && (page_res_it.block () != page_res_it.next_block ())) || - (page_res_it.next_word () == NULL); + (page_res_it.next_word () == nullptr); - if (page_res_it.next_word () != NULL) + if (page_res_it.next_word () != nullptr) nextword = page_res_it.next_word ()->word; else - nextword = NULL; - if (page_res_it.next_block () != NULL) + nextword = nullptr; + if (page_res_it.next_block () != nullptr) nextblock = page_res_it.next_block ()->block; else - nextblock = NULL; + nextblock = nullptr; //regardless of tilde crunching write_results(page_res_it, determine_newline_type(page_res_it.word()->word, @@ -256,7 +256,7 @@ char determine_newline_type( //test line ends if (!word->flag (W_EOL)) return FALSE; //not end of line - if (next_word == NULL || next_block == NULL || block != next_block) + if (next_word == nullptr || next_block == nullptr || block != next_block) return CTRL_NEWLINE; if (next_word->space () > 0) return CTRL_HARDLINE; //it is tabbed diff --git a/ccmain/pageiterator.cpp b/ccmain/pageiterator.cpp index f7f9829b46..d6d862267e 100644 --- a/ccmain/pageiterator.cpp +++ b/ccmain/pageiterator.cpp @@ -31,10 +31,10 @@ PageIterator::PageIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale, int rect_width, int rect_height) : page_res_(page_res), tesseract_(tesseract), - word_(NULL), + word_(nullptr), word_length_(0), blob_index_(0), - cblob_it_(NULL), + cblob_it_(nullptr), include_upper_dots_(false), include_lower_dots_(false), scale_(scale), @@ -60,10 +60,10 @@ PageIterator::~PageIterator() { PageIterator::PageIterator(const PageIterator& src) : page_res_(src.page_res_), tesseract_(src.tesseract_), - word_(NULL), + word_(nullptr), word_length_(src.word_length_), blob_index_(src.blob_index_), - cblob_it_(NULL), + cblob_it_(nullptr), include_upper_dots_(src.include_upper_dots_), include_lower_dots_(src.include_lower_dots_), scale_(src.scale_), @@ -94,8 +94,8 @@ const PageIterator& PageIterator::operator=(const PageIterator& src) { } bool PageIterator::PositionedAtSameWord(const PAGE_RES_IT* other) const { - return (it_ == NULL && it_ == other) || - ((other != NULL) && (it_ != NULL) && (*it_ == *other)); + return (it_ == nullptr && it_ == other) || + ((other != nullptr) && (it_ != nullptr) && (*it_ == *other)); } // ============= Moving around within the page ============. @@ -107,7 +107,7 @@ void PageIterator::Begin() { } void PageIterator::RestartParagraph() { - if (it_->block() == NULL) return; // At end of the document. + if (it_->block() == nullptr) return; // At end of the document. PAGE_RES_IT para(page_res_); PAGE_RES_IT next_para(para); next_para.forward_paragraph(); @@ -144,8 +144,8 @@ void PageIterator::RestartRow() { * the appropriate language has been loaded into Tesseract. */ bool PageIterator::Next(PageIteratorLevel level) { - if (it_->block() == NULL) return false; // Already at the end! - if (it_->word() == NULL) + if (it_->block() == nullptr) return false; // Already at the end! + if (it_->word() == nullptr) level = RIL_BLOCK; switch (level) { @@ -163,7 +163,7 @@ bool PageIterator::Next(PageIteratorLevel level) { it_->forward_with_empties(); break; case RIL_SYMBOL: - if (cblob_it_ != NULL) + if (cblob_it_ != nullptr) cblob_it_->forward(); ++blob_index_; if (blob_index_ >= word_length_) @@ -173,7 +173,7 @@ bool PageIterator::Next(PageIteratorLevel level) { break; } BeginWord(0); - return it_->block() != NULL; + return it_->block() != nullptr; } /** @@ -182,8 +182,8 @@ bool PageIterator::Next(PageIteratorLevel level) { * moved to the start of a RIL_PARA. */ bool PageIterator::IsAtBeginningOf(PageIteratorLevel level) const { - if (it_->block() == NULL) return false; // Already at the end! - if (it_->word() == NULL) return true; // In an image block. + if (it_->block() == nullptr) return false; // Already at the end! + if (it_->word() == nullptr) return true; // In an image block. switch (level) { case RIL_BLOCK: return blob_index_ == 0 && it_->block() != it_->prev_block(); @@ -267,7 +267,7 @@ bool PageIterator::BoundingBoxInternal(PageIteratorLevel level, if (Empty(level)) return false; TBOX box; - PARA *para = NULL; + PARA *para = nullptr; switch (level) { case RIL_BLOCK: box = it_->block()->block->restricted_bounding_box(include_upper_dots_, @@ -285,7 +285,7 @@ bool PageIterator::BoundingBoxInternal(PageIteratorLevel level, include_lower_dots_); break; case RIL_SYMBOL: - if (cblob_it_ == NULL) + if (cblob_it_ == nullptr) box = it_->word()->box_word->BlobBox(blob_index_); else box = cblob_it_->data()->bounding_box(); @@ -302,7 +302,7 @@ bool PageIterator::BoundingBoxInternal(PageIteratorLevel level, } } while (other.Next(RIL_TEXTLINE)); } - if (level != RIL_SYMBOL || cblob_it_ != NULL) + if (level != RIL_SYMBOL || cblob_it_ != nullptr) box.rotate(it_->block()->block->re_rotation()); // Now we have a box in tesseract coordinates relative to the image rectangle, // we have to convert the coords to a top-down system. @@ -346,8 +346,8 @@ bool PageIterator::BoundingBox(PageIteratorLevel level, const int padding, /** Return that there is no such object at a given level. */ bool PageIterator::Empty(PageIteratorLevel level) const { - if (it_->block() == NULL) return true; // Already at the end! - if (it_->word() == NULL && level != RIL_BLOCK) return true; // image block + if (it_->block() == nullptr) return true; // Already at the end! + if (it_->word() == nullptr && level != RIL_BLOCK) return true; // image block if (level == RIL_SYMBOL && blob_index_ >= word_length_) return true; // Zero length word, or already at the end of it. return false; @@ -355,9 +355,9 @@ bool PageIterator::Empty(PageIteratorLevel level) const { /** Returns the type of the current block. See apitypes.h for PolyBlockType. */ PolyBlockType PageIterator::BlockType() const { - if (it_->block() == NULL || it_->block()->block == NULL) + if (it_->block() == nullptr || it_->block()->block == nullptr) return PT_UNKNOWN; // Already at the end! - if (it_->block()->block->pdblk.poly_block() == NULL) + if (it_->block()->block->pdblk.poly_block() == nullptr) return PT_FLOWING_TEXT; // No layout analysis used - assume text. return it_->block()->block->pdblk.poly_block()->isA(); } @@ -365,10 +365,10 @@ PolyBlockType PageIterator::BlockType() const { /** Returns the polygon outline of the current block. The returned Pta must * be ptaDestroy-ed after use. */ Pta* PageIterator::BlockPolygon() const { - if (it_->block() == NULL || it_->block()->block == NULL) - return NULL; // Already at the end! - if (it_->block()->block->pdblk.poly_block() == NULL) - return NULL; // No layout analysis used - no polygon. + if (it_->block() == nullptr || it_->block()->block == nullptr) + return nullptr; // Already at the end! + if (it_->block()->block->pdblk.poly_block() == nullptr) + return nullptr; // No layout analysis used - no polygon. ICOORDELT_IT it(it_->block()->block->pdblk.poly_block()->points()); Pta* pta = ptaCreate(it.length()); int num_pts = 0; @@ -407,12 +407,12 @@ Pta* PageIterator::BlockPolygon() const { Pix* PageIterator::GetBinaryImage(PageIteratorLevel level) const { int left, top, right, bottom; if (!BoundingBoxInternal(level, &left, &top, &right, &bottom)) - return NULL; - if (level == RIL_SYMBOL && cblob_it_ != NULL && + return nullptr; + if (level == RIL_SYMBOL && cblob_it_ != nullptr && cblob_it_->data()->area() != 0) return cblob_it_->data()->render(); Box* box = boxCreate(left, top, right - left, bottom - top); - Pix* pix = pixClipRectangle(tesseract_->pix_binary(), box, NULL); + Pix* pix = pixClipRectangle(tesseract_->pix_binary(), box, nullptr); boxDestroy(&box); if (level == RIL_BLOCK || level == RIL_PARA) { // Clip to the block polygon as well. @@ -445,8 +445,8 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding, int* left, int* top) const { int right, bottom; if (!BoundingBox(level, left, top, &right, &bottom)) - return NULL; - if (original_img == NULL) + return nullptr; + if (original_img == nullptr) return GetBinaryImage(level); // Expand the box. @@ -455,7 +455,7 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding, right = MIN(right + padding, rect_width_); bottom = MIN(bottom + padding, rect_height_); Box* box = boxCreate(*left, *top, right - *left, bottom - *top); - Pix* grey_pix = pixClipRectangle(original_img, box, NULL); + Pix* grey_pix = pixClipRectangle(original_img, box, nullptr); boxDestroy(&box); if (level == RIL_BLOCK || level == RIL_PARA) { // Clip to the block polygon as well. @@ -486,7 +486,7 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding, */ bool PageIterator::Baseline(PageIteratorLevel level, int* x1, int* y1, int* x2, int* y2) const { - if (it_->word() == NULL) return false; // Already at the end! + if (it_->word() == nullptr) return false; // Already at the end! ROW* row = it_->row()->row; WERD* word = it_->word()->word; TBOX box = (level == RIL_WORD || level == RIL_SYMBOL) @@ -575,18 +575,18 @@ void PageIterator::ParagraphInfo(tesseract::ParagraphJustification *just, */ void PageIterator::BeginWord(int offset) { WERD_RES* word_res = it_->word(); - if (word_res == NULL) { + if (word_res == nullptr) { // This is a non-text block, so there is no word. word_length_ = 0; blob_index_ = 0; - word_ = NULL; + word_ = nullptr; return; } - if (word_res->best_choice != NULL) { + if (word_res->best_choice != nullptr) { // Recognition has been done, so we are using the box_word, which // is already baseline denormalized. word_length_ = word_res->best_choice->length(); - if (word_res->box_word != NULL) { + if (word_res->box_word != nullptr) { if (word_res->box_word->length() != word_length_) { tprintf("Corrupted word! best_choice[len=%d] = %s, box_word[len=%d]: ", word_length_, word_res->best_choice->unichar_string().string(), @@ -595,26 +595,26 @@ void PageIterator::BeginWord(int offset) { } ASSERT_HOST(word_res->box_word->length() == word_length_); } - word_ = NULL; + word_ = nullptr; // We will be iterating the box_word. delete cblob_it_; - cblob_it_ = NULL; + cblob_it_ = nullptr; } else { // No recognition yet, so a "symbol" is a cblob. word_ = word_res->word; - ASSERT_HOST(word_->cblob_list() != NULL); + ASSERT_HOST(word_->cblob_list() != nullptr); word_length_ = word_->cblob_list()->length(); - if (cblob_it_ == NULL) cblob_it_ = new C_BLOB_IT; + if (cblob_it_ == nullptr) cblob_it_ = new C_BLOB_IT; cblob_it_->set_to_list(word_->cblob_list()); } for (blob_index_ = 0; blob_index_ < offset; ++blob_index_) { - if (cblob_it_ != NULL) + if (cblob_it_ != nullptr) cblob_it_->forward(); } } bool PageIterator::SetWordBlamerBundle(BlamerBundle *blamer_bundle) { - if (it_->word() != NULL) { + if (it_->word() != nullptr) { it_->word()->blamer_bundle = blamer_bundle; return true; } else { diff --git a/ccmain/pageiterator.h b/ccmain/pageiterator.h index 719a1b6075..6929080852 100644 --- a/ccmain/pageiterator.h +++ b/ccmain/pageiterator.h @@ -228,7 +228,7 @@ class TESS_API PageIterator { * Returns the polygon outline of the current block. The returned Pta must * be ptaDestroy-ed after use. Note that the returned Pta lists the vertices * of the polygon, and the last edge is the line segment between the last - * point and the first point. NULL will be returned if the iterator is + * point and the first point. nullptr will be returned if the iterator is * at the end of the document or layout analysis was not used. */ Pta* BlockPolygon() const; @@ -310,7 +310,7 @@ class TESS_API PageIterator { bool *is_crown, int *first_line_indent) const; - // If the current WERD_RES (it_->word()) is not NULL, sets the BlamerBundle + // If the current WERD_RES (it_->word()) is not nullptr, sets the BlamerBundle // of the current word to the given pointer (takes ownership of the pointer) // and returns true. // Can only be used when iterating on the word level. @@ -334,7 +334,7 @@ class TESS_API PageIterator { PAGE_RES_IT* it_; /** * The current input WERD being iterated. If there is an output from OCR, - * then word_ is NULL. Owned by the API + * then word_ is nullptr. Owned by the API */ WERD* word_; /** The length of the current word_. */ @@ -342,7 +342,7 @@ class TESS_API PageIterator { /** The current blob index within the word. */ int blob_index_; /** - * Iterator to the blobs within the word. If NULL, then we are iterating + * Iterator to the blobs within the word. If nullptr, then we are iterating * OCR results in the box_word. * Owned by this ResultIterator. */ diff --git a/ccmain/pagesegmain.cpp b/ccmain/pagesegmain.cpp index 2fb3dba9cb..ea4f5d6913 100644 --- a/ccmain/pagesegmain.cpp +++ b/ccmain/pagesegmain.cpp @@ -57,26 +57,26 @@ const int kMaxCircleErosions = 8; // Helper to remove an enclosing circle from an image. // If there isn't one, then the image will most likely get badly mangled. -// The returned pix must be pixDestroyed after use. NULL may be returned +// The returned pix must be pixDestroyed after use. nullptr may be returned // if the image doesn't meet the trivial conditions that it uses to determine // success. static Pix* RemoveEnclosingCircle(Pix* pixs) { - Pix* pixsi = pixInvert(NULL, pixs); + Pix* pixsi = pixInvert(nullptr, pixs); Pix* pixc = pixCreateTemplate(pixs); pixSetOrClearBorder(pixc, 1, 1, 1, 1, PIX_SET); pixSeedfillBinary(pixc, pixc, pixsi, 4); pixInvert(pixc, pixc); pixDestroy(&pixsi); - Pix* pixt = pixAnd(NULL, pixs, pixc); + Pix* pixt = pixAnd(nullptr, pixs, pixc); l_int32 max_count; pixCountConnComp(pixt, 8, &max_count); // The count has to go up before we start looking for the minimum. l_int32 min_count = INT32_MAX; - Pix* pixout = NULL; + Pix* pixout = nullptr; for (int i = 1; i < kMaxCircleErosions; i++) { pixDestroy(&pixt); pixErodeBrick(pixc, pixc, 3, 3); - pixt = pixAnd(NULL, pixs, pixc); + pixt = pixAnd(nullptr, pixs, pixc); l_int32 count; pixCountConnComp(pixt, 8, &count); if (i == 1 || count > max_count) { @@ -85,7 +85,7 @@ static Pix* RemoveEnclosingCircle(Pix* pixs) { } else if (i > 1 && count < min_count) { min_count = count; pixDestroy(&pixout); - pixout = pixCopy(NULL, pixt); // Save the best. + pixout = pixCopy(nullptr, pixt); // Save the best. } else if (count >= min_count) { break; // We have passed by the best. } @@ -97,12 +97,12 @@ static Pix* RemoveEnclosingCircle(Pix* pixs) { /** * Segment the page according to the current value of tessedit_pageseg_mode. - * pix_binary_ is used as the source image and should not be NULL. + * pix_binary_ is used as the source image and should not be nullptr. * On return the blocks list owns all the constructed page layout. */ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks, Tesseract* osd_tess, OSResults* osr) { - ASSERT_HOST(pix_binary_ != NULL); + ASSERT_HOST(pix_binary_ != nullptr); int width = pixGetWidth(pix_binary_); int height = pixGetHeight(pix_binary_); // Get page segmentation mode. @@ -110,10 +110,10 @@ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks, static_cast(tessedit_pageseg_mode)); // If a UNLV zone file can be found, use that instead of segmentation. if (!PSM_COL_FIND_ENABLED(pageseg_mode) && - input_file != NULL && input_file->length() > 0) { + input_file != nullptr && input_file->length() > 0) { STRING name = *input_file; const char* lastdot = strrchr(name.string(), '.'); - if (lastdot != NULL) + if (lastdot != nullptr) name[lastdot - name.string()] = '\0'; read_unlv_file(name, width, height, blocks); } @@ -141,7 +141,7 @@ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks, PSM_SPARSE(pageseg_mode)) { auto_page_seg_ret_val = AutoPageSeg( pageseg_mode, blocks, &to_blocks, - enable_noise_removal ? &diacritic_blobs : NULL, osd_tess, osr); + enable_noise_removal ? &diacritic_blobs : nullptr, osd_tess, osr); if (pageseg_mode == PSM_OSD_ONLY) return auto_page_seg_ret_val; // To create blobs from the image region bounds uncomment this line: @@ -151,7 +151,7 @@ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks, reskew_ = FCOORD(1.0f, 0.0f); if (pageseg_mode == PSM_CIRCLE_WORD) { Pix* pixcleaned = RemoveEnclosingCircle(pix_binary_); - if (pixcleaned != NULL) { + if (pixcleaned != nullptr) { pixDestroy(&pix_binary_); pix_binary_ = pixcleaned; } @@ -205,8 +205,8 @@ int Tesseract::AutoPageSeg(PageSegMode pageseg_mode, BLOCK_LIST* blocks, TO_BLOCK_LIST* to_blocks, BLOBNBOX_LIST* diacritic_blobs, Tesseract* osd_tess, OSResults* osr) { - Pix* photomask_pix = NULL; - Pix* musicmask_pix = NULL; + Pix* photomask_pix = nullptr; + Pix* musicmask_pix = nullptr; // The blocks made by the ColumnFinder. Moved to blocks before return. BLOCK_LIST found_blocks; TO_BLOCK_LIST temp_blocks; @@ -215,10 +215,10 @@ int Tesseract::AutoPageSeg(PageSegMode pageseg_mode, BLOCK_LIST* blocks, pageseg_mode, blocks, osd_tess, osr, &temp_blocks, &photomask_pix, &musicmask_pix); int result = 0; - if (finder != NULL) { + if (finder != nullptr) { TO_BLOCK_IT to_block_it(&temp_blocks); TO_BLOCK* to_block = to_block_it.data(); - if (musicmask_pix != NULL) { + if (musicmask_pix != nullptr) { // TODO(rays) pass the musicmask_pix into FindBlocks and mark music // blocks separately. For now combine with photomask_pix. pixOr(photomask_pix, photomask_pix, musicmask_pix); @@ -262,7 +262,7 @@ static void AddAllScriptsConverted(const UNICHARSET& sid_set, * Sets up auto page segmentation, determines the orientation, and corrects it. * Somewhat arbitrary chunk of functionality, factored out of AutoPageSeg to * facilitate testing. - * photo_mask_pix is a pointer to a NULL pointer that will be filled on return + * photo_mask_pix is a pointer to a nullptr pointer that will be filled on return * with the leptonica photo mask, which must be pixDestroyed by the caller. * to_blocks is an empty list that will be filled with (usually a single) * block that is used during layout analysis. This ugly API is required @@ -281,7 +281,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation( TabVector_LIST h_lines; ICOORD bleft(0, 0); - ASSERT_HOST(pix_binary_ != NULL); + ASSERT_HOST(pix_binary_ != nullptr); if (tessedit_dump_pageseg_images) { pixa_debug_.AddPix(pix_binary_, "PageSegInput"); } @@ -309,7 +309,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation( ASSERT_HOST(to_blocks->singleton()); TO_BLOCK* to_block = to_block_it.data(); TBOX blkbox = to_block->block->pdblk.bounding_box(); - ColumnFinder* finder = NULL; + ColumnFinder* finder = nullptr; int estimated_resolution = source_resolution_; if (source_resolution_ == kMinCredibleResolution) { // Try to estimate resolution from typical body text size. @@ -347,7 +347,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation( finder->IsVerticallyAlignedText(textord_tabfind_vertical_text_ratio, to_block, &osd_blobs); } - if (PSM_OSD_ENABLED(pageseg_mode) && osd_tess != NULL && osr != NULL) { + if (PSM_OSD_ENABLED(pageseg_mode) && osd_tess != nullptr && osr != nullptr) { GenericVector osd_scripts; if (osd_tess != this) { // We are running osd as part of layout analysis, so constrain the @@ -361,7 +361,7 @@ ColumnFinder* Tesseract::SetupPageSegAndDetectOrientation( os_detect_blobs(&osd_scripts, &osd_blobs, osr, osd_tess); if (pageseg_mode == PSM_OSD_ONLY) { delete finder; - return NULL; + return nullptr; } osd_orientation = osr->best_result.orientation_id; double osd_score = osr->orientations[osd_orientation]; diff --git a/ccmain/pagewalk.cpp b/ccmain/pagewalk.cpp index bb34941974..a6dc0548e1 100644 --- a/ccmain/pagewalk.cpp +++ b/ccmain/pagewalk.cpp @@ -31,7 +31,7 @@ void Tesseract::process_selected_words( PAGE_RES* page_res, // blocks to check TBOX & selection_box, BOOL8(tesseract::Tesseract::*word_processor)(PAGE_RES_IT* pr_it)) { - for (PAGE_RES_IT page_res_it(page_res); page_res_it.word() != NULL; + for (PAGE_RES_IT page_res_it(page_res); page_res_it.word() != nullptr; page_res_it.forward()) { WERD* word = page_res_it.word()->word; if (word->bounding_box().overlap(selection_box)) { diff --git a/ccmain/par_control.cpp b/ccmain/par_control.cpp index be8d356397..a81dc6a7f9 100644 --- a/ccmain/par_control.cpp +++ b/ccmain/par_control.cpp @@ -25,7 +25,7 @@ namespace tesseract { struct BlobData { - BlobData() : blob(NULL), choices(NULL) {} + BlobData() : blob(nullptr), choices(nullptr) {} BlobData(int index, Tesseract* tess, const WERD_RES& word) : blob(word.chopped_word->blobs[index]), tesseract(tess), @@ -40,8 +40,8 @@ void Tesseract::PrerecAllWordsPar(const GenericVector& words) { // Prepare all the blobs. GenericVector blobs; for (int w = 0; w < words.size(); ++w) { - if (words[w].word->ratings != NULL && - words[w].word->ratings->get(0, 0) == NULL) { + if (words[w].word->ratings != nullptr && + words[w].word->ratings->get(0, 0) == nullptr) { for (int s = 0; s < words[w].lang_words.size(); ++s) { Tesseract* sub = s < sub_langs_.size() ? sub_langs_[s] : this; const WERD_RES& word = *words[w].lang_words[s]; @@ -58,13 +58,13 @@ void Tesseract::PrerecAllWordsPar(const GenericVector& words) { #endif // _OPENMP for (int b = 0; b < blobs.size(); ++b) { *blobs[b].choices = - blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL); + blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, nullptr); } } else { // TODO(AMD) parallelize this. for (int b = 0; b < blobs.size(); ++b) { *blobs[b].choices = - blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL); + blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, nullptr); } } } diff --git a/ccmain/paragraphs.cpp b/ccmain/paragraphs.cpp index 4268eafd23..9a6bf586b8 100644 --- a/ccmain/paragraphs.cpp +++ b/ccmain/paragraphs.cpp @@ -200,11 +200,11 @@ bool IsDigitLike(int ch) { } bool IsOpeningPunct(int ch) { - return strchr("'\"({[", ch) != NULL; + return strchr("'\"({[", ch) != nullptr; } bool IsTerminalPunct(int ch) { - return strchr(":'\".?!]})", ch) != NULL; + return strchr(":'\".?!]})", ch) != nullptr; } // Return a pointer after consuming as much text as qualifies as roman numeral. @@ -262,7 +262,7 @@ bool LikelyListNumeral(const STRING &word) { bool LikelyListMark(const STRING &word) { const char *kListMarks = "0Oo*.,+."; - return word.size() == 1 && strchr(kListMarks, word[0]) != NULL; + return word.size() == 1 && strchr(kListMarks, word[0]) != nullptr; } bool AsciiLikelyListItem(const STRING &word) { @@ -398,7 +398,7 @@ void LeftWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, *is_list = false; *starts_idea = false; *ends_idea = false; - if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty + if (utf8.size() == 0 || (werd != nullptr && werd->length() == 0)) { // Empty *ends_idea = true; return; } @@ -445,7 +445,7 @@ void RightWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, *is_list = false; *starts_idea = false; *ends_idea = false; - if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty + if (utf8.size() == 0 || (werd != nullptr && werd->length() == 0)) { // Empty *ends_idea = true; return; } @@ -491,7 +491,7 @@ void RowScratchRegisters::AppendDebugInfo(const ParagraphTheory &theory, int model_numbers = 0; for (int h = 0; h < hypotheses_.size(); h++) { - if (hypotheses_[h].model == NULL) + if (hypotheses_[h].model == nullptr) continue; if (model_numbers > 0) model_string += ","; @@ -566,7 +566,7 @@ void RowScratchRegisters::SetStartLine() { tprintf("Trying to set a line to be START when it's already BODY.\n"); } if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) { - hypotheses_.push_back_new(LineHypothesis(LT_START, NULL)); + hypotheses_.push_back_new(LineHypothesis(LT_START, nullptr)); } } @@ -576,20 +576,20 @@ void RowScratchRegisters::SetBodyLine() { tprintf("Trying to set a line to be BODY when it's already START.\n"); } if (current_lt == LT_UNKNOWN || current_lt == LT_START) { - hypotheses_.push_back_new(LineHypothesis(LT_BODY, NULL)); + hypotheses_.push_back_new(LineHypothesis(LT_BODY, nullptr)); } } void RowScratchRegisters::AddStartLine(const ParagraphModel *model) { hypotheses_.push_back_new(LineHypothesis(LT_START, model)); - int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, NULL)); + int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, nullptr)); if (old_idx >= 0) hypotheses_.remove(old_idx); } void RowScratchRegisters::AddBodyLine(const ParagraphModel *model) { hypotheses_.push_back_new(LineHypothesis(LT_BODY, model)); - int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, NULL)); + int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, nullptr)); if (old_idx >= 0) hypotheses_.remove(old_idx); } @@ -610,20 +610,20 @@ void RowScratchRegisters::StrongHypotheses(SetOfModels *models) const { void RowScratchRegisters::NonNullHypotheses(SetOfModels *models) const { for (int h = 0; h < hypotheses_.size(); h++) { - if (hypotheses_[h].model != NULL) + if (hypotheses_[h].model != nullptr) models->push_back_new(hypotheses_[h].model); } } const ParagraphModel *RowScratchRegisters::UniqueStartHypothesis() const { if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START) - return NULL; + return nullptr; return hypotheses_[0].model; } const ParagraphModel *RowScratchRegisters::UniqueBodyHypothesis() const { if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY) - return NULL; + return nullptr; return hypotheses_[0].model; } @@ -1236,7 +1236,7 @@ void ParagraphTheory::DiscardUnusedModels(const SetOfModels &used_models) { // Examine rows[start, end) and try to determine if an existing non-centered // paragraph model would fit them perfectly. If so, return a pointer to it. -// If not, return NULL. +// If not, return nullptr. const ParagraphModel *ParagraphTheory::Fits( const GenericVector *rows, int start, int end) const { for (int m = 0; m < models_->size(); m++) { @@ -1245,7 +1245,7 @@ const ParagraphModel *ParagraphTheory::Fits( RowsFitModel(rows, start, end, model)) return model; } - return NULL; + return nullptr; } void ParagraphTheory::NonCenteredModels(SetOfModels *models) { @@ -1492,9 +1492,9 @@ void DowngradeWeakestToCrowns(int debug_level, int start; for (int end = rows->size(); end > 0; end = start) { // Search back for a body line of a unique type. - const ParagraphModel *model = NULL; + const ParagraphModel *model = nullptr; while (end > 0 && - (model = (*rows)[end - 1].UniqueBodyHypothesis()) == NULL) { + (model = (*rows)[end - 1].UniqueBodyHypothesis()) == nullptr) { end--; } if (end == 0) break; @@ -1952,7 +1952,7 @@ void ModelStrongEvidence(int debug_level, // do so and mark this sequence with that model. if (end > start + 1) { // emit a new paragraph if we have more than one line. - const ParagraphModel *model = NULL; + const ParagraphModel *model = nullptr; ParagraphModel new_model = ParagraphModelByOutline( debug_level, rows, start, end, Epsilon(InterwordSpace(*rows, start, end))); @@ -2048,7 +2048,7 @@ void ConvertHypothesizedModelRunsToParagraphs( int start; for (; end > 0; end = start) { start = end - 1; - const ParagraphModel *model = NULL; + const ParagraphModel *model = nullptr; // TODO(eger): Be smarter about dealing with multiple hypotheses. bool single_line_paragraph = false; SetOfModels models; @@ -2064,10 +2064,10 @@ void ConvertHypothesizedModelRunsToParagraphs( // do nothing } if (start < 0 || rows[start].GetLineType(model) != LT_START) { - model = NULL; + model = nullptr; } } - if (model == NULL) { + if (model == nullptr) { continue; } // rows[start, end) should be a paragraph. @@ -2111,7 +2111,7 @@ void ConvertHypothesizedModelRunsToParagraphs( ? rows[start].ri_->rword_indicates_list_item : rows[start].ri_->lword_indicates_list_item; for (int row = start; row < end; row++) { - if ((*row_owners)[row] != NULL) { + if ((*row_owners)[row] != nullptr) { tprintf("Memory leak! ConvertHypothesizeModelRunsToParagraphs() called " "more than once!\n"); delete (*row_owners)[row]; @@ -2228,7 +2228,7 @@ void LeftoverSegments(const GenericVector &rows, } } -// Given a set of row_owners pointing to PARAs or NULL (no paragraph known), +// 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. void CanonicalizeDetectionResults( @@ -2237,9 +2237,9 @@ void CanonicalizeDetectionResults( GenericVector &rows = *row_owners; paragraphs->clear(); PARA_IT out(paragraphs); - PARA *formerly_null = NULL; + PARA *formerly_null = nullptr; for (int i = 0; i < rows.size(); i++) { - if (rows[i] == NULL) { + if (rows[i] == nullptr) { if (i == 0 || rows[i - 1] != formerly_null) { rows[i] = formerly_null = new PARA(); } else { @@ -2271,8 +2271,8 @@ void DetectParagraphs(int debug_level, GenericVector rows; ParagraphTheory theory(models); - // Initialize row_owners to be a bunch of NULL pointers. - row_owners->init_to_size(row_infos->size(), NULL); + // Initialize row_owners to be a bunch of nullptr pointers. + row_owners->init_to_size(row_infos->size(), nullptr); // Set up row scratch registers for the main algorithm. rows.init_to_size(row_infos->size(), RowScratchRegisters()); @@ -2352,7 +2352,7 @@ void DetectParagraphs(int debug_level, DebugDump(debug_level > 0, "Final Paragraph Segmentation", theory, rows); - // Finally, clean up any dangling NULL row paragraph parents. + // Finally, clean up any dangling nullptr row paragraph parents. CanonicalizeDetectionResults(row_owners, paragraphs); } @@ -2391,8 +2391,8 @@ void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, WERD_RES *word_res = page_res_it.restart_row(); ROW_RES *this_row = page_res_it.row(); - WERD_RES *lword = NULL; - WERD_RES *rword = NULL; + WERD_RES *lword = nullptr; + WERD_RES *rword = nullptr; info->num_words = 0; do { if (word_res) { @@ -2413,7 +2413,7 @@ void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, void InitializeRowInfo(bool after_recognition, const MutableIterator &it, RowInfo *info) { - if (it.PageResIt()->row() != NULL) { + if (it.PageResIt()->row() != nullptr) { ROW *row = it.PageResIt()->row()->row; info->pix_ldistance = row->lmargin(); info->pix_rdistance = row->rmargin(); @@ -2529,7 +2529,7 @@ void DetectParagraphs(int debug_level, do { if (!row.PageResIt()->row()) continue; // empty row. - row.PageResIt()->row()->row->set_para(NULL); + row.PageResIt()->row()->row->set_para(nullptr); row_infos.push_back(RowInfo()); RowInfo &ri = row_infos.back(); InitializeRowInfo(after_text_recognition, row, &ri); @@ -2562,7 +2562,7 @@ void DetectParagraphs(int debug_level, DetectParagraphs(debug_level, &row_infos, &row_owners, block->para_list(), models); } else { - row_owners.init_to_size(row_infos.size(), NULL); + row_owners.init_to_size(row_infos.size(), nullptr); CanonicalizeDetectionResults(&row_owners, block->para_list()); } diff --git a/ccmain/paragraphs_internal.h b/ccmain/paragraphs_internal.h index 5eeb8194f1..26df1ec819 100644 --- a/ccmain/paragraphs_internal.h +++ b/ccmain/paragraphs_internal.h @@ -73,11 +73,11 @@ extern const ParagraphModel *kCrownLeft; extern const ParagraphModel *kCrownRight; inline bool StrongModel(const ParagraphModel *model) { - return model != NULL && model != kCrownLeft && model != kCrownRight; + return model != nullptr && model != kCrownLeft && model != kCrownRight; } struct LineHypothesis { - LineHypothesis() : ty(LT_UNKNOWN), model(NULL) {} + LineHypothesis() : ty(LT_UNKNOWN), model(nullptr) {} LineHypothesis(LineType line_type, const ParagraphModel *m) : ty(line_type), model(m) {} LineHypothesis(const LineHypothesis &other) @@ -135,11 +135,11 @@ class RowScratchRegisters { void DiscardNonMatchingHypotheses(const SetOfModels &models); // If we have only one hypothesis and that is that this line is a paragraph - // start line of a certain model, return that model. Else return NULL. + // start line of a certain model, return that model. Else return nullptr. const ParagraphModel *UniqueStartHypothesis() const; // If we have only one hypothesis and that is that this line is a paragraph - // body line of a certain model, return that model. Else return NULL. + // body line of a certain model, return that model. Else return nullptr. const ParagraphModel *UniqueBodyHypothesis() const; // Return the indentation for the side opposite of the aligned side. @@ -206,7 +206,7 @@ class ParagraphTheory { void NonCenteredModels(SetOfModels *models); // If any of the non-centered paragraph models we know about fit - // rows[start, end), return it. Else NULL. + // rows[start, end), return it. Else nullptr. const ParagraphModel *Fits(const GenericVector *rows, int start, int end) const; @@ -301,7 +301,7 @@ bool LikelyParagraphStart(const RowScratchRegisters &before, const RowScratchRegisters &after, tesseract::ParagraphJustification j); -// Given a set of row_owners pointing to PARAs or NULL (no paragraph known), +// 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. void CanonicalizeDetectionResults( diff --git a/ccmain/paramsd.cpp b/ccmain/paramsd.cpp index a5fccf88e8..64ea851179 100644 --- a/ccmain/paramsd.cpp +++ b/ccmain/paramsd.cpp @@ -128,7 +128,7 @@ const char* ParamContent::GetDescription() const { else if (param_type_ == VT_BOOLEAN) { return bIt->info_str(); } else if (param_type_ == VT_DOUBLE) { return dIt->info_str(); } else if (param_type_ == VT_STRING) { return sIt->info_str(); } - else return NULL; + else return nullptr; } // Getter for the value. @@ -141,7 +141,7 @@ STRING ParamContent::GetValue() const { } else if (param_type_ == VT_DOUBLE) { result.add_str_double("", *dIt); } else if (param_type_ == VT_STRING) { - if (((STRING) * (sIt)).string() != NULL) { + if (((STRING) * (sIt)).string() != nullptr) { result = sIt->string(); } else { result = "Null"; @@ -160,7 +160,7 @@ void ParamContent::SetValue(const char* val) { } else if (param_type_ == VT_BOOLEAN) { bIt->set_value(atoi(val)); } else if (param_type_ == VT_DOUBLE) { - dIt->set_value(strtod(val, NULL)); + dIt->set_value(strtod(val, nullptr)); } else if (param_type_ == VT_STRING) { sIt->set_value(val); } @@ -201,7 +201,7 @@ SVMenuNode* ParamsEditor::BuildListOfAllLeaves(tesseract::Tesseract *tess) { // Add all parameters to a list. int v, i; - int num_iterations = (tess->params() == NULL) ? 1 : 2; + int num_iterations = (tess->params() == nullptr) ? 1 : 2; for (v = 0; v < num_iterations; ++v) { tesseract::ParamsVectors *vec = (v == 0) ? GlobalParams() : tess->params(); for (i = 0; i < vec->int_params.size(); ++i) { @@ -286,7 +286,7 @@ void ParamsEditor::Notify(const SVEvent* sve) { // empty window and attach the parameters editor to that window (ugly). ParamsEditor::ParamsEditor(tesseract::Tesseract* tess, ScrollView* sv) { - if (sv == NULL) { + if (sv == nullptr) { const char* name = "ParamEditorMAIN"; sv = new ScrollView(name, 1, 1, 200, 200, 300, 200); } @@ -323,7 +323,7 @@ void ParamsEditor::WriteParams(char *filename, FILE *fp; // input file char msg_str[255]; // if file exists - if ((fp = fopen (filename, "rb")) != NULL) { + if ((fp = fopen (filename, "rb")) != nullptr) { fclose(fp); sprintf (msg_str, "Overwrite file " "%s" "? (Y/N)", filename); int a = sv_window_->ShowYesNoDialog(msg_str); @@ -334,7 +334,7 @@ void ParamsEditor::WriteParams(char *filename, fp = fopen (filename, "wb"); // can we write to it? - if (fp == NULL) { + if (fp == nullptr) { sv_window_->AddMessage( "Can't write to file " "%s" diff --git a/ccmain/paramsd.h b/ccmain/paramsd.h index 6994827fc9..6b4f6336c1 100644 --- a/ccmain/paramsd.h +++ b/ccmain/paramsd.h @@ -93,7 +93,7 @@ class ParamsEditor : public SVEventHandler { // Integrate the parameters editor as popupmenu into the existing scrollview // window (usually the pg editor). If sv == null, create a new empty // empty window and attach the parameter editor to that window (ugly). - explicit ParamsEditor(tesseract::Tesseract*, ScrollView* sv = NULL); + explicit ParamsEditor(tesseract::Tesseract*, ScrollView* sv = nullptr); // Event listener. Waits for SVET_POPUP events and processes them. void Notify(const SVEvent* sve); diff --git a/ccmain/pgedit.cpp b/ccmain/pgedit.cpp index 436d6c0431..818454831c 100644 --- a/ccmain/pgedit.cpp +++ b/ccmain/pgedit.cpp @@ -109,9 +109,9 @@ ParamsEditor* pe; bool stillRunning = false; #ifdef __UNIX__ -FILE *debug_window = NULL; // opened on demand +FILE *debug_window = nullptr; // opened on demand #endif -ScrollView* bln_word_window = NULL; // baseline norm words +ScrollView* bln_word_window = nullptr; // baseline norm words CMD_EVENTS mode = CHANGE_DISP_CMD_EVENT; // selected words op @@ -125,7 +125,7 @@ BOOL8 display_image = FALSE; BOOL8 display_blocks = FALSE; BOOL8 display_baselines = FALSE; -PAGE_RES *current_page_res = NULL; +PAGE_RES *current_page_res = nullptr; STRING_VAR(editor_image_win_name, "EditorImage", "Editor image window name"); @@ -158,7 +158,7 @@ class BlnEventHandler : public SVEventHandler { public: void Notify(const SVEvent* sv_event) { if (sv_event->type == SVET_DESTROY) - bln_word_window = NULL; + bln_word_window = nullptr; else if (sv_event->type == SVET_CLICK) show_point(current_page_res, sv_event->x, sv_event->y); } @@ -171,7 +171,7 @@ class BlnEventHandler : public SVEventHandler { */ ScrollView* bln_word_window_handle() { // return handle // not opened yet - if (bln_word_window == NULL) { + if (bln_word_window == nullptr) { pgeditor_msg("Creating BLN word window..."); bln_word_window = new ScrollView(editor_word_name.string(), editor_word_xpos, editor_word_ypos, editor_word_width, @@ -316,7 +316,7 @@ void Tesseract::do_re_display( image_win->Brush(ScrollView::NONE); PAGE_RES_IT pr_it(current_page_res); - for (WERD_RES* word = pr_it.word(); word != NULL; word = pr_it.forward()) { + for (WERD_RES* word = pr_it.word(); word != nullptr; word = pr_it.forward()) { (this->*word_painter)(&pr_it); if (display_baselines && pr_it.row() != pr_it.prev_row()) pr_it.row()->row->plot_baseline(image_win, ScrollView::GREEN); @@ -359,7 +359,7 @@ void Tesseract::pgeditor_main(int width, int height, PAGE_RES *page_res) { image_win->SetVisible(true); image_win->AwaitEvent(SVET_DESTROY); - image_win->AddEventHandler(NULL); + image_win->AddEventHandler(nullptr); } } // namespace tesseract @@ -416,7 +416,7 @@ BOOL8 Tesseract::process_cmd_win_event( // UI command semantics case SHOW_SMALLCAPS_CMD_EVENT: case SHOW_DROPCAPS_CMD_EVENT: if (!recog_done) { - recog_all_words(current_page_res, NULL, NULL, NULL, 0); + recog_all_words(current_page_res, nullptr, nullptr, nullptr, 0); recog_done = true; } break; @@ -640,7 +640,7 @@ void Tesseract::process_image_event( // action in image win */ void Tesseract::debug_word(PAGE_RES* page_res, const TBOX &selection_box) { ResetAdaptiveClassifier(); - recog_all_words(page_res, NULL, &selection_box, word_config_.string(), 0); + recog_all_words(page_res, nullptr, &selection_box, word_config_.string(), 0); } } // namespace tesseract @@ -662,7 +662,7 @@ void show_point(PAGE_RES* page_res, float x, float y) { msg_ptr += sprintf(msg_ptr, "Pt:(%0.3f, %0.3f) ", x, y); - for (WERD_RES* word = pr_it.word(); word != NULL; word = pr_it.forward()) { + for (WERD_RES* word = pr_it.word(); word != nullptr; word = pr_it.forward()) { if (pr_it.row() != pr_it.prev_row() && pr_it.row()->row->bounding_box().contains(pt)) { msg_ptr += sprintf(msg_ptr, "BL(x)=%0.3f ", @@ -728,10 +728,10 @@ BOOL8 Tesseract:: word_blank_and_set_display(PAGE_RES_IT* pr_it) { */ BOOL8 Tesseract::word_bln_display(PAGE_RES_IT* pr_it) { WERD_RES* word_res = pr_it->word(); - if (word_res->chopped_word == NULL) { + if (word_res->chopped_word == nullptr) { // Setup word normalization parameters. word_res->SetupForRecognition(unicharset, this, BestPix(), - tessedit_ocr_engine_mode, NULL, + tessedit_ocr_engine_mode, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, @@ -767,11 +767,11 @@ BOOL8 Tesseract::word_display(PAGE_RES_IT* pr_it) { float shift; // from bot left C_BLOB_IT c_it; // cblob iterator - if (color_mode != CM_RAINBOW && word_res->box_word != NULL) { + if (color_mode != CM_RAINBOW && word_res->box_word != nullptr) { BoxWord* box_word = word_res->box_word; WERD_CHOICE* best_choice = word_res->best_choice; int length = box_word->length(); - if (word_res->fontinfo == NULL) return false; + if (word_res->fontinfo == nullptr) return false; const FontInfo& font_info = *word_res->fontinfo; for (int i = 0; i < length; ++i) { ScrollView::Color color = ScrollView::GREEN; @@ -858,28 +858,28 @@ BOOL8 Tesseract::word_display(PAGE_RES_IT* pr_it) { // Display correct text and blamer information. STRING text; STRING blame; - if (word->display_flag(DF_TEXT) && word->text() != NULL) { + if (word->display_flag(DF_TEXT) && word->text() != nullptr) { text = word->text(); } if (word->display_flag(DF_BLAMER) && - !(word_res->blamer_bundle != NULL && + !(word_res->blamer_bundle != nullptr && word_res->blamer_bundle->incorrect_result_reason() == IRR_CORRECT)) { text = ""; const BlamerBundle *blamer_bundle = word_res->blamer_bundle; - if (blamer_bundle == NULL) { + if (blamer_bundle == nullptr) { text += "NULL"; } else { text = blamer_bundle->TruthString(); } text += " -> "; STRING best_choice_str; - if (word_res->best_choice == NULL) { + if (word_res->best_choice == nullptr) { best_choice_str = "NULL"; } else { - word_res->best_choice->string_and_lengths(&best_choice_str, NULL); + word_res->best_choice->string_and_lengths(&best_choice_str, nullptr); } text += best_choice_str; - IncorrectResultReason reason = (blamer_bundle == NULL) ? + IncorrectResultReason reason = (blamer_bundle == nullptr) ? IRR_PAGE_LAYOUT : blamer_bundle->incorrect_result_reason(); ASSERT_HOST(reason < IRR_NUM_REASONS) blame += " ["; @@ -920,16 +920,16 @@ BOOL8 Tesseract::word_display(PAGE_RES_IT* pr_it) { * Dump members to the debug window */ BOOL8 Tesseract::word_dumper(PAGE_RES_IT* pr_it) { - if (pr_it->block()->block != NULL) { + if (pr_it->block()->block != nullptr) { tprintf("\nBlock data...\n"); - pr_it->block()->block->print(NULL, FALSE); + pr_it->block()->block->print(nullptr, FALSE); } tprintf("\nRow data...\n"); - pr_it->row()->row->print(NULL); + pr_it->row()->row->print(nullptr); tprintf("\nWord data...\n"); WERD_RES* word_res = pr_it->word(); word_res->word->print(); - if (word_res->blamer_bundle != NULL && wordrec_debug_blamer && + if (word_res->blamer_bundle != nullptr && wordrec_debug_blamer && word_res->blamer_bundle->incorrect_result_reason() != IRR_CORRECT) { tprintf("Current blamer debug: %s\n", word_res->blamer_bundle->debug().string()); @@ -960,11 +960,11 @@ BOOL8 Tesseract::word_set_display(PAGE_RES_IT* pr_it) { void Tesseract::blob_feature_display(PAGE_RES* page_res, const TBOX& selection_box) { PAGE_RES_IT* it = make_pseudo_word(page_res, selection_box); - if (it != NULL) { + if (it != nullptr) { WERD_RES* word_res = it->word(); word_res->x_height = it->row()->row->x_height(); word_res->SetupForRecognition(unicharset, this, BestPix(), - tessedit_ocr_engine_mode, NULL, + tessedit_ocr_engine_mode, nullptr, classify_bln_numeric_mode, textord_use_cjk_fp_model, poly_allow_detailed_fx, @@ -975,7 +975,7 @@ void Tesseract::blob_feature_display(PAGE_RES* page_res, GenericVector bl_features; GenericVector cn_features; Classify::ExtractFeatures(*bln_blob, classify_nonlinear_norm, &bl_features, - &cn_features, &fx_info, NULL); + &cn_features, &fx_info, nullptr); // Display baseline features. ScrollView* bl_win = CreateFeatureSpaceWindow("BL Features", 512, 0); ClearFeatureSpaceWindow(baseline, bl_win); diff --git a/ccmain/recogtraining.cpp b/ccmain/recogtraining.cpp index 523d3a9e9f..d9c0af8a31 100644 --- a/ccmain/recogtraining.cpp +++ b/ccmain/recogtraining.cpp @@ -43,7 +43,7 @@ FILE *Tesseract::init_recog_training(const STRING &fname) { STRING output_fname = fname; const char *lastdot = strrchr(output_fname.string(), '.'); - if (lastdot != NULL) output_fname[lastdot - output_fname.string()] = '\0'; + if (lastdot != nullptr) output_fname[lastdot - output_fname.string()] = '\0'; output_fname += ".txt"; FILE *output_file = open_file(output_fname.string(), "a+"); return output_file; @@ -51,10 +51,10 @@ 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) { - while (page_res_it->block() != NULL && page_res_it->word() == NULL) + while (page_res_it->block() != nullptr && page_res_it->word() == nullptr) page_res_it->forward(); - if (page_res_it->word() != NULL) { + if (page_res_it->word() != nullptr) { *tbox = page_res_it->word()->word->bounding_box(); // If tbox->left() is negative, the training image has vertical text and @@ -82,7 +82,7 @@ void Tesseract::recog_training_segmented(const STRING &fname, FILE *output_file) { STRING box_fname = fname; const char *lastdot = strrchr(box_fname.string(), '.'); - if (lastdot != NULL) box_fname[lastdot - box_fname.string()] = '\0'; + if (lastdot != nullptr) box_fname[lastdot - box_fname.string()] = '\0'; box_fname += ".box"; // ReadNextBox() will close box_file FILE *box_file = open_file(box_fname.string(), "r"); @@ -138,10 +138,10 @@ void Tesseract::recog_training_segmented(const STRING &fname, // werd_res's don't get uch_sets, tesseract will crash when you try // to iterate over them. :-( int total_words = 0; - for (page_res_it.restart_page(); page_res_it.block() != NULL; + for (page_res_it.restart_page(); page_res_it.block() != nullptr; page_res_it.forward()) { if (page_res_it.word()) { - if (page_res_it.word()->uch_set == NULL) + if (page_res_it.word()->uch_set == nullptr) page_res_it.word()->SetupFake(unicharset); total_words++; } @@ -209,11 +209,11 @@ void Tesseract::ambigs_classify_and_output(const char *label, classify_word_and_language(1, pr_it, &word_data); WERD_RES* werd_res = word_data.word; WERD_CHOICE *best_choice = werd_res->best_choice; - ASSERT_HOST(best_choice != NULL); + ASSERT_HOST(best_choice != nullptr); // Compute the number of unichars in the label. GenericVector encoding; - if (!unicharset.encode_string(label, true, &encoding, NULL, NULL)) { + if (!unicharset.encode_string(label, true, &encoding, nullptr, nullptr)) { tprintf("Not outputting illegal unichar %s\n", label); return; } diff --git a/ccmain/reject.cpp b/ccmain/reject.cpp index a80fa22766..fbb09462f0 100644 --- a/ccmain/reject.cpp +++ b/ccmain/reject.cpp @@ -56,7 +56,7 @@ CLISTIZEH (STRING) CLISTIZE (STRING) namespace tesseract { void Tesseract::set_done(WERD_RES *word, int16_t pass) { word->done = word->tess_accepted && - (strchr(word->best_choice->unichar_string().string(), ' ') == NULL); + (strchr(word->best_choice->unichar_string().string(), ' ') == nullptr); bool word_is_ambig = word->best_choice->dangerous_ambig_found(); bool word_from_dict = word->best_choice->permuter() == SYSTEM_DAWG_PERM || word->best_choice->permuter() == FREQ_DAWG_PERM || @@ -120,7 +120,7 @@ void Tesseract::make_reject_map(WERD_RES *word, ROW *row, int16_t pass) { word->reject_map.rej_word_not_tess_accepted (); if (rej_use_tess_blanks && - (strchr (word->best_choice->unichar_string().string (), ' ') != NULL)) + (strchr (word->best_choice->unichar_string().string (), ' ') != nullptr)) word->reject_map.rej_word_contains_blanks (); WERD_CHOICE* best_choice = word->best_choice; @@ -312,7 +312,7 @@ BOOL8 Tesseract::one_ell_conflict(WERD_RES *word_res, BOOL8 update_map) { If there are no occurrences of the conflict set characters then the word is OK. */ - if (strpbrk (word, conflict_set_I_l_1.string ()) == NULL) + if (strpbrk (word, conflict_set_I_l_1.string ()) == nullptr) return FALSE; /* diff --git a/ccmain/resultiterator.cpp b/ccmain/resultiterator.cpp index 32445fb2ae..5c502cbdbb 100644 --- a/ccmain/resultiterator.cpp +++ b/ccmain/resultiterator.cpp @@ -39,7 +39,7 @@ ResultIterator::ResultIterator(const LTRResultIterator &resit) BoolParam *p = ParamUtils::FindParam( "preserve_interword_spaces", GlobalParams()->bool_params, tesseract_->params()->bool_params); - if (p != NULL) preserve_interword_spaces_ = (bool)(*p); + if (p != nullptr) preserve_interword_spaces_ = (bool)(*p); current_paragraph_is_ltr_ = CurrentParagraphIsLtr(); MoveToLogicalStartOfTextline(); @@ -237,7 +237,7 @@ void ResultIterator::CalculateTextlineOrder( GenericVectorEqEq *word_indices) const { GenericVector dirs; GenericVector *directions; - directions = (dirs_arg != NULL) ? dirs_arg : &dirs; + directions = (dirs_arg != nullptr) ? dirs_arg : &dirs; directions->truncate(0); // A LTRResultIterator goes strictly left-to-right word order. @@ -419,7 +419,7 @@ void ResultIterator::Begin() { } bool ResultIterator::Next(PageIteratorLevel level) { - if (it_->block() == NULL) return false; // already at end! + if (it_->block() == nullptr) return false; // already at end! switch (level) { case RIL_BLOCK: // explicit fall-through case RIL_PARA: // explicit fall-through @@ -432,7 +432,7 @@ bool ResultIterator::Next(PageIteratorLevel level) { } in_minor_direction_ = false; MoveToLogicalStartOfTextline(); - return it_->block() != NULL; + return it_->block() != nullptr; case RIL_SYMBOL: { GenericVector blob_order; @@ -452,7 +452,7 @@ bool ResultIterator::Next(PageIteratorLevel level) { } case RIL_WORD: // explicit fall-through. { - if (it_->word() == NULL) return Next(RIL_BLOCK); + if (it_->word() == nullptr) return Next(RIL_BLOCK); GenericVectorEqEq word_indices; int this_word_index = LTRWordIndex(); CalculateTextlineOrder(current_paragraph_is_ltr_, @@ -494,8 +494,8 @@ bool ResultIterator::Next(PageIteratorLevel level) { } bool ResultIterator::IsAtBeginningOf(PageIteratorLevel level) const { - if (it_->block() == NULL) return false; // Already at the end! - if (it_->word() == NULL) return true; // In an image block. + if (it_->block() == nullptr) return false; // Already at the end! + if (it_->word() == nullptr) return true; // In an image block. if (level == RIL_SYMBOL) return true; // Always at beginning of a symbol. bool at_word_start = IsAtFirstSymbolOfWord(); @@ -560,7 +560,7 @@ int ResultIterator::BlanksBeforeWord() const { * object at the given level. Use delete [] to free after use. */ char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const { - if (it_->word() == NULL) return NULL; // Already at the end! + if (it_->word() == nullptr) return nullptr; // Already at the end! STRING text; switch (level) { case RIL_BLOCK: @@ -604,7 +604,7 @@ char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const { void ResultIterator::AppendUTF8WordText(STRING *text) const { if (!it_->word()) return; - ASSERT_HOST(it_->word()->best_choice != NULL); + ASSERT_HOST(it_->word()->best_choice != nullptr); bool reading_direction_is_ltr = current_paragraph_is_ltr_ ^ in_minor_direction_; if (at_beginning_of_minor_run_) { @@ -670,7 +670,7 @@ void ResultIterator::AppendUTF8ParagraphText(STRING *text) const { if (it.Empty(RIL_WORD)) return; do { it.IterateAndAppendUTF8TextlineText(text); - } while (it.it_->block() != NULL && !it.IsAtBeginningOf(RIL_PARA)); + } while (it.it_->block() != nullptr && !it.IsAtBeginningOf(RIL_PARA)); } bool ResultIterator::BidiDebug(int min_level) const { @@ -678,7 +678,7 @@ bool ResultIterator::BidiDebug(int min_level) const { IntParam *p = ParamUtils::FindParam( "bidi_debug", GlobalParams()->int_params, tesseract_->params()->int_params); - if (p != NULL) debug_level = (int32_t)(*p); + if (p != nullptr) debug_level = (int32_t)(*p); return debug_level >= min_level; } diff --git a/ccmain/resultiterator.h b/ccmain/resultiterator.h index 9651cab9f4..cea489603a 100644 --- a/ccmain/resultiterator.h +++ b/ccmain/resultiterator.h @@ -163,7 +163,7 @@ class TESS_API ResultIterator : public LTRResultIterator { void CalculateTextlineOrder(bool paragraph_is_ltr, const LTRResultIterator &resit, GenericVectorEqEq *indices) const; - /** Same as above, but the caller's ssd gets filled in if ssd != NULL. */ + /** Same as above, but the caller's ssd gets filled in if ssd != nullptr. */ void CalculateTextlineOrder(bool paragraph_is_ltr, const LTRResultIterator &resit, GenericVector *ssd, diff --git a/ccmain/superscript.cpp b/ccmain/superscript.cpp index 7fe9bf6ebe..75e12b6472 100644 --- a/ccmain/superscript.cpp +++ b/ccmain/superscript.cpp @@ -135,7 +135,7 @@ bool Tesseract::SubAndSuperscriptFix(WERD_RES *word) { last_char_certainty <= unlikely_threshold) { ScriptPos rpos; YOutlierPieces(word, last_word_char, super_y_bottom, sub_y_top, - NULL, NULL, &rpos, &num_remainder_trailing); + nullptr, nullptr, &rpos, &num_remainder_trailing); if (num_trailing > 0 && rpos != sp_trailing) num_remainder_trailing = 0; if (num_remainder_trailing > 0 && last_char_certainty < trailing_certainty) { @@ -150,7 +150,7 @@ bool Tesseract::SubAndSuperscriptFix(WERD_RES *word) { first_char_certainty <= unlikely_threshold) { ScriptPos lpos; YOutlierPieces(word, num_leading, super_y_bottom, sub_y_top, - &lpos, &num_remainder_leading, NULL, NULL); + &lpos, &num_remainder_leading, nullptr, nullptr); if (num_leading > 0 && lpos != sp_leading) num_remainder_leading = 0; if (num_remainder_leading > 0 && first_char_certainty < leading_certainty) { @@ -392,11 +392,11 @@ WERD_RES *Tesseract::TrySuperscriptSplits( // Chop apart the word into up to three pieces. - BlamerBundle *bb0 = NULL; - BlamerBundle *bb1 = NULL; - WERD_RES *prefix = NULL; - WERD_RES *core = NULL; - WERD_RES *suffix = NULL; + BlamerBundle *bb0 = nullptr; + BlamerBundle *bb1 = nullptr; + WERD_RES *prefix = nullptr; + WERD_RES *core = nullptr; + WERD_RES *suffix = nullptr; if (num_chopped_leading > 0) { prefix = new WERD_RES(*word); split_word(prefix, num_chopped_leading, &core, &bb0); @@ -463,11 +463,11 @@ WERD_RES *Tesseract::TrySuperscriptSplits( bool good_prefix = !prefix || BelievableSuperscript( superscript_debug >= 1, *prefix, superscript_bettered_certainty * leading_certainty, - retry_rebuild_leading, NULL); + retry_rebuild_leading, nullptr); bool good_suffix = !suffix || BelievableSuperscript( superscript_debug >= 1, *suffix, superscript_bettered_certainty * trailing_certainty, - NULL, retry_rebuild_trailing); + nullptr, retry_rebuild_trailing); *is_good = good_prefix && good_suffix; if (!*is_good && !*retry_rebuild_leading && !*retry_rebuild_trailing) { @@ -476,7 +476,7 @@ WERD_RES *Tesseract::TrySuperscriptSplits( delete prefix; delete suffix; delete bb1; - return NULL; + return nullptr; } recog_word_recursive(core); @@ -489,7 +489,7 @@ WERD_RES *Tesseract::TrySuperscriptSplits( prefix->SetAllScriptPositions(leading_pos); join_words(prefix, core, bb0); core = prefix; - prefix = NULL; + prefix = nullptr; } if (superscript_debug >= 1) { diff --git a/ccmain/tessbox.cpp b/ccmain/tessbox.cpp index 6efbd3aaed..f198d1491a 100644 --- a/ccmain/tessbox.cpp +++ b/ccmain/tessbox.cpp @@ -51,7 +51,7 @@ void Tesseract::tess_segment_pass_n(int pass_n, WERD_RES *word) { else set_pass2(); recog_word(word); - if (word->best_choice == NULL) + if (word->best_choice == nullptr) word->SetupFake(*word->uch_set); if (word->word->flag(W_DONT_CHOP)) { wordrec_enable_assoc.set_value(saved_enable_assoc); diff --git a/ccmain/tessedit.cpp b/ccmain/tessedit.cpp index 8cb1a916fc..e07be68233 100644 --- a/ccmain/tessedit.cpp +++ b/ccmain/tessedit.cpp @@ -50,7 +50,7 @@ // config under api #define API_CONFIG "configs/api_config" -ETEXT_DESC *global_monitor = NULL; // progress monitor +ETEXT_DESC *global_monitor = nullptr; // progress monitor namespace tesseract { @@ -63,13 +63,13 @@ void Tesseract::read_config_file(const char *filename, path += "configs/"; path += filename; FILE* fp; - if ((fp = fopen(path.string(), "rb")) != NULL) { + if ((fp = fopen(path.string(), "rb")) != nullptr) { fclose(fp); } else { path = datadir; path += "tessconfigs/"; path += filename; - if ((fp = fopen(path.string(), "rb")) != NULL) { + if ((fp = fopen(path.string(), "rb")) != nullptr) { fclose(fp); } else { path = filename; @@ -98,7 +98,7 @@ bool Tesseract::init_tesseract_lang_data( main_setup(arg0, textbase); // Set the language data path prefix - lang = language != NULL ? language : "eng"; + lang = language != nullptr ? language : "eng"; language_data_path_prefix = datadir; language_data_path_prefix += lang; language_data_path_prefix += "."; @@ -141,7 +141,7 @@ bool Tesseract::init_tesseract_lang_data( // Set params specified in vars_vec (done after setting params from config // files, so that params in vars_vec can override those from files). - if (vars_vec != NULL && vars_values != NULL) { + if (vars_vec != nullptr && vars_values != nullptr) { for (int i = 0; i < vars_vec->size(); ++i) { if (!ParamUtils::SetParam((*vars_vec)[i].string(), (*vars_values)[i].string(), @@ -154,7 +154,7 @@ bool Tesseract::init_tesseract_lang_data( if (((STRING &)tessedit_write_params_to_file).length() > 0) { FILE *params_file = fopen(tessedit_write_params_to_file.string(), "wb"); - if (params_file != NULL) { + if (params_file != nullptr) { ParamUtils::PrintParams(params_file, this->params()); fclose(params_file); } else { @@ -265,7 +265,7 @@ void Tesseract::ParseLanguageString(const char* lang_str, // Find the index of the end of the lang code in string start. int end = strlen(start); const char* plus = strchr(start, '+'); - if (plus != NULL && plus - start < end) + if (plus != nullptr && plus - start < end) end = plus - start; STRING lang_code(start); lang_code.truncate_at(end); @@ -373,7 +373,7 @@ int Tesseract::init_tesseract(const char *arg0, const char *textbase, // language is the language code to load. // oem controls which engine(s) will operate on the image // configs (argv) is an array of config filenames to load variables from. -// May be NULL. +// May be nullptr. // configs_size (argc) is the number of elements in configs. // vars_vec is an optional vector of variables to set. // vars_values is an optional corresponding vector of values for the variables @@ -447,7 +447,7 @@ void Tesseract::SetupUniversalFontIds() { int Tesseract::init_tesseract_lm(const char *arg0, const char *textbase, const char *language, TessdataManager *mgr) { if (!init_tesseract_lang_data(arg0, textbase, language, OEM_TESSERACT_ONLY, - NULL, 0, NULL, NULL, false, mgr)) + nullptr, 0, nullptr, nullptr, false, mgr)) return -1; getDict().SetupForLoad(Dict::GlobalDawgCache()); getDict().Load(lang, mgr); diff --git a/ccmain/tesseractclass.cpp b/ccmain/tesseractclass.cpp index 63de2f2285..60db38615a 100644 --- a/ccmain/tesseractclass.cpp +++ b/ccmain/tesseractclass.cpp @@ -509,23 +509,23 @@ Tesseract::Tesseract() "Page separator (default is form feed control character)", this->params()), - backup_config_file_(NULL), - pix_binary_(NULL), - pix_grey_(NULL), - pix_original_(NULL), - pix_thresholds_(NULL), + backup_config_file_(nullptr), + pix_binary_(nullptr), + pix_grey_(nullptr), + pix_original_(nullptr), + pix_thresholds_(nullptr), source_resolution_(0), textord_(this), right_to_left_(false), - scaled_color_(NULL), + scaled_color_(nullptr), scaled_factor_(-1), deskew_(1.0f, 0.0f), reskew_(1.0f, 0.0f), most_recently_used_(this), font_table_size_(0), - equ_detect_(NULL), + equ_detect_(nullptr), #ifndef ANDROID_BUILD - lstm_recognizer_(NULL), + lstm_recognizer_(nullptr), #endif train_line_page_num_(0) { } @@ -537,7 +537,7 @@ Tesseract::~Tesseract() { sub_langs_.delete_data_pointers(); #ifndef ANDROID_BUILD delete lstm_recognizer_; - lstm_recognizer_ = NULL; + lstm_recognizer_ = nullptr; #endif } diff --git a/ccmain/tesseractclass.h b/ccmain/tesseractclass.h index 39a64f5dea..2eb14f6444 100644 --- a/ccmain/tesseractclass.h +++ b/ccmain/tesseractclass.h @@ -136,12 +136,12 @@ struct TesseractStats { // Struct to hold all the pointers to relevant data for processing a word. struct WordData { - WordData() : word(NULL), row(NULL), block(NULL), prev_word(NULL) {} + WordData() : word(nullptr), row(nullptr), block(nullptr), prev_word(nullptr) {} explicit WordData(const PAGE_RES_IT& page_res_it) : word(page_res_it.word()), row(page_res_it.row()->row), - block(page_res_it.block()->block), prev_word(NULL) {} + block(page_res_it.block()->block), prev_word(nullptr) {} WordData(BLOCK* block_in, ROW* row_in, WERD_RES* word_res) - : word(word_res), row(row_in), block(block_in), prev_word(NULL) {} + : word(word_res), row(row_in), block(block_in), prev_word(nullptr) {} WERD_RES* word; ROW* row; @@ -152,7 +152,7 @@ struct WordData { // Definition of a Tesseract WordRecognizer. The WordData provides the context // of row/block, in_word holds an initialized, possibly pre-classified word, -// that the recognizer may or may not consume (but if so it sets *in_word=NULL) +// that the recognizer may or may not consume (but if so it sets *in_word=nullptr) // and produces one or more output words in out_words, which may be the // consumed in_word, or may be generated independently. // This api allows both a conventional tesseract classifier to work, or a @@ -220,7 +220,7 @@ class Tesseract : public Wordrec { Pix* BestPix() const { if (pixGetWidth(pix_original_) == ImageWidth()) return pix_original_; - else if (pix_grey_ != NULL) + else if (pix_grey_ != nullptr) return pix_grey_; else return pix_binary_; @@ -395,7 +395,7 @@ class Tesseract : public Wordrec { bool* make_next_word_fuzzy); // Attempts to put noise/diacritic outlines into the blobs that they overlap. // Input: a set of noisy outlines that probably belong to the real_word. - // Output: outlines that overlapped blobs are set to NULL and put back into + // Output: outlines that overlapped blobs are set to nullptr and put back into // the word, either in the blobs or in the reject list. void AssignDiacriticsToOverlappingBlobs( const GenericVector& outlines, int pass, WERD* real_word, @@ -516,7 +516,7 @@ class Tesseract : public Wordrec { const char *language, OcrEngineMode oem) { TessdataManager mgr; - return init_tesseract(datapath, NULL, language, oem, NULL, 0, NULL, NULL, + return init_tesseract(datapath, nullptr, language, oem, nullptr, 0, nullptr, nullptr, false, &mgr); } // Common initialization for a single language. @@ -528,7 +528,7 @@ class Tesseract : public Wordrec { // language is the language code to load. // oem controls which engine(s) will operate on the image // configs (argv) is an array of config filenames to load variables from. - // May be NULL. + // May be nullptr. // configs_size (argc) is the number of elements in configs. // vars_vec is an optional vector of variables to set. // vars_values is an optional corresponding vector of values for the variables @@ -1126,7 +1126,7 @@ class Tesseract : public Wordrec { // Image used for input to layout analysis and tesseract recognition. // May be modified by the ShiroRekhaSplitter to eliminate the top-line. Pix* pix_binary_; - // Grey-level input image if the input was not binary, otherwise NULL. + // Grey-level input image if the input was not binary, otherwise nullptr. Pix* pix_grey_; // Original input image. Color if the input was color. Pix* pix_original_; diff --git a/ccmain/tfacepp.cpp b/ccmain/tfacepp.cpp index fc6d91cb6c..85d00e6fc8 100644 --- a/ccmain/tfacepp.cpp +++ b/ccmain/tfacepp.cpp @@ -44,7 +44,7 @@ **********************************************************************/ namespace tesseract { void Tesseract::recog_word(WERD_RES *word) { - if (wordrec_skip_no_truth_words && (word->blamer_bundle == NULL || + if (wordrec_skip_no_truth_words && (word->blamer_bundle == nullptr || word->blamer_bundle->incorrect_result_reason() == IRR_NO_TRUTH)) { if (classify_debug_level) tprintf("No truth for word - skipping\n"); word->tess_failed = true; @@ -64,7 +64,7 @@ void Tesseract::recog_word(WERD_RES *word) { // segmentation states. if (!word->StatesAllValid()) { tprintf("Not all words have valid states relative to ratings matrix!!"); - word->DebugWordChoices(true, NULL); + word->DebugWordChoices(true, nullptr); ASSERT_HOST(word->StatesAllValid()); } if (tessedit_override_permuter) { @@ -88,8 +88,8 @@ void Tesseract::recog_word(WERD_RES *word) { } } // Factored out from control.cpp - ASSERT_HOST((word->best_choice == NULL) == (word->raw_choice == NULL)); - if (word->best_choice == NULL || word->best_choice->length() == 0 || + ASSERT_HOST((word->best_choice == nullptr) == (word->raw_choice == nullptr)); + if (word->best_choice == nullptr || word->best_choice->length() == 0 || static_cast(strspn(word->best_choice->unichar_string().string(), " ")) == word->best_choice->length()) { word->tess_failed = true; @@ -156,8 +156,8 @@ void Tesseract::split_and_recog_word(WERD_RES *word) { } ASSERT_HOST(split_index > 0); - WERD_RES *word2 = NULL; - BlamerBundle *orig_bb = NULL; + WERD_RES *word2 = nullptr; + BlamerBundle *orig_bb = nullptr; split_word(word, split_index, &word2, &orig_bb); // Recognize the first part of the word. @@ -187,7 +187,7 @@ void Tesseract::split_word(WERD_RES *word, // Save a copy of the blamer bundle so we can try to reconstruct it below. BlamerBundle *orig_bb = - word->blamer_bundle ? new BlamerBundle(*word->blamer_bundle) : NULL; + word->blamer_bundle ? new BlamerBundle(*word->blamer_bundle) : nullptr; WERD_RES *word2 = new WERD_RES(*word); @@ -200,9 +200,9 @@ void Tesseract::split_word(WERD_RES *word, chopped2->blobs.push_back(chopped->blobs[i]); } chopped->blobs.truncate(split_pt); - word->chopped_word = NULL; + word->chopped_word = nullptr; delete word2->chopped_word; - word2->chopped_word = NULL; + word2->chopped_word = nullptr; const UNICHARSET &unicharset = *word->uch_set; word->ClearResults(); @@ -213,7 +213,7 @@ void Tesseract::split_word(WERD_RES *word, word2->SetupBasicsFromChoppedWord(unicharset); // Try to adjust the blamer bundle. - if (orig_bb != NULL) { + if (orig_bb != nullptr) { // TODO(rays) Looks like a leak to me. // orig_bb should take, rather than copy. word->blamer_bundle = new BlamerBundle(); @@ -314,7 +314,7 @@ void Tesseract::join_words(WERD_RES *word, // Restore the pointer to original blamer bundle and combine blamer // information recorded in the splits. - if (orig_bb != NULL) { + if (orig_bb != nullptr) { orig_bb->JoinBlames(*word->blamer_bundle, *word2->blamer_bundle, wordrec_debug_blamer); delete word->blamer_bundle; diff --git a/ccmain/thresholder.cpp b/ccmain/thresholder.cpp index 13f8209387..9a28d41d45 100644 --- a/ccmain/thresholder.cpp +++ b/ccmain/thresholder.cpp @@ -30,7 +30,7 @@ namespace tesseract { ImageThresholder::ImageThresholder() - : pix_(NULL), + : pix_(nullptr), image_width_(0), image_height_(0), pix_channels_(0), pix_wpl_(0), scale_(1), yres_(300), estimated_res_(300) { @@ -48,7 +48,7 @@ void ImageThresholder::Clear() { // Return true if no image has been set. bool ImageThresholder::IsEmpty() const { - return pix_ == NULL; + return pix_ == nullptr; } // SetImage makes a copy of all the image data, so it may be deleted @@ -146,7 +146,7 @@ void ImageThresholder::GetImageSizes(int* left, int* top, // immediately after, but may not go away until after the Thresholder has // finished with it. void ImageThresholder::SetImage(const Pix* pix) { - if (pix_ != NULL) + if (pix_ != nullptr) pixDestroy(&pix_); Pix* src = const_cast(pix); int depth; @@ -166,7 +166,7 @@ void ImageThresholder::SetImage(const Pix* pix) { } else if (depth > 1 && depth < 8) { pix_ = pixConvertTo8(src, false); } else { - pix_ = pixCopy(NULL, src); + pix_ = pixCopy(nullptr, src); } depth = pixGetDepth(pix_); pix_channels_ = depth / 8; @@ -203,9 +203,9 @@ bool ImageThresholder::ThresholdToPix(PageSegMode pageseg_mode, Pix** pix) { // to the extreme of a 1x1 pixel thresholds image. // Ideally the 8 bit threshold should be the exact threshold used to generate // the binary image in ThresholdToPix, but this is not a hard constraint. -// Returns NULL if the input is binary. PixDestroy after use. +// Returns nullptr if the input is binary. PixDestroy after use. Pix* ImageThresholder::GetPixRectThresholds() { - if (IsBinary()) return NULL; + if (IsBinary()) return nullptr; Pix* pix_grey = GetPixRectGrey(); int width = pixGetWidth(pix_grey); int height = pixGetHeight(pix_grey); @@ -238,7 +238,7 @@ Pix* ImageThresholder::GetPixRect() { } else { // Crop to the given rectangle. Box* box = boxCreate(rect_left_, rect_top_, rect_width_, rect_height_); - Pix* cropped = pixClipRectangle(pix_, box, NULL); + Pix* cropped = pixClipRectangle(pix_, box, nullptr); boxDestroy(&box); return cropped; } diff --git a/ccmain/thresholder.h b/ccmain/thresholder.h index f2b870d89e..30b1d37cc6 100644 --- a/ccmain/thresholder.h +++ b/ccmain/thresholder.h @@ -126,7 +126,7 @@ class TESS_API ImageThresholder { // to the extreme of a 1x1 pixel thresholds image. // Ideally the 8 bit threshold should be the exact threshold used to generate // the binary image in ThresholdToPix, but this is not a hard constraint. - // Returns NULL if the input is binary. PixDestroy after use. + // Returns nullptr if the input is binary. PixDestroy after use. virtual Pix* GetPixRectThresholds(); /// Get a clone/copy of the source image rectangle. diff --git a/ccmain/werdit.cpp b/ccmain/werdit.cpp index 945781a84a..274ec0b429 100644 --- a/ccmain/werdit.cpp +++ b/ccmain/werdit.cpp @@ -33,7 +33,7 @@ PAGE_RES_IT* make_pseudo_word(PAGE_RES* page_res, const TBOX& selection_box) { C_BLOB_LIST new_blobs; // list of gathered blobs C_BLOB_IT new_blob_it = &new_blobs; // iterator - for (WERD_RES* word_res = pr_it.word(); word_res != NULL; + for (WERD_RES* word_res = pr_it.word(); word_res != nullptr; word_res = pr_it.forward()) { WERD* word = word_res->word; if (word->bounding_box().overlap(selection_box)) { @@ -46,14 +46,14 @@ PAGE_RES_IT* make_pseudo_word(PAGE_RES* page_res, const TBOX& selection_box) { } } if (!new_blobs.empty()) { - WERD* pseudo_word = new WERD(&new_blobs, 1, NULL); + WERD* pseudo_word = new WERD(&new_blobs, 1, nullptr); word_res = pr_it.InsertSimpleCloneWord(*word_res, pseudo_word); PAGE_RES_IT* it = new PAGE_RES_IT(page_res); - while (it->word() != word_res && it->word() != NULL) it->forward(); + while (it->word() != word_res && it->word() != nullptr) it->forward(); ASSERT_HOST(it->word() == word_res); return it; } } } - return NULL; + return nullptr; }