Skip to content

Commit eb8f13b

Browse files
committed
Support image width and height larger than 32767
Signed-off-by: Stefan Weil <[email protected]>
1 parent 93348a8 commit eb8f13b

15 files changed

+121
-134
lines changed

Diff for: 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 <cstdint> // for int32_t
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(int32_t vx, int32_t 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+
int32_t x = 0; // absolute x coord.
90+
int32_t y = 0; // absolute y coord.
9191
};
9292

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

Diff for: src/ccstruct/mod128.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* File: mod128.cpp (Formerly dir128.c)
33
* Description: Code to convert a DIR128 to an ICOORD.
4-
* Author: Ray Smith
4+
* Author: Ray Smith
55
*
66
* (C) Copyright 1991, Hewlett-Packard Ltd.
77
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@
2020

2121
namespace tesseract {
2222

23-
static const int16_t idirtab[] = {
23+
static const int32_t idirtab[] = {
2424
1000, 0, 998, 49, 995, 98, 989, 146, 980, 195, 970, 242, 956, 290, 941,
2525
336, 923, 382, 903, 427, 881, 471, 857, 514, 831, 555, 803, 595, 773, 634,
2626
740, 671, 707, 707, 671, 740, 634, 773, 595, 803, 555, 831, 514, 857, 471,

Diff for: src/ccstruct/ocrblock.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ BLOCK::BLOCK(const char *name, ///< filename
3535
bool prop, ///< proportional
3636
int16_t kern, ///< kerning
3737
int16_t space, ///< spacing
38-
int16_t xmin, ///< bottom left
39-
int16_t ymin, int16_t xmax, ///< top right
40-
int16_t ymax)
38+
int32_t xmin, ///< bottom left
39+
int32_t ymin, int32_t xmax, ///< top right
40+
int32_t ymax)
4141
: pdblk(xmin, ymin, xmax, ymax)
4242
, filename(name)
4343
, re_rotation_(1.0f, 0.0f)

Diff for: 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+
int32_t xmin, ///< bottom left
43+
int32_t ymin,
44+
int32_t xmax, ///< top right
45+
int32_t ymax);
4646

4747
~BLOCK() = default;
4848

Diff for: 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+
int32_t xmin, // bottom left
46+
int32_t ymin,
47+
int32_t xmax, // top right
48+
int32_t 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+
int32_t BLOCK_LINE_IT::get_line( // get a line
354+
int32_t y, // line to get
355+
int32_t &xext // output extent
355356
) {
356357
ICOORD bleft; // bounding box
357358
ICOORD tright; // of block & rect

Diff for: 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(int32_t xmin, ///< bottom left
45+
int32_t ymin,
46+
int32_t xmax, ///< top right
47+
int32_t 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+
int32_t ymin = 0; ///< bottom of rectangle
149+
int32_t 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+
int32_t get_line(int32_t y, int32_t &xext);
176176

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

Diff for: src/ccstruct/points.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ICOORD {
4343
/// constructor
4444
///@param xin x value
4545
///@param yin y value
46-
ICOORD(int16_t xin, int16_t yin) {
46+
ICOORD(int32_t xin, int32_t yin) {
4747
xcoord = xin;
4848
ycoord = yin;
4949
}
@@ -54,20 +54,20 @@ class ICOORD {
5454
bool Serialize(TFile *f) const;
5555

5656
/// access function
57-
int16_t x() const {
57+
int32_t x() const {
5858
return xcoord;
5959
}
6060
/// access_function
61-
int16_t y() const {
61+
int32_t y() const {
6262
return ycoord;
6363
}
6464

6565
/// rewrite function
66-
void set_x(int16_t xin) {
66+
void set_x(int32_t xin) {
6767
xcoord = xin; // write new value
6868
}
6969
/// rewrite function
70-
void set_y(int16_t yin) { // value to set
70+
void set_y(int32_t yin) { // value to set
7171
ycoord = yin;
7272
}
7373

@@ -128,15 +128,15 @@ class ICOORD {
128128
/// cross product
129129
friend int32_t operator*(const ICOORD &, const ICOORD &);
130130
/// multiply
131-
friend ICOORD operator*(const ICOORD &, int16_t);
131+
friend ICOORD operator*(const ICOORD &, int32_t);
132132
/// multiply
133-
friend ICOORD operator*(int16_t, const ICOORD &);
133+
friend ICOORD operator*(int32_t, const ICOORD &);
134134
/// multiply
135-
friend ICOORD &operator*=(ICOORD &, int16_t);
135+
friend ICOORD &operator*=(ICOORD &, int32_t);
136136
/// divide
137-
friend ICOORD operator/(const ICOORD &, int16_t);
137+
friend ICOORD operator/(const ICOORD &, int32_t);
138138
/// divide
139-
friend ICOORD &operator/=(ICOORD &, int16_t);
139+
friend ICOORD &operator/=(ICOORD &, int32_t);
140140
/// rotate
141141
///@param vec by vector
142142
void rotate(const FCOORD &vec);
@@ -155,8 +155,8 @@ class ICOORD {
155155
bool DeSerialize(bool swap, FILE *fp);
156156

157157
protected:
158-
int16_t xcoord; ///< x value
159-
int16_t ycoord; ///< y value
158+
int32_t xcoord; ///< x value
159+
int32_t ycoord; ///< y value
160160
};
161161

162162
class ICOORDELT : public ELIST_LINK,
@@ -171,7 +171,7 @@ class ICOORDELT : public ELIST_LINK,
171171
/// constructor
172172
///@param xin x value
173173
///@param yin y value
174-
ICOORDELT(int16_t xin, int16_t yin) {
174+
ICOORDELT(int32_t xin, int32_t yin) {
175175
xcoord = xin;
176176
ycoord = yin;
177177
}
@@ -438,7 +438,7 @@ inline int32_t operator*( // cross product
438438

439439
inline ICOORD operator*( // scalar multiply
440440
const ICOORD &op1, // operands
441-
int16_t scale) {
441+
int32_t scale) {
442442
ICOORD result; // output
443443

444444
result.xcoord = op1.xcoord * scale;
@@ -447,7 +447,7 @@ inline ICOORD operator*( // scalar multiply
447447
}
448448

449449
inline ICOORD operator*( // scalar multiply
450-
int16_t scale,
450+
int32_t scale,
451451
const ICOORD &op1 // operands
452452
) {
453453
ICOORD result; // output
@@ -465,7 +465,7 @@ inline ICOORD operator*( // scalar multiply
465465

466466
inline ICOORD &operator*=( // scalar multiply
467467
ICOORD &op1, // operands
468-
int16_t scale) {
468+
int32_t scale) {
469469
op1.xcoord *= scale;
470470
op1.ycoord *= scale;
471471
return op1;
@@ -479,7 +479,7 @@ inline ICOORD &operator*=( // scalar multiply
479479

480480
inline ICOORD operator/( // scalar divide
481481
const ICOORD &op1, // operands
482-
int16_t scale) {
482+
int32_t scale) {
483483
ICOORD result; // output
484484

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

496496
inline ICOORD &operator/=( // scalar divide
497497
ICOORD &op1, // operands
498-
int16_t scale) {
498+
int32_t scale) {
499499
op1.xcoord /= scale;
500500
op1.ycoord /= scale;
501501
return op1;
@@ -509,8 +509,8 @@ inline ICOORD &operator/=( // scalar divide
509509

510510
inline void ICOORD::rotate( // rotate by vector
511511
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));
512+
auto tmp = static_cast<int32_t>(std::floor(xcoord * vec.x() - ycoord * vec.y() + 0.5f));
513+
ycoord = static_cast<int32_t>(std::floor(ycoord * vec.x() + xcoord * vec.y() + 0.5f));
514514
xcoord = tmp;
515515
}
516516

Diff for: 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<int32_t>(floor(pos.x() + 0.5)));
202+
pt->set_y(static_cast<int32_t>(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(int32_t 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<int32_t>(fx), 0);
360355
r.add_to_end(x);
361356
}
362357
}

Diff for: 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(int32_t y);
110110

111111
private:
112112
POLY_BLOCK *block;

Diff for: 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+
int32_t left;
87+
int32_t bottom;
88+
int32_t right;
89+
int32_t 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)