mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Added some comments and fixed up lines over 100 columns.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1134 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
963c449b81
commit
5c627db289
|
@ -42,6 +42,7 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
return decode(image, null);
|
return decode(image, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note that we don't try rotation without the try harder flag, even if rotation was supported.
|
||||||
public final Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
|
public final Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
|
||||||
try {
|
try {
|
||||||
return doDecode(image, hints);
|
return doDecode(image, hints);
|
||||||
|
@ -184,7 +185,7 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
counters[counterPosition] = 1;
|
counters[counterPosition] = 1;
|
||||||
isWhite ^= true; // isWhite = !isWhite; Is this too clever? shorter byte code, no conditional
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -36,6 +36,9 @@ import java.util.Hashtable;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractUPCEANReader extends AbstractOneDReader implements UPCEANReader {
|
public abstract class AbstractUPCEANReader extends AbstractOneDReader implements UPCEANReader {
|
||||||
|
|
||||||
|
// These two values are critical for determining how permissive the decoding will be.
|
||||||
|
// We've arrived at these values through a lot of trial and error. Setting them any higher
|
||||||
|
// lets false positives creep in quickly.
|
||||||
private static final int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
private static final int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
||||||
private static final int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
|
private static final int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
|
||||||
|
|
||||||
|
@ -274,7 +277,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
}
|
}
|
||||||
counters[counterPosition] = 1;
|
counters[counterPosition] = 1;
|
||||||
isWhite ^= true; // isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw ReaderException.getInstance();
|
throw ReaderException.getInstance();
|
||||||
|
|
|
@ -68,7 +68,8 @@ public final class EAN13Reader extends AbstractUPCEANReader {
|
||||||
decodeMiddleCounters = new int[4];
|
decodeMiddleCounters = new int[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) throws ReaderException {
|
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
|
||||||
|
throws ReaderException {
|
||||||
int[] counters = decodeMiddleCounters;
|
int[] counters = decodeMiddleCounters;
|
||||||
counters[0] = 0;
|
counters[0] = 0;
|
||||||
counters[1] = 0;
|
counters[1] = 0;
|
||||||
|
@ -111,15 +112,17 @@ public final class EAN13Reader extends AbstractUPCEANReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded digits
|
* Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded
|
||||||
* in a barcode, determines the implicitly encoded first digit and adds it to the result string.
|
* digits in a barcode, determines the implicitly encoded first digit and adds it to the
|
||||||
|
* result string.
|
||||||
*
|
*
|
||||||
* @param resultString string to insert decoded first digit into
|
* @param resultString string to insert decoded first digit into
|
||||||
* @param lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to
|
* @param lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to
|
||||||
* encode digits
|
* encode digits
|
||||||
* @throws ReaderException if first digit cannot be determined
|
* @throws ReaderException if first digit cannot be determined
|
||||||
*/
|
*/
|
||||||
private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound) throws ReaderException {
|
private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound)
|
||||||
|
throws ReaderException {
|
||||||
for (int d = 0; d < 10; d++) {
|
for (int d = 0; d < 10; d++) {
|
||||||
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
|
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
|
||||||
resultString.insert(0, (char) ('0' + d));
|
resultString.insert(0, (char) ('0' + d));
|
||||||
|
|
|
@ -34,8 +34,10 @@ public final class MultiFormatOneDReader extends AbstractOneDReader {
|
||||||
private final Vector readers;
|
private final Vector readers;
|
||||||
|
|
||||||
public MultiFormatOneDReader(Hashtable hints) {
|
public MultiFormatOneDReader(Hashtable hints) {
|
||||||
Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
Vector possibleFormats = hints == null ? null :
|
||||||
boolean useCode39CheckDigit = hints != null && hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
|
(Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
||||||
|
boolean useCode39CheckDigit = hints != null &&
|
||||||
|
hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
|
||||||
readers = new Vector();
|
readers = new Vector();
|
||||||
if (possibleFormats != null) {
|
if (possibleFormats != null) {
|
||||||
if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
|
if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
|
||||||
|
|
|
@ -37,7 +37,8 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader {
|
||||||
private final Vector readers;
|
private final Vector readers;
|
||||||
|
|
||||||
public MultiFormatUPCEANReader(Hashtable hints) {
|
public MultiFormatUPCEANReader(Hashtable hints) {
|
||||||
Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
Vector possibleFormats = hints == null ? null :
|
||||||
|
(Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
||||||
readers = new Vector();
|
readers = new Vector();
|
||||||
if (possibleFormats != null) {
|
if (possibleFormats != null) {
|
||||||
if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
|
if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
|
||||||
|
@ -82,8 +83,10 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader {
|
||||||
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
||||||
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
||||||
// result if appropriate.
|
// result if appropriate.
|
||||||
if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) && result.getText().charAt(0) == '0') {
|
if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) &&
|
||||||
return new Result(result.getText().substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
|
result.getText().charAt(0) == '0') {
|
||||||
|
return new Result(result.getText().substring(1), null, result.getResultPoints(),
|
||||||
|
BarcodeFormat.UPC_A);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,8 @@ public final class UPCEReader extends AbstractUPCEANReader {
|
||||||
decodeMiddleCounters = new int[4];
|
decodeMiddleCounters = new int[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) throws ReaderException {
|
protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result)
|
||||||
|
throws ReaderException {
|
||||||
int[] counters = decodeMiddleCounters;
|
int[] counters = decodeMiddleCounters;
|
||||||
counters[0] = 0;
|
counters[0] = 0;
|
||||||
counters[1] = 0;
|
counters[1] = 0;
|
||||||
|
|
Loading…
Reference in a new issue