本文整理汇总了Java中com.google.zxing.ChecksumException.getChecksumInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ChecksumException.getChecksumInstance方法的具体用法?Java ChecksumException.getChecksumInstance怎么用?Java ChecksumException.getChecksumInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.ChecksumException
的用法示例。
在下文中一共展示了ChecksumException.getChecksumInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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];
}
}
示例3: 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];
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: createDecoderResultFromAmbiguousValues
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
/**
* This method deals with the fact, that the decoding process doesn't always yield a single most likely value. The
* current error correction implementation doesn't deal with erasures very well, so it's better to provide a value
* for these ambiguous codewords instead of treating it as an erasure. The problem is that we don't know which of
* the ambiguous values to choose. We try decode using the first value, and if that fails, we use another of the
* ambiguous values and try to decode again. This usually only happens on very hard to read and decode barcodes,
* so decoding the normal barcodes is not affected by this.
*
* @param erasureArray contains the indexes of erasures
* @param ambiguousIndexes array with the indexes that have more than one most likely value
* @param ambiguousIndexValues two dimensional array that contains the ambiguous values. The first dimension must
* be the same length as the ambiguousIndexes array
*/
private static DecoderResult createDecoderResultFromAmbiguousValues(int ecLevel,
int[] codewords,
int[] erasureArray,
int[] ambiguousIndexes,
int[][] ambiguousIndexValues)
throws FormatException, ChecksumException {
int[] ambiguousIndexCount = new int[ambiguousIndexes.length];
int tries = 100;
while (tries-- > 0) {
for (int i = 0; i < ambiguousIndexCount.length; i++) {
codewords[ambiguousIndexes[i]] = ambiguousIndexValues[i][ambiguousIndexCount[i]];
}
try {
return decodeCodewords(codewords, ecLevel, erasureArray);
} catch (ChecksumException ignored) {
//
}
if (ambiguousIndexCount.length == 0) {
throw ChecksumException.getChecksumInstance();
}
for (int i = 0; i < ambiguousIndexCount.length; i++) {
if (ambiguousIndexCount[i] < ambiguousIndexValues[i].length - 1) {
ambiguousIndexCount[i]++;
break;
} else {
ambiguousIndexCount[i] = 0;
if (i == ambiguousIndexCount.length - 1) {
throw ChecksumException.getChecksumInstance();
}
}
}
}
throw ChecksumException.getChecksumInstance();
}
示例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.</p>
*
* @param codewords data and error correction codewords
* @param erasures positions of any known erasures
* @param numECCodewords number of error correction codewords that are available in codewords
* @throws ChecksumException if error correction fails
*/
private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws ChecksumException {
if (erasures != null &&
erasures.length > numECCodewords / 2 + MAX_ERRORS ||
numECCodewords < 0 ||
numECCodewords > MAX_EC_CODEWORDS) {
// Too many errors or EC Codewords is corrupted
throw ChecksumException.getChecksumInstance();
}
return errorCorrection.decode(codewords, numECCodewords, erasures);
}
示例8: checkOneChecksum
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
private static void checkOneChecksum(CharSequence result, int checkPosition, int weightMax)
throws ChecksumException {
int weight = 1;
int total = 0;
for (int i = checkPosition - 1; i >= 0; i--) {
total += weight * ALPHABET_STRING.indexOf(result.charAt(i));
if (++weight > weightMax) {
weight = 1;
}
}
if (result.charAt(checkPosition) != ALPHABET[total % 47]) {
throw ChecksumException.getChecksumInstance();
}
}
示例9: 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;
// in EVEN or ODD mode only half the codewords
int divisor = mode == ALL ? 1 : 2;
// First read into an array of ints
int[] codewordsInts = new int[codewords / divisor];
for (int i = 0; i < codewords; i++) {
if ((mode == ALL) || (i % 2 == (mode - 1))) {
codewordsInts[i / divisor] = codewordBytes[i + start] & 0xFF;
}
}
try {
rsDecoder.decode(codewordsInts, ecCodewords / divisor);
} 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 < dataCodewords; i++) {
if ((mode == ALL) || (i % 2 == (mode - 1))) {
codewordBytes[i + start] = (byte) codewordsInts[i / divisor];
}
}
}
示例10: createDecoderResultFromAmbiguousValues
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
private static DecoderResult createDecoderResultFromAmbiguousValues(int ecLevel, int[]
codewords, int[] erasureArray, int[] ambiguousIndexes, int[][] ambiguousIndexValues)
throws FormatException, ChecksumException {
int i;
int[] ambiguousIndexCount = new int[ambiguousIndexes.length];
int tries = 100;
while (true) {
int tries2 = tries - 1;
if (tries > 0) {
for (i = 0; i < ambiguousIndexCount.length; i++) {
codewords[ambiguousIndexes[i]] =
ambiguousIndexValues[i][ambiguousIndexCount[i]];
}
try {
break;
} catch (ChecksumException e) {
if (ambiguousIndexCount.length == 0) {
throw ChecksumException.getChecksumInstance();
}
for (i = 0; i < ambiguousIndexCount.length; i++) {
if (ambiguousIndexCount[i] < ambiguousIndexValues[i].length - 1) {
ambiguousIndexCount[i] = ambiguousIndexCount[i] + 1;
break;
}
ambiguousIndexCount[i] = 0;
if (i == ambiguousIndexCount.length - 1) {
throw ChecksumException.getChecksumInstance();
}
}
tries = tries2;
}
} else {
throw ChecksumException.getChecksumInstance();
}
}
return decodeCodewords(codewords, ecLevel, erasureArray);
}
示例11: correctErrors
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws
ChecksumException {
if ((erasures == null || erasures.length <= (numECCodewords / 2) + 3) && numECCodewords
>= 0 && numECCodewords <= 512) {
return errorCorrection.decode(codewords, numECCodewords, erasures);
}
throw ChecksumException.getChecksumInstance();
}
示例12: decode
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
public int decode(int[] received, int numECCodewords, int[] erasures) throws ChecksumException {
int i;
ModulusPoly poly = new ModulusPoly(this.field, received);
int[] S = new int[numECCodewords];
boolean error = false;
for (i = numECCodewords; i > 0; i--) {
int eval = poly.evaluateAt(this.field.exp(i));
S[numECCodewords - i] = eval;
if (eval != 0) {
error = true;
}
}
if (!error) {
return 0;
}
ModulusPoly knownErrors = this.field.getOne();
if (erasures != null) {
for (int erasure : erasures) {
int b = this.field.exp((received.length - 1) - erasure);
knownErrors = knownErrors.multiply(new ModulusPoly(this.field, new int[]{this
.field.subtract(0, b), 1}));
}
}
ModulusPoly[] sigmaOmega = runEuclideanAlgorithm(this.field.buildMonomial(numECCodewords,
1), new ModulusPoly(this.field, S), numECCodewords);
ModulusPoly sigma = sigmaOmega[0];
ModulusPoly omega = sigmaOmega[1];
int[] errorLocations = findErrorLocations(sigma);
int[] errorMagnitudes = findErrorMagnitudes(omega, sigma, errorLocations);
for (i = 0; i < errorLocations.length; i++) {
int position = (received.length - 1) - this.field.log(errorLocations[i]);
if (position < 0) {
throw ChecksumException.getChecksumInstance();
}
received[position] = this.field.subtract(received[position], errorMagnitudes[i]);
}
return errorLocations.length;
}
示例13: findErrorLocations
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
private int[] findErrorLocations(ModulusPoly errorLocator) throws ChecksumException {
int numErrors = errorLocator.getDegree();
int[] result = new int[numErrors];
int e = 0;
for (int i = 1; i < this.field.getSize() && e < numErrors; i++) {
if (errorLocator.evaluateAt(i) == 0) {
result[e] = this.field.inverse(i);
e++;
}
}
if (e == numErrors) {
return result;
}
throw ChecksumException.getChecksumInstance();
}
示例14: checkOneChecksum
import com.google.zxing.ChecksumException; //导入方法依赖的package包/类
private static void checkOneChecksum(CharSequence result, int checkPosition, int weightMax)
throws ChecksumException {
int weight = 1;
int total = 0;
for (int i = checkPosition - 1; i >= 0; i--) {
total += ALPHABET_STRING.indexOf(result.charAt(i)) * weight;
weight++;
if (weight > weightMax) {
weight = 1;
}
}
if (result.charAt(checkPosition) != ALPHABET[total % 47]) {
throw ChecksumException.getChecksumInstance();
}
}
示例15: 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;
// in EVEN or ODD mode only half the codewords
int divisor = mode == ALL ? 1 : 2;
// First read into an array of ints
int[] codewordsInts = new int[codewords / divisor];
for (int i = 0; i < codewords; i++) {
if ((mode == ALL) || (i % 2 == (mode - 1))) {
codewordsInts[i / divisor] = codewordBytes[i + start] & 0xFF;
}
}
try {
rsDecoder.decode(codewordsInts, ecCodewords / divisor);
} catch (ReedSolomonException rse) {
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 < dataCodewords; i++) {
if ((mode == ALL) || (i % 2 == (mode - 1))) {
codewordBytes[i + start] = (byte) codewordsInts[i / divisor];
}
}
}