* <p>Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.</p>
*
* @author Sean Owen
+ * @see Code93Reader
*/
public final class Code39Reader extends OneDReader {
- private static final String ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
+ static final String ALPHABET_STRING = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%";
private static final char[] ALPHABET = ALPHABET_STRING.toCharArray();
/**
* The 9 least-significant bits of each int correspond to the pattern of wide and narrow,
* with 1s representing "wide" and 0s representing narrow.
*/
- private static final int[] CHARACTER_ENCODINGS = {
+ static final int[] CHARACTER_ENCODINGS = {
0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, // 0-9
0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, // A-J
0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, // K-T
for (int i = 0; i < max; i++) {
total += ALPHABET_STRING.indexOf(result.charAt(i));
}
- if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
+ if (result.charAt(max) != ALPHABET[total % 43]) {
throw ChecksumException.getChecksumInstance();
}
result.deleteCharAt(max);
}
- String resultString = result.toString();
- if (extendedMode) {
- resultString = decodeExtended(resultString);
- }
-
- if (resultString.length() == 0) {
+ if (result.length() == 0) {
// Almost surely a false positive
throw NotFoundException.getNotFoundInstance();
}
+ String resultString;
+ if (extendedMode) {
+ resultString = decodeExtended(result);
+ } else {
+ resultString = result.toString();
+ }
+
float left = (float) (start[1] + start[0]) / 2.0f;
float right = (float) (nextStart + lastStart) / 2.0f;
return new Result(
throw NotFoundException.getNotFoundInstance();
}
- private static String decodeExtended(String encoded) throws FormatException {
+ private static String decodeExtended(StringBuffer encoded) throws FormatException {
int length = encoded.length();
StringBuffer decoded = new StringBuffer(length);
for (int i = 0; i < length; i++) {