mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-03 00:49:01 +08:00
mfoutline: Modernize code
- Use C++ enums - Use strongly typed C++11 enum for DIRECTION and optimize struct MFEDGEPT - Use float constant for MF_SCALE_FACTOR - Replace macros by inline functions - Fix documentation comment This fixes several warnings from clang. Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
7ec5f0ca02
commit
672d67859f
@ -63,7 +63,7 @@ MFOUTLINE ConvertOutline(TESSLINE *outline) {
|
||||
if (EdgePoint->pos.x != NextPoint->pos.x ||
|
||||
EdgePoint->pos.y != NextPoint->pos.y) {
|
||||
NewPoint = NewEdgePoint();
|
||||
ClearMark(NewPoint);
|
||||
NewPoint->ClearMark();
|
||||
NewPoint->Hidden = EdgePoint->IsHidden();
|
||||
NewPoint->Point.x = EdgePoint->pos.x;
|
||||
NewPoint->Point.y = EdgePoint->pos.y;
|
||||
@ -192,7 +192,7 @@ void MarkDirectionChanges(MFOUTLINE Outline) {
|
||||
Last = First;
|
||||
do {
|
||||
Current = NextDirectionChange (Last);
|
||||
MarkPoint (PointAt (Current));
|
||||
PointAt(Current)->MarkPoint();
|
||||
Last = Current;
|
||||
}
|
||||
while (Last != First);
|
||||
@ -303,7 +303,8 @@ void Classify::NormalizeOutlines(LIST Outlines,
|
||||
* starts at Start and ends at End. Note that the previous
|
||||
* direction of End must also be changed to reflect the
|
||||
* change in direction of the point before it.
|
||||
* @param Start, End defines segment of outline to be modified
|
||||
* @param Start defines start of segment of outline to be modified
|
||||
* @param End defines end of segment of outline to be modified
|
||||
* @param Direction new direction to assign to segment
|
||||
*/
|
||||
void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction) {
|
||||
|
@ -26,12 +26,9 @@
|
||||
#include "oldlist.h"
|
||||
#include "params.h"
|
||||
|
||||
#define NORMAL_X_HEIGHT (0.5)
|
||||
#define NORMAL_BASELINE (0.0)
|
||||
|
||||
using MFOUTLINE = LIST;
|
||||
|
||||
typedef enum {
|
||||
enum DIRECTION : uint8_t {
|
||||
north,
|
||||
south,
|
||||
east,
|
||||
@ -40,39 +37,56 @@ typedef enum {
|
||||
northwest,
|
||||
southeast,
|
||||
southwest
|
||||
} DIRECTION;
|
||||
};
|
||||
|
||||
struct MFEDGEPT {
|
||||
// Inline functions for manipulating micro-feature outline edge points.
|
||||
|
||||
void ClearMark() {
|
||||
ExtremityMark = false;
|
||||
}
|
||||
|
||||
void MarkPoint() {
|
||||
ExtremityMark = true;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
FPOINT Point;
|
||||
float Slope;
|
||||
unsigned Padding : 20;
|
||||
bool Hidden : true;
|
||||
bool ExtremityMark : true;
|
||||
DIRECTION Direction : 4;
|
||||
DIRECTION PreviousDirection : 4;
|
||||
} MFEDGEPT;
|
||||
bool Hidden;
|
||||
bool ExtremityMark;
|
||||
DIRECTION Direction;
|
||||
DIRECTION PreviousDirection;
|
||||
};
|
||||
|
||||
typedef enum { outer, hole } OUTLINETYPE;
|
||||
enum OUTLINETYPE { outer, hole };
|
||||
|
||||
typedef enum { baseline, character } NORM_METHOD;
|
||||
enum NORM_METHOD { baseline, character };
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Macros
|
||||
----------------------------------------------------------------------------**/
|
||||
#define AverageOf(A, B) (((A) + (B)) / 2)
|
||||
|
||||
/* macro for computing the scale factor to use to normalize characters */
|
||||
#define MF_SCALE_FACTOR (NORMAL_X_HEIGHT / kBlnXHeight)
|
||||
// Constant for computing the scale factor to use to normalize characters.
|
||||
const float MF_SCALE_FACTOR = 0.5f / kBlnXHeight;
|
||||
|
||||
/* macros for manipulating micro-feature outlines */
|
||||
#define DegenerateOutline(O) (((O) == NIL_LIST) || ((O) == list_rest(O)))
|
||||
#define PointAt(O) ((MFEDGEPT*)first_node(O))
|
||||
#define NextPointAfter(E) (list_rest(E))
|
||||
#define MakeOutlineCircular(O) (set_rest(last(O), (O)))
|
||||
// Inline functions for manipulating micro-feature outlines.
|
||||
|
||||
/* macros for manipulating micro-feature outline edge points */
|
||||
#define ClearMark(P) ((P)->ExtremityMark = false)
|
||||
#define MarkPoint(P) ((P)->ExtremityMark = true)
|
||||
static inline bool DegenerateOutline(MFOUTLINE Outline) {
|
||||
return (Outline == NIL_LIST) || (Outline == list_rest(Outline));
|
||||
}
|
||||
|
||||
static inline MFEDGEPT* PointAt(MFOUTLINE Outline) {
|
||||
return reinterpret_cast<MFEDGEPT*>first_node(Outline);
|
||||
}
|
||||
|
||||
static inline MFOUTLINE NextPointAfter(MFOUTLINE Outline) {
|
||||
return list_rest(Outline);
|
||||
}
|
||||
|
||||
static inline void MakeOutlineCircular(MFOUTLINE Outline) {
|
||||
set_rest(last(Outline), Outline);
|
||||
}
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
|
Loading…
Reference in New Issue
Block a user