Skip to content

Commit

Permalink
Merge pull request #906 from stweil/casts
Browse files Browse the repository at this point in the history
Remove some type casts
  • Loading branch information
zdenop committed May 11, 2017
2 parents 8b65bb3 + 7831a35 commit da3c462
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 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
5 changes: 2 additions & 3 deletions ccutil/serialis.cpp
Expand Up @@ -109,11 +109,10 @@ int TFile::FRead(void* buffer, int size, int count) {
ASSERT_HOST(!is_writing_);
int required_size = size * count;
if (required_size <= 0) return 0;
char* char_buffer = static_cast<char*>(buffer);
if (data_->size() - offset_ < required_size)
required_size = data_->size() - offset_;
if (required_size > 0 && char_buffer != NULL)
memcpy(char_buffer, &(*data_)[offset_], required_size);
if (required_size > 0 && buffer != NULL)
memcpy(buffer, &(*data_)[offset_], required_size);
offset_ += required_size;
return required_size / size;
}
Expand Down

0 comments on commit da3c462

Please sign in to comment.