Skip to content

Commit

Permalink
Fixed a lot of compiler/clang warnings
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1015 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith@gmail.com committed Jan 25, 2014
1 parent aa62157 commit d11dc04
Show file tree
Hide file tree
Showing 51 changed files with 154 additions and 368 deletions.
2 changes: 0 additions & 2 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,6 @@ void TessBaseAPI::AdaptToCharacter(const char *unichar_repr,
tesseract_->classify_bln_numeric_mode,
tesseract_->pix_binary());
float threshold;
UNICHAR_ID best_class = 0;
float best_rating = -100;


Expand All @@ -2295,7 +2294,6 @@ void TessBaseAPI::AdaptToCharacter(const char *unichar_repr,
choice_it.forward()) {
if (choice_it.data()->rating() > best_rating) {
best_rating = choice_it.data()->rating();
best_class = choice_it.data()->unichar_id();
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template <typename T> class GenericVector;
class PAGE_RES;
class PAGE_RES_IT;
class ParagraphModel;
class BlamerBundle;
struct BlamerBundle;
class BLOCK_LIST;
class DENORM;
class IMAGE;
Expand Down
13 changes: 5 additions & 8 deletions api/pdfrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,10 @@ char* TessPDFRenderer::GetPDFTextObjects(TessBaseAPI* api,
break;
}

const char *font_name;
bool bold, italic, underlined, monospace, serif, smallcaps;
int font_id;
font_name = res_it->WordFontAttributes(&bold, &italic, &underlined,
&monospace, &serif, &smallcaps,
&pointsize, &font_id);
res_it->WordFontAttributes(&bold, &italic, &underlined, &monospace,
&serif, &smallcaps, &pointsize, &font_id);

if (pointsize != old_pointsize) {
char textfont[20];
Expand All @@ -209,7 +207,6 @@ char* TessPDFRenderer::GetPDFTextObjects(TessBaseAPI* api,
old_y = y;

bool last_word_in_line = res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD);
bool last_word_in_para = res_it->IsAtFinalElement(RIL_PARA, RIL_WORD);
bool last_word_in_block = res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD);
STRING pdf_word("");
int pdf_word_len = 0;
Expand All @@ -221,7 +218,7 @@ char* TessPDFRenderer::GetPDFTextObjects(TessBaseAPI* api,
string_32 utf32;
CubeUtils::UTF8ToUTF32(grapheme, &utf32);
char utf16[20];
for (int i = 0; i < utf32.length(); i++) {
for (int i = 0; i < static_cast<int>(utf32.length()); i++) {
snprintf(utf16, sizeof(utf16), "<%04X>", utf32[i]);
pdf_word += utf16;
pdf_word_len++;
Expand Down Expand Up @@ -262,7 +259,6 @@ bool TessPDFRenderer::BeginDocumentHandler() {
AppendPDFObject(buf);

// CATALOG
long int catalog = obj_;
snprintf(buf, sizeof(buf),
"1 0 obj\n"
"<<\n"
Expand Down Expand Up @@ -479,7 +475,8 @@ bool TessPDFRenderer::fileToPDFObj(char *filename, long int objnum,
if (!pdf_object)
return false;
memcpy(*pdf_object, b1, b1_len);
if (fread(*pdf_object + b1_len, 1, jpeg_size, fp) != jpeg_size) {
if (static_cast<int>(fread(*pdf_object + b1_len, 1, jpeg_size, fp)) !=
jpeg_size) {
delete[] pdf_object;
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ int main(int argc, char **argv) {
pixs = pixReadMem(&ch_data[0], ch_data.size());
}

if (pagesegmode == tesseract::PSM_AUTO_OSD) {
if (pagesegmode == tesseract::PSM_AUTO_ONLY ||
pagesegmode == tesseract::PSM_OSD_ONLY) {
tesseract::Orientation orientation;
tesseract::WritingDirection direction;
tesseract::TextlineOrder order;
Expand Down
1 change: 0 additions & 1 deletion ccmain/ltrresultiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ bool LTRResultIterator::SymbolIsDropcap() const {
ChoiceIterator::ChoiceIterator(const LTRResultIterator& result_it) {
ASSERT_HOST(result_it.it_->word() != NULL);
word_res_ = result_it.it_->word();
PAGE_RES_IT res_it(*result_it.it_);
BLOB_CHOICE_LIST* choices = NULL;
if (word_res_->ratings != NULL)
choices = word_res_->GetBlobChoices(result_it.blob_index_);
Expand Down
12 changes: 0 additions & 12 deletions ccmain/osdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,8 @@ bool OrientationDetector::detect_blob(BLOB_CHOICE_LIST* scores) {
float first = -1;
float second = -1;

int idx = -1;
for (int i = 0; i < 4; ++i) {
if (osr_->orientations[i] > first) {
idx = i;
second = first;
first = osr_->orientations[i];
} else if (osr_->orientations[i] > second) {
Expand Down Expand Up @@ -443,14 +441,9 @@ void ScriptDetector::detect_blob(BLOB_CHOICE_LIST* scores) {
float prev_score = -1;
int script_count = 0;
int prev_id = -1;
int prev_script;
int prev_class_id = -1;
int prev_fontinfo_id = -1;
const char* prev_unichar = "";
const char* unichar = "";
float next_best_score = -1.0;
int next_best_script_id = -1;
const char* next_best_unichar = "";

for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
choice_it.forward()) {
Expand All @@ -466,15 +459,10 @@ void ScriptDetector::detect_blob(BLOB_CHOICE_LIST* scores) {
prev_score = -choice->certainty();
script_count = 1;
prev_id = id;
prev_script = choice->script_id();
prev_unichar = unichar;
prev_class_id = choice->unichar_id();
prev_fontinfo_id = choice->fontinfo_id();
} else if (-choice->certainty() < prev_score + kNonAmbiguousMargin) {
++script_count;
next_best_score = -choice->certainty();
next_best_script_id = choice->script_id();
next_best_unichar = tess_->unicharset.id_to_unichar(choice->unichar_id());
}

if (strlen(prev_unichar) == 1)
Expand Down
58 changes: 2 additions & 56 deletions ccmain/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void Tesseract::output_pass( //Tess output pass //send to api
PAGE_RES_IT &page_res_it,
const TBOX *target_word_box) {
BLOCK_RES *block_of_last_word;
inT16 block_id;
BOOL8 force_eol; //During output
BLOCK *nextblock; //block of next word
WERD *nextword; //next word
Expand All @@ -95,7 +94,6 @@ void Tesseract::output_pass( //Tess output pass //send to api
if (tessedit_write_block_separators &&
block_of_last_word != page_res_it.block ()) {
block_of_last_word = page_res_it.block ();
block_id = block_of_last_word->block->index();
}

force_eol = (tessedit_write_block_separators &&
Expand Down Expand Up @@ -137,18 +135,10 @@ void Tesseract::write_results(PAGE_RES_IT &page_res_it,
BOOL8 force_eol) { // override tilde crunch?
WERD_RES *word = page_res_it.word();
const UNICHARSET &uchset = *word->uch_set;
STRING repetition_code;
const STRING *wordstr;
STRING wordstr_lengths;
int i;
char unrecognised = STRING (unrecognised_char)[0];
char ep_chars[32]; //Only for unlv_tilde_crunch
int ep_chars_index = 0;
char txt_chs[32]; //Only for unlv_tilde_crunch
char map_chs[32]; //Only for unlv_tilde_crunch
int txt_index = 0;
BOOL8 need_reject = FALSE;
UNICHAR_ID space = uchset.unichar_to_id(" ");

if ((word->unlv_crunch_mode != CR_NONE ||
word->best_choice->length() == 0) &&
!tessedit_zero_kelvin_rejection && !tessedit_word_for_word) {
Expand All @@ -162,10 +152,6 @@ void Tesseract::write_results(PAGE_RES_IT &page_res_it,
(word->word->space () > 0) &&
!word->word->flag (W_FUZZY_NON) &&
!word->word->flag (W_FUZZY_SP)) {
// Write a space to separate from preceeding good text.
txt_chs[txt_index] = ' ';
map_chs[txt_index++] = '1';
ep_chars[ep_chars_index++] = ' ';
stats_.last_char_was_tilde = false;
}
need_reject = TRUE;
Expand All @@ -174,50 +160,16 @@ void Tesseract::write_results(PAGE_RES_IT &page_res_it,
(force_eol && stats_.write_results_empty_block)) {
/* Write a reject char - mark as rejected unless zero_rejection mode */
stats_.last_char_was_tilde = TRUE;
txt_chs[txt_index] = unrecognised;
if (tessedit_zero_rejection || (suspect_level == 0)) {
map_chs[txt_index++] = '1';
ep_chars[ep_chars_index++] = unrecognised;
}
else {
map_chs[txt_index++] = '0';
/*
The ep_choice string is a faked reject to allow newdiff to sync the
.etx with the .txt and .map files.
*/
ep_chars[ep_chars_index++] = CTRL_INSET; // escape code
//dummy reject
ep_chars[ep_chars_index++] = 1;
//dummy reject
ep_chars[ep_chars_index++] = 1;
//type
ep_chars[ep_chars_index++] = 2;
//dummy reject
ep_chars[ep_chars_index++] = 1;
//dummy reject
ep_chars[ep_chars_index++] = 1;
}
stats_.tilde_crunch_written = true;
stats_.last_char_was_newline = false;
stats_.write_results_empty_block = false;
}

if ((word->word->flag (W_EOL) && !stats_.last_char_was_newline) || force_eol) {
/* Add a new line output */
txt_chs[txt_index] = '\n';
map_chs[txt_index++] = '\n';
//end line
ep_chars[ep_chars_index++] = newline_type;

//Cos of the real newline
stats_.tilde_crunch_written = false;
stats_.last_char_was_newline = true;
stats_.last_char_was_tilde = false;
}
txt_chs[txt_index] = '\0';
map_chs[txt_index] = '\0';
ep_chars[ep_chars_index] = '\0'; // terminate string
word->ep_choice = new WERD_CHOICE(ep_chars, uchset);

if (force_eol)
stats_.write_results_empty_block = true;
Expand Down Expand Up @@ -266,13 +218,7 @@ void Tesseract::write_results(PAGE_RES_IT &page_res_it,
word->best_choice->debug_string().string(),
dict_word(*(word->best_choice)));
}
if (word->word->flag (W_REP_CHAR) && tessedit_write_rep_codes) {
repetition_code = "|^~R";
wordstr_lengths = "\001\001\001\001";
repetition_code += uchset.id_to_unichar(get_rep_char(word));
wordstr_lengths += strlen(uchset.id_to_unichar(get_rep_char(word)));
wordstr = &repetition_code;
} else {
if (!word->word->flag (W_REP_CHAR) || !tessedit_write_rep_codes) {
if (tessedit_zero_rejection) {
/* OVERRIDE ALL REJECTION MECHANISMS - ONLY REJECT TESS FAILURES */
for (i = 0; i < word->best_choice->length(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion ccmain/pageiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "publictypes.h"
#include "platform.h"

class BlamerBundle;
struct BlamerBundle;
class C_BLOB_IT;
class PAGE_RES;
class PAGE_RES_IT;
Expand Down
11 changes: 0 additions & 11 deletions ccmain/reject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ void Tesseract::flip_hyphens(WERD_RES *word_res) {

int num_blobs = word_res->rebuild_word->NumBlobs();
UNICHAR_ID unichar_dash = word_res->uch_set->unichar_to_id("-");
bool modified = false;
for (i = 0; i < best_choice->length() && i < num_blobs; ++i) {
TBLOB* blob = word_res->rebuild_word->blobs[i];
out_box = blob->bounding_box();
Expand All @@ -647,7 +646,6 @@ void Tesseract::flip_hyphens(WERD_RES *word_res) {
word_res->uch_set->get_enabled(unichar_dash)) {
/* Certain HYPHEN */
best_choice->set_unichar_id(unichar_dash, i);
modified = true;
if (word_res->reject_map[i].rejected())
word_res->reject_map[i].setrej_hyphen_accept();
}
Expand Down Expand Up @@ -702,7 +700,6 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
!word_res->uch_set->get_enabled(unichar_O)) {
return; // 0 or O are not present/enabled in unicharset
}
bool modified = false;
for (i = 1; i < best_choice->length(); ++i) {
if (best_choice->unichar_id(i) == unichar_0 ||
best_choice->unichar_id(i) == unichar_O) {
Expand All @@ -711,7 +708,6 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
non_O_upper(*word_res->uch_set, best_choice->unichar_id(i+1))) {
best_choice->set_unichar_id(unichar_O, i);
modified = true;
}
/* A00A */
if (non_O_upper(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
Expand All @@ -721,7 +717,6 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
(i+2) < best_choice->length() &&
non_O_upper(*word_res->uch_set, best_choice->unichar_id(i+2))) {
best_choice->set_unichar_id(unichar_O, i);
modified = true;
i++;
}
/* AA0<non digit or end of word> */
Expand All @@ -734,14 +729,12 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
!word_res->uch_set->eq(best_choice->unichar_id(i+1), "I")) ||
(i == best_choice->length() - 1))) {
best_choice->set_unichar_id(unichar_O, i);
modified = true;
}
/* 9O9 */
if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
(i+1) < best_choice->length() &&
non_0_digit(*word_res->uch_set, best_choice->unichar_id(i+1))) {
best_choice->set_unichar_id(unichar_0, i);
modified = true;
}
/* 9OOO */
if (non_0_digit(*word_res->uch_set, best_choice->unichar_id(i-1)) &&
Expand All @@ -753,7 +746,6 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
best_choice->set_unichar_id(unichar_0, i);
best_choice->set_unichar_id(unichar_0, i+1);
best_choice->set_unichar_id(unichar_0, i+2);
modified = true;
i += 2;
}
/* 9OO<non upper> */
Expand All @@ -764,7 +756,6 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
!word_res->uch_set->get_isupper(best_choice->unichar_id(i+2))) {
best_choice->set_unichar_id(unichar_0, i);
best_choice->set_unichar_id(unichar_0, i+1);
modified = true;
i++;
}
/* 9O<non upper> */
Expand All @@ -781,13 +772,11 @@ void Tesseract::flip_0O(WERD_RES *word_res) {
best_choice->unichar_id(i-2) == unichar_O)) {
if (best_choice->unichar_id(i-2) == unichar_O) {
best_choice->set_unichar_id(unichar_0, i-2);
modified = true;
}
while (i < best_choice->length() &&
(best_choice->unichar_id(i) == unichar_O ||
best_choice->unichar_id(i) == unichar_0)) {
best_choice->set_unichar_id(unichar_0, i);
modified = true;
i++;
}
i--;
Expand Down
6 changes: 2 additions & 4 deletions ccmain/tfacepp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,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 ||
strspn(word->best_choice->unichar_string().string(), " ") ==
word->best_choice->length()) {
static_cast<int>(strspn(word->best_choice->unichar_string().string(),
" ")) == word->best_choice->length()) {
word->tess_failed = true;
word->reject_map.initialise(word->box_word->length());
word->reject_map.rej_word_tess_failure();
Expand Down Expand Up @@ -145,8 +145,6 @@ void Tesseract::split_and_recog_word(WERD_RES *word) {
// Find the biggest blob gap in the chopped_word.
int bestgap = -MAX_INT32;
int split_index = 0;
TBLOB* best_end = NULL;
TBLOB* prev_blob = NULL;
for (int b = 1; b < word->chopped_word->NumBlobs(); ++b) {
TBOX prev_box = word->chopped_word->blobs[b - 1]->bounding_box();
TBOX blob_box = word->chopped_word->blobs[b]->bounding_box();
Expand Down
1 change: 0 additions & 1 deletion ccstruct/blobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ static TESSLINE** ApproximateOutlineList(bool allow_detailed_fx,
// contain pointers to the input C_OUTLINEs that enable higher-resolution
// feature extraction that does not use the polygonal approximation.
TBLOB* TBLOB::PolygonalCopy(bool allow_detailed_fx, C_BLOB* src) {
C_OUTLINE_IT ol_it = src->out_list();
TBLOB* tblob = new TBLOB;
ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
&tblob->outlines);
Expand Down
6 changes: 4 additions & 2 deletions ccstruct/fontinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ bool read_info(FILE* f, FontInfo* fi, bool swap) {
Reverse32(&size);
char* font_name = new char[size + 1];
fi->name = font_name;
if (fread(font_name, sizeof(*font_name), size, f) != size) return false;
if (static_cast<int>(fread(font_name, sizeof(*font_name), size, f)) != size)
return false;
font_name[size] = '\0';
if (fread(&fi->properties, sizeof(fi->properties), 1, f) != 1) return false;
if (swap)
Expand All @@ -167,7 +168,8 @@ bool read_info(FILE* f, FontInfo* fi, bool swap) {
bool write_info(FILE* f, const FontInfo& fi) {
inT32 size = strlen(fi.name);
if (fwrite(&size, sizeof(size), 1, f) != 1) return false;
if (fwrite(fi.name, sizeof(*fi.name), size, f) != size) return false;
if (static_cast<int>(fwrite(fi.name, sizeof(*fi.name), size, f)) != size)
return false;
if (fwrite(&fi.properties, sizeof(fi.properties), 1, f) != 1) return false;
return true;
}
Expand Down
Loading

0 comments on commit d11dc04

Please sign in to comment.