X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Foned%2FEAN13Reader.java;h=9c90e83ed21adffe58f294067acfa3448179745f;hb=15c31851811509205c843513211574f3b80db110;hp=16f77d1f79e8ab5728c3843bf133fa4519ae3718;hpb=4b7e347031d7d2053257c15ce5a9b301de777824;p=zxing.git diff --git a/core/src/com/google/zxing/oned/EAN13Reader.java b/core/src/com/google/zxing/oned/EAN13Reader.java index 16f77d1f..9c90e83e 100644 --- a/core/src/com/google/zxing/oned/EAN13Reader.java +++ b/core/src/com/google/zxing/oned/EAN13Reader.java @@ -1,5 +1,5 @@ /* - * 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. @@ -16,17 +16,18 @@ 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; /** *

Implements decoding of the EAN-13 format.

* * @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, @@ -50,20 +51,30 @@ public final class EAN13Reader extends AbstractUPCEANReader { // 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]; @@ -96,28 +107,29 @@ public final class EAN13Reader extends AbstractUPCEANReader { return rowOffset; } + BarcodeFormat getBarcodeFormat() { + return BarcodeFormat.EAN_13; + } + /** - * 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 + * @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]) { - // OK, if the first digit is a 0, then this is effectively also a UPC-A code. - // I think it's best (?) to go ahead and treat it as if it had matched as UPC-A, and return a result - // *without* the leading 0 - if (d != 0) { - resultString.insert(0, (char) ('0' + 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 +}