mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
91 lines
3.0 KiB
Java
91 lines
3.0 KiB
Java
/*
|
|
* 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.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.google.zxing.oned;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.BinaryBitmap;
|
|
import com.google.zxing.ChecksumException;
|
|
import com.google.zxing.DecodeHintType;
|
|
import com.google.zxing.FormatException;
|
|
import com.google.zxing.NotFoundException;
|
|
import com.google.zxing.RXingResult;
|
|
import com.google.zxing.common.BitArray;
|
|
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* <p>Implements decoding of the UPC-A format.</p>
|
|
*
|
|
* @author dswitkin@google.com (Daniel Switkin)
|
|
* @author Sean Owen
|
|
*/
|
|
public final class UPCAReader extends UPCEANReader {
|
|
|
|
private final UPCEANReader ean13Reader = new EAN13Reader();
|
|
|
|
@Override
|
|
public RXingResult decodeRow(int rowNumber,
|
|
BitArray row,
|
|
int[] startGuardRange,
|
|
Map<DecodeHintType,?> hints)
|
|
throws NotFoundException, FormatException, ChecksumException {
|
|
return maybeReturnRXingResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
|
|
}
|
|
|
|
@Override
|
|
public RXingResult decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints)
|
|
throws NotFoundException, FormatException, ChecksumException {
|
|
return maybeReturnRXingResult(ean13Reader.decodeRow(rowNumber, row, hints));
|
|
}
|
|
|
|
@Override
|
|
public RXingResult decode(BinaryBitmap image) throws NotFoundException, FormatException {
|
|
return maybeReturnRXingResult(ean13Reader.decode(image));
|
|
}
|
|
|
|
@Override
|
|
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
|
throws NotFoundException, FormatException {
|
|
return maybeReturnRXingResult(ean13Reader.decode(image, hints));
|
|
}
|
|
|
|
@Override
|
|
BarcodeFormat getBarcodeFormat() {
|
|
return BarcodeFormat.UPC_A;
|
|
}
|
|
|
|
@Override
|
|
protected int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString)
|
|
throws NotFoundException {
|
|
return ean13Reader.decodeMiddle(row, startRange, resultString);
|
|
}
|
|
|
|
private static RXingResult maybeReturnRXingResult(RXingResult result) throws FormatException {
|
|
String text = result.getText();
|
|
if (text.charAt(0) == '0') {
|
|
RXingResult upcaRXingResult = new RXingResult(text.substring(1), null, result.getRXingResultPoints(), BarcodeFormat.UPC_A);
|
|
if (result.getRXingResultMetadata() != null) {
|
|
upcaRXingResult.putAllMetadata(result.getRXingResultMetadata());
|
|
}
|
|
return upcaRXingResult;
|
|
} else {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
}
|
|
|
|
}
|