Commit 98cc2d7d for tesseract
commit 98cc2d7d58ca58511f7561ddd4804f8a5e5f3e6f
Author: Stefan Weil <sw@weilnetz.de>
Date: Thu Jun 4 14:55:20 2026 +0200
Replace C-casts and code using `(void)`
Assisted-by: OpenCode / BigPickle
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp
index 3b31b65a..89e2f669 100644
--- a/src/api/baseapi.cpp
+++ b/src/api/baseapi.cpp
@@ -225,7 +225,7 @@ bool TessBaseAPI::GetIntVariable(const char *name, int *value) const {
if (p == nullptr) {
return false;
}
- *value = (int32_t)(*p);
+ *value = static_cast<int32_t>(*p);
return true;
}
@@ -251,7 +251,7 @@ bool TessBaseAPI::GetDoubleVariable(const char *name, double *value) const {
if (p == nullptr) {
return false;
}
- *value = (double)(*p);
+ *value = static_cast<double>(*p);
return true;
}
@@ -527,7 +527,7 @@ void TessBaseAPI::SetImage(Pix *pix) {
// remove alpha channel from png
Pix *p1 = pixRemoveAlpha(pix);
pixSetSpp(p1, 3);
- (void)pixCopy(pix, p1);
+ static_cast<void>(pixCopy(pix, p1));
pixDestroy(&p1);
}
thresholder_->SetImage(pix);
diff --git a/src/ccmain/osdetect.cpp b/src/ccmain/osdetect.cpp
index 55b38825..3a1071ae 100644
--- a/src/ccmain/osdetect.cpp
+++ b/src/ccmain/osdetect.cpp
@@ -112,7 +112,7 @@ int OSResults::get_best_script(int orientation_id) const {
}
// Print the script scores for all possible orientations.
-void OSResults::print_scores(void) const {
+void OSResults::print_scores() const {
for (int i = 0; i < 4; ++i) {
tprintf("Orientation id #%d", i);
print_scores(i);
diff --git a/src/ccmain/pgedit.cpp b/src/ccmain/pgedit.cpp
index 27f9b215..ccf85699 100644
--- a/src/ccmain/pgedit.cpp
+++ b/src/ccmain/pgedit.cpp
@@ -778,10 +778,10 @@ bool Tesseract::word_display(PAGE_RES_IT *pr_it) {
// display bounding box
if (word->display_flag(DF_BOX)) {
word->bounding_box().plot(image_win,
- static_cast<ScrollView::Color>((int32_t)editor_image_word_bb_color),
- static_cast<ScrollView::Color>((int32_t)editor_image_word_bb_color));
+ static_cast<ScrollView::Color>(static_cast<int32_t>(editor_image_word_bb_color)),
+ static_cast<ScrollView::Color>(static_cast<int32_t>(editor_image_word_bb_color)));
- auto c = static_cast<ScrollView::Color>((int32_t)editor_image_blob_bb_color);
+ auto c = static_cast<ScrollView::Color>(static_cast<int32_t>(editor_image_blob_bb_color));
image_win->Pen(c);
// cblob iterator
C_BLOB_IT c_it(word->cblob_list());
@@ -859,8 +859,8 @@ bool Tesseract::word_display(PAGE_RES_IT *pr_it) {
if (!displayed_something) { // display BBox anyway
word->bounding_box().plot(image_win,
- static_cast<ScrollView::Color>((int32_t)editor_image_word_bb_color),
- static_cast<ScrollView::Color>((int32_t)editor_image_word_bb_color));
+ static_cast<ScrollView::Color>(static_cast<int32_t>(editor_image_word_bb_color)),
+ static_cast<ScrollView::Color>(static_cast<int32_t>(editor_image_word_bb_color)));
}
return true;
}
diff --git a/src/ccmain/resultiterator.cpp b/src/ccmain/resultiterator.cpp
index 1fe45842..f0a7d675 100644
--- a/src/ccmain/resultiterator.cpp
+++ b/src/ccmain/resultiterator.cpp
@@ -43,7 +43,7 @@ ResultIterator::ResultIterator(const LTRResultIterator &resit) : LTRResultIterat
auto *p = ParamUtils::FindParam<BoolParam>(
"preserve_interword_spaces", GlobalParams()->bool_params, tesseract_->params()->bool_params);
if (p != nullptr) {
- preserve_interword_spaces_ = (bool)(*p);
+ preserve_interword_spaces_ = static_cast<bool>(*p);
}
current_paragraph_is_ltr_ = CurrentParagraphIsLtr();
@@ -781,7 +781,7 @@ bool ResultIterator::BidiDebug(int min_level) const {
auto *p = ParamUtils::FindParam<IntParam>("bidi_debug", GlobalParams()->int_params,
tesseract_->params()->int_params);
if (p != nullptr) {
- debug_level = (int32_t)(*p);
+ debug_level = static_cast<int32_t>(*p);
}
return debug_level >= min_level;
}
diff --git a/src/ccmain/thresholder.cpp b/src/ccmain/thresholder.cpp
index 20c73649..0ace8a1d 100644
--- a/src/ccmain/thresholder.cpp
+++ b/src/ccmain/thresholder.cpp
@@ -242,8 +242,8 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
}
r = pixSauvolaBinarizeTiled(pix_grey, half_window_size, kfactor, nx, ny,
- (PIX**)pix_thresholds,
- (PIX**)pix_binary);
+ static_cast<PIX **>(pix_thresholds),
+ static_cast<PIX **>(pix_binary));
} else { // if (method == ThresholdMethod::LeptonicaOtsu)
int tile_size;
double tile_size_factor;
@@ -269,8 +269,8 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
r = pixOtsuAdaptiveThreshold(pix_grey, tile_size, tile_size,
half_smooth_size, half_smooth_size,
score_fraction,
- (PIX**)pix_thresholds,
- (PIX**)pix_binary);
+ static_cast<PIX **>(pix_thresholds),
+ static_cast<PIX **>(pix_binary));
}
bool ok = (r == 0);
diff --git a/src/ccstruct/ratngs.cpp b/src/ccstruct/ratngs.cpp
index 502ec4f4..9cd8093a 100644
--- a/src/ccstruct/ratngs.cpp
+++ b/src/ccstruct/ratngs.cpp
@@ -433,7 +433,7 @@ void WERD_CHOICE::string_and_lengths(std::string *word_str, std::string *word_le
const char *ch = unicharset_->id_to_unichar_ext(unichar_ids_[i]);
*word_str += ch;
if (word_lengths_str != nullptr) {
- *word_lengths_str += (char)strlen(ch);
+ *word_lengths_str += static_cast<char>(strlen(ch));
}
}
}
diff --git a/src/ccutil/params.cpp b/src/ccutil/params.cpp
index c4e087f0..3be34f4e 100644
--- a/src/ccutil/params.cpp
+++ b/src/ccutil/params.cpp
@@ -168,7 +168,7 @@ void ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
for (int v = 0; v < num_iterations; ++v) {
const ParamsVectors *vec = (v == 0) ? GlobalParams() : member_params;
for (auto int_param : vec->int_params) {
- stream << int_param->name_str() << '\t' << (int32_t)(*int_param) << '\t'
+ stream << int_param->name_str() << '\t' << static_cast<int32_t>(*int_param) << '\t'
<< int_param->info_str() << '\n';
}
for (auto bool_param : vec->bool_params) {
@@ -180,7 +180,7 @@ void ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
<< string_param->info_str() << '\n';
}
for (auto double_param : vec->double_params) {
- stream << double_param->name_str() << '\t' << (double)(*double_param) << '\t'
+ stream << double_param->name_str() << '\t' << static_cast<double>(*double_param) << '\t'
<< double_param->info_str() << '\n';
}
}
diff --git a/src/classify/fpoint.h b/src/classify/fpoint.h
index 2b273954..69f13d0d 100644
--- a/src/classify/fpoint.h
+++ b/src/classify/fpoint.h
@@ -38,7 +38,7 @@ using FVECTOR = FPOINT;
#define XDelta(A, B) ((B).x - (A).x)
#define YDelta(A, B) ((B).y - (A).y)
#define SlopeFrom(A, B) (YDelta(A, B) / XDelta(A, B))
-#define AngleFrom(A, B) (atan2((double)YDelta(A, B), (double)XDelta(A, B)))
+#define AngleFrom(A, B) (atan2(static_cast<double>(YDelta(A, B)), static_cast<double>(XDelta(A, B))))
#define XIntersectionOf(A, B, X) (SlopeFrom(A, B) * ((X)-A.x) + A.y)
diff --git a/src/classify/mf.cpp b/src/classify/mf.cpp
index 000c78cc..d56bb111 100644
--- a/src/classify/mf.cpp
+++ b/src/classify/mf.cpp
@@ -51,11 +51,11 @@ FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm) {
for (auto &f : features) {
auto Feature = new FEATURE_STRUCT(&MicroFeatureDesc);
- for (int i = 0; i < (int)MicroFeatureParameter::MFCount; ++i)
+ for (int i = 0; i < static_cast<int>(MicroFeatureParameter::MFCount); ++i)
Feature->Params[i] = f[i];
// Bulge features are deprecated and should not be used. Set to 0.
- Feature->Params[(int)MicroFeatureParameter::MFBulge1] = 0.0f;
- Feature->Params[(int)MicroFeatureParameter::MFBulge2] = 0.0f;
+ Feature->Params[static_cast<int>(MicroFeatureParameter::MFBulge1)] = 0.0f;
+ Feature->Params[static_cast<int>(MicroFeatureParameter::MFBulge2)] = 0.0f;
#ifndef _WIN32
// Assert that feature parameters are well defined.
diff --git a/src/classify/mfdefs.h b/src/classify/mfdefs.h
index 38ef2502..0820da67 100644
--- a/src/classify/mfdefs.h
+++ b/src/classify/mfdefs.h
@@ -33,7 +33,7 @@ enum class MicroFeatureParameter {
MFCount // For array sizes.
};
-using MicroFeature = std::array<float, (int)MicroFeatureParameter::MFCount>;
+using MicroFeature = std::array<float, static_cast<int>(MicroFeatureParameter::MFCount)>;
using MICROFEATURES = std::forward_list<MicroFeature>;
} // namespace tesseract
diff --git a/src/classify/mfx.cpp b/src/classify/mfx.cpp
index 93ea6d54..1058e076 100644
--- a/src/classify/mfx.cpp
+++ b/src/classify/mfx.cpp
@@ -131,12 +131,12 @@ MicroFeature ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End) {
P2 = PointAt(End);
MicroFeature NewFeature;
- NewFeature[(int)MicroFeatureParameter::MFXPosition] = AverageOf(P1->Point.x, P2->Point.x);
- NewFeature[(int)MicroFeatureParameter::MFYPosition] = AverageOf(P1->Point.y, P2->Point.y);
- NewFeature[(int)MicroFeatureParameter::MFLength] = DistanceBetween(P1->Point, P2->Point);
- NewFeature[(int)MicroFeatureParameter::MFDirection] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
- NewFeature[(int)MicroFeatureParameter::MFBulge1] = 0.0f; // deprecated
- NewFeature[(int)MicroFeatureParameter::MFBulge2] = 0.0f; // deprecated
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFXPosition)] = AverageOf(P1->Point.x, P2->Point.x);
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFYPosition)] = AverageOf(P1->Point.y, P2->Point.y);
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFLength)] = DistanceBetween(P1->Point, P2->Point);
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFDirection)] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFBulge1)] = 0.0f; // deprecated
+ NewFeature[static_cast<int>(MicroFeatureParameter::MFBulge2)] = 0.0f; // deprecated
return NewFeature;
} /* ExtractMicroFeature */
diff --git a/src/classify/trainingsample.cpp b/src/classify/trainingsample.cpp
index ef255f94..f08c1a2b 100644
--- a/src/classify/trainingsample.cpp
+++ b/src/classify/trainingsample.cpp
@@ -263,7 +263,7 @@ void TrainingSample::ExtractCharDesc(int int_feature_type, int micro_type, int c
num_micro_features_ = char_features->NumFeatures;
micro_features_ = new MicroFeature[num_micro_features_];
for (uint32_t f = 0; f < num_micro_features_; ++f) {
- for (int d = 0; d < (int)MicroFeatureParameter::MFCount; ++d) {
+ for (int d = 0; d < static_cast<int>(MicroFeatureParameter::MFCount); ++d) {
micro_features_[f][d] = char_features->Features[f]->Params[d];
}
}
diff --git a/src/dict/dawg.h b/src/dict/dawg.h
index b87b3880..08d737e4 100644
--- a/src/dict/dawg.h
+++ b/src/dict/dawg.h
@@ -178,22 +178,17 @@ public:
/// Fills vec with unichar ids that represent the character classes
/// of the given unichar_id.
- virtual void unichar_id_to_patterns(UNICHAR_ID unichar_id,
- const UNICHARSET &unicharset,
- std::vector<UNICHAR_ID> *vec) const {
- (void)unichar_id;
- (void)unicharset;
- (void)vec;
+ virtual void unichar_id_to_patterns([[maybe_unused]] UNICHAR_ID unichar_id,
+ [[maybe_unused]] const UNICHARSET &unicharset,
+ [[maybe_unused]] std::vector<UNICHAR_ID> *vec) const {
}
/// Returns the given EDGE_REF if the EDGE_RECORD that it points to has
/// a self loop and the given unichar_id matches the unichar_id stored in the
/// EDGE_RECORD, returns NO_EDGE otherwise.
- virtual EDGE_REF pattern_loop_edge(EDGE_REF edge_ref, UNICHAR_ID unichar_id,
- bool word_end) const {
- (void)edge_ref;
- (void)unichar_id;
- (void)word_end;
+ virtual EDGE_REF pattern_loop_edge([[maybe_unused]] EDGE_REF edge_ref,
+ [[maybe_unused]] UNICHAR_ID unichar_id,
+ [[maybe_unused]] bool word_end) const {
return false;
}
diff --git a/src/dict/dict.h b/src/dict/dict.h
index 51872bcc..0c65f8c8 100644
--- a/src/dict/dict.h
+++ b/src/dict/dict.h
@@ -42,7 +42,7 @@ class MATRIX;
class WERD_RES;
#define CHARS_PER_LINE 500
-#define MAX_WERD_LENGTH (int64_t)128
+#define MAX_WERD_LENGTH static_cast<int64_t>(128)
#define NO_RATING -1
/** Struct used to hold temporary information about fragments. */
@@ -361,13 +361,11 @@ public:
}
/// Default (no-op) implementation of probability in context function.
- double def_probability_in_context(const char *lang, const char *context, int context_bytes,
- const char *character, int character_bytes) {
- (void)lang;
- (void)context;
- (void)context_bytes;
- (void)character;
- (void)character_bytes;
+ double def_probability_in_context([[maybe_unused]] const char *lang,
+ [[maybe_unused]] const char *context,
+ [[maybe_unused]] int context_bytes,
+ [[maybe_unused]] const char *character,
+ [[maybe_unused]] int character_bytes) {
return 0.0;
}
diff --git a/src/textord/makerow.cpp b/src/textord/makerow.cpp
index ca7aea7b..f1c2f10a 100644
--- a/src/textord/makerow.cpp
+++ b/src/textord/makerow.cpp
@@ -1228,7 +1228,7 @@ void compute_row_stats( // find lines
// too big so use max
}
if (block->line_size < textord_min_xheight) {
- block->line_size = (float)textord_min_xheight;
+ block->line_size = static_cast<float>(textord_min_xheight);
}
block->line_spacing = rows[row_index]->spacing;
block->max_blob_size = block->line_spacing * textord_excess_blobsize;
diff --git a/src/textord/oldbasel.cpp b/src/textord/oldbasel.cpp
index fe26591f..0b21c77c 100644
--- a/src/textord/oldbasel.cpp
+++ b/src/textord/oldbasel.cpp
@@ -143,7 +143,7 @@ void Textord::correlate_lines(TO_BLOCK *block, float gradient) {
block->xheight = block->line_size * tesseract::CCStruct::kXHeightFraction;
}
if (block->xheight < textord_min_xheight) {
- block->xheight = (float)textord_min_xheight;
+ block->xheight = static_cast<float>(textord_min_xheight);
}
} else {
compute_block_xheight(block, gradient);
@@ -1219,7 +1219,7 @@ bool split_stepped_spline( // make xstarts
doneany = true;
} else if (textord_debug_baselines) {
tprintf("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n", startindex,
- centreindex, endindex, (int32_t)textord_spline_medianwin);
+ centreindex, endindex, static_cast<int32_t>(textord_spline_medianwin));
}
}
// else tprintf("Spline step at %d is %g\n",
diff --git a/src/textord/topitch.cpp b/src/textord/topitch.cpp
index ece82db6..a829c286 100644
--- a/src/textord/topitch.cpp
+++ b/src/textord/topitch.cpp
@@ -261,7 +261,7 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
}
}
if (bad_row->fixed_pitch < textord_min_xheight) {
- bad_row->fixed_pitch = (float)textord_min_xheight;
+ bad_row->fixed_pitch = static_cast<float>(textord_min_xheight);
}
bad_row->kern_size = bad_row->fixed_pitch / 4;
bad_row->min_space = static_cast<int32_t>(bad_row->fixed_pitch * 0.6);
diff --git a/src/training/common/commandlineflags.cpp b/src/training/common/commandlineflags.cpp
index f5157e33..8ecd1cb3 100644
--- a/src/training/common/commandlineflags.cpp
+++ b/src/training/common/commandlineflags.cpp
@@ -27,7 +27,7 @@ static bool IntFlagExists(const char *flag_name, int32_t *value) {
if (p == nullptr) {
return false;
}
- *value = (int32_t)(*p);
+ *value = static_cast<int32_t>(*p);
return true;
}
diff --git a/src/training/common/mastertrainer.cpp b/src/training/common/mastertrainer.cpp
index 05b54b5d..f7eb7351 100644
--- a/src/training/common/mastertrainer.cpp
+++ b/src/training/common/mastertrainer.cpp
@@ -587,7 +587,7 @@ CLUSTERER *MasterTrainer::SetupForClustering(
int shape_id, int *num_samples) {
int desc_index = ShortNameToFeatureType(feature_defs, kMicroFeatureType);
int num_params = feature_defs.FeatureDesc[desc_index]->NumParams;
- ASSERT_HOST(num_params == (int)MicroFeatureParameter::MFCount);
+ ASSERT_HOST(num_params == static_cast<int>(MicroFeatureParameter::MFCount));
CLUSTERER *clusterer = MakeClusterer(
num_params, feature_defs.FeatureDesc[desc_index]->ParamDesc);
diff --git a/src/viewer/scrollview.cpp b/src/viewer/scrollview.cpp
index 9c0c4e81..4b4f6113 100644
--- a/src/viewer/scrollview.cpp
+++ b/src/viewer/scrollview.cpp
@@ -153,8 +153,7 @@ void ScrollView::MessageReceiver() {
// Check if any of the threads currently waiting want it.
std::pair<ScrollView *, SVEventType> awaiting_list(cur->window, cur->type);
std::pair<ScrollView *, SVEventType> awaiting_list_any(cur->window, SVET_ANY);
- std::pair<ScrollView *, SVEventType> awaiting_list_any_window((ScrollView *)nullptr,
- SVET_ANY);
+ std::pair<ScrollView *, SVEventType> awaiting_list_any_window(nullptr, SVET_ANY);
waiting_for_events_mu->lock();
if (waiting_for_events.count(awaiting_list) > 0) {
waiting_for_events[awaiting_list].second = std::move(cur);
diff --git a/src/viewer/scrollview.h b/src/viewer/scrollview.h
index 175483af..7e4f22e5 100644
--- a/src/viewer/scrollview.h
+++ b/src/viewer/scrollview.h
@@ -95,8 +95,7 @@ public:
// Gets called by the SV Window. Does nothing on default, overwrite this
// to implement the desired behaviour
- virtual void Notify(const SVEvent *sve) {
- (void)sve;
+ virtual void Notify([[maybe_unused]] const SVEvent *sve) {
}
};