Merge pull request #1893 from stweil/clean

Fix some compiler warnings and clean code
This commit is contained in:
Egor Pugin 2018-09-03 23:22:24 +03:00 committed by GitHub
commit 56b449f745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 66 additions and 124 deletions

View File

@ -696,7 +696,7 @@ bool TessPDFRenderer::BeginDocumentHandler() {
}
bool TessPDFRenderer::imageToPDFObj(Pix *pix,
char *filename,
const char* filename,
long int objnum,
char **pdf_object,
long int *pdf_object_size) {
@ -845,7 +845,7 @@ bool TessPDFRenderer::AddImageHandler(TessBaseAPI* api) {
char buf[kBasicBufSize];
char buf2[kBasicBufSize];
Pix *pix = api->GetInputImage();
char *filename = (char *)api->GetInputName();
const char* filename = reinterpret_cast<const char*>(api->GetInputName());
int ppi = api->GetSourceYResolution();
if (!pix || ppi <= 0)
return false;

View File

@ -212,8 +212,8 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
// Create the /Contents object for an entire page.
char* GetPDFTextObjects(TessBaseAPI* api, double width, double height);
// Turn an image into a PDF object. Only transcode if we have to.
static bool imageToPDFObj(Pix *pix, char *filename, long int objnum,
char **pdf_object, long int *pdf_object_size);
static bool imageToPDFObj(Pix* pix, const char* filename, long int objnum,
char** pdf_object, long int* pdf_object_size);
};

View File

@ -24,7 +24,6 @@
#include "blobs.h" // for TWERD, TBLOB, TESSLINE
#include "boxword.h" // for BoxWord
#include "errcode.h" // for ASSERT_HOST
#include "genblob.h" // for c_blob_comparator
#include "host.h" // for FALSE, TRUE
#include "normalis.h" // for kBlnXHeight, kBlnBaselineOffset
#include "ocrclass.h" // for ETEXT_DESC
@ -49,6 +48,23 @@ class ROW;
namespace tesseract {
/**********************************************************************
* c_blob_comparator()
*
* Blob comparator used to sort a blob list so that blobs are in increasing
* order of left edge.
**********************************************************************/
static int c_blob_comparator( // sort blobs
const void *blob1p, // ptr to ptr to blob1
const void *blob2p // ptr to ptr to blob2
) {
const C_BLOB *blob1 = *reinterpret_cast<const C_BLOB* const*>(blob1p);
const C_BLOB *blob2 = *reinterpret_cast<const C_BLOB* const*>(blob2p);
return blob1->bounding_box ().left () - blob2->bounding_box ().left ();
}
/**
* @name fix_fuzzy_spaces()
* Walk over the page finding sequences of words joined by fuzzy spaces. Extract

View File

@ -14,7 +14,7 @@ pkginclude_HEADERS = publictypes.h
noinst_HEADERS = \
blamer.h blobbox.h blobs.h blread.h boxread.h boxword.h \
ccstruct.h coutln.h crakedge.h \
debugpixa.h detlinefit.h dppoint.h fontinfo.h genblob.h \
debugpixa.h detlinefit.h dppoint.h fontinfo.h \
imagedata.h \
ipoints.h \
linlsq.h matrix.h mod128.h normalis.h \
@ -28,7 +28,7 @@ noinst_LTLIBRARIES = libtesseract_ccstruct.la
libtesseract_ccstruct_la_SOURCES = \
blamer.cpp blobbox.cpp blobs.cpp blread.cpp boxread.cpp boxword.cpp ccstruct.cpp coutln.cpp \
detlinefit.cpp dppoint.cpp fontinfo.cpp genblob.cpp \
detlinefit.cpp dppoint.cpp fontinfo.cpp \
imagedata.cpp \
linlsq.cpp matrix.cpp mod128.cpp normalis.cpp \
ocrblock.cpp ocrpara.cpp ocrrow.cpp otsuthr.cpp \

View File

@ -1,38 +0,0 @@
/**********************************************************************
* File: genblob.cpp (Formerly gblob.c)
* Description: Generic Blob processing routines
* Author: Phil Cheatle
* Created: Mon Nov 25 10:53:26 GMT 1991
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*
**********************************************************************/
#include "genblob.h"
#include "stepblob.h"
/**********************************************************************
* c_blob_comparator()
*
* Blob comparator used to sort a blob list so that blobs are in increasing
* order of left edge.
**********************************************************************/
int c_blob_comparator( // sort blobs
const void *blob1p, // ptr to ptr to blob1
const void *blob2p // ptr to ptr to blob2
) {
C_BLOB *blob1 = *(C_BLOB **) blob1p;
C_BLOB *blob2 = *(C_BLOB **) blob2p;
return blob1->bounding_box ().left () - blob2->bounding_box ().left ();
}

View File

@ -1,27 +0,0 @@
/**********************************************************************
* File: genblob.h (Formerly gblob.h)
* Description: Generic Blob processing routines
* Author: Phil Cheatle
* Created: Mon Nov 25 10:53:26 GMT 1991
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*
**********************************************************************/
#ifndef GENBLOB_H
#define GENBLOB_H
// Sort function to sort blobs by ascending left edge.
int c_blob_comparator(const void *blob1p, // ptr to ptr to blob1
const void *blob2p);
#endif

View File

@ -17,9 +17,9 @@
*
**********************************************************************/
#include "mod128.h"
#include "mod128.h"
const int16_t idirtab[] = {
static const int16_t idirtab[] = {
1000, 0, 998, 49, 995, 98, 989, 146,
980, 195, 970, 242, 956, 290, 941, 336,
923, 382, 903, 427, 881, 471, 857, 514,
@ -54,7 +54,7 @@ const int16_t idirtab[] = {
980, -195, 989, -146, 995, -98, 998, -49
};
const ICOORD *dirtab = (ICOORD *) idirtab;
const ICOORD* dirtab = reinterpret_cast<const ICOORD*>(idirtab);
/**********************************************************************
* DIR128::DIR128

View File

@ -68,11 +68,9 @@ BLOCK::BLOCK(const char *name, //< filename
* Sort Comparator: Return <0 if row1 top < row2 top
*/
int decreasing_top_order( //
const void *row1,
const void *row2) {
return (*(ROW **) row2)->bounding_box ().top () -
(*(ROW **) row1)->bounding_box ().top ();
static int decreasing_top_order(const void *row1, const void *row2) {
return (*reinterpret_cast<ROW* const*>(row2))->bounding_box().top() -
(*reinterpret_cast<ROW* const*>(row1))->bounding_box().top();
}

View File

@ -211,8 +211,6 @@ class BLOCK:public ELIST_LINK
ICOORD median_size_; //< Median size of blobs.
};
int decreasing_top_order(const void *row1, const void *row2);
// A function to print segmentation stats for the given block list.
void PrintSegmentationStats(BLOCK_LIST* block_list);

View File

@ -171,6 +171,4 @@ class DLLSYM BLOCK_LINE_IT
BLOCK_RECT_IT rect_it; //< rectangle iterator
};
int decreasing_top_order(const void *row1,
const void *row2);
#endif

View File

@ -27,7 +27,6 @@
#include "config_auto.h"
#endif
#define PBLOCK_LABEL_SIZE 150
#define INTERSECTING INT16_MAX
int lessthan(const void *first, const void *second);
@ -191,8 +190,8 @@ void POLY_BLOCK::rotate(FCOORD rotation) {
pos.set_x (pt->x ());
pos.set_y (pt->y ());
pos.rotate (rotation);
pt->set_x ((int16_t) (floor (pos.x () + 0.5)));
pt->set_y ((int16_t) (floor (pos.y () + 0.5)));
pt->set_x(static_cast<int16_t>(floor(pos.x() + 0.5)));
pt->set_y(static_cast<int16_t>(floor(pos.y() + 0.5)));
pts.forward ();
}
while (!pts.at_first ());
@ -289,7 +288,7 @@ void POLY_BLOCK::fill(ScrollView* window, ScrollView::Color colour) {
// Last pixel is start pixel + length.
width = s_it.data ()->y ();
window->SetCursor(s_it.data ()->x (), y);
window->DrawTo(s_it.data ()->x () + (float) width, y);
window->DrawTo(s_it.data()->x() + static_cast<float>(width), y);
}
}
}
@ -343,9 +342,7 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
ICOORDELT_IT v, r;
ICOORDELT_LIST *result;
ICOORDELT *x, *current, *previous;
float fy, fx;
fy = (float) (y + 0.5);
float fy = y + 0.5f;
result = new ICOORDELT_LIST ();
r.set_to_list (result);
v.set_to_list (block->points ());
@ -355,11 +352,10 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
|| ((v.data_relative (-1)->y () <= y) && (v.data ()->y () > y))) {
previous = v.data_relative (-1);
current = v.data ();
fx = (float) (0.5 + previous->x () +
(current->x () - previous->x ()) * (fy -
previous->y ()) /
(current->y () - previous->y ()));
x = new ICOORDELT ((int16_t) fx, 0);
float fx = 0.5f + previous->x() +
(current->x() - previous->x()) * (fy - previous->y()) /
(current->y() - previous->y());
x = new ICOORDELT(static_cast<int16_t>(fx), 0);
r.add_to_end (x);
}
}
@ -380,8 +376,8 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
int lessthan(const void *first, const void *second) {
ICOORDELT *p1 = (*(ICOORDELT **) first);
ICOORDELT *p2 = (*(ICOORDELT **) second);
const ICOORDELT *p1 = *reinterpret_cast<const ICOORDELT* const*>(first);
const ICOORDELT *p2 = *reinterpret_cast<const ICOORDELT* const*>(second);
if (p1->x () < p2->x ())
return (-1);

View File

@ -125,7 +125,7 @@ WERD::WERD(C_BLOB_LIST * blob_list, //< In word order
while (!end_it.at_last ())
end_it.forward (); //move to last
((C_BLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);
(reinterpret_cast<C_BLOB_LIST*>(&cblobs))->assign_to_sublist(&start_it, &end_it);
//move to our list
blanks = clone->blanks;
// fprintf(stderr,"Wrong constructor!!!!\n");
@ -391,8 +391,8 @@ WERD & WERD::operator= (const WERD & source) {
*/
int word_comparator(const void *word1p, const void *word2p) {
WERD *word1 = *(WERD **)word1p;
WERD *word2 = *(WERD **)word2p;
const WERD *word1 = *reinterpret_cast<const WERD* const*>(word1p);
const WERD *word2 = *reinterpret_cast<const WERD* const*>(word2p);
return word1->bounding_box().left() - word2->bounding_box().left();
}

View File

@ -101,18 +101,6 @@ template<typename T> inline void Swap(T* p1, T* p2) {
*p1 = tmp;
}
// qsort function to sort 2 floats.
inline int sort_floats(const void *arg1, const void *arg2) {
float diff = *((float *) arg1) - *((float *) arg2);
if (diff > 0) {
return 1;
} else if (diff < 0) {
return -1;
} else {
return 0;
}
}
// return the smallest multiple of block_size greater than or equal to n.
inline int RoundUp(int n, int block_size) {
return block_size * ((n + block_size - 1) / block_size);

View File

@ -682,8 +682,8 @@ void FPRow::DebugOutputResult(int row_index) {
real_row_->space_size, real_row_->space_threshold,
real_row_->xheight);
for (size_t i = 0; i < num_chars(); i++) {
tprintf("Char %d: is_final=%d is_good=%d num_blobs=%d: ",
for (unsigned i = 0; i < num_chars(); i++) {
tprintf("Char %u: is_final=%d is_good=%d num_blobs=%d: ",
i, is_final(i), is_good(i), character(i)->num_blobs());
box(i).print();
}
@ -1078,7 +1078,7 @@ void compute_fixed_pitch_cjk(ICOORD page_tr,
return;
}
size_t iteration = 0;
unsigned iteration = 0;
do {
analyzer.MergeFragments();
analyzer.FinalizeLargeChars();
@ -1087,7 +1087,7 @@ void compute_fixed_pitch_cjk(ICOORD page_tr,
} while (analyzer.Pass2Analyze() && iteration < analyzer.max_iteration());
if (textord_debug_pitch_test) {
tprintf("compute_fixed_pitch_cjk finished after %d iteration (limit=%d)\n",
tprintf("compute_fixed_pitch_cjk finished after %u iteration (limit=%u)\n",
iteration, analyzer.max_iteration());
}

View File

@ -144,7 +144,7 @@ static float MakeRowFromSubBlobs(TO_BLOCK* block, C_BLOB* blob,
return 0.0f;
for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
// Deep copy the child outline and use that to make a blob.
C_BLOB* blob = new C_BLOB(C_OUTLINE::deep_copy(ol_it.data()));
blob = new C_BLOB(C_OUTLINE::deep_copy(ol_it.data()));
// Correct direction as needed.
blob->CheckInverseFlagAndDirection();
BLOBNBOX* bbox = new BLOBNBOX(blob);
@ -2576,9 +2576,9 @@ int blob_x_order( //sort function
const void *item1, //items to compare
const void *item2) {
//converted ptr
BLOBNBOX *blob1 = *(BLOBNBOX **) item1;
const BLOBNBOX *blob1 = *reinterpret_cast<const BLOBNBOX* const*>(item1);
//converted ptr
BLOBNBOX *blob2 = *(BLOBNBOX **) item2;
const BLOBNBOX *blob2 = *reinterpret_cast<const BLOBNBOX* const*>(item2);
if (blob1->bounding_box ().left () < blob2->bounding_box ().left ())
return -1;
@ -2598,9 +2598,9 @@ int row_y_order( //sort function
const void *item1, //items to compare
const void *item2) {
//converted ptr
TO_ROW *row1 = *(TO_ROW **) item1;
const TO_ROW *row1 = *reinterpret_cast<const TO_ROW* const*>(item1);
//converted ptr
TO_ROW *row2 = *(TO_ROW **) item2;
const TO_ROW *row2 = *reinterpret_cast<const TO_ROW* const*>(item2);
if (row1->parallel_c () > row2->parallel_c ())
return -1;
@ -2620,9 +2620,9 @@ int row_spacing_order( //sort function
const void *item1, //items to compare
const void *item2) {
//converted ptr
TO_ROW *row1 = *(TO_ROW **) item1;
const TO_ROW *row1 = *reinterpret_cast<const TO_ROW* const*>(item1);
//converted ptr
TO_ROW *row2 = *(TO_ROW **) item2;
const TO_ROW *row2 = *reinterpret_cast<const TO_ROW* const*>(item2);
if (row1->spacing < row2->spacing)
return -1;

View File

@ -60,6 +60,19 @@ EXTERN double_VAR (textord_balance_factor, 1.0,
#define BLOCK_STATS_CLUSTERS 10
#define MAX_ALLOWED_PITCH 100 //max pixel pitch.
// qsort function to sort 2 floats.
static int sort_floats(const void *arg1, const void *arg2) {
float diff = *reinterpret_cast<const float*>(arg1) -
*reinterpret_cast<const float*>(arg2);
if (diff > 0) {
return 1;
} else if (diff < 0) {
return -1;
} else {
return 0;
}
}
/**********************************************************************
* compute_fixed_pitch
*