Skip to content

Commit 8c75d26

Browse files
committed
Remove unneeded type casts when using Leptonica macro GET_DATA_BYTE
The first parameter is casted to an unsigned byte by Leptonica, so we don't need additional type casts in Tesseract code. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 8b65bb3 commit 8c75d26

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

ccmain/thresholder.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
311311
for (int x = 0; x < rect_width_; ++x) {
312312
bool white_result = true;
313313
for (int ch = 0; ch < num_channels; ++ch) {
314-
int pixel = GET_DATA_BYTE(const_cast<void*>(
315-
static_cast<const void *>(linedata)),
314+
int pixel = GET_DATA_BYTE(linedata,
316315
(x + rect_left_) * num_channels + ch);
317316
if (hi_values[ch] >= 0 &&
318317
(pixel > thresholds[ch]) == (hi_values[ch] == 0)) {

ccstruct/coutln.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -654,24 +654,19 @@ static void ComputeGradient(const l_uint32* data, int wpl,
654654
const l_uint32* line = data + y * wpl;
655655
int pix_x_y =
656656
x < width && y < height
657-
? GET_DATA_BYTE(
658-
const_cast<void*>(static_cast<const void*>(line)), x)
657+
? GET_DATA_BYTE(line, x)
659658
: 255;
660659
int pix_x_prevy =
661660
x < width && y > 0
662-
? GET_DATA_BYTE(
663-
const_cast<void*>(static_cast<const void*>(line - wpl)), x)
661+
? GET_DATA_BYTE(line - wpl, x)
664662
: 255;
665663
int pix_prevx_prevy =
666664
x > 0 && y > 0
667-
? GET_DATA_BYTE(
668-
const_cast<void*>(static_cast<void const*>(line - wpl)),
669-
x - 1)
665+
? GET_DATA_BYTE(line - wpl, x - 1)
670666
: 255;
671667
int pix_prevx_y =
672668
x > 0 && y < height
673-
? GET_DATA_BYTE(
674-
const_cast<void*>(static_cast<const void*>(line)), x - 1)
669+
? GET_DATA_BYTE(line, x - 1)
675670
: 255;
676671
gradient->set_x(pix_x_y + pix_x_prevy - (pix_prevx_y + pix_prevx_prevy));
677672
gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y));
@@ -688,10 +683,8 @@ static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
688683
if (y <= 0 || y >= height)
689684
return false;
690685
const l_uint32* line = data + y * wpl;
691-
int pixel1 = GET_DATA_BYTE(
692-
const_cast<void*>(static_cast<const void*>(line - wpl)), x);
693-
int pixel2 =
694-
GET_DATA_BYTE(const_cast<void*>(static_cast<const void*>(line)), x);
686+
int pixel1 = GET_DATA_BYTE(line - wpl, x);
687+
int pixel2 = GET_DATA_BYTE(line, x);
695688
int diff = (pixel2 - pixel1) * diff_sign;
696689
if (diff > *best_diff) {
697690
*best_diff = diff;
@@ -711,10 +704,8 @@ static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
711704
int* best_diff, int* best_sum, int* best_x) {
712705
if (x <= 0 || x >= width)
713706
return false;
714-
int pixel1 = GET_DATA_BYTE(
715-
const_cast<void*>(static_cast<const void*>(line)), x - 1);
716-
int pixel2 =
717-
GET_DATA_BYTE(const_cast<void*>(static_cast<const void*>(line)), x);
707+
int pixel1 = GET_DATA_BYTE(line, x - 1);
708+
int pixel2 = GET_DATA_BYTE(line, x);
718709
int diff = (pixel2 - pixel1) * diff_sign;
719710
if (diff > *best_diff) {
720711
*best_diff = diff;

ccstruct/otsuthr.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ void HistogramRect(Pix* src_pix, int channel,
161161
for (int y = top; y < bottom; ++y) {
162162
const l_uint32* linedata = srcdata + y * src_wpl;
163163
for (int x = 0; x < width; ++x) {
164-
int pixel = GET_DATA_BYTE(const_cast<void*>(
165-
static_cast<const void *>(linedata)),
166-
(x + left) * num_channels + channel);
164+
int pixel = GET_DATA_BYTE(linedata,
165+
(x + left) * num_channels + channel);
167166
++histogram[pixel];
168167
}
169168
}

0 commit comments

Comments
 (0)