Skip to content

Commit

Permalink
Format API header files
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Nov 2, 2019
1 parent 29dcfb0 commit 90db9b5
Show file tree
Hide file tree
Showing 13 changed files with 462 additions and 507 deletions.
223 changes: 110 additions & 113 deletions include/tesseract/baseapi.h

Large diffs are not rendered by default.

447 changes: 203 additions & 244 deletions include/tesseract/capi.h

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions include/tesseract/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

#include <algorithm>
#include <cassert>
#include <climits> // for LONG_MAX
#include <cstdint> // for uint32_t
#include <climits> // for LONG_MAX
#include <cstdint> // for uint32_t
#include <cstdio>
#include <cstdlib>
#include <functional> // for std::function
#include <functional> // for std::function

#include "helpers.h"
#include "serialis.h"
Expand Down Expand Up @@ -173,8 +173,7 @@ class GenericVector {
// Returns false on error or if the callback returns false.
// DEPRECATED. Use [De]Serialize[Classes] instead.
bool write(FILE* f, std::function<bool(FILE*, const T&)> cb) const;
bool read(tesseract::TFile* f,
std::function<bool(tesseract::TFile*, T*)> cb);
bool read(tesseract::TFile* f, std::function<bool(tesseract::TFile*, T*)> cb);
// Writes a vector of simple types to the given file. Assumes that bitwise
// read/write of T will work. Returns false in case of error.
// TODO(rays) Change all callers to use TFile and remove deprecated methods.
Expand Down Expand Up @@ -647,12 +646,12 @@ class GenericVectorEqEq : public GenericVector<T> {
GenericVectorEqEq() {
using namespace std::placeholders; // for _1
GenericVector<T>::set_compare_callback(
std::bind(tesseract::cmp_eq<T>, _1, _2));
std::bind(tesseract::cmp_eq<T>, _1, _2));
}
explicit GenericVectorEqEq(int size) : GenericVector<T>(size) {
using namespace std::placeholders; // for _1
GenericVector<T>::set_compare_callback(
std::bind(tesseract::cmp_eq<T>, _1, _2));
std::bind(tesseract::cmp_eq<T>, _1, _2));
}
};

Expand Down Expand Up @@ -881,8 +880,8 @@ void GenericVector<T>::delete_data_pointers() {
}

template <typename T>
bool GenericVector<T>::write(
FILE* f, std::function<bool(FILE*, const T&)> cb) const {
bool GenericVector<T>::write(FILE* f,
std::function<bool(FILE*, const T&)> cb) const {
if (fwrite(&size_reserved_, sizeof(size_reserved_), 1, f) != 1) {
return false;
}
Expand All @@ -904,8 +903,8 @@ bool GenericVector<T>::write(
}

template <typename T>
bool GenericVector<T>::read(
tesseract::TFile* f, std::function<bool(tesseract::TFile*, T*)> cb) {
bool GenericVector<T>::read(tesseract::TFile* f,
std::function<bool(tesseract::TFile*, T*)> cb) {
int32_t reserved;
if (f->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand Down
38 changes: 17 additions & 21 deletions include/tesseract/ltrresultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Tesseract;

class TESS_API LTRResultIterator : public PageIterator {
friend class ChoiceIterator;

public:
// page_res and tesseract come directly from the BaseAPI.
// The rectangle parameters are copied indirectly from the Thresholder,
Expand All @@ -59,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,
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 @@ -84,10 +84,10 @@ class TESS_API LTRResultIterator : public PageIterator {
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)
Expand All @@ -107,14 +107,10 @@ 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.
Expand All @@ -137,22 +133,22 @@ 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.
Expand All @@ -164,7 +160,7 @@ class TESS_API LTRResultIterator : public PageIterator {

// 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 @@ -182,8 +178,8 @@ class TESS_API LTRResultIterator : public PageIterator {
bool SymbolIsDropcap() const;

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

// Class to iterate over the classifier choices for a single RIL_SYMBOL.
Expand Down Expand Up @@ -222,7 +218,7 @@ class ChoiceIterator {
std::vector<std::vector<std::pair<const char*, float>>>* Timesteps() const;

private:
//clears the remaining spaces out of the results and adapt the probabilities
// 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_;
Expand Down
30 changes: 14 additions & 16 deletions include/tesseract/osdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class BLOB_CHOICE_LIST;
class STRING;
class TO_BLOCK_LIST;
class UNICHARSET;
template <typename T> class GenericVector;
template <typename T>
class GenericVector;

namespace tesseract {
class Tesseract;
Expand All @@ -38,8 +39,8 @@ class Tesseract;
const int kMaxNumberOfScripts = 116 + 1 + 2 + 1;

struct OSBestResult {
OSBestResult() : orientation_id(0), script_id(0), sconfidence(0.0),
oconfidence(0.0) {}
OSBestResult()
: orientation_id(0), script_id(0), sconfidence(0.0), oconfidence(0.0) {}
int orientation_id;
int script_id;
float sconfidence;
Expand All @@ -49,8 +50,7 @@ struct OSBestResult {
struct OSResults {
OSResults() : unicharset(nullptr) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < kMaxNumberOfScripts; ++j)
scripts_na[i][j] = 0;
for (int j = 0; j < kMaxNumberOfScripts; ++j) scripts_na[i][j] = 0;
orientations[i] = 0;
}
}
Expand Down Expand Up @@ -87,17 +87,19 @@ class OrientationDetector {
OSResults* results);
bool detect_blob(BLOB_CHOICE_LIST* scores);
int get_orientation();

private:
OSResults* osr_;
const GenericVector<int>* allowed_scripts_;
};

class ScriptDetector {
public:
ScriptDetector(const GenericVector<int>* allowed_scripts,
OSResults* osr, tesseract::Tesseract* tess);
ScriptDetector(const GenericVector<int>* allowed_scripts, OSResults* osr,
tesseract::Tesseract* tess);
void detect_blob(BLOB_CHOICE_LIST* scores);
bool must_stop(int orientation);

private:
OSResults* osr_;
static const char* korean_script_;
Expand All @@ -115,22 +117,18 @@ class ScriptDetector {
const GenericVector<int>* allowed_scripts_;
};

int orientation_and_script_detection(STRING& filename,
OSResults*,
int orientation_and_script_detection(STRING& filename, OSResults*,
tesseract::Tesseract*);

int os_detect(TO_BLOCK_LIST* port_blocks,
OSResults* osr,
int os_detect(TO_BLOCK_LIST* port_blocks, OSResults* osr,
tesseract::Tesseract* tess);

int os_detect_blobs(const GenericVector<int>* allowed_scripts,
BLOBNBOX_CLIST* blob_list,
OSResults* osr,
BLOBNBOX_CLIST* blob_list, OSResults* osr,
tesseract::Tesseract* tess);

bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o,
ScriptDetector* s, OSResults*,
tesseract::Tesseract* tess);
bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o, ScriptDetector* s,
OSResults*, tesseract::Tesseract* tess);

// Helper method to convert an orientation index to its value in degrees.
// The value represents the amount of clockwise rotation in degrees that must be
Expand Down
42 changes: 20 additions & 22 deletions include/tesseract/pageiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ class TESS_API PageIterator {
* that tesseract has been given by the Thresholder.
* After the constructor, Begin has already been called.
*/
PageIterator(PAGE_RES* page_res, Tesseract* tesseract,
int scale, int scaled_yres,
int rect_left, int rect_top,
int rect_width, int rect_height);
PageIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale,
int scaled_yres, int rect_left, int rect_top, int rect_width,
int rect_height);
virtual ~PageIterator();

/**
Expand Down Expand Up @@ -164,7 +163,7 @@ class TESS_API PageIterator {
* equal to other: 0
* after other: 1
*/
int Cmp(const PageIterator &other) const;
int Cmp(const PageIterator& other) const;

// ============= Accessing data ==============.
// Coordinate system:
Expand Down Expand Up @@ -203,17 +202,17 @@ class TESS_API PageIterator {
* from a grey image. The padding argument to GetImage can be used to expand
* the image to include more foreground pixels. See GetImage below.
*/
bool BoundingBox(PageIteratorLevel level,
int* left, int* top, int* right, int* bottom) const;
bool BoundingBox(PageIteratorLevel level, int padding,
int* left, int* top, int* right, int* bottom) const;
bool BoundingBox(PageIteratorLevel level, int* left, int* top, int* right,
int* bottom) const;
bool BoundingBox(PageIteratorLevel level, int padding, int* left, int* top,
int* right, int* bottom) const;
/**
* Returns the bounding rectangle of the object in a coordinate system of the
* working image rectangle having its origin at (rect_left_, rect_top_) with
* respect to the original image and is scaled by a factor scale_.
*/
bool BoundingBoxInternal(PageIteratorLevel level,
int* left, int* top, int* right, int* bottom) const;
bool BoundingBoxInternal(PageIteratorLevel level, int* left, int* top,
int* right, int* bottom) const;

/** Returns whether there is no object of a given level. */
bool Empty(PageIteratorLevel level) const;
Expand Down Expand Up @@ -261,8 +260,8 @@ class TESS_API PageIterator {
* WARNING: with vertical text, baselines may be vertical!
* Returns false if there is no baseline at the current position.
*/
bool Baseline(PageIteratorLevel level,
int* x1, int* y1, int* x2, int* y2) const;
bool Baseline(PageIteratorLevel level, int* x1, int* y1, int* x2,
int* y2) const;

/**
* Returns orientation for the block the iterator points to.
Expand All @@ -272,10 +271,10 @@ class TESS_API PageIterator {
* block anti-clockwise for it to be level?
* -Pi/4 <= deskew_angle <= Pi/4
*/
void Orientation(tesseract::Orientation *orientation,
tesseract::WritingDirection *writing_direction,
tesseract::TextlineOrder *textline_order,
float *deskew_angle) const;
void Orientation(tesseract::Orientation* orientation,
tesseract::WritingDirection* writing_direction,
tesseract::TextlineOrder* textline_order,
float* deskew_angle) const;

/**
* Returns information about the current paragraph, if available.
Expand Down Expand Up @@ -305,16 +304,15 @@ class TESS_API PageIterator {
* first_line_indent for subsequent paragraphs in this block
* of text.
*/
void ParagraphInfo(tesseract::ParagraphJustification *justification,
bool *is_list_item,
bool *is_crown,
int *first_line_indent) const;
void ParagraphInfo(tesseract::ParagraphJustification* justification,
bool* is_list_item, bool* is_crown,
int* first_line_indent) const;

// If the current WERD_RES (it_->word()) is not nullptr, sets the BlamerBundle
// of the current word to the given pointer (takes ownership of the pointer)
// and returns true.
// Can only be used when iterating on the word level.
bool SetWordBlamerBundle(BlamerBundle *blamer_bundle);
bool SetWordBlamerBundle(BlamerBundle* blamer_bundle);

protected:
/**
Expand Down
Loading

0 comments on commit 90db9b5

Please sign in to comment.