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>
This commit is contained in:
Stefan Weil 2017-05-11 20:04:23 +02:00
parent 8b65bb3ae7
commit 8c75d26657
3 changed files with 11 additions and 22 deletions

View File

@ -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)) {

View File

@ -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));
@ -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;
@ -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;

View File

@ -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];
}
}