Skip to content

Commit

Permalink
show page 0 for multipage tiff;
Browse files Browse the repository at this point in the history
Windows: use binary mode for fopen (issue 70);
autotools: fixed cutil/Makefile.am, improved tessdata/Makefile.am;

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@604 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
zdenop@gmail.com committed Aug 11, 2011
1 parent 4abdfdb commit 7ec3dca
Show file tree
Hide file tree
Showing 29 changed files with 56 additions and 117 deletions.
8 changes: 4 additions & 4 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Boxa* TessBaseAPI::GetComponentImages(PageIteratorLevel level,
void TessBaseAPI::DumpPGM(const char* filename) {
if (tesseract_ == NULL)
return;
FILE *fp = fopen(filename, "w");
FILE *fp = fopen(filename, "wb");
Pix* pix = tesseract_->pix_binary();
int width = pixGetWidth(pix);
int height = pixGetHeight(pix);
Expand Down Expand Up @@ -644,7 +644,7 @@ bool TessBaseAPI::ProcessPages(const char* filename,
if (npages > 0) {
for (; page < npages && (pix = pixReadTiff(filename, page)) != NULL;
++page) {
if (page > 0)
if (page >= 0)
tprintf(_("Page %d\n"), page);
char page_str[kMaxIntSize];
snprintf(page_str, kMaxIntSize - 1, "%d", page);
Expand All @@ -665,7 +665,7 @@ bool TessBaseAPI::ProcessPages(const char* filename,
pixDestroy(&pix);
} else {
// The file is not an image file, so try it as a list of filenames.
FILE* fimg = fopen(filename, "r");
FILE* fimg = fopen(filename, "rb");
if (fimg == NULL) {
tprintf(_("File %s cannot be opened!\n"), filename);
return false;
Expand Down Expand Up @@ -742,7 +742,7 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
}
if (failed && retry_config != NULL && retry_config[0] != '\0') {
// Save current config variables before switching modes.
FILE* fp = fopen(kOldVarsFile, "w");
FILE* fp = fopen(kOldVarsFile, "wb");
PrintVariables(fp);
fclose(fp);
// Switch to alternate mode for retry.
Expand Down
4 changes: 2 additions & 2 deletions api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int main(int argc, char **argv) {
tesseract::TessBaseAPI::Version());


FILE* fin = fopen(image, "r");
FILE* fin = fopen(image, "rb");
if (fin == NULL) {
printf("Cannot open input file: %s\n", image);
exit(2);
Expand All @@ -134,7 +134,7 @@ int main(int argc, char **argv) {
api.GetBoolVariable("tessedit_create_boxfile", &output_box);
STRING outfile = output;
outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt";
FILE* fout = fopen(outfile.string(), "w");
FILE* fout = fopen(outfile.string(), "wb");
if (fout == NULL) {
tprintf(_("Cannot create output file %s\n"), outfile.string());
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions ccmain/paramsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ void ParamsEditor::WriteParams(char *filename,
FILE *fp; // input file
char msg_str[255];
// if file exists
if ((fp = fopen (filename, "r")) != NULL) {
if ((fp = fopen (filename, "rb")) != NULL) {
fclose(fp);
sprintf (msg_str, "Overwrite file " "%s" "? (Y/N)", filename);
int a = sv_window_->ShowYesNoDialog(msg_str);
if (a == 'n') { return; } // dont write
}


fp = fopen (filename, "w"); // can we write to it?
fp = fopen (filename, "wb"); // can we write to it?
if (fp == NULL) {
sv_window_->AddMessage("Cant write to file " "%s" "", filename);
return;
Expand Down
6 changes: 3 additions & 3 deletions ccmain/tessedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ void Tesseract::read_config_file(const char *filename, bool init_only) {
path += "configs/";
path += filename;
FILE* fp;
if ((fp = fopen(path.string(), "r")) != NULL) {
if ((fp = fopen(path.string(), "rb")) != NULL) {
fclose(fp);
} else {
path = datadir;
path += "tessconfigs/";
path += filename;
if ((fp = fopen(path.string(), "r")) != NULL) {
if ((fp = fopen(path.string(), "rb")) != NULL) {
fclose(fp);
} else {
path = filename;
Expand Down Expand Up @@ -148,7 +148,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(), "w");
FILE *params_file = fopen(tessedit_write_params_to_file.string(), "wb");
if (params_file != NULL) {
ParamUtils::PrintParams(params_file, this->params());
fclose(params_file);
Expand Down
2 changes: 1 addition & 1 deletion ccmain/tesseract_cube_combiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool TesseractCubeCombiner::LoadCombinerNet() {
".tesseract_cube.nn";

// Return false if file does not exist
FILE *fp = fopen(net_file_name.c_str(), "r");
FILE *fp = fopen(net_file_name.c_str(), "rb");
if (fp == NULL)
return false;
else
Expand Down
2 changes: 1 addition & 1 deletion ccstruct/blread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool read_unlv_file( //print list of sides
BLOCK_IT block_it = blocks; //block iterator

name += UNLV_EXT; //add extension
if ((pdfp = fopen (name.string (), "r")) == NULL) {
if ((pdfp = fopen (name.string (), "rb")) == NULL) {
return false; //didn't read one
}
else {
Expand Down
2 changes: 1 addition & 1 deletion ccutil/boxread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FILE* OpenBoxFile(const STRING& fname) {

filename += ".box";
FILE* box_file = NULL;
if (!(box_file = fopen(filename.string(), "r"))) {
if (!(box_file = fopen(filename.string(), "rb"))) {
CANTOPENFILE.error("read_next_box", TESSEXIT,
"Cant open box file %s",
filename.string());
Expand Down
2 changes: 1 addition & 1 deletion ccutil/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool ParamUtils::ReadParamsFile(const char *file, bool init_only,
nameoffset = 0;
}

fp = fopen(file + nameoffset, "r");
fp = fopen(file + nameoffset, "rb");
if (fp == NULL) {
tprintf("read_params_file: Can't open %s\n", file + nameoffset);
return true;
Expand Down
6 changes: 4 additions & 2 deletions ccutil/tessdatamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ bool TessdataManager::CombineDataFiles(
kTessdataFileSuffixes[i], &type, &text_file));
STRING filename = language_data_path_prefix;
filename += kTessdataFileSuffixes[i];
file_ptr[i] = fopen(filename.string(), text_file ? "r" : "rb");
// file_ptr[i] = fopen(filename.string(), text_file ? "r" : "rb");
file_ptr[i] = fopen(filename.string(), "rb");
if (file_ptr[i] != NULL) {
offset_table[type] = ftell(output_file);
CopyFile(file_ptr[i], output_file, text_file, -1);
Expand Down Expand Up @@ -181,7 +182,8 @@ bool TessdataManager::OverwriteComponents(
// Open the files with the new components.
for (i = 0; i < num_new_components; ++i) {
TessdataTypeFromFileName(component_filenames[i], &type, &text_file);
file_ptr[type] = fopen(component_filenames[i], text_file ? "r" : "rb");
// file_ptr[type] = fopen(component_filenames[i], text_file ? "r" : "rb");
file_ptr[type] = fopen(component_filenames[i], "rb");
}

// Write updated data to the output traineddata file.
Expand Down
2 changes: 1 addition & 1 deletion ccutil/tprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const char *format, ... //special message
va_end(args);

if (debugfp == NULL && strlen (debug_file.string ()) > 0)
debugfp = fopen (debug_file.string (), "w");
debugfp = fopen (debug_file.string (), "wb");
else if (debugfp != NULL && strlen (debug_file.string ()) == 0) {
fclose(debugfp);
debugfp = NULL;
Expand Down
4 changes: 2 additions & 2 deletions ccutil/unicharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class UNICHARSET {
// Opens the file indicated by filename and saves unicharset to that file.
// Returns true if the operation is successful.
bool save_to_file(const char * const filename) const {
FILE* file = fopen(filename, "w+");
FILE* file = fopen(filename, "w+b");
if (file == NULL) return false;
bool result = save_to_file(file);
fclose(file);
Expand All @@ -241,7 +241,7 @@ class UNICHARSET {
// from the given file. The previous data is lost.
// Returns true if the operation is successful.
bool load_from_file(const char* const filename, bool skip_fragments) {
FILE* file = fopen(filename, "r");
FILE* file = fopen(filename, "rb");
if (file == NULL) return false;
bool result = load_from_file(file, skip_fragments);
fclose(file);
Expand Down
2 changes: 1 addition & 1 deletion classify/blobclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void LearnBlob(const FEATURE_DEFS_STRUCT &FeatureDefs, const STRING& filename,
// the name of the file is the name of the image plus TRAIN_SUFFIX
if (FeatureFile == NULL) {
Filename += TRAIN_SUFFIX;
FeatureFile = Efopen(Filename.string(), "w");
FeatureFile = Efopen(Filename.string(), "wb");
cprintf("TRAINING ... Font name = %s\n", CurrFontName.string());
}

Expand Down
12 changes: 6 additions & 6 deletions classify/picofeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
iterate(RemainingOutlines) {
Outline = (MFOUTLINE) first_node (RemainingOutlines);
/*---------Debug--------------------------------------------------*
OFile = fopen ("f:/ims/debug/pfOutline.logCPP", "r");
OFile = fopen ("f:/ims/debug/pfOutline.logCPP", "rb");
if (OFile == NULL)
{
OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "w");
OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "wb");
WriteOutline(OFile, Outline);
}
else
{
fclose (OFile);
OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "a");
OFile = Efopen ("f:/ims/debug/pfOutline.logCPP", "ab");
}
WriteOutline(OFile, Outline);
fclose (OFile);
Expand All @@ -97,16 +97,16 @@ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
if (classify_norm_method == baseline)
NormalizePicoX(FeatureSet);
/*---------Debug--------------------------------------------------*
File = fopen ("f:/ims/debug/pfFeatSet.logCPP", "r");
File = fopen ("f:/ims/debug/pfFeatSet.logCPP", "rb");
if (File == NULL)
{
File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "w");
File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "wb");
WriteFeatureSet(File, FeatureSet);
}
else
{
fclose (File);
File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "a");
File = Efopen ("f:/ims/debug/pfFeatSet.logCPP", "ab");
}
WriteFeatureSet(File, FeatureSet);
fclose (File);
Expand Down
2 changes: 1 addition & 1 deletion cube/cached_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool CachedFile::Open() {
return true;
}

fp_ = fopen(file_name_.c_str(), "r");
fp_ = fopen(file_name_.c_str(), "rb");
if (fp_ == NULL) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions cube/char_samp_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CharSampSet * CharSampSet::FromCharDumpFile(string file_name) {
FILE *fp;
unsigned int val32;
// open the file
fp = fopen(file_name.c_str(), "r");
fp = fopen(file_name.c_str(), "rb");
if (fp == NULL) {
return NULL;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ FILE *CharSampSet::CreateCharDumpFile(string file_name) {
FILE *fp;
unsigned int val32;
// create the file
fp = fopen(file_name.c_str(), "w");
fp = fopen(file_name.c_str(), "wb");
if (!fp) {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions cube/conv_net_classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool ConvNetCharClassifier::LoadFoldingSets(const string &data_file_path,
fold_file_name += ".cube.fold";

// folding sets are optional
FILE *fp = fopen(fold_file_name.c_str(), "r");
FILE *fp = fopen(fold_file_name.c_str(), "rb");
if (fp == NULL) {
return true;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ bool ConvNetCharClassifier::LoadNets(const string &data_file_path,
char_net_file += ".cube.nn";

// neural network is optional
FILE *fp = fopen(char_net_file.c_str(), "r");
FILE *fp = fopen(char_net_file.c_str(), "rb");
if (fp == NULL) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion cube/cube_tuning_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bool CubeTuningParams::Load(string tuning_params_file) {

// Save the parameters to a file
bool CubeTuningParams::Save(string file_name) {
FILE *params_file = fopen(file_name.c_str(), "w");
FILE *params_file = fopen(file_name.c_str(), "wb");
if (params_file == NULL) {
fprintf(stderr, "Cube ERROR (CubeTuningParams::Save): error opening file "
"%s for write.\n", file_name.c_str());
Expand Down
2 changes: 1 addition & 1 deletion cube/cube_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ unsigned char *CubeUtils::GetImageData(Pix *pix, int left, int top,
// read file contents to a string
bool CubeUtils::ReadFileToString(const string &file_name, string *str) {
str->clear();
FILE *fp = fopen(file_name.c_str(), "r");
FILE *fp = fopen(file_name.c_str(), "rb");
if (fp == NULL) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions cube/hybrid_neural_net_classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ bool HybridNeuralNetCharClassifier::LoadFoldingSets(
fold_file_name += ".cube.fold";

// folding sets are optional
FILE *fp = fopen(fold_file_name.c_str(), "r");
FILE *fp = fopen(fold_file_name.c_str(), "rb");
if (fp == NULL) {
return true;
}
Expand Down Expand Up @@ -316,7 +316,7 @@ bool HybridNeuralNetCharClassifier::LoadNets(const string &data_file_path,
hybrid_net_file += ".cube.hybrid";

// neural network is optional
FILE *fp = fopen(hybrid_net_file.c_str(), "r");
FILE *fp = fopen(hybrid_net_file.c_str(), "rb");
if (fp == NULL) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion cutil/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBDIRS =
AM_CPPFLAGS = -I$(top_srcdir)/ccutil
AM_CPPFLAGS = -I$(top_srcdir)/ccutil -I$(top_srcdir)/viewer

include_HEADERS = \
bitvec.h callcpp.h const.h cutil.h cutil_class.h danerror.h efio.h \
Expand Down
2 changes: 1 addition & 1 deletion cutil/cutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ FILE *open_file(const char *filename, const char *mode) {
bool exists_file(const char *filename) {
bool exists = false;
FILE *f = NULL;
if ((f = fopen(filename, "r")) != NULL) {
if ((f = fopen(filename, "rb")) != NULL) {
fclose(f);
exists = true;
}
Expand Down
63 changes: 2 additions & 61 deletions tessdata/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
datadir = @datadir@/tessdata
data_DATA = ara.cube.bigrams \
ara.cube.fold \
ara.cube.lm \
ara.cube.nn \
ara.cube.params \
ara.cube.size \
ara.cube.word-freq \
ara.traineddata \
eng.cube.bigrams \
eng.cube.lm \
eng.cube.params \
eng.cube.word-freq \
eng.traineddata \
eng.cube.fold \
eng.cube.nn \
eng.cube.size \
eng.tesseract_cube.nn \
bul.traineddata \
cat.traineddata \
ces.traineddata \
chi_sim.traineddata \
chi_tra.traineddata \
dan.traineddata \
dan-frak.traineddata \
deu.traineddata \
ell.traineddata \
fin.traineddata \
fra.traineddata \
heb.traineddata \
hin.cube.bigrams \
hin.cube.lm \
hin.cube.params \
hin.cube.word-freq \
hin.tesseract_cube.nn \
hin.traineddata \
hrv.traineddata \
hun.traineddata \
ind.traineddata \
ita.traineddata \
jpn.traineddata \
kor.traineddata \
lav.traineddata \
lit.traineddata \
nld.traineddata \
nor.traineddata \
osd.traineddata \
pol.traineddata \
por.traineddata \
ron.traineddata \
rus.traineddata \
slk.traineddata \
slk-frak.traineddata \
slv.traineddata \
spa.traineddata \
srp.traineddata \
swe.traineddata \
tgl.traineddata \
tha.traineddata \
tur.traineddata \
ukr.traineddata \
vie.traineddata
data_DATA = *.traineddata \
*.cube.*

SUBDIRS = configs tessconfigs

Loading

0 comments on commit 7ec3dca

Please sign in to comment.