Skip to content

Commit

Permalink
Fix some of vector<bool> cases for msvc.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Dec 26, 2020
1 parent 6b22972 commit c8b8d26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions include/tesseract/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ class GenericVector : public std::vector<T> {
std::function<bool(const T&, const T&)> compare_cb_;
};

#ifdef _MSC_VER
// msvc does not have ::data() in vector<bool>,
// so we add custom specialization
template <>
class GenericVector<bool> : public std::vector<bool> {};
#endif

// The default FileReader loads the whole file into the vector of char,
// returning false on error.
inline bool LoadDataFromFile(const char* filename, GenericVector<char>* data) {
Expand Down
14 changes: 7 additions & 7 deletions src/ccmain/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,9 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs(
GenericVector<bool>* overlapped_any_blob,
GenericVector<C_BLOB*>* target_blobs) {
GenericVector<bool> 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(), nullptr);
word_wanted->resize(outlines.size(), false);
overlapped_any_blob->resize(outlines.size(), false);
target_blobs->resize(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
Expand All @@ -1018,7 +1018,7 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs(
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
C_BLOB* blob = blob_it.data();
const TBOX blob_box = blob->bounding_box();
blob_wanted.init_to_size(outlines.size(), false);
blob_wanted.resize(outlines.size(), false);
int num_blob_outlines = 0;
for (int i = 0; i < outlines.size(); ++i) {
if (blob_box.major_x_overlap(outlines[i]->bounding_box()) &&
Expand Down Expand Up @@ -1059,13 +1059,13 @@ void Tesseract::AssignDiacriticsToNewBlobs(
PAGE_RES_IT* pr_it, GenericVector<bool>* word_wanted,
GenericVector<C_BLOB*>* target_blobs) {
GenericVector<bool> blob_wanted;
word_wanted->init_to_size(outlines.size(), false);
target_blobs->init_to_size(outlines.size(), nullptr);
word_wanted->resize(outlines.size(), false);
target_blobs->resize(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] == nullptr) continue;
// Get a set of adjacent outlines that don't overlap any existing blob.
blob_wanted.init_to_size(outlines.size(), false);
blob_wanted.resize(outlines.size(), false);
int num_blob_outlines = 0;
TBOX total_ol_box(outlines[i]->bounding_box());
while (i < outlines.size() && outlines[i] != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/unicharcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void UnicharCompress::ComputeCodeRange() {
// Initializes the decoding hash_map from the encoding array.
void UnicharCompress::SetupDecoder() {
Cleanup();
is_valid_start_.init_to_size(code_range_, false);
is_valid_start_.resize(code_range_, false);
for (int c = 0; c < encoder_.size(); ++c) {
const RecodedCharID& code = encoder_[c];
decoder_[code] = c;
Expand Down

0 comments on commit c8b8d26

Please sign in to comment.