mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Closes Issue #607 : guard against very narrow images which would otherwise cause an exception
This commit is contained in:
parent
b1f4b5a269
commit
6cdc7493d5
|
@ -62,22 +62,29 @@ public class GlobalHistogramBinarizer extends Binarizer {
|
||||||
byte[] localLuminances = source.getRow(y, luminances);
|
byte[] localLuminances = source.getRow(y, luminances);
|
||||||
int[] localBuckets = buckets;
|
int[] localBuckets = buckets;
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
int pixel = localLuminances[x] & 0xff;
|
localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++;
|
||||||
localBuckets[pixel >> LUMINANCE_SHIFT]++;
|
|
||||||
}
|
}
|
||||||
int blackPoint = estimateBlackPoint(localBuckets);
|
int blackPoint = estimateBlackPoint(localBuckets);
|
||||||
|
|
||||||
int left = localLuminances[0] & 0xff;
|
if (width < 3) {
|
||||||
int center = localLuminances[1] & 0xff;
|
// Special case for very small images
|
||||||
for (int x = 1; x < width - 1; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
int right = localLuminances[x + 1] & 0xff;
|
if ((localLuminances[x] & 0xff) < blackPoint) {
|
||||||
// A simple -1 4 -1 box filter with a weight of 2.
|
row.set(x);
|
||||||
int luminance = ((center * 4) - left - right) / 2;
|
}
|
||||||
if (luminance < blackPoint) {
|
}
|
||||||
row.set(x);
|
} else {
|
||||||
|
int left = localLuminances[0] & 0xff;
|
||||||
|
int center = localLuminances[1] & 0xff;
|
||||||
|
for (int x = 1; x < width - 1; x++) {
|
||||||
|
int right = localLuminances[x + 1] & 0xff;
|
||||||
|
// A simple -1 4 -1 box filter with a weight of 2.
|
||||||
|
if (((center * 4) - left - right) / 2 < blackPoint) {
|
||||||
|
row.set(x);
|
||||||
|
}
|
||||||
|
left = center;
|
||||||
|
center = right;
|
||||||
}
|
}
|
||||||
left = center;
|
|
||||||
center = right;
|
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue