mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-06 01:04:57 +08:00
ocrclass: Modernize and format code
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
85957e9673
commit
1948f0d520
@ -26,9 +26,8 @@
|
||||
#ifndef CCUTIL_OCRCLASS_H_
|
||||
#define CCUTIL_OCRCLASS_H_
|
||||
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include "host.h"
|
||||
#include <ctime>
|
||||
|
||||
/**********************************************************************
|
||||
* EANYCODE_CHAR
|
||||
@ -54,26 +53,26 @@
|
||||
* version.
|
||||
**********************************************************************/
|
||||
|
||||
typedef struct { /*single character */
|
||||
// It should be noted that the format for char_code for version 2.0 and beyond
|
||||
// is UTF8 which means that ASCII characters will come out as one structure but
|
||||
// other characters will be returned in two or more instances of this structure
|
||||
// with a single byte of the UTF8 code in each, but each will have the same
|
||||
// bounding box. Programs which want to handle languagues with different
|
||||
// characters sets will need to handle extended characters appropriately, but
|
||||
// *all* code needs to be prepared to receive UTF8 coded characters for
|
||||
// characters such as bullet and fancy quotes.
|
||||
uint16_t char_code; /*character itself */
|
||||
int16_t left; /*of char (-1) */
|
||||
int16_t right; /*of char (-1) */
|
||||
int16_t top; /*of char (-1) */
|
||||
int16_t bottom; /*of char (-1) */
|
||||
int16_t font_index; /*what font (0) */
|
||||
uint8_t confidence; /*0=perfect, 100=reject (0/100) */
|
||||
uint8_t point_size; /*of char, 72=i inch, (10) */
|
||||
int8_t blanks; /*no of spaces before this char (1) */
|
||||
uint8_t formatting; /*char formatting (0) */
|
||||
} EANYCODE_CHAR; /*single character */
|
||||
typedef struct { /*single character */
|
||||
// It should be noted that the format for char_code for version 2.0 and beyond
|
||||
// is UTF8 which means that ASCII characters will come out as one structure
|
||||
// but other characters will be returned in two or more instances of this
|
||||
// structure with a single byte of the UTF8 code in each, but each will have
|
||||
// the same bounding box. Programs which want to handle languagues with
|
||||
// different characters sets will need to handle extended characters
|
||||
// appropriately, but *all* code needs to be prepared to receive UTF8 coded
|
||||
// characters for characters such as bullet and fancy quotes.
|
||||
uint16_t char_code; /*character itself */
|
||||
int16_t left; /*of char (-1) */
|
||||
int16_t right; /*of char (-1) */
|
||||
int16_t top; /*of char (-1) */
|
||||
int16_t bottom; /*of char (-1) */
|
||||
int16_t font_index; /*what font (0) */
|
||||
uint8_t confidence; /*0=perfect, 100=reject (0/100) */
|
||||
uint8_t point_size; /*of char, 72=i inch, (10) */
|
||||
int8_t blanks; /*no of spaces before this char (1) */
|
||||
uint8_t formatting; /*char formatting (0) */
|
||||
} EANYCODE_CHAR; /*single character */
|
||||
|
||||
/**********************************************************************
|
||||
* ETEXT_DESC
|
||||
@ -93,41 +92,31 @@ typedef struct { /*single character */
|
||||
**********************************************************************/
|
||||
class ETEXT_DESC;
|
||||
|
||||
typedef bool (*CANCEL_FUNC)(void* cancel_this, int words);
|
||||
typedef bool (*PROGRESS_FUNC)(int progress, int left, int right, int top,
|
||||
int bottom);
|
||||
typedef bool (*PROGRESS_FUNC2)(ETEXT_DESC* ths, int left, int right, int top,
|
||||
int bottom);
|
||||
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);
|
||||
|
||||
class ETEXT_DESC { // output header
|
||||
class ETEXT_DESC { // output header
|
||||
public:
|
||||
int16_t count; /// chars in this buffer(0)
|
||||
int16_t progress; /// percent complete increasing (0-100)
|
||||
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; /// true if not last
|
||||
volatile int8_t ocr_alive; /// ocr sets to 1, HP 0
|
||||
int8_t err_code; /// for errcode use
|
||||
CANCEL_FUNC cancel; /// returns true to cancel
|
||||
PROGRESS_FUNC progress_callback; /// called whenever progress increases
|
||||
PROGRESS_FUNC2 progress_callback2;/// monitor-aware progress callback
|
||||
void* cancel_this; /// 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
|
||||
* 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
|
||||
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
|
||||
|
||||
ETEXT_DESC()
|
||||
: count(0),
|
||||
progress(0),
|
||||
more_to_come(0),
|
||||
ocr_alive(0),
|
||||
err_code(0),
|
||||
cancel(nullptr),
|
||||
progress_callback(nullptr),
|
||||
progress_callback2(&default_progress_func),
|
||||
cancel_this(nullptr) {
|
||||
ETEXT_DESC() : progress_callback2(&default_progress_func) {
|
||||
end_time = std::chrono::time_point<std::chrono::steady_clock,
|
||||
std::chrono::milliseconds>();
|
||||
}
|
||||
@ -136,29 +125,29 @@ class ETEXT_DESC { // output header
|
||||
void set_deadline_msecs(int32_t deadline_msecs) {
|
||||
if (deadline_msecs > 0) {
|
||||
end_time = std::chrono::steady_clock::now() +
|
||||
std::chrono::milliseconds(deadline_msecs);
|
||||
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())
|
||||
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)
|
||||
{
|
||||
if (ths->progress_callback) {
|
||||
return (*(ths->progress_callback))(ths->progress, left, right, top, 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 true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // CCUTIL_OCRCLASS_H_
|
||||
|
Loading…
Reference in New Issue
Block a user