Update Codabar style and disable it as its causing too many false positives
[zxing.git] / core / src / com / google / zxing / oned / MultiFormatOneDReader.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.oned;
18
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.DecodeHintType;
21 import com.google.zxing.NotFoundException;
22 import com.google.zxing.Reader;
23 import com.google.zxing.ReaderException;
24 import com.google.zxing.Result;
25 import com.google.zxing.common.BitArray;
26 import com.google.zxing.oned.rss.RSS14Reader;
27 import com.google.zxing.oned.rss.expanded.RSSExpandedReader;
28
29 import java.util.Hashtable;
30 import java.util.Vector;
31
32 /**
33  * @author dswitkin@google.com (Daniel Switkin)
34  * @author Sean Owen
35  */
36 public final class MultiFormatOneDReader extends OneDReader {
37
38   private final Vector readers;
39
40   public MultiFormatOneDReader(Hashtable hints) {
41     Vector possibleFormats = hints == null ? null :
42         (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
43     boolean useCode39CheckDigit = hints != null &&
44         hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
45     readers = new Vector();
46     if (possibleFormats != null) {
47       if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
48           possibleFormats.contains(BarcodeFormat.UPC_A) ||
49           possibleFormats.contains(BarcodeFormat.EAN_8) ||
50           possibleFormats.contains(BarcodeFormat.UPC_E)) {
51         readers.addElement(new MultiFormatUPCEANReader(hints));
52       }
53       if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
54         readers.addElement(new Code39Reader(useCode39CheckDigit));
55       }
56       if (possibleFormats.contains(BarcodeFormat.CODE_93)) {
57         readers.addElement(new Code93Reader());
58       }
59       if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
60         readers.addElement(new Code128Reader());
61       }
62       if (possibleFormats.contains(BarcodeFormat.ITF)) {
63          readers.addElement(new ITFReader());
64       }
65       if (possibleFormats.contains(BarcodeFormat.CODABAR)) {
66          readers.addElement(new CodaBarReader());
67       }
68       if (possibleFormats.contains(BarcodeFormat.RSS14)) {
69          readers.addElement(new RSS14Reader());
70       }
71       if (possibleFormats.contains(BarcodeFormat.RSS_EXPANDED)){
72         readers.addElement(new RSSExpandedReader());
73       }
74     }
75     if (readers.isEmpty()) {
76       readers.addElement(new MultiFormatUPCEANReader(hints));
77       readers.addElement(new Code39Reader());
78       //readers.addElement(new CodaBarReader());
79       readers.addElement(new Code93Reader());      
80       readers.addElement(new Code128Reader());
81       readers.addElement(new ITFReader());
82       readers.addElement(new RSS14Reader());      
83       readers.addElement(new RSSExpandedReader());      
84     }
85   }
86
87   public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
88     int size = readers.size();
89     for (int i = 0; i < size; i++) {
90       OneDReader reader = (OneDReader) readers.elementAt(i);
91       try {
92         return reader.decodeRow(rowNumber, row, hints);
93       } catch (ReaderException re) {
94         // continue
95       }
96     }
97
98     throw NotFoundException.getNotFoundInstance();
99   }
100
101   public void reset() {
102     int size = readers.size();
103     for (int i = 0; i < size; i++) {
104       Reader reader = (Reader) readers.elementAt(i);
105       reader.reset();
106     }
107   }
108
109 }