mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Code analysis tweaks
git-svn-id: https://zxing.googlecode.com/svn/trunk@1003 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
f09b742ea2
commit
597fcfb23d
|
@ -31,7 +31,7 @@ public abstract class Binarizer {
|
||||||
|
|
||||||
private final LuminanceSource source;
|
private final LuminanceSource source;
|
||||||
|
|
||||||
public Binarizer(LuminanceSource source) {
|
protected Binarizer(LuminanceSource source) {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
throw new IllegalArgumentException("Source must be non-null.");
|
throw new IllegalArgumentException("Source must be non-null.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public abstract class LuminanceSource {
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
public LuminanceSource(int width, int height) {
|
protected LuminanceSource(int width, int height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public final class ByteArray {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean empty() {
|
public boolean isEmpty() {
|
||||||
return size == 0;
|
return size == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public final class ByteMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer(2 * width * height + 2);
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
switch (bytes[y][x]) {
|
switch (bytes[y][x]) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ public final class GlobalHistogramBinarizer extends Binarizer {
|
||||||
for (int y = 1; y < 5; y++) {
|
for (int y = 1; y < 5; y++) {
|
||||||
int row = height * y / 5;
|
int row = height * y / 5;
|
||||||
byte[] localLuminances = source.getRow(row, luminances);
|
byte[] localLuminances = source.getRow(row, luminances);
|
||||||
int right = width * 4 / 5;
|
int right = (width << 2) / 5;
|
||||||
for (int x = width / 5; x < right; x++) {
|
for (int x = width / 5; x < right; x++) {
|
||||||
int pixel = localLuminances[x] & 0xff;
|
int pixel = localLuminances[x] & 0xff;
|
||||||
localBuckets[pixel >> LUMINANCE_SHIFT]++;
|
localBuckets[pixel >> LUMINANCE_SHIFT]++;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package com.google.zxing.common;
|
package com.google.zxing.common;
|
||||||
|
|
||||||
import com.google.zxing.Binarizer;
|
import com.google.zxing.Binarizer;
|
||||||
import com.google.zxing.ReaderException;
|
|
||||||
import com.google.zxing.LuminanceSource;
|
import com.google.zxing.LuminanceSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,12 +37,12 @@ public final class LocalBlockBinarizer extends Binarizer {
|
||||||
super(source);
|
super(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitArray getBlackRow(int y, BitArray row) throws ReaderException {
|
public BitArray getBlackRow(int y, BitArray row) {
|
||||||
binarizeEntireImage();
|
binarizeEntireImage();
|
||||||
return matrix.getRow(y, row);
|
return matrix.getRow(y, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitMatrix getBlackMatrix() throws ReaderException {
|
public BitMatrix getBlackMatrix() {
|
||||||
binarizeEntireImage();
|
binarizeEntireImage();
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
@ -80,11 +79,11 @@ public final class LocalBlockBinarizer extends Binarizer {
|
||||||
int stride, int[][] blackPoints, BitMatrix matrix) {
|
int stride, int[][] blackPoints, BitMatrix matrix) {
|
||||||
for (int y = 0; y < subHeight; y++) {
|
for (int y = 0; y < subHeight; y++) {
|
||||||
for (int x = 0; x < subWidth; x++) {
|
for (int x = 0; x < subWidth; x++) {
|
||||||
int sum = 0;
|
|
||||||
int left = (x > 1) ? x : 2;
|
int left = (x > 1) ? x : 2;
|
||||||
left = (left < subWidth - 2) ? left : subWidth - 3;
|
left = (left < subWidth - 2) ? left : subWidth - 3;
|
||||||
int top = (y > 1) ? y : 2;
|
int top = (y > 1) ? y : 2;
|
||||||
top = (top < subHeight - 2) ? top : subHeight - 3;
|
top = (top < subHeight - 2) ? top : subHeight - 3;
|
||||||
|
int sum = 0;
|
||||||
for (int z = -2; z <= 2; z++) {
|
for (int z = -2; z <= 2; z++) {
|
||||||
sum += blackPoints[top + z][left - 2];
|
sum += blackPoints[top + z][left - 2];
|
||||||
sum += blackPoints[top + z][left - 1];
|
sum += blackPoints[top + z][left - 1];
|
||||||
|
@ -93,7 +92,7 @@ public final class LocalBlockBinarizer extends Binarizer {
|
||||||
sum += blackPoints[top + z][left + 2];
|
sum += blackPoints[top + z][left + 2];
|
||||||
}
|
}
|
||||||
int average = sum / 25;
|
int average = sum / 25;
|
||||||
threshold8x8Block(luminances, x * 8, y * 8, average, stride, matrix);
|
threshold8x8Block(luminances, x << 3, y << 3, average, stride, matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +121,7 @@ public final class LocalBlockBinarizer extends Binarizer {
|
||||||
int min = 255;
|
int min = 255;
|
||||||
int max = 0;
|
int max = 0;
|
||||||
for (int yy = 0; yy < 8; yy++) {
|
for (int yy = 0; yy < 8; yy++) {
|
||||||
int offset = (y * 8 + yy) * stride + (x * 8);
|
int offset = ((y << 3) + yy) * stride + (x << 3);
|
||||||
for (int xx = 0; xx < 8; xx++) {
|
for (int xx = 0; xx < 8; xx++) {
|
||||||
int pixel = luminances[offset + xx] & 0xff;
|
int pixel = luminances[offset + xx] & 0xff;
|
||||||
sum += pixel;
|
sum += pixel;
|
||||||
|
|
|
@ -18,7 +18,6 @@ package com.google.zxing.common.detector;
|
||||||
|
|
||||||
import com.google.zxing.ReaderException;
|
import com.google.zxing.ReaderException;
|
||||||
import com.google.zxing.ResultPoint;
|
import com.google.zxing.ResultPoint;
|
||||||
import com.google.zxing.common.BitArray;
|
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue