mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 17:13:09 +08:00
Use std::bitset<16> instead of custom BITS16.
This commit is contained in:
parent
9710bc0465
commit
9cc7bdeaa6
@ -61,14 +61,14 @@ bool Tesseract::word_adaptable( //should we adapt?
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags.bit (ADAPTABLE_WERD)) {
|
||||
if (flags[ADAPTABLE_WERD]) {
|
||||
status |= word->tess_would_adapt; // result of Classify::AdaptableWord()
|
||||
if (tessedit_adaption_debug && !status) {
|
||||
tprintf("tess_would_adapt bit is false\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (flags.bit (ACCEPTABLE_WERD)) {
|
||||
if (flags[ACCEPTABLE_WERD]) {
|
||||
status |= word->tess_accepted;
|
||||
if (tessedit_adaption_debug && !status) {
|
||||
tprintf("tess_accepted bit is false\n");
|
||||
@ -79,7 +79,7 @@ bool Tesseract::word_adaptable( //should we adapt?
|
||||
return false; // ignore other checks
|
||||
}
|
||||
|
||||
if (flags.bit (CHECK_DAWGS) &&
|
||||
if (flags[CHECK_DAWGS] &&
|
||||
(word->best_choice->permuter () != SYSTEM_DAWG_PERM) &&
|
||||
(word->best_choice->permuter () != FREQ_DAWG_PERM) &&
|
||||
(word->best_choice->permuter () != USER_DAWG_PERM) &&
|
||||
@ -88,18 +88,18 @@ bool Tesseract::word_adaptable( //should we adapt?
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags.bit (CHECK_ONE_ELL_CONFLICT) && one_ell_conflict (word, false)) {
|
||||
if (flags[CHECK_ONE_ELL_CONFLICT] && one_ell_conflict (word, false)) {
|
||||
if (tessedit_adaption_debug) tprintf("word has ell conflict\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags.bit (CHECK_SPACES) &&
|
||||
if (flags[CHECK_SPACES] &&
|
||||
(strchr(word->best_choice->unichar_string().c_str(), ' ') != nullptr)) {
|
||||
if (tessedit_adaption_debug) tprintf("word contains spaces\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags.bit (CHECK_AMBIG_WERD) &&
|
||||
if (flags[CHECK_AMBIG_WERD] &&
|
||||
word->best_choice->dangerous_ambig_found()) {
|
||||
if (tessedit_adaption_debug) tprintf("word is ambiguous\n");
|
||||
return false;
|
||||
|
@ -384,7 +384,7 @@ void Tesseract::pgeditor_main(int width, int height, PAGE_RES *page_res) {
|
||||
stillRunning = true;
|
||||
|
||||
build_image_window(width, height);
|
||||
word_display_mode.turn_on_bit(DF_EDGE_STEP);
|
||||
word_display_mode.set(DF_EDGE_STEP);
|
||||
do_re_display(&tesseract::Tesseract::word_set_display);
|
||||
#ifndef GRAPHICS_DISABLED
|
||||
pe = new ParamsEditor(this, image_win);
|
||||
@ -463,45 +463,45 @@ bool Tesseract::process_cmd_win_event( // UI command semantics
|
||||
break;
|
||||
case BOUNDING_BOX_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_BOX);
|
||||
word_display_mode.set(DF_BOX);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_BOX);
|
||||
word_display_mode.reset(DF_BOX);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case BLAMER_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_BLAMER);
|
||||
word_display_mode.set(DF_BLAMER);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_BLAMER);
|
||||
word_display_mode.reset(DF_BLAMER);
|
||||
do_re_display(&tesseract::Tesseract::word_display);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case CORRECT_TEXT_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_TEXT);
|
||||
word_display_mode.set(DF_TEXT);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_TEXT);
|
||||
word_display_mode.reset(DF_TEXT);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case POLYGONAL_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_POLYGONAL);
|
||||
word_display_mode.set(DF_POLYGONAL);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_POLYGONAL);
|
||||
word_display_mode.reset(DF_POLYGONAL);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case BL_NORM_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_BN_POLYGONAL);
|
||||
word_display_mode.set(DF_BN_POLYGONAL);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_BN_POLYGONAL);
|
||||
word_display_mode.reset(DF_BN_POLYGONAL);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case BITMAP_CMD_EVENT:
|
||||
if (new_value[0] == 'T')
|
||||
word_display_mode.turn_on_bit(DF_EDGE_STEP);
|
||||
word_display_mode.set(DF_EDGE_STEP);
|
||||
else
|
||||
word_display_mode.turn_off_bit(DF_EDGE_STEP);
|
||||
word_display_mode.reset(DF_EDGE_STEP);
|
||||
mode = CHANGE_DISP_CMD_EVENT;
|
||||
break;
|
||||
case UNIFORM_DISP_CMD_EVENT:
|
||||
@ -924,13 +924,13 @@ bool Tesseract::word_dumper(PAGE_RES_IT* pr_it) {
|
||||
*/
|
||||
bool Tesseract::word_set_display(PAGE_RES_IT* pr_it) {
|
||||
WERD* word = pr_it->word()->word;
|
||||
word->set_display_flag(DF_BOX, word_display_mode.bit(DF_BOX));
|
||||
word->set_display_flag(DF_TEXT, word_display_mode.bit(DF_TEXT));
|
||||
word->set_display_flag(DF_POLYGONAL, word_display_mode.bit(DF_POLYGONAL));
|
||||
word->set_display_flag(DF_EDGE_STEP, word_display_mode.bit(DF_EDGE_STEP));
|
||||
word->set_display_flag(DF_BOX, word_display_mode[DF_BOX]);
|
||||
word->set_display_flag(DF_TEXT, word_display_mode[DF_TEXT]);
|
||||
word->set_display_flag(DF_POLYGONAL, word_display_mode[DF_POLYGONAL]);
|
||||
word->set_display_flag(DF_EDGE_STEP, word_display_mode[DF_EDGE_STEP]);
|
||||
word->set_display_flag(DF_BN_POLYGONAL,
|
||||
word_display_mode.bit(DF_BN_POLYGONAL));
|
||||
word->set_display_flag(DF_BLAMER, word_display_mode.bit(DF_BLAMER));
|
||||
word_display_mode[DF_BN_POLYGONAL]);
|
||||
word->set_display_flag(DF_BLAMER, word_display_mode[DF_BLAMER]);
|
||||
return word_display(pr_it);
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,12 @@ class C_OUTLINE:public ELIST_LINK {
|
||||
|
||||
bool flag( //test flag
|
||||
C_OUTLINE_FLAGS mask) const { //flag to test
|
||||
return flags.bit(mask);
|
||||
return flags[mask];
|
||||
}
|
||||
void set_flag( //set flag value
|
||||
C_OUTLINE_FLAGS mask, //flag to test
|
||||
bool value) { //value to set
|
||||
flags.set_bit(mask, value);
|
||||
flags.set(mask, value);
|
||||
}
|
||||
|
||||
C_OUTLINE_LIST *child() { //get child list
|
||||
|
@ -104,9 +104,9 @@ class REJ
|
||||
|
||||
void set_flag(REJ_FLAGS rej_flag) {
|
||||
if (rej_flag < 16)
|
||||
flags1.turn_on_bit (rej_flag);
|
||||
flags1.set(rej_flag);
|
||||
else
|
||||
flags2.turn_on_bit (rej_flag - 16);
|
||||
flags2.set(rej_flag - 16);
|
||||
}
|
||||
|
||||
bool rej_before_nn_accept();
|
||||
@ -134,9 +134,9 @@ class REJ
|
||||
|
||||
bool flag(REJ_FLAGS rej_flag) {
|
||||
if (rej_flag < 16)
|
||||
return flags1.bit (rej_flag);
|
||||
return flags1[rej_flag];
|
||||
else
|
||||
return flags2.bit (rej_flag - 16);
|
||||
return flags2[rej_flag - 16];
|
||||
}
|
||||
|
||||
char display_char() {
|
||||
|
@ -90,13 +90,13 @@ WERD::WERD(C_BLOB_LIST* blob_list, uint8_t blank_count, const char* text)
|
||||
}
|
||||
}
|
||||
|
||||
flags.set_bit(W_INVERSE, (inverted_vote > non_inverted_vote));
|
||||
flags.set(W_INVERSE, (inverted_vote > non_inverted_vote));
|
||||
|
||||
start_it.set_to_list(&cblobs);
|
||||
if (start_it.empty()) return;
|
||||
for (start_it.mark_cycle_pt(); !start_it.cycled_list(); start_it.forward()) {
|
||||
c_outline_it.set_to_list(start_it.data()->out_list());
|
||||
if (c_outline_it.data()->flag(COUT_INVERSE) != flags.bit(W_INVERSE))
|
||||
if (c_outline_it.data()->flag(COUT_INVERSE) != flags[W_INVERSE])
|
||||
rej_cblob_it.add_after_then_move(start_it.extract());
|
||||
}
|
||||
}
|
||||
@ -257,21 +257,21 @@ void WERD::copy_on(WERD* other) {
|
||||
void WERD::print() {
|
||||
tprintf("Blanks= %d\n", blanks);
|
||||
bounding_box().print();
|
||||
tprintf("Flags = %d = 0%o\n", flags.val, flags.val);
|
||||
tprintf(" W_SEGMENTED = %s\n", flags.bit(W_SEGMENTED) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_ITALIC = %s\n", flags.bit(W_ITALIC) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_BOL = %s\n", flags.bit(W_BOL) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_EOL = %s\n", flags.bit(W_EOL) ? "TRUE" : "FALSE");
|
||||
tprintf("Flags = %d = 0%o\n", flags.to_ulong(), flags.to_ulong());
|
||||
tprintf(" W_SEGMENTED = %s\n", flags[W_SEGMENTED] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_ITALIC = %s\n", flags[W_ITALIC] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_BOL = %s\n", flags[W_BOL] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_EOL = %s\n", flags[W_EOL] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_NORMALIZED = %s\n",
|
||||
flags.bit(W_NORMALIZED) ? "TRUE" : "FALSE");
|
||||
flags[W_NORMALIZED] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_SCRIPT_HAS_XHEIGHT = %s\n",
|
||||
flags.bit(W_SCRIPT_HAS_XHEIGHT) ? "TRUE" : "FALSE");
|
||||
flags[W_SCRIPT_HAS_XHEIGHT] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_SCRIPT_IS_LATIN = %s\n",
|
||||
flags.bit(W_SCRIPT_IS_LATIN) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_DONT_CHOP = %s\n", flags.bit(W_DONT_CHOP) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_REP_CHAR = %s\n", flags.bit(W_REP_CHAR) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_FUZZY_SP = %s\n", flags.bit(W_FUZZY_SP) ? "TRUE" : "FALSE");
|
||||
tprintf(" W_FUZZY_NON = %s\n", flags.bit(W_FUZZY_NON) ? "TRUE" : "FALSE");
|
||||
flags[W_SCRIPT_IS_LATIN] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_DONT_CHOP = %s\n", flags[W_DONT_CHOP] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_REP_CHAR = %s\n", flags[W_REP_CHAR] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_FUZZY_SP = %s\n", flags[W_FUZZY_SP] ? "TRUE" : "FALSE");
|
||||
tprintf(" W_FUZZY_NON = %s\n", flags[W_FUZZY_NON] ? "TRUE" : "FALSE");
|
||||
tprintf("Correct= %s\n", correct.c_str());
|
||||
tprintf("Rejected cblob count = %d\n", rej_cblobs.length());
|
||||
tprintf("Script = %d\n", script_id_);
|
||||
|
@ -117,12 +117,12 @@ class TESS_API WERD : public ELIST2_LINK {
|
||||
const char* text() const { return correct.c_str(); }
|
||||
void set_text(const char* new_text) { correct = new_text; }
|
||||
|
||||
bool flag(WERD_FLAGS mask) const { return flags.bit(mask); }
|
||||
void set_flag(WERD_FLAGS mask, bool value) { flags.set_bit(mask, value); }
|
||||
bool flag(WERD_FLAGS mask) const { return flags[mask]; }
|
||||
void set_flag(WERD_FLAGS mask, bool value) { flags.set(mask, value); }
|
||||
|
||||
bool display_flag(uint8_t flag) const { return disp_flags.bit(flag); }
|
||||
bool display_flag(uint8_t flag) const { return disp_flags[flag]; }
|
||||
void set_display_flag(uint8_t flag, bool value) {
|
||||
disp_flags.set_bit(flag, value);
|
||||
disp_flags.set(flag, value);
|
||||
}
|
||||
|
||||
WERD* shallow_copy(); // shallow copy word
|
||||
|
@ -19,39 +19,8 @@
|
||||
#ifndef BITS16_H
|
||||
#define BITS16_H
|
||||
|
||||
#include <cstdint> // for uint8_t, ...
|
||||
#include <tesseract/export.h> // for DLLSYM
|
||||
#include <bitset>
|
||||
|
||||
class BITS16 {
|
||||
public:
|
||||
uint16_t val = 0;
|
||||
|
||||
BITS16() = default;
|
||||
BITS16(uint16_t init) : val(init) {}
|
||||
|
||||
void turn_on_bit( // flip specified bit
|
||||
uint8_t bit_num) { // bit to flip 0..7
|
||||
val = static_cast<uint16_t>(val | 01 << bit_num);
|
||||
}
|
||||
|
||||
void turn_off_bit( // flip specified bit
|
||||
uint8_t bit_num) { // bit to flip 0..7
|
||||
val = static_cast<uint16_t>(val & ~(01 << bit_num));
|
||||
}
|
||||
|
||||
void set_bit( // flip specified bit
|
||||
uint8_t bit_num, // bit to flip 0..7
|
||||
bool value) { // value to flip to
|
||||
if (value)
|
||||
val = static_cast<uint16_t>(val | 01 << bit_num);
|
||||
else
|
||||
val = static_cast<uint16_t>(val & ~(01 << bit_num));
|
||||
}
|
||||
|
||||
bool bit( // access bit
|
||||
uint8_t bit_num) const { // bit to access
|
||||
return (val >> bit_num) & 01;
|
||||
}
|
||||
};
|
||||
using BITS16 = std::bitset<16>;
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user