本文整理汇总了Java中com.google.zxing.ChecksumException类的典型用法代码示例。如果您正苦于以下问题:Java ChecksumException类的具体用法?Java ChecksumException怎么用?Java ChecksumException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChecksumException类属于com.google.zxing包,在下文中一共展示了ChecksumException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple)
throws NotFoundException, FormatException, ChecksumException {
List<Result> results = new ArrayList<>();
PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
for (ResultPoint[] points : detectorResult.getPoints()) {
DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5],
points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points));
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417);
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel());
PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther();
if (pdf417ResultMetadata != null) {
result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
}
results.add(result);
}
return results.toArray(new Result[results.size()]);
}
示例2: decodeCodewords
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures) throws FormatException,
ChecksumException {
if (codewords.length == 0) {
throw FormatException.getFormatInstance();
}
int numECCodewords = 1 << (ecLevel + 1);
int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);
verifyCodewordCount(codewords, numECCodewords);
// Decode the codewords
DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, String.valueOf(ecLevel));
decoderResult.setErrorsCorrected(correctedErrorsCount);
decoderResult.setErasures(erasures.length);
return decoderResult;
}
示例3: findErrorLocations
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private int[] findErrorLocations(ModulusPoly errorLocator) throws ChecksumException {
// This is a direct application of Chien's search
int numErrors = errorLocator.getDegree();
int[] result = new int[numErrors];
int e = 0;
for (int i = 1; i < field.getSize() && e < numErrors; i++) {
if (errorLocator.evaluateAt(i) == 0) {
result[e] = field.inverse(i);
e++;
}
}
if (e != numErrors) {
throw ChecksumException.getChecksumInstance();
}
return result;
}
示例4: correctErrors
import com.google.zxing.ChecksumException; //导入依赖的package包/类
/**
* <p>Given data and error-correction codewords received, possibly corrupted by errors, attempts to
* correct the errors in-place using Reed-Solomon error correction.</p>
*
* @param codewordBytes data and error correction codewords
* @param numDataCodewords number of codewords that are data bytes
* @throws ChecksumException if error correction fails
*/
private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {
int numCodewords = codewordBytes.length;
// First read into an array of ints
int[] codewordsInts = new int[numCodewords];
for (int i = 0; i < numCodewords; i++) {
codewordsInts[i] = codewordBytes[i] & 0xFF;
}
int numECCodewords = codewordBytes.length - numDataCodewords;
try {
rsDecoder.decode(codewordsInts, numECCodewords);
} catch (ReedSolomonException ignored) {
throw ChecksumException.getChecksumInstance();
}
// Copy back into array of bytes -- only need to worry about the bytes that were data
// We don't care about errors in the error-correction codewords
for (int i = 0; i < numDataCodewords; i++) {
codewordBytes[i] = (byte) codewordsInts[i];
}
}
示例5: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
decoderResult = decoder.decode(bits);
points = NO_POINTS;
} else {
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
decoderResult = decoder.decode(detectorResult.getBits());
points = detectorResult.getPoints();
}
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
BarcodeFormat.DATA_MATRIX);
List<byte[]> byteSegments = decoderResult.getByteSegments();
if (byteSegments != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
}
String ecLevel = decoderResult.getECLevel();
if (ecLevel != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
}
return result;
}
示例6: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
decoderResult = decoder.decode(bits, hints);
} else {
throw NotFoundException.getNotFoundInstance();
}
ResultPoint[] points = NO_POINTS;
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);
String ecLevel = decoderResult.getECLevel();
if (ecLevel != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
}
return result;
}
示例7: correctErrors
import com.google.zxing.ChecksumException; //导入依赖的package包/类
/**
* <p>Given data and error-correction codewords received, possibly corrupted by errors, attempts to
* correct the errors in-place using Reed-Solomon error correction.</p>
*
* @param codewordBytes data and error correction codewords
* @param numDataCodewords number of codewords that are data bytes
* @throws ChecksumException if error correction fails
*/
private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {
int numCodewords = codewordBytes.length;
// First read into an array of ints
int[] codewordsInts = new int[numCodewords];
for (int i = 0; i < numCodewords; i++) {
codewordsInts[i] = codewordBytes[i] & 0xFF;
}
try {
rsDecoder.decode(codewordsInts, codewordBytes.length - numDataCodewords);
} catch (ReedSolomonException ignored) {
throw ChecksumException.getChecksumInstance();
}
// Copy back into array of bytes -- only need to worry about the bytes that were data
// We don't care about errors in the error-correction codewords
for (int i = 0; i < numDataCodewords; i++) {
codewordBytes[i] = (byte) codewordsInts[i];
}
}
示例8: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean
multiple) throws NotFoundException, FormatException, ChecksumException {
List<Result> results = new ArrayList();
PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
for (ResultPoint[] points : detectorResult.getPoints()) {
DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(),
points[4], points[5], points[6], points[7], getMinCodewordWidth(points),
getMaxCodewordWidth(points));
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
points, BarcodeFormat.PDF_417);
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult
.getECLevel());
PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult
.getOther();
if (pdf417ResultMetadata != null) {
result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
}
results.add(result);
}
return (Result[]) results.toArray(new Result[results.size()]);
}
示例9: correctErrors
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws
ChecksumException {
int i;
int numCodewords = codewordBytes.length;
int[] codewordsInts = new int[numCodewords];
for (i = 0; i < numCodewords; i++) {
codewordsInts[i] = codewordBytes[i] & 255;
}
try {
this.rsDecoder.decode(codewordsInts, codewordBytes.length - numDataCodewords);
for (i = 0; i < numDataCodewords; i++) {
codewordBytes[i] = (byte) codewordsInts[i];
}
} catch (ReedSolomonException e) {
throw ChecksumException.getChecksumInstance();
}
}
示例10: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
if (hints == null || !hints.containsKey(DecodeHintType.PURE_BARCODE)) {
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
decoderResult = this.decoder.decode(detectorResult.getBits());
points = detectorResult.getPoints();
} else {
decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix()));
points = NO_POINTS;
}
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
BarcodeFormat.DATA_MATRIX);
List<byte[]> byteSegments = decoderResult.getByteSegments();
if (byteSegments != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
}
String ecLevel = decoderResult.getECLevel();
if (ecLevel != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
}
return result;
}
示例11: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException {
BitMatrixParser parser = new BitMatrixParser(bits);
DataBlock[] dataBlocks = DataBlock.getDataBlocks(parser.readCodewords(), parser
.getVersion());
int dataBlocksCount = dataBlocks.length;
int totalBytes = 0;
for (DataBlock db : dataBlocks) {
totalBytes += db.getNumDataCodewords();
}
byte[] resultBytes = new byte[totalBytes];
for (int j = 0; j < dataBlocksCount; j++) {
DataBlock dataBlock = dataBlocks[j];
byte[] codewordBytes = dataBlock.getCodewords();
int numDataCodewords = dataBlock.getNumDataCodewords();
correctErrors(codewordBytes, numDataCodewords);
for (int i = 0; i < numDataCodewords; i++) {
resultBytes[(i * dataBlocksCount) + j] = codewordBytes[i];
}
}
return DecodedBitStreamParser.decode(resultBytes);
}
示例12: decode
import com.google.zxing.ChecksumException; //导入依赖的package包/类
public DecoderResult decode(BitMatrix bits, Map<DecodeHintType, ?> map) throws
FormatException, ChecksumException {
byte[] datawords;
byte[] codewords = new BitMatrixParser(bits).readCodewords();
correctErrors(codewords, 0, 10, 10, 0);
int mode = codewords[0] & 15;
switch (mode) {
case 2:
case 3:
case 4:
correctErrors(codewords, 20, 84, 40, 1);
correctErrors(codewords, 20, 84, 40, 2);
datawords = new byte[94];
break;
case 5:
correctErrors(codewords, 20, 68, 56, 1);
correctErrors(codewords, 20, 68, 56, 2);
datawords = new byte[78];
break;
default:
throw FormatException.getFormatInstance();
}
System.arraycopy(codewords, 0, datawords, 0, 10);
System.arraycopy(codewords, 20, datawords, 10, datawords.length - 10);
return DecodedBitStreamParser.decode(datawords, mode);
}
示例13: correctErrors
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private void correctErrors(byte[] codewordBytes, int start, int dataCodewords, int
ecCodewords, int mode) throws ChecksumException {
int codewords = dataCodewords + ecCodewords;
int divisor = mode == 0 ? 1 : 2;
int[] codewordsInts = new int[(codewords / divisor)];
int i = 0;
while (i < codewords) {
if (mode == 0 || i % 2 == mode - 1) {
codewordsInts[i / divisor] = codewordBytes[i + start] & 255;
}
i++;
}
try {
this.rsDecoder.decode(codewordsInts, ecCodewords / divisor);
i = 0;
while (i < dataCodewords) {
if (mode == 0 || i % 2 == mode - 1) {
codewordBytes[i + start] = (byte) codewordsInts[i / divisor];
}
i++;
}
} catch (ReedSolomonException e) {
throw ChecksumException.getChecksumInstance();
}
}
示例14: decodeMultiple
import com.google.zxing.ChecksumException; //导入依赖的package包/类
@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
try {
return decode(image, hints, true);
} catch (FormatException | ChecksumException ignored) {
throw NotFoundException.getNotFoundInstance();
}
}
示例15: createDecoderResult
import com.google.zxing.ChecksumException; //导入依赖的package包/类
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
ChecksumException, NotFoundException {
BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
adjustCodewordCount(detectionResult, barcodeMatrix);
Collection<Integer> erasures = new ArrayList<>();
int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
List<int[]> ambiguousIndexValuesList = new ArrayList<>();
List<Integer> ambiguousIndexesList = new ArrayList<>();
for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
int[] values = barcodeMatrix[row][column + 1].getValue();
int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
if (values.length == 0) {
erasures.add(codewordIndex);
} else if (values.length == 1) {
codewords[codewordIndex] = values[0];
} else {
ambiguousIndexesList.add(codewordIndex);
ambiguousIndexValuesList.add(values);
}
}
}
int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
for (int i = 0; i < ambiguousIndexValues.length; i++) {
ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
}
return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}