mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
117 lines
5.3 KiB
Java
117 lines
5.3 KiB
Java
package com.google.zxing.common.reedsolomon;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public final class ReedSolomonDecoder {
|
|
private final GenericGF field;
|
|
|
|
public ReedSolomonDecoder(GenericGF genericGF) {
|
|
this.field = genericGF;
|
|
}
|
|
|
|
public void decode(int[] iArr, int i) throws ReedSolomonException {
|
|
GenericGFPoly genericGFPoly = new GenericGFPoly(this.field, iArr);
|
|
int[] iArr2 = new int[i];
|
|
boolean z = true;
|
|
for (int i2 = 0; i2 < i; i2++) {
|
|
GenericGF genericGF = this.field;
|
|
int evaluateAt = genericGFPoly.evaluateAt(genericGF.exp(genericGF.getGeneratorBase() + i2));
|
|
iArr2[(i - 1) - i2] = evaluateAt;
|
|
if (evaluateAt != 0) {
|
|
z = false;
|
|
}
|
|
}
|
|
if (z) {
|
|
return;
|
|
}
|
|
GenericGFPoly[] runEuclideanAlgorithm = runEuclideanAlgorithm(this.field.buildMonomial(i, 1), new GenericGFPoly(this.field, iArr2), i);
|
|
GenericGFPoly genericGFPoly2 = runEuclideanAlgorithm[0];
|
|
GenericGFPoly genericGFPoly3 = runEuclideanAlgorithm[1];
|
|
int[] findErrorLocations = findErrorLocations(genericGFPoly2);
|
|
int[] findErrorMagnitudes = findErrorMagnitudes(genericGFPoly3, findErrorLocations);
|
|
for (int i3 = 0; i3 < findErrorLocations.length; i3++) {
|
|
int length = (iArr.length - 1) - this.field.log(findErrorLocations[i3]);
|
|
if (length < 0) {
|
|
throw new ReedSolomonException("Bad error location");
|
|
}
|
|
iArr[length] = GenericGF.addOrSubtract(iArr[length], findErrorMagnitudes[i3]);
|
|
}
|
|
}
|
|
|
|
private GenericGFPoly[] runEuclideanAlgorithm(GenericGFPoly genericGFPoly, GenericGFPoly genericGFPoly2, int i) throws ReedSolomonException {
|
|
if (genericGFPoly.getDegree() < genericGFPoly2.getDegree()) {
|
|
genericGFPoly2 = genericGFPoly;
|
|
genericGFPoly = genericGFPoly2;
|
|
}
|
|
GenericGFPoly zero = this.field.getZero();
|
|
GenericGFPoly one = this.field.getOne();
|
|
do {
|
|
GenericGFPoly genericGFPoly3 = genericGFPoly2;
|
|
genericGFPoly2 = genericGFPoly;
|
|
genericGFPoly = genericGFPoly3;
|
|
GenericGFPoly genericGFPoly4 = one;
|
|
GenericGFPoly genericGFPoly5 = zero;
|
|
zero = genericGFPoly4;
|
|
if (genericGFPoly.getDegree() >= i / 2) {
|
|
if (genericGFPoly.isZero()) {
|
|
throw new ReedSolomonException("r_{i-1} was zero");
|
|
}
|
|
GenericGFPoly zero2 = this.field.getZero();
|
|
int inverse = this.field.inverse(genericGFPoly.getCoefficient(genericGFPoly.getDegree()));
|
|
while (genericGFPoly2.getDegree() >= genericGFPoly.getDegree() && !genericGFPoly2.isZero()) {
|
|
int degree = genericGFPoly2.getDegree() - genericGFPoly.getDegree();
|
|
int multiply = this.field.multiply(genericGFPoly2.getCoefficient(genericGFPoly2.getDegree()), inverse);
|
|
zero2 = zero2.addOrSubtract(this.field.buildMonomial(degree, multiply));
|
|
genericGFPoly2 = genericGFPoly2.addOrSubtract(genericGFPoly.multiplyByMonomial(degree, multiply));
|
|
}
|
|
one = zero2.multiply(zero).addOrSubtract(genericGFPoly5);
|
|
} else {
|
|
int coefficient = zero.getCoefficient(0);
|
|
if (coefficient == 0) {
|
|
throw new ReedSolomonException("sigmaTilde(0) was zero");
|
|
}
|
|
int inverse2 = this.field.inverse(coefficient);
|
|
return new GenericGFPoly[]{zero.multiply(inverse2), genericGFPoly.multiply(inverse2)};
|
|
}
|
|
} while (genericGFPoly2.getDegree() < genericGFPoly.getDegree());
|
|
throw new IllegalStateException("Division algorithm failed to reduce polynomial?");
|
|
}
|
|
|
|
private int[] findErrorLocations(GenericGFPoly genericGFPoly) throws ReedSolomonException {
|
|
int degree = genericGFPoly.getDegree();
|
|
if (degree == 1) {
|
|
return new int[]{genericGFPoly.getCoefficient(1)};
|
|
}
|
|
int[] iArr = new int[degree];
|
|
int i = 0;
|
|
for (int i2 = 1; i2 < this.field.getSize() && i < degree; i2++) {
|
|
if (genericGFPoly.evaluateAt(i2) == 0) {
|
|
iArr[i] = this.field.inverse(i2);
|
|
i++;
|
|
}
|
|
}
|
|
if (i == degree) {
|
|
return iArr;
|
|
}
|
|
throw new ReedSolomonException("Error locator degree does not match number of roots");
|
|
}
|
|
|
|
private int[] findErrorMagnitudes(GenericGFPoly genericGFPoly, int[] iArr) {
|
|
int length = iArr.length;
|
|
int[] iArr2 = new int[length];
|
|
for (int i = 0; i < length; i++) {
|
|
int inverse = this.field.inverse(iArr[i]);
|
|
int i2 = 1;
|
|
for (int i3 = 0; i3 < length; i3++) {
|
|
if (i != i3) {
|
|
int multiply = this.field.multiply(iArr[i3], inverse);
|
|
i2 = this.field.multiply(i2, (multiply & 1) == 0 ? multiply | 1 : multiply & (-2));
|
|
}
|
|
}
|
|
iArr2[i] = this.field.multiply(genericGFPoly.evaluateAt(inverse), this.field.inverse(i2));
|
|
if (this.field.getGeneratorBase() != 0) {
|
|
iArr2[i] = this.field.multiply(iArr2[i], inverse);
|
|
}
|
|
}
|
|
return iArr2;
|
|
}
|
|
}
|