import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitArray;
-import com.google.zxing.common.GenericResultPoint;
import java.util.Hashtable;
/**
* <p>Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.</p>
*
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
*/
public final class Code39Reader extends AbstractOneDReader {
public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
int[] start = findAsteriskPattern(row);
-
int nextStart = start[1];
-
int end = row.getSize();
// Read off white space
// If 50% of last pattern size, following last pattern, is not whitespace, fail
// (but if it's whitespace to the very end of the image, that's OK)
if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
- throw new ReaderException("Pattern not followed by whitespace");
+ throw ReaderException.getInstance();
}
if (usingCheckDigit) {
total += ALPHABET_STRING.indexOf(result.charAt(i));
}
if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
- throw new ReaderException("Checksum failed");
+ throw ReaderException.getInstance();
}
result.deleteCharAt(max);
}
if (resultString.length() == 0) {
// Almost surely a false positive
- throw new ReaderException("Empty barcode found; assuming a false positive");
+ throw ReaderException.getInstance();
}
float left = (float) (start[1] + start[0]) / 2.0f;
resultString,
null,
new ResultPoint[]{
- new GenericResultPoint(left, (float) rowNumber),
- new GenericResultPoint(right, (float) rowNumber)},
+ new ResultPoint(left, (float) rowNumber),
+ new ResultPoint(right, (float) rowNumber)},
BarcodeFormat.CODE_39);
}
for (int i = rowOffset; i < width; i++) {
boolean pixel = row.get(i);
- if ((!pixel && isWhite) || (pixel && !isWhite)) {
+ if (pixel ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
counterPosition++;
}
counters[counterPosition] = 1;
- isWhite = !isWhite;
+ isWhite ^= true; // isWhite = !isWhite;
}
}
- throw new ReaderException("Can't find pattern");
+ throw ReaderException.getInstance();
}
private static int toNarrowWidePattern(int[] counters) throws ReaderException {
wideCounters--;
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
if ((counter << 1) >= totalWideCountersWidth) {
- throw new ReaderException("Wide bars vary too much in width, rejecting");
+ throw ReaderException.getInstance();
}
}
}
return pattern;
}
} while (wideCounters > 3);
- throw new ReaderException("Can't find 3 wide bars/spaces out of 9");
+ throw ReaderException.getInstance();
}
private static char patternToChar(int pattern) throws ReaderException {
return ALPHABET[i];
}
}
- throw new ReaderException("Pattern did not match character encoding");
+ throw ReaderException.getInstance();
}
private static String decodeExtended(String encoded) throws ReaderException {
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next + 32);
} else {
- throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+ throw ReaderException.getInstance();
}
break;
case '$':
if (next >= 'A' && next <= 'Z') {
decodedChar = (char) (next - 64);
} else {
- throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+ throw ReaderException.getInstance();
}
break;
case '%':
} else if (next >= 'F' && next <= 'W') {
decodedChar = (char) (next - 11);
} else {
- throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+ throw ReaderException.getInstance();
}
break;
case '/':
} else if (next == 'Z') {
decodedChar = ':';
} else {
- throw new ReaderException("Invalid extended sequence: " + c + next);
+ throw ReaderException.getInstance();
}
break;
}