Skip to content

Commit

Permalink
[clang-format] Execute clang format on include and src dirs.
Browse files Browse the repository at this point in the history
Script:
find include src -type f | sort > all.txt
find include src -type f | grep -v "\.cpp" | grep -v "\.h" | sort > skip.txt
comm -23 all.txt skip.txt | xargs clang-format -i
  • Loading branch information
egorpugin committed Mar 12, 2021
1 parent afa476b commit 0eb7ba8
Show file tree
Hide file tree
Showing 513 changed files with 68,725 additions and 74,039 deletions.
267 changes: 127 additions & 140 deletions include/tesseract/baseapi.h

Large diffs are not rendered by default.

470 changes: 205 additions & 265 deletions include/tesseract/capi.h

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions include/tesseract/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
#define TESSERACT_PLATFORM_H_

#ifndef TESS_API
# if defined(_WIN32) || defined(__CYGWIN__)
# if defined(TESS_EXPORTS)
# define TESS_API __declspec(dllexport)
# elif defined(TESS_IMPORTS)
# define TESS_API __declspec(dllimport)
# if defined(_WIN32) || defined(__CYGWIN__)
# if defined(TESS_EXPORTS)
# define TESS_API __declspec(dllexport)
# elif defined(TESS_IMPORTS)
# define TESS_API __declspec(dllimport)
# else
# define TESS_API
# endif
# else
# define TESS_API
# if defined(TESS_EXPORTS) || defined(TESS_IMPORTS)
# define TESS_API __attribute__((visibility("default")))
# else
# define TESS_API
# endif
# endif
# else
# if defined(TESS_EXPORTS) || defined(TESS_IMPORTS)
# define TESS_API __attribute__((visibility("default")))
# else
# define TESS_API
# endif
# endif
#endif

#endif // TESSERACT_PLATFORM_H_
#endif // TESSERACT_PLATFORM_H_
77 changes: 37 additions & 40 deletions include/tesseract/ltrresultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#ifndef TESSERACT_CCMAIN_LTR_RESULT_ITERATOR_H_
#define TESSERACT_CCMAIN_LTR_RESULT_ITERATOR_H_

#include "pageiterator.h" // for PageIterator
#include "export.h" // for TESS_API
#include "publictypes.h" // for PageIteratorLevel
#include "unichar.h" // for StrongScriptDirection
#include "export.h" // for TESS_API
#include "pageiterator.h" // for PageIterator
#include "publictypes.h" // for PageIteratorLevel
#include "unichar.h" // for StrongScriptDirection

namespace tesseract {

Expand All @@ -47,7 +47,7 @@ class Tesseract;
class TESS_API LTRResultIterator : public PageIterator {
friend class ChoiceIterator;

public:
public:
// page_res and tesseract come directly from the BaseAPI.
// The rectangle parameters are copied indirectly from the Thresholder,
// via the BaseAPI. They represent the coordinates of some rectangle in an
Expand All @@ -60,9 +60,8 @@ class TESS_API LTRResultIterator : public PageIterator {
// The scaled_yres indicates the effective resolution of the binary image
// that tesseract has been given by the Thresholder.
// After the constructor, Begin has already been called.
LTRResultIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale,
int scaled_yres, int rect_left, int rect_top,
int rect_width, int rect_height);
LTRResultIterator(PAGE_RES *page_res, Tesseract *tesseract, int scale, int scaled_yres,
int rect_left, int rect_top, int rect_width, int rect_height);

~LTRResultIterator() override;

Expand All @@ -81,21 +80,20 @@ class TESS_API LTRResultIterator : public PageIterator {

// Returns the null terminated UTF-8 encoded text string for the current
// object at the given level. Use delete [] to free after use.
char* GetUTF8Text(PageIteratorLevel level) const;
char *GetUTF8Text(PageIteratorLevel level) const;

// Set the string inserted at the end of each text line. "\n" by default.
void SetLineSeparator(const char* new_line);
void SetLineSeparator(const char *new_line);

// Set the string inserted at the end of each paragraph. "\n" by default.
void SetParagraphSeparator(const char* new_para);
void SetParagraphSeparator(const char *new_para);

// Returns the mean confidence of the current object at the given level.
// The number should be interpreted as a percent probability. (0.0f-100.0f)
float Confidence(PageIteratorLevel level) const;

// Returns the attributes of the current row.
void RowAttributes(float* row_height, float* descenders,
float* ascenders) const;
void RowAttributes(float *row_height, float *descenders, float *ascenders) const;

// ============= Functions that refer to words only ============.

Expand All @@ -107,14 +105,13 @@ class TESS_API LTRResultIterator : public PageIterator {
// the iterator itself, ie rendered invalid by various members of
// TessBaseAPI, including Init, SetImage, End or deleting the TessBaseAPI.
// Pointsize is returned in printers points (1/72 inch.)
const char* WordFontAttributes(bool* is_bold, bool* is_italic,
bool* is_underlined, bool* is_monospace,
bool* is_serif, bool* is_smallcaps,
int* pointsize, int* font_id) const;
const char *WordFontAttributes(bool *is_bold, bool *is_italic, bool *is_underlined,
bool *is_monospace, bool *is_serif, bool *is_smallcaps,
int *pointsize, int *font_id) const;

// Return the name of the language used to recognize this word.
// On error, nullptr. Do not delete this pointer.
const char* WordRecognitionLanguage() const;
const char *WordRecognitionLanguage() const;

// Return the overall directionality of this word.
StrongScriptDirection WordDirection() const;
Expand All @@ -133,34 +130,34 @@ class TESS_API LTRResultIterator : public PageIterator {

// Returns the pointer to ParamsTrainingBundle stored in the BlamerBundle
// of the current word.
const void* GetParamsTrainingBundle() const;
const void *GetParamsTrainingBundle() const;

// Returns a pointer to the string with blamer information for this word.
// Assumes that the word's blamer_bundle is not nullptr.
const char* GetBlamerDebug() const;
const char *GetBlamerDebug() const;

// Returns a pointer to the string with misadaption information for this word.
// Assumes that the word's blamer_bundle is not nullptr.
const char* GetBlamerMisadaptionDebug() const;
const char *GetBlamerMisadaptionDebug() const;

// Returns true if a truth string was recorded for the current word.
bool HasTruthString() const;

// Returns true if the given string is equivalent to the truth string for
// the current word.
bool EquivalentToTruth(const char* str) const;
bool EquivalentToTruth(const char *str) const;

// Returns a null terminated UTF-8 encoded truth string for the current word.
// Use delete [] to free after use.
char* WordTruthUTF8Text() const;
char *WordTruthUTF8Text() const;

// Returns a null terminated UTF-8 encoded normalized OCR string for the
// current word. Use delete [] to free after use.
char* WordNormedUTF8Text() const;
char *WordNormedUTF8Text() const;

// Returns a pointer to serialized choice lattice.
// Fills lattice_size with the number of bytes in lattice data.
const char* WordLattice(int* lattice_size) const;
const char *WordLattice(int *lattice_size) const;

// ============= Functions that refer to symbols only ============.

Expand All @@ -177,18 +174,18 @@ class TESS_API LTRResultIterator : public PageIterator {
// this will return the attributes of the first symbol in that word.
bool SymbolIsDropcap() const;

protected:
const char* line_separator_;
const char* paragraph_separator_;
protected:
const char *line_separator_;
const char *paragraph_separator_;
};

// Class to iterate over the classifier choices for a single RIL_SYMBOL.
class TESS_API ChoiceIterator {
public:
public:
// Construction is from a LTRResultIterator that points to the symbol of
// interest. The ChoiceIterator allows a one-shot iteration over the
// choices for this symbol and after that is is useless.
explicit ChoiceIterator(const LTRResultIterator& result_it);
explicit ChoiceIterator(const LTRResultIterator &result_it);
~ChoiceIterator();

// Moves to the next choice for the symbol and returns false if there
Expand All @@ -201,7 +198,7 @@ class TESS_API ChoiceIterator {
// choice.
// NOTE: Unlike LTRResultIterator::GetUTF8Text, the return points to an
// internal structure and should NOT be delete[]ed to free after use.
const char* GetUTF8Text() const;
const char *GetUTF8Text() const;

// Returns the confidence of the current choice depending on the used language
// data. If only LSTM traineddata is used the value range is 0.0f - 1.0f. All
Expand All @@ -215,19 +212,19 @@ class TESS_API ChoiceIterator {
// selected symbol. A timestep is a vector containing pairs of symbols and
// floating point numbers. The number states the probability for the
// corresponding symbol.
std::vector<std::vector<std::pair<const char*, float>>>* Timesteps() const;
std::vector<std::vector<std::pair<const char *, float>>> *Timesteps() const;

private:
private:
// clears the remaining spaces out of the results and adapt the probabilities
void filterSpaces();
// Pointer to the WERD_RES object owned by the API.
WERD_RES* word_res_;
WERD_RES *word_res_;
// Iterator over the blob choices.
BLOB_CHOICE_IT* choice_it_;
std::vector<std::pair<const char*, float>>* LSTM_choices_ = nullptr;
std::vector<std::pair<const char*, float>>::iterator LSTM_choice_it_;
BLOB_CHOICE_IT *choice_it_;
std::vector<std::pair<const char *, float>> *LSTM_choices_ = nullptr;
std::vector<std::pair<const char *, float>>::iterator LSTM_choice_it_;

const int* tstep_index_;
const int *tstep_index_;
// regulates the rating granularity
double rating_coefficient_;
// leading blanks
Expand All @@ -236,6 +233,6 @@ class TESS_API ChoiceIterator {
bool oemLSTM_;
};

} // namespace tesseract.
} // namespace tesseract.

#endif // TESSERACT_CCMAIN_LTR_RESULT_ITERATOR_H_
#endif // TESSERACT_CCMAIN_LTR_RESULT_ITERATOR_H_
48 changes: 21 additions & 27 deletions include/tesseract/ocrclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,64 +94,58 @@ typedef struct { /*single character */
**********************************************************************/
class ETEXT_DESC;

using CANCEL_FUNC = bool (*)(void*, int);
using CANCEL_FUNC = bool (*)(void *, int);
using PROGRESS_FUNC = bool (*)(int, int, int, int, int);
using PROGRESS_FUNC2 = bool (*)(ETEXT_DESC*, int, int, int, int);
using PROGRESS_FUNC2 = bool (*)(ETEXT_DESC *, int, int, int, int);

class ETEXT_DESC { // output header
public:
int16_t count{0}; /// chars in this buffer(0)
int16_t progress{0}; /// percent complete increasing (0-100)
class ETEXT_DESC { // output header
public:
int16_t count{0}; /// chars in this buffer(0)
int16_t progress{0}; /// percent complete increasing (0-100)
/** Progress monitor covers word recognition and it does not cover layout
* analysis.
* See Ray comment in https://github.com/tesseract-ocr/tesseract/pull/27 */
int8_t more_to_come{0}; /// true if not last
volatile int8_t ocr_alive{0}; /// ocr sets to 1, HP 0
int8_t err_code{0}; /// for errcode use
CANCEL_FUNC cancel{nullptr}; /// returns true to cancel
PROGRESS_FUNC progress_callback{
nullptr}; /// called whenever progress increases
PROGRESS_FUNC2 progress_callback2; /// monitor-aware progress callback
void* cancel_this{nullptr}; /// this or other data for cancel
int8_t more_to_come{0}; /// true if not last
volatile int8_t ocr_alive{0}; /// ocr sets to 1, HP 0
int8_t err_code{0}; /// for errcode use
CANCEL_FUNC cancel{nullptr}; /// returns true to cancel
PROGRESS_FUNC progress_callback{nullptr}; /// called whenever progress increases
PROGRESS_FUNC2 progress_callback2; /// monitor-aware progress callback
void *cancel_this{nullptr}; /// this or other data for cancel
std::chrono::steady_clock::time_point end_time;
/// Time to stop. Expected to be set only
/// by call to set_deadline_msecs().
EANYCODE_CHAR text[1]{}; /// character data
EANYCODE_CHAR text[1]{}; /// character data

ETEXT_DESC() : progress_callback2(&default_progress_func) {
end_time = std::chrono::time_point<std::chrono::steady_clock,
std::chrono::milliseconds>();
end_time = std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds>();
}

// Sets the end time to be deadline_msecs milliseconds from now.
void set_deadline_msecs(int32_t deadline_msecs) {
if (deadline_msecs > 0) {
end_time = std::chrono::steady_clock::now() +
std::chrono::milliseconds(deadline_msecs);
end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(deadline_msecs);
}
}

// Returns false if we've not passed the end_time, or have not set a deadline.
bool deadline_exceeded() const {
if (end_time.time_since_epoch() ==
std::chrono::steady_clock::duration::zero()) {
if (end_time.time_since_epoch() == std::chrono::steady_clock::duration::zero()) {
return false;
}
auto now = std::chrono::steady_clock::now();
return (now > end_time);
}

private:
static bool default_progress_func(ETEXT_DESC* ths, int left, int right,
int top, int bottom) {
private:
static bool default_progress_func(ETEXT_DESC *ths, int left, int right, int top, int bottom) {
if (ths->progress_callback != nullptr) {
return (*(ths->progress_callback))(ths->progress, left, right, top,
bottom);
return (*(ths->progress_callback))(ths->progress, left, right, top, bottom);
}
return true;
}
};

} // namespace tesseract

#endif // CCUTIL_OCRCLASS_H_
#endif // CCUTIL_OCRCLASS_H_
Loading

0 comments on commit 0eb7ba8

Please sign in to comment.