Skip to content

Commit

Permalink
Remove unneeded type casts when using Leptonica macro GET_DATA_BYTE
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stweil committed May 11, 2017
1 parent 8b65bb3 commit 8c75d26
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
3 changes: 1 addition & 2 deletions ccmain/thresholder.cpp
Expand Up @@ -311,8 +311,7 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
for (int x = 0; x < rect_width_; ++x) {
bool white_result = true;
for (int ch = 0; ch < num_channels; ++ch) {
int pixel = GET_DATA_BYTE(const_cast<void*>(
static_cast<const void *>(linedata)),
int pixel = GET_DATA_BYTE(linedata,
(x + rect_left_) * num_channels + ch);
if (hi_values[ch] >= 0 &&
(pixel > thresholds[ch]) == (hi_values[ch] == 0)) {
Expand Down
25 changes: 8 additions & 17 deletions ccstruct/coutln.cpp
Expand Up @@ -654,24 +654,19 @@ static void ComputeGradient(const l_uint32* data, int wpl,
const l_uint32* line = data + y * wpl;
int pix_x_y =
x < width && y < height
? GET_DATA_BYTE(
const_cast<void*>(static_cast<const void*>(line)), x)
? GET_DATA_BYTE(line, x)
: 255;
int pix_x_prevy =
x < width && y > 0
? GET_DATA_BYTE(
const_cast<void*>(static_cast<const void*>(line - wpl)), x)
? GET_DATA_BYTE(line - wpl, x)
: 255;
int pix_prevx_prevy =
x > 0 && y > 0
? GET_DATA_BYTE(
const_cast<void*>(static_cast<void const*>(line - wpl)),
x - 1)
? GET_DATA_BYTE(line - wpl, x - 1)
: 255;
int pix_prevx_y =
x > 0 && y < height
? GET_DATA_BYTE(
const_cast<void*>(static_cast<const void*>(line)), x - 1)
? GET_DATA_BYTE(line, x - 1)
: 255;
gradient->set_x(pix_x_y + pix_x_prevy - (pix_prevx_y + pix_prevx_prevy));
gradient->set_y(pix_x_prevy + pix_prevx_prevy - (pix_x_y + pix_prevx_y));
Expand All @@ -688,10 +683,8 @@ static bool EvaluateVerticalDiff(const l_uint32* data, int wpl, int diff_sign,
if (y <= 0 || y >= height)
return false;
const l_uint32* line = data + y * wpl;
int pixel1 = GET_DATA_BYTE(
const_cast<void*>(static_cast<const void*>(line - wpl)), x);
int pixel2 =
GET_DATA_BYTE(const_cast<void*>(static_cast<const void*>(line)), x);
int pixel1 = GET_DATA_BYTE(line - wpl, x);
int pixel2 = GET_DATA_BYTE(line, x);
int diff = (pixel2 - pixel1) * diff_sign;
if (diff > *best_diff) {
*best_diff = diff;
Expand All @@ -711,10 +704,8 @@ static bool EvaluateHorizontalDiff(const l_uint32* line, int diff_sign,
int* best_diff, int* best_sum, int* best_x) {
if (x <= 0 || x >= width)
return false;
int pixel1 = GET_DATA_BYTE(
const_cast<void*>(static_cast<const void*>(line)), x - 1);
int pixel2 =
GET_DATA_BYTE(const_cast<void*>(static_cast<const void*>(line)), x);
int pixel1 = GET_DATA_BYTE(line, x - 1);
int pixel2 = GET_DATA_BYTE(line, x);
int diff = (pixel2 - pixel1) * diff_sign;
if (diff > *best_diff) {
*best_diff = diff;
Expand Down
5 changes: 2 additions & 3 deletions ccstruct/otsuthr.cpp
Expand Up @@ -161,9 +161,8 @@ void HistogramRect(Pix* src_pix, int channel,
for (int y = top; y < bottom; ++y) {
const l_uint32* linedata = srcdata + y * src_wpl;
for (int x = 0; x < width; ++x) {
int pixel = GET_DATA_BYTE(const_cast<void*>(
static_cast<const void *>(linedata)),
(x + left) * num_channels + channel);
int pixel = GET_DATA_BYTE(linedata,
(x + left) * num_channels + channel);
++histogram[pixel];
}
}
Expand Down

0 comments on commit 8c75d26

Please sign in to comment.