jimu-decompiled/sources/com/google/zxing/qrcode/decoder/BitMatrixParser.java
2025-05-13 19:24:51 +02:00

178 lines
4.8 KiB
Java

package com.google.zxing.qrcode.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.common.BitMatrix;
/* loaded from: classes.dex */
final class BitMatrixParser {
private final BitMatrix a;
private Version b;
private FormatInformation c;
private boolean d;
BitMatrixParser(BitMatrix bitMatrix) throws FormatException {
int i = bitMatrix.i();
if (i < 21 || (i & 3) != 1) {
throw FormatException.getFormatInstance();
}
this.a = bitMatrix;
}
private int a(int i, int i2, int i3) {
return this.d ? this.a.b(i2, i) : this.a.b(i, i2) ? (i3 << 1) | 1 : i3 << 1;
}
byte[] b() throws FormatException {
FormatInformation c = c();
Version d = d();
DataMask dataMask = DataMask.values()[c.a()];
int i = this.a.i();
dataMask.a(this.a, i);
BitMatrix a = d.a();
byte[] bArr = new byte[d.d()];
int i2 = i - 1;
int i3 = i2;
int i4 = 0;
boolean z = true;
int i5 = 0;
int i6 = 0;
while (i3 > 0) {
if (i3 == 6) {
i3--;
}
int i7 = i6;
int i8 = i5;
int i9 = i4;
int i10 = 0;
while (i10 < i) {
int i11 = z ? i2 - i10 : i10;
int i12 = i7;
int i13 = i8;
int i14 = i9;
for (int i15 = 0; i15 < 2; i15++) {
int i16 = i3 - i15;
if (!a.b(i16, i11)) {
i13++;
int i17 = i12 << 1;
int i18 = this.a.b(i16, i11) ? i17 | 1 : i17;
if (i13 == 8) {
bArr[i14] = (byte) i18;
i14++;
i13 = 0;
i12 = 0;
} else {
i12 = i18;
}
}
}
i10++;
i9 = i14;
i8 = i13;
i7 = i12;
}
z = !z;
i3 -= 2;
i4 = i9;
i5 = i8;
i6 = i7;
}
if (i4 == d.d()) {
return bArr;
}
throw FormatException.getFormatInstance();
}
FormatInformation c() throws FormatException {
FormatInformation formatInformation = this.c;
if (formatInformation != null) {
return formatInformation;
}
int i = 0;
int i2 = 0;
for (int i3 = 0; i3 < 6; i3++) {
i2 = a(i3, 8, i2);
}
int a = a(8, 7, a(8, 8, a(7, 8, i2)));
for (int i4 = 5; i4 >= 0; i4--) {
a = a(8, i4, a);
}
int i5 = this.a.i();
int i6 = i5 - 7;
for (int i7 = i5 - 1; i7 >= i6; i7--) {
i = a(8, i7, i);
}
for (int i8 = i5 - 8; i8 < i5; i8++) {
i = a(i8, 8, i);
}
this.c = FormatInformation.a(a, i);
FormatInformation formatInformation2 = this.c;
if (formatInformation2 != null) {
return formatInformation2;
}
throw FormatException.getFormatInstance();
}
Version d() throws FormatException {
Version version = this.b;
if (version != null) {
return version;
}
int i = this.a.i();
int i2 = (i - 17) / 4;
if (i2 <= 6) {
return Version.c(i2);
}
int i3 = i - 11;
int i4 = 0;
int i5 = 0;
for (int i6 = 5; i6 >= 0; i6--) {
for (int i7 = i - 9; i7 >= i3; i7--) {
i5 = a(i7, i6, i5);
}
}
Version a = Version.a(i5);
if (a != null && a.c() == i) {
this.b = a;
return a;
}
for (int i8 = 5; i8 >= 0; i8--) {
for (int i9 = i - 9; i9 >= i3; i9--) {
i4 = a(i8, i9, i4);
}
}
Version a2 = Version.a(i4);
if (a2 == null || a2.c() != i) {
throw FormatException.getFormatInstance();
}
this.b = a2;
return a2;
}
void e() {
if (this.c == null) {
return;
}
DataMask.values()[this.c.a()].a(this.a, this.a.i());
}
void a(boolean z) {
this.b = null;
this.c = null;
this.d = z;
}
void a() {
int i = 0;
while (i < this.a.k()) {
int i2 = i + 1;
for (int i3 = i2; i3 < this.a.i(); i3++) {
if (this.a.b(i, i3) != this.a.b(i3, i)) {
this.a.a(i3, i);
this.a.a(i, i3);
}
}
i = i2;
}
}
}