2 * Copyright 2007 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing;
19 import com.google.zxing.qrcode.QRCodeReader;
20 import com.google.zxing.upc.UPCReader;
22 import java.util.Hashtable;
25 * <p>This implementation can detect barcodes in one of several formats within
26 * an image, and then decode what it finds. This implementation supports all
27 * barcode formats that this library supports.</p>
29 * <p>For now, only delegates to {@link QRCodeReader}.</p>
31 * @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
33 public final class MultiFormatReader implements Reader {
35 public Result decode(MonochromeBitmapSource image) throws ReaderException {
36 return decode(image, null);
39 public Result decode(MonochromeBitmapSource image, Hashtable hints)
40 throws ReaderException {
41 Hashtable possibleFormats =
42 hints == null ? null : (Hashtable) hints.get(DecodeHintType.POSSIBLE_FORMATS);
43 boolean tryUPC = false;
44 boolean tryQR = false;
46 if (possibleFormats == null) {
49 } else if (possibleFormats.contains(BarcodeFormat.UPC)) {
51 } else if (possibleFormats.contains(BarcodeFormat.QR_CODE)) {
54 throw new ReaderException();
57 // UPC is much faster to decode, so try it first.
60 return new UPCReader().decode(image, hints);
61 } catch (ReaderException e) {
65 // Then fall through to QR codes.
68 return new QRCodeReader().decode(image, hints);
69 } catch (ReaderException e) {
73 throw new ReaderException();