Skip to content

Commit 59fbad0

Browse files
committed
Prepare support for image width and height larger than 32767
Avoid using int16_t and use a new data type TDimension where needed. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 56f54c2 commit 59fbad0

16 files changed

+138
-145
lines changed

src/ccstruct/blobs.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include <tesseract/publictypes.h> // for OcrEngineMode
3030

31-
#include <cstdint> // for int16_t
31+
#include "tesstypes.h" // for TDimension
3232

3333
struct Pix;
3434

@@ -46,8 +46,8 @@ class WERD;
4646
----------------------------------------------------------------------*/
4747

4848
struct TPOINT {
49-
TPOINT() : x(0), y(0) {}
50-
TPOINT(int16_t vx, int16_t vy) : x(vx), y(vy) {}
49+
TPOINT() = default;
50+
TPOINT(TDimension vx, TDimension vy) : x(vx), y(vy) {}
5151
TPOINT(const ICOORD &ic) : x(ic.x()), y(ic.y()) {}
5252

5353
void operator+=(const TPOINT &other) {
@@ -86,8 +86,8 @@ struct TPOINT {
8686
return x * x + y * y;
8787
}
8888

89-
int16_t x; // absolute x coord.
90-
int16_t y; // absolute y coord.
89+
TDimension x = 0; // absolute x coord.
90+
TDimension y = 0; // absolute y coord.
9191
};
9292

9393
using VECTOR = TPOINT; // structure for coordinates.

src/ccstruct/ocrblock.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ namespace tesseract {
3131
*
3232
* Constructor for a simple rectangular block.
3333
*/
34-
BLOCK::BLOCK(const char *name, ///< filename
35-
bool prop, ///< proportional
36-
int16_t kern, ///< kerning
37-
int16_t space, ///< spacing
38-
int16_t xmin, ///< bottom left
39-
int16_t ymin, int16_t xmax, ///< top right
40-
int16_t ymax)
34+
BLOCK::BLOCK(const char *name, ///< filename
35+
bool prop, ///< proportional
36+
int16_t kern, ///< kerning
37+
int16_t space, ///< spacing
38+
TDimension xmin, ///< bottom left
39+
TDimension ymin,
40+
TDimension xmax, ///< top right
41+
TDimension ymax)
4142
: pdblk(xmin, ymin, xmax, ymax)
4243
, filename(name)
4344
, re_rotation_(1.0f, 0.0f)

src/ccstruct/ocrblock.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class TESS_API BLOCK : public ELIST_LINK
3939
bool prop, ///< proportional
4040
int16_t kern, ///< kerning
4141
int16_t space, ///< spacing
42-
int16_t xmin, ///< bottom left
43-
int16_t ymin,
44-
int16_t xmax, ///< top right
45-
int16_t ymax);
42+
TDimension xmin, ///< bottom left
43+
TDimension ymin,
44+
TDimension xmax, ///< top right
45+
TDimension ymax);
4646

4747
~BLOCK() = default;
4848

src/ccstruct/pdblock.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ constexpr ERRCODE LOSTBLOCKLINE("Can't find rectangle for line");
4242
* Constructor for a simple rectangular block.
4343
**********************************************************************/
4444
PDBLK::PDBLK( // rectangular block
45-
int16_t xmin, // bottom left
46-
int16_t ymin, int16_t xmax, // top right
47-
int16_t ymax)
45+
TDimension xmin, // bottom left
46+
TDimension ymin,
47+
TDimension xmax, // top right
48+
TDimension ymax)
4849
: box(ICOORD(xmin, ymin), ICOORD(xmax, ymax)) {
4950
// boundaries
5051
ICOORDELT_IT left_it = &leftside;
@@ -349,9 +350,9 @@ void BLOCK_RECT_IT::forward() { // next rectangle
349350
* Get the the start and width of a line in the block.
350351
**********************************************************************/
351352

352-
int16_t BLOCK_LINE_IT::get_line( // get a line
353-
int16_t y, // line to get
354-
int16_t &xext // output extent
353+
TDimension BLOCK_LINE_IT::get_line( // get a line
354+
TDimension y, // line to get
355+
TDimension &xext // output extent
355356
) {
356357
ICOORD bleft; // bounding box
357358
ICOORD tright; // of block & rect

src/ccstruct/pdblock.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class PDBLK {
4141
index_ = 0;
4242
}
4343
/// simple constructor
44-
PDBLK(int16_t xmin, ///< bottom left
45-
int16_t ymin,
46-
int16_t xmax, ///< top right
47-
int16_t ymax);
44+
PDBLK(TDimension xmin, ///< bottom left
45+
TDimension ymin,
46+
TDimension xmax, ///< top right
47+
TDimension ymax);
4848

4949
/// set vertex lists
5050
///@param left list of left vertices
@@ -145,8 +145,8 @@ class BLOCK_RECT_IT // rectangle iterator
145145
}
146146

147147
private:
148-
int16_t ymin = 0; ///< bottom of rectangle
149-
int16_t ymax = 0; ///< top of rectangle
148+
TDimension ymin = 0; ///< bottom of rectangle
149+
TDimension ymax = 0; ///< top of rectangle
150150
PDBLK *block = nullptr; ///< block to iterate
151151
ICOORDELT_IT left_it; ///< boundary iterators
152152
ICOORDELT_IT right_it;
@@ -172,7 +172,7 @@ class BLOCK_LINE_IT {
172172
/// get a line
173173
///@param y line to get
174174
///@param xext output extent
175-
int16_t get_line(int16_t y, int16_t &xext);
175+
TDimension get_line(TDimension y, TDimension &xext);
176176

177177
private:
178178
PDBLK *block; ///< block to iterate

src/ccstruct/points.h

+21-20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "elst.h"
2323
#include "errcode.h" // for ASSERT_HOST
24+
#include "tesstypes.h" // for TDimension
2425

2526
#include <tesseract/export.h> // for DLLSYM
2627

@@ -43,7 +44,7 @@ class ICOORD {
4344
/// constructor
4445
///@param xin x value
4546
///@param yin y value
46-
ICOORD(int16_t xin, int16_t yin) {
47+
ICOORD(TDimension xin, TDimension yin) {
4748
xcoord = xin;
4849
ycoord = yin;
4950
}
@@ -54,20 +55,20 @@ class ICOORD {
5455
bool Serialize(TFile *f) const;
5556

5657
/// access function
57-
int16_t x() const {
58+
TDimension x() const {
5859
return xcoord;
5960
}
6061
/// access_function
61-
int16_t y() const {
62+
TDimension y() const {
6263
return ycoord;
6364
}
6465

6566
/// rewrite function
66-
void set_x(int16_t xin) {
67+
void set_x(TDimension xin) {
6768
xcoord = xin; // write new value
6869
}
6970
/// rewrite function
70-
void set_y(int16_t yin) { // value to set
71+
void set_y(TDimension yin) { // value to set
7172
ycoord = yin;
7273
}
7374

@@ -128,15 +129,15 @@ class ICOORD {
128129
/// cross product
129130
friend int32_t operator*(const ICOORD &, const ICOORD &);
130131
/// multiply
131-
friend ICOORD operator*(const ICOORD &, int16_t);
132+
friend ICOORD operator*(const ICOORD &, TDimension);
132133
/// multiply
133-
friend ICOORD operator*(int16_t, const ICOORD &);
134+
friend ICOORD operator*(TDimension, const ICOORD &);
134135
/// multiply
135-
friend ICOORD &operator*=(ICOORD &, int16_t);
136+
friend ICOORD &operator*=(ICOORD &, TDimension);
136137
/// divide
137-
friend ICOORD operator/(const ICOORD &, int16_t);
138+
friend ICOORD operator/(const ICOORD &, TDimension);
138139
/// divide
139-
friend ICOORD &operator/=(ICOORD &, int16_t);
140+
friend ICOORD &operator/=(ICOORD &, TDimension);
140141
/// rotate
141142
///@param vec by vector
142143
void rotate(const FCOORD &vec);
@@ -155,8 +156,8 @@ class ICOORD {
155156
bool DeSerialize(bool swap, FILE *fp);
156157

157158
protected:
158-
int16_t xcoord; ///< x value
159-
int16_t ycoord; ///< y value
159+
TDimension xcoord; ///< x value
160+
TDimension ycoord; ///< y value
160161
};
161162

162163
class ICOORDELT : public ELIST_LINK,
@@ -171,7 +172,7 @@ class ICOORDELT : public ELIST_LINK,
171172
/// constructor
172173
///@param xin x value
173174
///@param yin y value
174-
ICOORDELT(int16_t xin, int16_t yin) {
175+
ICOORDELT(TDimension xin, TDimension yin) {
175176
xcoord = xin;
176177
ycoord = yin;
177178
}
@@ -438,7 +439,7 @@ inline int32_t operator*( // cross product
438439

439440
inline ICOORD operator*( // scalar multiply
440441
const ICOORD &op1, // operands
441-
int16_t scale) {
442+
TDimension scale) {
442443
ICOORD result; // output
443444

444445
result.xcoord = op1.xcoord * scale;
@@ -447,7 +448,7 @@ inline ICOORD operator*( // scalar multiply
447448
}
448449

449450
inline ICOORD operator*( // scalar multiply
450-
int16_t scale,
451+
TDimension scale,
451452
const ICOORD &op1 // operands
452453
) {
453454
ICOORD result; // output
@@ -465,7 +466,7 @@ inline ICOORD operator*( // scalar multiply
465466

466467
inline ICOORD &operator*=( // scalar multiply
467468
ICOORD &op1, // operands
468-
int16_t scale) {
469+
TDimension scale) {
469470
op1.xcoord *= scale;
470471
op1.ycoord *= scale;
471472
return op1;
@@ -479,7 +480,7 @@ inline ICOORD &operator*=( // scalar multiply
479480

480481
inline ICOORD operator/( // scalar divide
481482
const ICOORD &op1, // operands
482-
int16_t scale) {
483+
TDimension scale) {
483484
ICOORD result; // output
484485

485486
result.xcoord = op1.xcoord / scale;
@@ -495,7 +496,7 @@ inline ICOORD operator/( // scalar divide
495496

496497
inline ICOORD &operator/=( // scalar divide
497498
ICOORD &op1, // operands
498-
int16_t scale) {
499+
TDimension scale) {
499500
op1.xcoord /= scale;
500501
op1.ycoord /= scale;
501502
return op1;
@@ -509,8 +510,8 @@ inline ICOORD &operator/=( // scalar divide
509510

510511
inline void ICOORD::rotate( // rotate by vector
511512
const FCOORD &vec) {
512-
auto tmp = static_cast<int16_t>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
513-
ycoord = static_cast<int16_t>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
513+
auto tmp = static_cast<TDimension>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
514+
ycoord = static_cast<TDimension>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
514515
xcoord = tmp;
515516
}
516517

src/ccstruct/polyblk.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ void POLY_BLOCK::rotate(FCOORD rotation) {
198198
pos.set_x(pt->x());
199199
pos.set_y(pt->y());
200200
pos.rotate(rotation);
201-
pt->set_x(static_cast<int16_t>(floor(pos.x() + 0.5)));
202-
pt->set_y(static_cast<int16_t>(floor(pos.y() + 0.5)));
201+
pt->set_x(static_cast<TDimension>(floor(pos.x() + 0.5)));
202+
pt->set_y(static_cast<TDimension>(floor(pos.y() + 0.5)));
203203
pts.forward();
204204
} while (!pts.at_first());
205205
compute_bb();
@@ -270,30 +270,25 @@ void POLY_BLOCK::plot(ScrollView *window, int32_t num) {
270270
}
271271

272272
void POLY_BLOCK::fill(ScrollView *window, ScrollView::Color colour) {
273-
int16_t y;
274-
int16_t width;
275-
PB_LINE_IT *lines;
276273
ICOORDELT_IT s_it;
277274

278-
lines = new PB_LINE_IT(this);
275+
std::unique_ptr<PB_LINE_IT> lines(new PB_LINE_IT(this));
279276
window->Pen(colour);
280277

281-
for (y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) {
278+
for (auto y = this->bounding_box()->bottom(); y <= this->bounding_box()->top(); y++) {
282279
const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments(lines->get_line(y));
283280
if (!segments->empty()) {
284281
s_it.set_to_list(segments.get());
285282
for (s_it.mark_cycle_pt(); !s_it.cycled_list(); s_it.forward()) {
286283
// Note different use of ICOORDELT, x coord is x coord of pixel
287284
// at the start of line segment, y coord is length of line segment
288285
// Last pixel is start pixel + length.
289-
width = s_it.data()->y();
286+
auto width = s_it.data()->y();
290287
window->SetCursor(s_it.data()->x(), y);
291288
window->DrawTo(s_it.data()->x() + static_cast<float>(width), y);
292289
}
293290
}
294291
}
295-
296-
delete lines;
297292
}
298293
#endif
299294

@@ -339,7 +334,7 @@ bool POLY_BLOCK::overlap(POLY_BLOCK *other) {
339334
return false;
340335
}
341336

342-
ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
337+
ICOORDELT_LIST *PB_LINE_IT::get_line(TDimension y) {
343338
ICOORDELT_IT v, r;
344339
ICOORDELT_LIST *result;
345340
ICOORDELT *x, *current, *previous;
@@ -356,7 +351,7 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(int16_t y) {
356351
float fx =
357352
0.5f + previous->x() +
358353
(current->x() - previous->x()) * (fy - previous->y()) / (current->y() - previous->y());
359-
x = new ICOORDELT(static_cast<int16_t>(fx), 0);
354+
x = new ICOORDELT(static_cast<TDimension>(fx), 0);
360355
r.add_to_end(x);
361356
}
362357
}

src/ccstruct/polyblk.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PB_LINE_IT {
106106
// Each element of the returned list is the start (x) and extent(y) of
107107
// a run inside the region.
108108
// Delete the returned list after use.
109-
ICOORDELT_LIST *get_line(int16_t y);
109+
ICOORDELT_LIST *get_line(TDimension y);
110110

111111
private:
112112
POLY_BLOCK *block;

src/ccstruct/rect.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void TBOX::rotate_large(const FCOORD &vec) {
8383

8484
TBOX TBOX::intersection( // shared area box
8585
const TBOX &box) const {
86-
int16_t left;
87-
int16_t bottom;
88-
int16_t right;
89-
int16_t top;
86+
TDimension left;
87+
TDimension bottom;
88+
TDimension right;
89+
TDimension top;
9090
if (overlap(box)) {
9191
if (box.bot_left.x() > bot_left.x()) {
9292
left = box.bot_left.x();

0 commit comments

Comments
 (0)