/*
- * Copyright 2008 Google Inc.
+ * Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package com.google.zxing.oned;
-import com.google.zxing.ReaderException;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.NotFoundException;
import com.google.zxing.common.BitArray;
/**
* <p>Implements decoding of the EAN-13 format.</p>
*
* @author dswitkin@google.com (Daniel Switkin)
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
* @author alasdair@google.com (Alasdair Mackintosh)
*/
-public final class EAN13Reader extends AbstractUPCEANReader {
+public final class EAN13Reader extends UPCEANReader {
// For an EAN-13 barcode, the first digit is represented by the parities used
// to encode the next six digits, according to the table below. For example,
// Note that the encoding for '0' uses the same parity as a UPC barcode. Hence
// a UPC barcode can be converted to an EAN-13 barcode by prepending a 0.
//
- // The encodong is represented by the following array, which is a bit pattern
+ // The encoding is represented by the following array, which is a bit pattern
// using Odd = 0 and Even = 1. For example, 5 is represented by:
//
// Odd Even Even Odd Odd Even
// in binary:
// 0 1 1 0 0 1 == 0x19
//
- private static final int[] FIRST_DIGIT_ENCODINGS = {
+ static final int[] FIRST_DIGIT_ENCODINGS = {
0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A
};
- protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) throws ReaderException {
+ private final int[] decodeMiddleCounters;
- int[] counters = new int[4];
+ public EAN13Reader() {
+ decodeMiddleCounters = new int[4];
+ }
+
+ protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
+ throws NotFoundException {
+ int[] counters = decodeMiddleCounters;
+ counters[0] = 0;
+ counters[1] = 0;
+ counters[2] = 0;
+ counters[3] = 0;
int end = row.getSize();
int rowOffset = startRange[1];
}
/**
- * Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded digits
- * in a barcode, determines the implicitly encoded first digit and adds it to the result string.
+ * Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded
+ * 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 lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to
- * encode digits
- * @throws ReaderException if first digit cannot be determined
+ * encode digits
+ * @throws NotFoundException 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 NotFoundException {
for (int d = 0; d < 10; d++) {
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
resultString.insert(0, (char) ('0' + d));
return;
}
}
- throw new ReaderException("Unable to determine first digit");
+ throw NotFoundException.getNotFoundInstance();
}
-}
\ No newline at end of file
+}