Port back speedup to C++ from rev 2174

git-svn-id: https://zxing.googlecode.com/svn/trunk@2176 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-02-10 17:04:06 +00:00
parent e4bfbeea82
commit 4a6daef483

View file

@ -45,6 +45,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
private static final int BLOCK_SIZE = 1 << BLOCK_SIZE_POWER;
private static final int BLOCK_SIZE_MASK = BLOCK_SIZE - 1;
private static final int MINIMUM_DIMENSION = BLOCK_SIZE * 5;
private static final int MIN_DYNAMIC_RANGE = 24;
private BitMatrix matrix;
@ -158,6 +159,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
int pixel = luminances[offset + xx] & 0xFF;
sum += pixel;
// still looking for good contrast
if (pixel < min) {
min = pixel;
}
@ -165,11 +167,20 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
max = pixel;
}
}
// short-circuit min/max tests once dynamic range is met
if (max - min > MIN_DYNAMIC_RANGE) {
// finish the rest of the rows quickly
for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
sum += luminances[offset + xx] & 0xFF;
}
}
}
}
// The default estimate is the average of the values in the block.
int average = sum >> 6;
if (max - min <= 24) {
int average = sum >> (BLOCK_SIZE_POWER * 2);
if (max - min <= MIN_DYNAMIC_RANGE) {
// If variation within the block is low, assume this is a block with only light or only
// dark pixels. In that case we do not want to use the average, as it would divide this
// low contrast area into black and white pixels, essentially creating data out of noise.