2 * Copyright 2008 ZXing authors
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.oned;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.ReaderException;
21 import com.google.zxing.Result;
22 import com.google.zxing.BinaryBitmap;
23 import com.google.zxing.common.BitArray;
25 import java.util.Hashtable;
28 * <p>Implements decoding of the UPC-A format.</p>
30 * @author dswitkin@google.com (Daniel Switkin)
33 public final class UPCAReader implements UPCEANReader {
35 private final UPCEANReader ean13Reader = new EAN13Reader();
37 public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Hashtable hints)
38 throws ReaderException {
39 return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
42 public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
43 return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, hints));
46 public Result decode(BinaryBitmap image) throws ReaderException {
47 return maybeReturnResult(ean13Reader.decode(image));
50 public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
51 return maybeReturnResult(ean13Reader.decode(image, hints));
54 private static Result maybeReturnResult(Result result) throws ReaderException {
55 String text = result.getText();
56 if (text.charAt(0) == '0') {
57 return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
59 throw ReaderException.getInstance();