mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
172 lines
6.2 KiB
Java
172 lines
6.2 KiB
Java
package com.google.zxing.qrcode.decoder;
|
|
|
|
import com.google.zxing.FormatException;
|
|
import com.google.zxing.common.BitMatrix;
|
|
|
|
/* loaded from: classes3.dex */
|
|
final class BitMatrixParser {
|
|
private final BitMatrix bitMatrix;
|
|
private boolean mirror;
|
|
private FormatInformation parsedFormatInfo;
|
|
private Version parsedVersion;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void setMirror(boolean z) {
|
|
this.parsedVersion = null;
|
|
this.parsedFormatInfo = null;
|
|
this.mirror = z;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public BitMatrixParser(BitMatrix bitMatrix) throws FormatException {
|
|
int height = bitMatrix.getHeight();
|
|
if (height < 21 || (height & 3) != 1) {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
this.bitMatrix = bitMatrix;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public FormatInformation readFormatInformation() throws FormatException {
|
|
FormatInformation formatInformation = this.parsedFormatInfo;
|
|
if (formatInformation != null) {
|
|
return formatInformation;
|
|
}
|
|
int i = 0;
|
|
int i2 = 0;
|
|
for (int i3 = 0; i3 < 6; i3++) {
|
|
i2 = copyBit(i3, 8, i2);
|
|
}
|
|
int copyBit = copyBit(8, 7, copyBit(8, 8, copyBit(7, 8, i2)));
|
|
for (int i4 = 5; i4 >= 0; i4--) {
|
|
copyBit = copyBit(8, i4, copyBit);
|
|
}
|
|
int height = this.bitMatrix.getHeight();
|
|
int i5 = height - 7;
|
|
for (int i6 = height - 1; i6 >= i5; i6--) {
|
|
i = copyBit(8, i6, i);
|
|
}
|
|
for (int i7 = height - 8; i7 < height; i7++) {
|
|
i = copyBit(i7, 8, i);
|
|
}
|
|
FormatInformation decodeFormatInformation = FormatInformation.decodeFormatInformation(copyBit, i);
|
|
this.parsedFormatInfo = decodeFormatInformation;
|
|
if (decodeFormatInformation != null) {
|
|
return decodeFormatInformation;
|
|
}
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public Version readVersion() throws FormatException {
|
|
Version version = this.parsedVersion;
|
|
if (version != null) {
|
|
return version;
|
|
}
|
|
int height = this.bitMatrix.getHeight();
|
|
int i = (height - 17) / 4;
|
|
if (i <= 6) {
|
|
return Version.getVersionForNumber(i);
|
|
}
|
|
int i2 = height - 11;
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
for (int i5 = 5; i5 >= 0; i5--) {
|
|
for (int i6 = height - 9; i6 >= i2; i6--) {
|
|
i4 = copyBit(i6, i5, i4);
|
|
}
|
|
}
|
|
Version decodeVersionInformation = Version.decodeVersionInformation(i4);
|
|
if (decodeVersionInformation != null && decodeVersionInformation.getDimensionForVersion() == height) {
|
|
this.parsedVersion = decodeVersionInformation;
|
|
return decodeVersionInformation;
|
|
}
|
|
for (int i7 = 5; i7 >= 0; i7--) {
|
|
for (int i8 = height - 9; i8 >= i2; i8--) {
|
|
i3 = copyBit(i7, i8, i3);
|
|
}
|
|
}
|
|
Version decodeVersionInformation2 = Version.decodeVersionInformation(i3);
|
|
if (decodeVersionInformation2 == null || decodeVersionInformation2.getDimensionForVersion() != height) {
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
this.parsedVersion = decodeVersionInformation2;
|
|
return decodeVersionInformation2;
|
|
}
|
|
|
|
private int copyBit(int i, int i2, int i3) {
|
|
boolean z = this.mirror;
|
|
BitMatrix bitMatrix = this.bitMatrix;
|
|
return z ? bitMatrix.get(i2, i) : bitMatrix.get(i, i2) ? (i3 << 1) | 1 : i3 << 1;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public byte[] readCodewords() throws FormatException {
|
|
FormatInformation readFormatInformation = readFormatInformation();
|
|
Version readVersion = readVersion();
|
|
DataMask dataMask = DataMask.values()[readFormatInformation.getDataMask()];
|
|
int height = this.bitMatrix.getHeight();
|
|
dataMask.unmaskBitMatrix(this.bitMatrix, height);
|
|
BitMatrix buildFunctionPattern = readVersion.buildFunctionPattern();
|
|
byte[] bArr = new byte[readVersion.getTotalCodewords()];
|
|
int i = height - 1;
|
|
boolean z = true;
|
|
int i2 = i;
|
|
int i3 = 0;
|
|
int i4 = 0;
|
|
int i5 = 0;
|
|
while (i2 > 0) {
|
|
if (i2 == 6) {
|
|
i2--;
|
|
}
|
|
for (int i6 = 0; i6 < height; i6++) {
|
|
int i7 = z ? i - i6 : i6;
|
|
for (int i8 = 0; i8 < 2; i8++) {
|
|
int i9 = i2 - i8;
|
|
if (!buildFunctionPattern.get(i9, i7)) {
|
|
i4++;
|
|
i5 <<= 1;
|
|
if (this.bitMatrix.get(i9, i7)) {
|
|
i5 |= 1;
|
|
}
|
|
if (i4 == 8) {
|
|
bArr[i3] = (byte) i5;
|
|
i3++;
|
|
i4 = 0;
|
|
i5 = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
z = !z;
|
|
i2 -= 2;
|
|
}
|
|
if (i3 == readVersion.getTotalCodewords()) {
|
|
return bArr;
|
|
}
|
|
throw FormatException.getFormatInstance();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void remask() {
|
|
if (this.parsedFormatInfo == null) {
|
|
return;
|
|
}
|
|
DataMask.values()[this.parsedFormatInfo.getDataMask()].unmaskBitMatrix(this.bitMatrix, this.bitMatrix.getHeight());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void mirror() {
|
|
int i = 0;
|
|
while (i < this.bitMatrix.getWidth()) {
|
|
int i2 = i + 1;
|
|
for (int i3 = i2; i3 < this.bitMatrix.getHeight(); i3++) {
|
|
if (this.bitMatrix.get(i, i3) != this.bitMatrix.get(i3, i)) {
|
|
this.bitMatrix.flip(i3, i);
|
|
this.bitMatrix.flip(i, i3);
|
|
}
|
|
}
|
|
i = i2;
|
|
}
|
|
}
|
|
}
|