diff --git a/src/ccstruct/blobs.h b/src/ccstruct/blobs.h index 02ae2e8839..a13a4d913c 100644 --- a/src/ccstruct/blobs.h +++ b/src/ccstruct/blobs.h @@ -28,7 +28,7 @@ #include // for OcrEngineMode -#include // for int16_t +#include "tesstypes.h" // for TDimension struct Pix; @@ -46,8 +46,8 @@ class WERD; ----------------------------------------------------------------------*/ struct TPOINT { - TPOINT() : x(0), y(0) {} - TPOINT(int16_t vx, int16_t vy) : x(vx), y(vy) {} + TPOINT() = default; + TPOINT(TDimension vx, TDimension vy) : x(vx), y(vy) {} TPOINT(const ICOORD &ic) : x(ic.x()), y(ic.y()) {} void operator+=(const TPOINT &other) { @@ -86,8 +86,8 @@ struct TPOINT { return x * x + y * y; } - int16_t x; // absolute x coord. - int16_t y; // absolute y coord. + TDimension x = 0; // absolute x coord. + TDimension y = 0; // absolute y coord. }; using VECTOR = TPOINT; // structure for coordinates. diff --git a/src/ccstruct/mod128.cpp b/src/ccstruct/mod128.cpp index abebe296f4..27280cd716 100644 --- a/src/ccstruct/mod128.cpp +++ b/src/ccstruct/mod128.cpp @@ -20,7 +20,7 @@ namespace tesseract { -static const int16_t idirtab[] = { +static const TDimension 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, 831, 555, 803, 595, 773, 634, 740, 671, 707, 707, 671, 740, 634, 773, 595, 803, 555, 831, 514, 857, 471, diff --git a/src/ccstruct/ocrblock.cpp b/src/ccstruct/ocrblock.cpp index 8a7fa6fa1a..0ab809c59b 100644 --- a/src/ccstruct/ocrblock.cpp +++ b/src/ccstruct/ocrblock.cpp @@ -31,13 +31,14 @@ namespace tesseract { * * Constructor for a simple rectangular block. */ -BLOCK::BLOCK(const char *name, ///< filename - bool prop, ///< proportional - int16_t kern, ///< kerning - int16_t space, ///< spacing - int16_t xmin, ///< bottom left - int16_t ymin, int16_t xmax, ///< top right - int16_t ymax) +BLOCK::BLOCK(const char *name, ///< filename + bool prop, ///< proportional + int16_t kern, ///< kerning + int16_t space, ///< spacing + TDimension xmin, ///< bottom left + TDimension ymin, + TDimension xmax, ///< top right + TDimension ymax) : pdblk(xmin, ymin, xmax, ymax) , filename(name) , re_rotation_(1.0f, 0.0f) diff --git a/src/ccstruct/ocrblock.h b/src/ccstruct/ocrblock.h index bde794d9bc..88753b4b47 100644 --- a/src/ccstruct/ocrblock.h +++ b/src/ccstruct/ocrblock.h @@ -39,10 +39,10 @@ class TESS_API BLOCK : public ELIST_LINK bool prop, ///< proportional int16_t kern, ///< kerning int16_t space, ///< spacing - int16_t xmin, ///< bottom left - int16_t ymin, - int16_t xmax, ///< top right - int16_t ymax); + TDimension xmin, ///< bottom left + TDimension ymin, + TDimension xmax, ///< top right + TDimension ymax); ~BLOCK() = default; diff --git a/src/ccstruct/pdblock.cpp b/src/ccstruct/pdblock.cpp index 7ee76e6580..7cabb573ab 100644 --- a/src/ccstruct/pdblock.cpp +++ b/src/ccstruct/pdblock.cpp @@ -42,9 +42,10 @@ constexpr ERRCODE LOSTBLOCKLINE("Can't find rectangle for line"); * Constructor for a simple rectangular block. **********************************************************************/ PDBLK::PDBLK( // rectangular block - int16_t xmin, // bottom left - int16_t ymin, int16_t xmax, // top right - int16_t ymax) + TDimension xmin, // bottom left + TDimension ymin, + TDimension xmax, // top right + TDimension ymax) : box(ICOORD(xmin, ymin), ICOORD(xmax, ymax)) { // boundaries ICOORDELT_IT left_it = &leftside; @@ -349,9 +350,9 @@ void BLOCK_RECT_IT::forward() { // next rectangle * Get the the start and width of a line in the block. **********************************************************************/ -int16_t BLOCK_LINE_IT::get_line( // get a line - int16_t y, // line to get - int16_t &xext // output extent +TDimension BLOCK_LINE_IT::get_line( // get a line + TDimension y, // line to get + TDimension &xext // output extent ) { ICOORD bleft; // bounding box ICOORD tright; // of block & rect diff --git a/src/ccstruct/pdblock.h b/src/ccstruct/pdblock.h index b7b2b8dd69..f08bfbac29 100644 --- a/src/ccstruct/pdblock.h +++ b/src/ccstruct/pdblock.h @@ -41,10 +41,10 @@ class PDBLK { index_ = 0; } /// simple constructor - PDBLK(int16_t xmin, ///< bottom left - int16_t ymin, - int16_t xmax, ///< top right - int16_t ymax); + PDBLK(TDimension xmin, ///< bottom left + TDimension ymin, + TDimension xmax, ///< top right + TDimension ymax); /// set vertex lists ///@param left list of left vertices @@ -145,8 +145,8 @@ class BLOCK_RECT_IT // rectangle iterator } private: - int16_t ymin = 0; ///< bottom of rectangle - int16_t ymax = 0; ///< top of rectangle + TDimension ymin = 0; ///< bottom of rectangle + TDimension ymax = 0; ///< top of rectangle PDBLK *block = nullptr; ///< block to iterate ICOORDELT_IT left_it; ///< boundary iterators ICOORDELT_IT right_it; @@ -172,7 +172,7 @@ class BLOCK_LINE_IT { /// get a line ///@param y line to get ///@param xext output extent - int16_t get_line(int16_t y, int16_t &xext); + TDimension get_line(TDimension y, TDimension &xext); private: PDBLK *block; ///< block to iterate diff --git a/src/ccstruct/points.cpp b/src/ccstruct/points.cpp index 1e0375e740..d001953b33 100644 --- a/src/ccstruct/points.cpp +++ b/src/ccstruct/points.cpp @@ -40,12 +40,32 @@ bool FCOORD::normalise() { // Convert to unit vec return true; } +// Deserialize an ICOORD. +// For compatibility reasons it uses unsigned 16 bit coordinates +// instead of 32 bit coordinates. bool ICOORD::DeSerialize(TFile *f) { - return f->DeSerialize(&xcoord) && f->DeSerialize(&ycoord); + bool success = false; + uint16_t coord; + if (f->DeSerialize(&coord)) { + xcoord = coord; + if (f->DeSerialize(&coord)) { + ycoord = coord; + success = true; + } + } + return success; } +// Serialize an ICOORD. +// For compatibility reasons it uses unsigned 16 bit coordinates +// instead of 32 bit coordinates. bool ICOORD::Serialize(TFile *f) const { - return f->Serialize(&xcoord) && f->Serialize(&ycoord); + uint16_t coord; + coord = xcoord; + auto success = f->Serialize(&coord); + coord = ycoord; + success = success && f->Serialize(&coord); + return success; } // Set from the given x,y, shrinking the vector to fit if needed. diff --git a/src/ccstruct/points.h b/src/ccstruct/points.h index 61d1a162ef..c8c46ad161 100644 --- a/src/ccstruct/points.h +++ b/src/ccstruct/points.h @@ -21,6 +21,7 @@ #include "elst.h" #include "errcode.h" // for ASSERT_HOST +#include "tesstypes.h" // for TDimension #include // for DLLSYM @@ -43,7 +44,7 @@ class ICOORD { /// constructor ///@param xin x value ///@param yin y value - ICOORD(int16_t xin, int16_t yin) { + ICOORD(TDimension xin, TDimension yin) { xcoord = xin; ycoord = yin; } @@ -54,20 +55,20 @@ class ICOORD { bool Serialize(TFile *f) const; /// access function - int16_t x() const { + TDimension x() const { return xcoord; } /// access_function - int16_t y() const { + TDimension y() const { return ycoord; } /// rewrite function - void set_x(int16_t xin) { + void set_x(TDimension xin) { xcoord = xin; // write new value } /// rewrite function - void set_y(int16_t yin) { // value to set + void set_y(TDimension yin) { // value to set ycoord = yin; } @@ -128,15 +129,15 @@ class ICOORD { /// cross product friend int32_t operator*(const ICOORD &, const ICOORD &); /// multiply - friend ICOORD operator*(const ICOORD &, int16_t); + friend ICOORD operator*(const ICOORD &, TDimension); /// multiply - friend ICOORD operator*(int16_t, const ICOORD &); + friend ICOORD operator*(TDimension, const ICOORD &); /// multiply - friend ICOORD &operator*=(ICOORD &, int16_t); + friend ICOORD &operator*=(ICOORD &, TDimension); /// divide - friend ICOORD operator/(const ICOORD &, int16_t); + friend ICOORD operator/(const ICOORD &, TDimension); /// divide - friend ICOORD &operator/=(ICOORD &, int16_t); + friend ICOORD &operator/=(ICOORD &, TDimension); /// rotate ///@param vec by vector void rotate(const FCOORD &vec); @@ -155,8 +156,8 @@ class ICOORD { bool DeSerialize(bool swap, FILE *fp); protected: - int16_t xcoord; ///< x value - int16_t ycoord; ///< y value + TDimension xcoord; ///< x value + TDimension ycoord; ///< y value }; class ICOORDELT : public ELIST_LINK, @@ -171,7 +172,7 @@ class ICOORDELT : public ELIST_LINK, /// constructor ///@param xin x value ///@param yin y value - ICOORDELT(int16_t xin, int16_t yin) { + ICOORDELT(TDimension xin, TDimension yin) { xcoord = xin; ycoord = yin; } @@ -438,7 +439,7 @@ inline int32_t operator*( // cross product inline ICOORD operator*( // scalar multiply const ICOORD &op1, // operands - int16_t scale) { + TDimension scale) { ICOORD result; // output result.xcoord = op1.xcoord * scale; @@ -447,7 +448,7 @@ inline ICOORD operator*( // scalar multiply } inline ICOORD operator*( // scalar multiply - int16_t scale, + TDimension scale, const ICOORD &op1 // operands ) { ICOORD result; // output @@ -465,7 +466,7 @@ inline ICOORD operator*( // scalar multiply inline ICOORD &operator*=( // scalar multiply ICOORD &op1, // operands - int16_t scale) { + TDimension scale) { op1.xcoord *= scale; op1.ycoord *= scale; return op1; @@ -479,7 +480,7 @@ inline ICOORD &operator*=( // scalar multiply inline ICOORD operator/( // scalar divide const ICOORD &op1, // operands - int16_t scale) { + TDimension scale) { ICOORD result; // output result.xcoord = op1.xcoord / scale; @@ -495,7 +496,7 @@ inline ICOORD operator/( // scalar divide inline ICOORD &operator/=( // scalar divide ICOORD &op1, // operands - int16_t scale) { + TDimension scale) { op1.xcoord /= scale; op1.ycoord /= scale; return op1; @@ -509,8 +510,8 @@ inline ICOORD &operator/=( // scalar divide inline void ICOORD::rotate( // rotate by vector const FCOORD &vec) { - auto tmp = static_cast(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f)); - ycoord = static_cast(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f)); + auto tmp = static_cast(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f)); + ycoord = static_cast(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f)); xcoord = tmp; } diff --git a/src/ccstruct/polyblk.cpp b/src/ccstruct/polyblk.cpp index a7125445f5..8c21fd8dc0 100644 --- a/src/ccstruct/polyblk.cpp +++ b/src/ccstruct/polyblk.cpp @@ -198,8 +198,8 @@ void POLY_BLOCK::rotate(FCOORD rotation) { pos.set_x(pt->x()); pos.set_y(pt->y()); pos.rotate(rotation); - pt->set_x(static_cast(floor(pos.x() + 0.5))); - pt->set_y(static_cast(floor(pos.y() + 0.5))); + pt->set_x(static_cast(floor(pos.x() + 0.5))); + pt->set_y(static_cast(floor(pos.y() + 0.5))); pts.forward(); } while (!pts.at_first()); compute_bb(); @@ -270,15 +270,12 @@ void POLY_BLOCK::plot(ScrollView *window, int32_t num) { } void POLY_BLOCK::fill(ScrollView *window, ScrollView::Color colour) { - int16_t y; - int16_t width; - PB_LINE_IT *lines; ICOORDELT_IT s_it; - lines = new PB_LINE_IT(this); + std::unique_ptr lines(new PB_LINE_IT(this)); window->Pen(colour); - for (y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) { + for (auto y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) { const std::unique_ptr segments(lines->get_line(y)); if (!segments->empty()) { s_it.set_to_list(segments.get()); @@ -286,14 +283,12 @@ void POLY_BLOCK::fill(ScrollView *window, ScrollView::Color colour) { // Note different use of ICOORDELT, x coord is x coord of pixel // at the start of line segment, y coord is length of line segment // Last pixel is start pixel + length. - width = s_it.data()->y(); + auto width = s_it.data()->y(); window->SetCursor(s_it.data()->x(), y); window->DrawTo(s_it.data()->x() + static_cast(width), y); } } } - - delete lines; } #endif @@ -339,7 +334,7 @@ bool POLY_BLOCK::overlap(POLY_BLOCK *other) { return false; } -ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) { +ICOORDELT_LIST *PB_LINE_IT::get_line(TDimension y) { ICOORDELT_IT v, r; ICOORDELT_LIST *result; ICOORDELT *x, *current, *previous; @@ -356,7 +351,7 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) { float fx = 0.5f + previous->x() + (current->x() - previous->x()) * (fy - previous->y()) / (current->y() - previous->y()); - x = new ICOORDELT(static_cast(fx), 0); + x = new ICOORDELT(static_cast(fx), 0); r.add_to_end(x); } } diff --git a/src/ccstruct/polyblk.h b/src/ccstruct/polyblk.h index eeb3aa0481..e302993a00 100644 --- a/src/ccstruct/polyblk.h +++ b/src/ccstruct/polyblk.h @@ -106,7 +106,7 @@ class PB_LINE_IT { // Each element of the returned list is the start (x) and extent(y) of // a run inside the region. // Delete the returned list after use. - ICOORDELT_LIST *get_line(int16_t y); + ICOORDELT_LIST *get_line(TDimension y); private: POLY_BLOCK *block; diff --git a/src/ccstruct/rect.cpp b/src/ccstruct/rect.cpp index 9948859581..e7bee86384 100644 --- a/src/ccstruct/rect.cpp +++ b/src/ccstruct/rect.cpp @@ -83,10 +83,10 @@ void TBOX::rotate_large(const FCOORD &vec) { TBOX TBOX::intersection( // shared area box const TBOX &box) const { - int16_t left; - int16_t bottom; - int16_t right; - int16_t top; + TDimension left; + TDimension bottom; + TDimension right; + TDimension top; if (overlap(box)) { if (box.bot_left.x() > bot_left.x()) { left = box.bot_left.x(); diff --git a/src/ccstruct/rect.h b/src/ccstruct/rect.h index 9917c94c4d..ab4f57beb5 100644 --- a/src/ccstruct/rect.h +++ b/src/ccstruct/rect.h @@ -21,6 +21,7 @@ #include "points.h" // for ICOORD, FCOORD #include "scrollview.h" // for ScrollView, ScrollView::Color +#include "tesstypes.h" // for TDimension #include "tprintf.h" // for tprintf #include // for DLLSYM @@ -50,7 +51,7 @@ class TESS_API TBOX { // bounding box // in the right order. //********************************************************************* TBOX( // constructor - int16_t left, int16_t bottom, int16_t right, int16_t top) + TDimension left, TDimension bottom, TDimension right, TDimension top) : bot_left(left, bottom), top_right(right, top) {} TBOX( // box around FCOORD @@ -64,28 +65,28 @@ class TESS_API TBOX { // bounding box return bot_left == other.bot_left && top_right == other.top_right; } - int16_t top() const { // coord of top + TDimension top() const { // coord of top return top_right.y(); } void set_top(int y) { top_right.set_y(y); } - int16_t bottom() const { // coord of bottom + TDimension bottom() const { // coord of bottom return bot_left.y(); } void set_bottom(int y) { bot_left.set_y(y); } - int16_t left() const { // coord of left + TDimension left() const { // coord of left return bot_left.x(); } void set_left(int x) { bot_left.set_x(x); } - int16_t right() const { // coord of right + TDimension right() const { // coord of right return top_right.x(); } void set_right(int x) { @@ -114,7 +115,7 @@ class TESS_API TBOX { // bounding box return top_right; } - int16_t height() const { // how high is it? + TDimension height() const { // how high is it? if (!null_box()) { return top_right.y() - bot_left.y(); } else { @@ -122,7 +123,7 @@ class TESS_API TBOX { // bounding box } } - int16_t width() const { // how high is it? + TDimension width() const { // how high is it? if (!null_box()) { return top_right.x() - bot_left.x(); } else { @@ -147,22 +148,22 @@ class TESS_API TBOX { // bounding box } void move_bottom_edge( // move one edge - const int16_t y) { // by +/- y + const TDimension y) { // by +/- y bot_left += ICOORD(0, y); } void move_left_edge( // move one edge - const int16_t x) { // by +/- x + const TDimension x) { // by +/- x bot_left += ICOORD(x, 0); } void move_right_edge( // move one edge - const int16_t x) { // by +/- x + const TDimension x) { // by +/- x top_right += ICOORD(x, 0); } void move_top_edge( // move one edge - const int16_t y) { // by +/- y + const TDimension y) { // by +/- y top_right += ICOORD(0, y); } @@ -174,33 +175,33 @@ class TESS_API TBOX { // bounding box void move( // move box const FCOORD vec) { // by float vector - bot_left.set_x(static_cast(std::floor(bot_left.x() + vec.x()))); + bot_left.set_x(static_cast(std::floor(bot_left.x() + vec.x()))); // round left - bot_left.set_y(static_cast(std::floor(bot_left.y() + vec.y()))); + bot_left.set_y(static_cast(std::floor(bot_left.y() + vec.y()))); // round down - top_right.set_x(static_cast(std::ceil(top_right.x() + vec.x()))); + top_right.set_x(static_cast(std::ceil(top_right.x() + vec.x()))); // round right - top_right.set_y(static_cast(std::ceil(top_right.y() + vec.y()))); + top_right.set_y(static_cast(std::ceil(top_right.y() + vec.y()))); // round up } void scale( // scale box const float f) { // by multiplier // round left - bot_left.set_x(static_cast(std::floor(bot_left.x() * f))); + bot_left.set_x(static_cast(std::floor(bot_left.x() * f))); // round down - bot_left.set_y(static_cast(std::floor(bot_left.y() * f))); + bot_left.set_y(static_cast(std::floor(bot_left.y() * f))); // round right - top_right.set_x(static_cast(std::ceil(top_right.x() * f))); + top_right.set_x(static_cast(std::ceil(top_right.x() * f))); // round up - top_right.set_y(static_cast(std::ceil(top_right.y() * f))); + top_right.set_y(static_cast(std::ceil(top_right.y() * f))); } void scale( // scale box const FCOORD vec) { // by float vector - bot_left.set_x(static_cast(std::floor(bot_left.x() * vec.x()))); - bot_left.set_y(static_cast(std::floor(bot_left.y() * vec.y()))); - top_right.set_x(static_cast(std::ceil(top_right.x() * vec.x()))); - top_right.set_y(static_cast(std::ceil(top_right.y() * vec.y()))); + bot_left.set_x(static_cast(std::floor(bot_left.x() * vec.x()))); + bot_left.set_y(static_cast(std::floor(bot_left.y() * vec.y()))); + top_right.set_x(static_cast(std::ceil(top_right.x() * vec.x()))); + top_right.set_y(static_cast(std::ceil(top_right.y() * vec.y()))); } // rotate doesn't enlarge the box - it just rotates the bottom-left @@ -330,9 +331,9 @@ inline TBOX::TBOX( // constructor const FCOORD pt // floating centre ) { bot_left = - ICOORD(static_cast(std::floor(pt.x())), static_cast(std::floor(pt.y()))); + ICOORD(static_cast(std::floor(pt.x())), static_cast(std::floor(pt.y()))); top_right = - ICOORD(static_cast(std::ceil(pt.x())), static_cast(std::ceil(pt.y()))); + ICOORD(static_cast(std::ceil(pt.x())), static_cast(std::ceil(pt.y()))); } /********************************************************************** @@ -416,7 +417,7 @@ inline bool TBOX::x_overlap(const TBOX &box) const { **********************************************************************/ inline bool TBOX::major_x_overlap(const TBOX &box) const { - int16_t overlap = box.width(); + TDimension overlap = box.width(); if (this->left() > box.left()) { overlap -= this->left() - box.left(); } @@ -442,7 +443,7 @@ inline bool TBOX::y_overlap(const TBOX &box) const { **********************************************************************/ inline bool TBOX::major_y_overlap(const TBOX &box) const { - int16_t overlap = box.height(); + TDimension overlap = box.height(); if (this->bottom() > box.bottom()) { overlap -= this->bottom() - box.bottom(); } diff --git a/src/ccutil/tesstypes.h b/src/ccutil/tesstypes.h index 390fa32667..326d4c52d8 100644 --- a/src/ccutil/tesstypes.h +++ b/src/ccutil/tesstypes.h @@ -17,12 +17,16 @@ #ifndef TESSERACT_TESSTYPES_H #define TESSERACT_TESSTYPES_H -#include // for int16_t +#include // for int16_t, int32_t namespace tesseract { // Image dimensions (width and height, coordinates). +#if defined(LARGE_IMAGES) +using TDimension = int32_t; +#else using TDimension = int16_t; +#endif // Floating point data type used for LSTM calculations. #if defined(FAST_FLOAT) diff --git a/src/textord/blkocc.cpp b/src/textord/blkocc.cpp index 9ad8d8342c..9ffc1a2a13 100644 --- a/src/textord/blkocc.cpp +++ b/src/textord/blkocc.cpp @@ -50,16 +50,11 @@ bool test_underline( // look for underlines int16_t baseline, ///< coords of baseline int16_t xheight ///< height of line ) { - int16_t occ; - int16_t blob_width; // width of blob - TBOX blob_box; // bounding box - int32_t desc_occ; - int32_t x_occ; - int32_t asc_occ; + TDimension occ; STATS projection; - blob_box = blob->bounding_box(); - blob_width = blob->bounding_box().width(); + auto blob_box = blob->bounding_box(); + auto blob_width = blob->bounding_box().width(); projection.set_range(blob_box.bottom(), blob_box.top() + 1); if (testing_on) { // blob->plot(to_win,GOLDENROD,GOLDENROD); @@ -73,21 +68,21 @@ bool test_underline( // look for underlines blob->bounding_box().right(), blob->bounding_box().top(), baseline); } horizontal_cblob_projection(blob, &projection); - desc_occ = 0; + TDimension desc_occ = 0; for (occ = blob_box.bottom(); occ < baseline; occ++) { if (occ <= blob_box.top() && projection.pile_count(occ) > desc_occ) { // max in region desc_occ = projection.pile_count(occ); } } - x_occ = 0; + TDimension x_occ = 0; for (occ = baseline; occ <= baseline + xheight; occ++) { if (occ >= blob_box.bottom() && occ <= blob_box.top() && projection.pile_count(occ) > x_occ) { // max in region x_occ = projection.pile_count(occ); } } - asc_occ = 0; + TDimension asc_occ = 0; for (occ = baseline + xheight + 1; occ <= blob_box.top(); occ++) { if (occ >= blob_box.bottom() && projection.pile_count(occ) > asc_occ) { asc_occ = projection.pile_count(occ); diff --git a/src/textord/edgblob.cpp b/src/textord/edgblob.cpp index 26b6d22510..ee3e1560f4 100644 --- a/src/textord/edgblob.cpp +++ b/src/textord/edgblob.cpp @@ -77,8 +77,8 @@ OL_BUCKETS::OL_BUCKETS(ICOORD bleft, // corners */ C_OUTLINE_LIST *OL_BUCKETS::operator()( // array access - int16_t x, // image coords - int16_t y) { + TDimension x, // image coords + TDimension y) { return &buckets[(y - bl.y()) / BUCKETSIZE * bxdim + (x - bl.x()) / BUCKETSIZE]; } @@ -122,9 +122,8 @@ int32_t OL_BUCKETS::outline_complexity(C_OUTLINE *outline, // parent outline int32_t max_count, // max output int16_t depth // recurion depth ) { - int16_t xmin, xmax; // coord limits - int16_t ymin, ymax; - int16_t xindex, yindex; // current bucket + TDimension xmin, xmax; // coord limits + TDimension ymin, ymax; C_OUTLINE *child; // current child int32_t child_count; // no of children int32_t grandchild_count; // no of grandchildren @@ -141,8 +140,8 @@ int32_t OL_BUCKETS::outline_complexity(C_OUTLINE *outline, // parent outline return max_count + depth; } - for (yindex = ymin; yindex <= ymax; yindex++) { - for (xindex = xmin; xindex <= xmax; xindex++) { + for (auto yindex = ymin; yindex <= ymax; yindex++) { + for (auto xindex = xmin; xindex <= xmax; xindex++) { child_it.set_to_list(&buckets[yindex * bxdim + xindex]); if (child_it.empty()) { continue; @@ -198,9 +197,8 @@ int32_t OL_BUCKETS::count_children( // recursive count int32_t max_count // max output ) { bool parent_box; // could it be boxy - int16_t xmin, xmax; // coord limits - int16_t ymin, ymax; - int16_t xindex, yindex; // current bucket + TDimension xmin, xmax; // coord limits + TDimension ymin, ymax; C_OUTLINE *child; // current child int32_t child_count; // no of children int32_t grandchild_count; // no of grandchildren @@ -221,8 +219,8 @@ int32_t OL_BUCKETS::count_children( // recursive count parent_area = 0; max_parent_area = 0; parent_box = true; - for (yindex = ymin; yindex <= ymax; yindex++) { - for (xindex = xmin; xindex <= xmax; xindex++) { + for (auto yindex = ymin; yindex <= ymax; yindex++) { + for (auto xindex = xmin; xindex <= xmax; xindex++) { child_it.set_to_list(&buckets[yindex * bxdim + xindex]); if (child_it.empty()) { continue; @@ -321,9 +319,8 @@ void OL_BUCKETS::extract_children( // recursive count C_OUTLINE *outline, // parent outline C_OUTLINE_IT *it // destination iterator ) { - int16_t xmin, xmax; // coord limits - int16_t ymin, ymax; - int16_t xindex, yindex; // current bucket + TDimension xmin, xmax; // coord limits + TDimension ymin, ymax; TBOX olbox; C_OUTLINE_IT child_it; // search iterator @@ -332,8 +329,8 @@ void OL_BUCKETS::extract_children( // recursive count xmax = (olbox.right() - bl.x()) / BUCKETSIZE; ymin = (olbox.bottom() - bl.y()) / BUCKETSIZE; ymax = (olbox.top() - bl.y()) / BUCKETSIZE; - for (yindex = ymin; yindex <= ymax; yindex++) { - for (xindex = xmin; xindex <= xmax; xindex++) { + for (auto yindex = ymin; yindex <= ymax; yindex++) { + for (auto xindex = xmin; xindex <= xmax; xindex++) { child_it.set_to_list(&buckets[yindex * bxdim + xindex]); for (child_it.mark_cycle_pt(); !child_it.cycled_list(); child_it.forward()) { diff --git a/src/textord/edgblob.h b/src/textord/edgblob.h index c3db12be08..949e12e863 100644 --- a/src/textord/edgblob.h +++ b/src/textord/edgblob.h @@ -34,8 +34,8 @@ class OL_BUCKETS { ICOORD tright); C_OUTLINE_LIST *operator()( // array access - int16_t x, // image coords - int16_t y); + TDimension x, // image coords + TDimension y); // first non-empty bucket C_OUTLINE_LIST *start_scan(); // next non-empty bucket diff --git a/src/textord/scanedg.cpp b/src/textord/scanedg.cpp index 6c18bdd76c..d416695c1b 100644 --- a/src/textord/scanedg.cpp +++ b/src/textord/scanedg.cpp @@ -44,11 +44,11 @@ static void free_crackedges(CRACKEDGE *start); static void join_edges(CRACKEDGE *edge1, CRACKEDGE *edge2, CRACKEDGE **free_cracks, C_OUTLINE_IT *outline_it); -static void line_edges(int16_t x, int16_t y, int16_t xext, uint8_t uppercolour, uint8_t *bwpos, +static void line_edges(TDimension x, TDimension y, TDimension xext, uint8_t uppercolour, uint8_t *bwpos, CRACKEDGE **prevline, CRACKEDGE **free_cracks, C_OUTLINE_IT *outline_it); static void make_margins(PDBLK *block, BLOCK_LINE_IT *line_it, uint8_t *pixels, uint8_t margin, - int16_t left, int16_t right, int16_t y); + TDimension left, TDimension right, TDimension y); static CRACKEDGE *h_edge(int sign, CRACKEDGE *join, CrackPos *pos); static CRACKEDGE *v_edge(int sign, CRACKEDGE *join, CrackPos *pos); @@ -114,14 +114,11 @@ static void make_margins( // get a line BLOCK_LINE_IT *line_it, // for old style uint8_t *pixels, // pixels to strip uint8_t margin, // white-out pixel - int16_t left, // block edges - int16_t right, - int16_t y // line coord + TDimension left, // block edges + TDimension right, + TDimension y // line coord ) { ICOORDELT_IT seg_it; - int32_t start; // of segment - int16_t xext; // of segment - int xindex; // index to pixel if (block->poly_block() != nullptr) { std::unique_ptr lines(new PB_LINE_IT(block->poly_block())); @@ -129,9 +126,9 @@ static void make_margins( // get a line if (!segments->empty()) { seg_it.set_to_list(segments.get()); seg_it.mark_cycle_pt(); - start = seg_it.data()->x(); - xext = seg_it.data()->y(); - for (xindex = left; xindex < right; xindex++) { + auto start = seg_it.data()->x(); + auto xext = seg_it.data()->y(); + for (auto xindex = left; xindex < right; xindex++) { if (xindex >= start && !seg_it.cycled_list()) { xindex = start + xext - 1; seg_it.forward(); @@ -142,16 +139,17 @@ static void make_margins( // get a line } } } else { - for (xindex = left; xindex < right; xindex++) { + for (auto xindex = left; xindex < right; xindex++) { pixels[xindex - left] = margin; } } } else { - start = line_it->get_line(y, xext); - for (xindex = left; xindex < start; xindex++) { + TDimension xext; // of segment + auto start = line_it->get_line(y, xext); + for (auto xindex = left; xindex < start; xindex++) { pixels[xindex - left] = margin; } - for (xindex = start + xext; xindex < right; xindex++) { + for (auto xindex = start + xext; xindex < right; xindex++) { pixels[xindex - left] = margin; } } @@ -164,9 +162,9 @@ static void make_margins( // get a line * When edges close into loops, send them for approximation. **********************************************************************/ -static void line_edges(int16_t x, // coord of line start - int16_t y, // coord of line - int16_t xext, // width of line +static void line_edges(TDimension x, // coord of line start + TDimension y, // coord of line + TDimension xext, // width of line uint8_t uppercolour, // start of prev line uint8_t *bwpos, // thresholded line CRACKEDGE **prevline, // edges in progress diff --git a/src/textord/tordmain.cpp b/src/textord/tordmain.cpp index 3e44fead2b..69812680b7 100644 --- a/src/textord/tordmain.cpp +++ b/src/textord/tordmain.cpp @@ -209,12 +209,8 @@ void assign_blobs_to_blocks2(Image pix, **********************************************************************/ void Textord::find_components(Image pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *to_blocks) { - int width = pixGetWidth(pix); - int height = pixGetHeight(pix); - if (width > INT16_MAX || height > INT16_MAX) { - tprintf("Input image too large! (%d, %d)\n", width, height); - return; // Can't handle it. - } + auto width = pixGetWidth(pix); + auto height = pixGetHeight(pix); BLOCK_IT block_it(blocks); // iterator for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) { diff --git a/src/textord/underlin.cpp b/src/textord/underlin.cpp index 8af534cf77..8d5abe2495 100644 --- a/src/textord/underlin.cpp +++ b/src/textord/underlin.cpp @@ -162,7 +162,6 @@ void find_underlined_blobs( // get chop points float baseline_offset, // amount to shrinke it ICOORDELT_LIST *chop_cells // places to chop ) { - int16_t x, y; // sides of blob ICOORD blob_chop; // sides of blob TBOX blob_box = u_line->bounding_box(); // cell iterator @@ -180,9 +179,10 @@ void find_underlined_blobs( // get chop points &middle_proj, &upper_proj); } - for (x = blob_box.left(); x < blob_box.right(); x++) { + for (auto x = blob_box.left(); x < blob_box.right(); x++) { if (middle_proj.pile_count(x) > 0) { - for (y = x + 1; y < blob_box.right() && middle_proj.pile_count(y) > 0; y++) { + auto y = x + 1; + for (; y < blob_box.right() && middle_proj.pile_count(y) > 0; y++) { ; } blob_chop = ICOORD(x, y);