package com.google.zxing.datamatrix.decoder; import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; /* loaded from: classes.dex */ final class BitMatrixParser { private final BitMatrix a; private final BitMatrix b; private final Version c; BitMatrixParser(BitMatrix bitMatrix) throws FormatException { int i = bitMatrix.i(); if (i < 8 || i > 144 || (i & 1) != 0) { throw FormatException.getFormatInstance(); } this.c = b(bitMatrix); this.a = a(bitMatrix); this.b = new BitMatrix(this.a.k(), this.a.i()); } private static Version b(BitMatrix bitMatrix) throws FormatException { return Version.a(bitMatrix.i(), bitMatrix.k()); } private int c(int i, int i2) { int i3 = i - 1; int i4 = (a(i3, 0, i, i2) ? 1 : 0) << 1; int i5 = i2 - 1; if (a(i3, i5, i, i2)) { i4 |= 1; } int i6 = i4 << 1; int i7 = i2 - 3; if (a(0, i7, i, i2)) { i6 |= 1; } int i8 = i6 << 1; int i9 = i2 - 2; if (a(0, i9, i, i2)) { i8 |= 1; } int i10 = i8 << 1; if (a(0, i5, i, i2)) { i10 |= 1; } int i11 = i10 << 1; if (a(1, i7, i, i2)) { i11 |= 1; } int i12 = i11 << 1; if (a(1, i9, i, i2)) { i12 |= 1; } int i13 = i12 << 1; return a(1, i5, i, i2) ? i13 | 1 : i13; } private int d(int i, int i2) { int i3 = (a(i + (-3), 0, i, i2) ? 1 : 0) << 1; if (a(i - 2, 0, i, i2)) { i3 |= 1; } int i4 = i3 << 1; if (a(i - 1, 0, i, i2)) { i4 |= 1; } int i5 = i4 << 1; if (a(0, i2 - 2, i, i2)) { i5 |= 1; } int i6 = i5 << 1; int i7 = i2 - 1; if (a(0, i7, i, i2)) { i6 |= 1; } int i8 = i6 << 1; if (a(1, i7, i, i2)) { i8 |= 1; } int i9 = i8 << 1; if (a(2, i7, i, i2)) { i9 |= 1; } int i10 = i9 << 1; return a(3, i7, i, i2) ? i10 | 1 : i10; } Version a() { return this.c; } private boolean a(int i, int i2, int i3, int i4) { if (i < 0) { i += i3; i2 += 4 - ((i3 + 4) & 7); } if (i2 < 0) { i2 += i4; i += 4 - ((i4 + 4) & 7); } this.b.c(i2, i); return this.a.b(i2, i); } private int a(int i, int i2) { int i3 = i - 1; int i4 = (a(i3, 0, i, i2) ? 1 : 0) << 1; if (a(i3, 1, i, i2)) { i4 |= 1; } int i5 = i4 << 1; if (a(i3, 2, i, i2)) { i5 |= 1; } int i6 = i5 << 1; if (a(0, i2 - 2, i, i2)) { i6 |= 1; } int i7 = i6 << 1; int i8 = i2 - 1; if (a(0, i8, i, i2)) { i7 |= 1; } int i9 = i7 << 1; if (a(1, i8, i, i2)) { i9 |= 1; } int i10 = i9 << 1; if (a(2, i8, i, i2)) { i10 |= 1; } int i11 = i10 << 1; return a(3, i8, i, i2) ? i11 | 1 : i11; } byte[] b() throws FormatException { byte[] bArr = new byte[this.c.f()]; int i = this.a.i(); int k = this.a.k(); int i2 = 4; int i3 = 0; boolean z = false; int i4 = 0; boolean z2 = false; boolean z3 = false; boolean z4 = false; while (true) { if (i2 == i && i3 == 0 && !z) { bArr[i4] = (byte) a(i, k); i2 -= 2; i3 += 2; i4++; z = true; } else { int i5 = i - 2; if (i2 == i5 && i3 == 0 && (k & 3) != 0 && !z2) { bArr[i4] = (byte) b(i, k); i2 -= 2; i3 += 2; i4++; z2 = true; } else if (i2 == i + 4 && i3 == 2 && (k & 7) == 0 && !z3) { bArr[i4] = (byte) c(i, k); i2 -= 2; i3 += 2; i4++; z3 = true; } else if (i2 == i5 && i3 == 0 && (k & 7) == 4 && !z4) { bArr[i4] = (byte) d(i, k); i2 -= 2; i3 += 2; i4++; z4 = true; } else { do { if (i2 < i && i3 >= 0 && !this.b.b(i3, i2)) { bArr[i4] = (byte) b(i2, i3, i, k); i4++; } i2 -= 2; i3 += 2; if (i2 < 0) { break; } } while (i3 < k); int i6 = i2 + 1; int i7 = i3 + 3; do { if (i6 >= 0 && i7 < k && !this.b.b(i7, i6)) { bArr[i4] = (byte) b(i6, i7, i, k); i4++; } i6 += 2; i7 -= 2; if (i6 >= i) { break; } } while (i7 >= 0); i2 = i6 + 3; i3 = i7 + 1; } } if (i2 >= i && i3 >= k) { break; } } if (i4 == this.c.f()) { return bArr; } throw FormatException.getFormatInstance(); } private BitMatrix a(BitMatrix bitMatrix) { int e = this.c.e(); int d = this.c.d(); if (bitMatrix.i() == e) { int b = this.c.b(); int a = this.c.a(); int i = e / b; int i2 = d / a; BitMatrix bitMatrix2 = new BitMatrix(i2 * a, i * b); for (int i3 = 0; i3 < i; i3++) { int i4 = i3 * b; for (int i5 = 0; i5 < i2; i5++) { int i6 = i5 * a; for (int i7 = 0; i7 < b; i7++) { int i8 = ((b + 2) * i3) + 1 + i7; int i9 = i4 + i7; for (int i10 = 0; i10 < a; i10++) { if (bitMatrix.b(((a + 2) * i5) + 1 + i10, i8)) { bitMatrix2.c(i6 + i10, i9); } } } } } return bitMatrix2; } throw new IllegalArgumentException("Dimension of bitMatrix must match the version size"); } private int b(int i, int i2, int i3, int i4) { int i5 = i - 2; int i6 = i2 - 2; int i7 = (a(i5, i6, i3, i4) ? 1 : 0) << 1; int i8 = i2 - 1; if (a(i5, i8, i3, i4)) { i7 |= 1; } int i9 = i7 << 1; int i10 = i - 1; if (a(i10, i6, i3, i4)) { i9 |= 1; } int i11 = i9 << 1; if (a(i10, i8, i3, i4)) { i11 |= 1; } int i12 = i11 << 1; if (a(i10, i2, i3, i4)) { i12 |= 1; } int i13 = i12 << 1; if (a(i, i6, i3, i4)) { i13 |= 1; } int i14 = i13 << 1; if (a(i, i8, i3, i4)) { i14 |= 1; } int i15 = i14 << 1; return a(i, i2, i3, i4) ? i15 | 1 : i15; } private int b(int i, int i2) { int i3 = (a(i + (-3), 0, i, i2) ? 1 : 0) << 1; if (a(i - 2, 0, i, i2)) { i3 |= 1; } int i4 = i3 << 1; if (a(i - 1, 0, i, i2)) { i4 |= 1; } int i5 = i4 << 1; if (a(0, i2 - 4, i, i2)) { i5 |= 1; } int i6 = i5 << 1; if (a(0, i2 - 3, i, i2)) { i6 |= 1; } int i7 = i6 << 1; if (a(0, i2 - 2, i, i2)) { i7 |= 1; } int i8 = i7 << 1; int i9 = i2 - 1; if (a(0, i9, i, i2)) { i8 |= 1; } int i10 = i8 << 1; return a(1, i9, i, i2) ? i10 | 1 : i10; } }