2 * Copyright 2009 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.pdf417;
\r
19 import com.google.zxing.BarcodeFormat;
\r
20 import com.google.zxing.BinaryBitmap;
\r
21 import com.google.zxing.DecodeHintType;
\r
22 import com.google.zxing.FormatException;
\r
23 import com.google.zxing.NotFoundException;
\r
24 import com.google.zxing.Reader;
\r
25 import com.google.zxing.Result;
\r
26 import com.google.zxing.ResultPoint;
\r
27 import com.google.zxing.common.BitMatrix;
\r
28 import com.google.zxing.common.DecoderResult;
\r
29 import com.google.zxing.common.DetectorResult;
\r
30 import com.google.zxing.pdf417.decoder.Decoder;
\r
31 import com.google.zxing.pdf417.detector.Detector;
\r
32 import com.google.zxing.qrcode.QRCodeReader;
\r
34 import java.util.Hashtable;
\r
37 * This implementation can detect and decode PDF417 codes in an image.
\r
39 * @author SITA Lab (kevin.osullivan@sita.aero)
\r
41 public final class PDF417Reader implements Reader {
\r
43 private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
\r
45 private final Decoder decoder = new Decoder();
\r
48 * Locates and decodes a PDF417 code in an image.
\r
50 * @return a String representing the content encoded by the PDF417 code
\r
51 * @throws NotFoundException if a PDF417 code cannot be found,
\r
52 * @throws FormatException if a PDF417 cannot be decoded
\r
54 public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {
\r
55 return decode(image, null);
\r
58 public Result decode(BinaryBitmap image, Hashtable hints)
\r
59 throws NotFoundException, FormatException {
\r
60 DecoderResult decoderResult;
\r
61 ResultPoint[] points;
\r
62 if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
\r
63 BitMatrix bits = QRCodeReader.extractPureBits(image.getBlackMatrix());
\r
64 decoderResult = decoder.decode(bits);
\r
67 DetectorResult detectorResult = new Detector(image).detect();
\r
68 decoderResult = decoder.decode(detectorResult.getBits());
\r
69 points = detectorResult.getPoints();
\r
71 return new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
\r
72 BarcodeFormat.PDF417);
\r
75 public void reset() {
\r