mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-03 00:49:01 +08:00
commit
da3c462f45
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user