Skip to content

Commit 687c9a4

Browse files
committed
Fix build error caused by ambiguous ClipToRange
Error message vom Appveyor CI: C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj] C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj] c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange' C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char' C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int' Signed-off-by: Stefan Weil <[email protected]>
1 parent 3530ea4 commit 687c9a4

File tree

8 files changed

+30
-34
lines changed

8 files changed

+30
-34
lines changed

ccmain/control.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1955,8 +1955,8 @@ void Tesseract::set_word_fonts(WERD_RES *word) {
19551955
word->fontinfo2 = font_id2 >= 0 ? &fontinfo_table_.get(font_id2) : NULL;
19561956
// Each score has a limit of UINT16_MAX, so divide by that to get the number
19571957
// of "votes" for that font, ie number of perfect scores.
1958-
word->fontinfo_id_count = ClipToRange(score1 / UINT16_MAX, 1, INT8_MAX);
1959-
word->fontinfo_id2_count = ClipToRange(score2 / UINT16_MAX, 0, INT8_MAX);
1958+
word->fontinfo_id_count = ClipToRange<int>(score1 / UINT16_MAX, 1, INT8_MAX);
1959+
word->fontinfo_id2_count = ClipToRange<int>(score2 / UINT16_MAX, 0, INT8_MAX);
19601960
if (score1 > 0) {
19611961
FontInfo fi = fontinfo_table_.get(font_id1);
19621962
if (tessedit_debug_fonts) {

ccstruct/coutln.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,8 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
806806
(best_x - x) * best_diff;
807807
}
808808
offsets[s].offset_numerator =
809-
static_cast<int8_t>(ClipToRange(offset, -INT8_MAX, INT8_MAX));
810-
offsets[s].pixel_diff = static_cast<uint8_t>(ClipToRange(best_diff, 0 ,
811-
UINT8_MAX));
809+
ClipToRange<int>(offset, -INT8_MAX, INT8_MAX);
810+
offsets[s].pixel_diff = ClipToRange<int>(best_diff, 0, UINT8_MAX);
812811
if (negative) gradient = -gradient;
813812
// Compute gradient angle quantized to 256 directions, rotated by 64 (pi/2)
814813
// to convert from gradient direction to edge direction.
@@ -891,9 +890,8 @@ void C_OUTLINE::ComputeBinaryOffsets() {
891890
offset = pos_totals[dir_index] - best_diff * edge_pos;
892891
}
893892
offsets[s].offset_numerator =
894-
static_cast<int8_t>(ClipToRange(offset, -INT8_MAX, INT8_MAX));
895-
offsets[s].pixel_diff = static_cast<uint8_t>(ClipToRange(best_diff, 0 ,
896-
UINT8_MAX));
893+
ClipToRange<int>(offset, -INT8_MAX, INT8_MAX);
894+
offsets[s].pixel_diff = ClipToRange<int>(best_diff, 0, UINT8_MAX);
897895
// The direction is just the vector from start to end of the window.
898896
FCOORD direction(head_pos.x() - tail_pos.x(), head_pos.y() - tail_pos.y());
899897
offsets[s].direction = direction.to_direction();

ccstruct/imagedata.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ WordFeature::WordFeature() : x_(0), y_(0), dir_(0) {
4747

4848
WordFeature::WordFeature(const FCOORD& fcoord, uint8_t dir)
4949
: x_(IntCastRounded(fcoord.x())),
50-
y_(ClipToRange(IntCastRounded(fcoord.y()), 0, UINT8_MAX)),
50+
y_(ClipToRange<int>(IntCastRounded(fcoord.y()), 0, UINT8_MAX)),
5151
dir_(dir) {
5252
}
5353

ccutil/unicharset.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,13 @@ class UNICHARSET {
543543
int min_bottom, int max_bottom,
544544
int min_top, int max_top) {
545545
unichars[unichar_id].properties.min_bottom =
546-
static_cast<uint8_t>(ClipToRange(min_bottom, 0, UINT8_MAX));
546+
ClipToRange<int>(min_bottom, 0, UINT8_MAX);
547547
unichars[unichar_id].properties.max_bottom =
548-
static_cast<uint8_t>(ClipToRange(max_bottom, 0, UINT8_MAX));
548+
ClipToRange<int>(max_bottom, 0, UINT8_MAX);
549549
unichars[unichar_id].properties.min_top =
550-
static_cast<uint8_t>(ClipToRange(min_top, 0, UINT8_MAX));
550+
ClipToRange<int>(min_top, 0, UINT8_MAX);
551551
unichars[unichar_id].properties.max_top =
552-
static_cast<uint8_t>(ClipToRange(max_top, 0, UINT8_MAX));
552+
ClipToRange<int>(max_top, 0, UINT8_MAX);
553553
}
554554
// Returns the width stats (as mean, sd) of the given unichar relative to the
555555
// median advance of all characters in the character set.

classify/intproto.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(const FCOORD& pos, uint8_t theta)
215215
}
216216
/** Builds a feature from ints with all the necessary clipping and casting. */
217217
INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(int x, int y, int theta)
218-
: X(static_cast<uint8_t>(ClipToRange(x, 0, UINT8_MAX))),
219-
Y(static_cast<uint8_t>(ClipToRange(y, 0, UINT8_MAX))),
220-
Theta(static_cast<uint8_t>(ClipToRange(theta, 0, UINT8_MAX))),
218+
: X(static_cast<uint8_t>(ClipToRange<int>(x, 0, UINT8_MAX))),
219+
Y(static_cast<uint8_t>(ClipToRange<int>(y, 0, UINT8_MAX))),
220+
Theta(static_cast<uint8_t>(ClipToRange<int>(theta, 0, UINT8_MAX))),
221221
CP_misses(0) {
222222
}
223223

@@ -434,11 +434,11 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
434434
*/
435435
uint8_t Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets) {
436436
int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
437-
return static_cast<uint8_t>(ClipToRange(bucket, 0, num_buckets - 1));
437+
return static_cast<uint8_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
438438
}
439439
uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets) {
440440
int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
441-
return static_cast<uint16_t>(ClipToRange(bucket, 0, num_buckets - 1));
441+
return static_cast<uint16_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
442442
}
443443

444444
/**

classify/trainingsample.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,10 @@ TrainingSample* TrainingSample::RandomizedCopy(int index) const {
168168
for (int i = 0; i < num_features_; ++i) {
169169
double result = (features_[i].X - kRandomizingCenter) * scaling;
170170
result += kRandomizingCenter;
171-
sample->features_[i].X = ClipToRange(static_cast<int>(result + 0.5), 0,
172-
UINT8_MAX);
171+
sample->features_[i].X = ClipToRange<int>(result + 0.5, 0, UINT8_MAX);
173172
result = (features_[i].Y - kRandomizingCenter) * scaling;
174173
result += kRandomizingCenter + yshift;
175-
sample->features_[i].Y = ClipToRange(static_cast<int>(result + 0.5), 0,
176-
UINT8_MAX);
174+
sample->features_[i].Y = ClipToRange<int>(result + 0.5, 0, UINT8_MAX);
177175
}
178176
}
179177
return sample;

lstm/networkio.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void NetworkIO::Copy1DGreyImage(int batch, Pix* pix, float black,
275275
void NetworkIO::SetPixel(int t, int f, int pixel, float black, float contrast) {
276276
float float_pixel = (pixel - black) / contrast - 1.0f;
277277
if (int_mode_) {
278-
i_[t][f] = ClipToRange(IntCastRounded((INT8_MAX + 1) * float_pixel),
278+
i_[t][f] = ClipToRange<int>(IntCastRounded((INT8_MAX + 1) * float_pixel),
279279
-INT8_MAX, INT8_MAX);
280280
} else {
281281
f_[t][f] = float_pixel;
@@ -306,12 +306,12 @@ Pix* NetworkIO::ToPix() const {
306306
for (int y = 0; y < num_features; ++y, im_y += im_height) {
307307
int pixel = features[y * feature_factor];
308308
// 1 or 2 features use greyscale.
309-
int red = ClipToRange(pixel + 128, 0, 255);
309+
int red = ClipToRange<int>(pixel + 128, 0, 255);
310310
int green = red, blue = red;
311311
if (feature_factor == 3) {
312312
// With 3 features assume RGB color.
313-
green = ClipToRange(features[y * feature_factor + 1] + 128, 0, 255);
314-
blue = ClipToRange(features[y * feature_factor + 2] + 128, 0, 255);
313+
green = ClipToRange<int>(features[y * feature_factor + 1] + 128, 0, 255);
314+
blue = ClipToRange<int>(features[y * feature_factor + 2] + 128, 0, 255);
315315
} else if (num_features > 3) {
316316
// More than 3 features use false yellow/blue color, assuming a signed
317317
// input in the range [-1,1].
@@ -333,18 +333,18 @@ Pix* NetworkIO::ToPix() const {
333333
for (int y = 0; y < num_features; ++y, im_y += im_height) {
334334
float pixel = features[y * feature_factor];
335335
// 1 or 2 features use greyscale.
336-
int red = ClipToRange(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
336+
int red = ClipToRange<int>(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
337337
int green = red, blue = red;
338338
if (feature_factor == 3) {
339339
// With 3 features assume RGB color.
340340
pixel = features[y * feature_factor + 1];
341-
green = ClipToRange(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
341+
green = ClipToRange<int>(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
342342
pixel = features[y * feature_factor + 2];
343-
blue = ClipToRange(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
343+
blue = ClipToRange<int>(IntCastRounded((pixel + 1.0f) * 127.5f), 0, 255);
344344
} else if (num_features > 3) {
345345
// More than 3 features use false yellow/blue color, assuming a signed
346346
// input in the range [-1,1].
347-
red = ClipToRange(IntCastRounded(fabs(pixel) * 255), 0, 255);
347+
red = ClipToRange<int>(IntCastRounded(fabs(pixel) * 255), 0, 255);
348348
if (pixel >= 0) {
349349
green = red;
350350
blue = 0;
@@ -653,8 +653,8 @@ void NetworkIO::WriteTimeStepPart(int t, int offset, int num_features,
653653
if (int_mode_) {
654654
int8_t* line = i_[t] + offset;
655655
for (int i = 0; i < num_features; ++i) {
656-
line[i] = ClipToRange(IntCastRounded(input[i] * INT8_MAX),
657-
-INT8_MAX, INT8_MAX);
656+
line[i] = ClipToRange<int>(IntCastRounded(input[i] * INT8_MAX),
657+
-INT8_MAX, INT8_MAX);
658658
}
659659
} else {
660660
float* line = f_[t] + offset;
@@ -973,7 +973,7 @@ void NetworkIO::ClipVector(int t, float range) {
973973
float* v = f_[t];
974974
int dim = f_.dim2();
975975
for (int i = 0; i < dim; ++i)
976-
v[i] = ClipToRange(v[i], -range, range);
976+
v[i] = ClipToRange<float>(v[i], -range, range);
977977
}
978978

979979
} // namespace tesseract.

textord/tospace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ BOOL8 Textord::make_a_word_break(
13351335
int num_blanks = current_gap;
13361336
if (row->space_size > 1.0f)
13371337
num_blanks = IntCastRounded(current_gap / row->space_size);
1338-
blanks = static_cast<uint8_t>(ClipToRange(num_blanks, 1, UINT8_MAX));
1338+
blanks = static_cast<uint8_t>(ClipToRange<int>(num_blanks, 1, UINT8_MAX));
13391339
fuzzy_sp = FALSE;
13401340
fuzzy_non = FALSE;
13411341
/*

0 commit comments

Comments
 (0)