package com.google.zxing.aztec.encoder; import com.google.zxing.common.BitArray; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.reedsolomon.GenericGF; import com.google.zxing.common.reedsolomon.ReedSolomonEncoder; /* loaded from: classes.dex */ public final class Encoder { private static final int[] a = {4, 6, 6, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12}; private static int a(int i, boolean z) { return ((z ? 88 : 112) + (i << 4)) * i; } public static AztecCode a(byte[] bArr, int i, int i2) { int i3; BitArray a2; BitArray bitArray; boolean z; int i4; int i5; int i6; BitArray a3 = new HighLevelEncoder(bArr).a(); int h = ((a3.h() * i) / 100) + 11; int h2 = a3.h() + h; int i7 = 0; int i8 = 1; if (i2 == 0) { BitArray bitArray2 = null; int i9 = 0; int i10 = 0; while (i9 <= 32) { boolean z2 = i9 <= 3; int i11 = z2 ? i9 + 1 : i9; int a4 = a(i11, z2); if (h2 <= a4) { if (bitArray2 == null || i10 != a[i11]) { i3 = a[i11]; a2 = a(a3, i3); } else { int i12 = i10; a2 = bitArray2; i3 = i12; } int i13 = a4 - (a4 % i3); if ((!z2 || a2.h() <= (i3 << 6)) && a2.h() + h <= i13) { bitArray = a2; z = z2; i4 = i11; i5 = a4; } else { BitArray bitArray3 = a2; i10 = i3; bitArray2 = bitArray3; } } i9++; i7 = 0; i8 = 1; } throw new IllegalArgumentException("Data too large for an Aztec code"); } z = i2 < 0; i4 = Math.abs(i2); if (i4 > (z ? 4 : 32)) { throw new IllegalArgumentException(String.format("Illegal value %s for layers", Integer.valueOf(i2))); } i5 = a(i4, z); i3 = a[i4]; int i14 = i5 - (i5 % i3); bitArray = a(a3, i3); if (bitArray.h() + h > i14) { throw new IllegalArgumentException("Data to large for user specified layer"); } if (z && bitArray.h() > (i3 << 6)) { throw new IllegalArgumentException("Data to large for user specified layer"); } BitArray b = b(bitArray, i5, i3); int h3 = bitArray.h() / i3; BitArray a5 = a(z, i4, h3); int i15 = (z ? 11 : 14) + (i4 << 2); int[] iArr = new int[i15]; int i16 = 2; if (z) { for (int i17 = 0; i17 < iArr.length; i17++) { iArr[i17] = i17; } i6 = i15; } else { int i18 = i15 / 2; i6 = i15 + 1 + (((i18 - 1) / 15) * 2); int i19 = i6 / 2; for (int i20 = 0; i20 < i18; i20++) { iArr[(i18 - i20) - i8] = (i19 - r14) - 1; iArr[i18 + i20] = (i20 / 15) + i20 + i19 + i8; } } BitMatrix bitMatrix = new BitMatrix(i6); int i21 = 0; int i22 = 0; while (i21 < i4) { int i23 = ((i4 - i21) << i16) + (z ? 9 : 12); int i24 = 0; while (i24 < i23) { int i25 = i24 << 1; while (i7 < i16) { if (b.a(i22 + i25 + i7)) { int i26 = i21 << 1; bitMatrix.c(iArr[i26 + i7], iArr[i26 + i24]); } if (b.a((i23 << 1) + i22 + i25 + i7)) { int i27 = i21 << 1; bitMatrix.c(iArr[i27 + i24], iArr[((i15 - 1) - i27) - i7]); } if (b.a((i23 << 2) + i22 + i25 + i7)) { int i28 = (i15 - 1) - (i21 << 1); bitMatrix.c(iArr[i28 - i7], iArr[i28 - i24]); } if (b.a((i23 * 6) + i22 + i25 + i7)) { int i29 = i21 << 1; bitMatrix.c(iArr[((i15 - 1) - i29) - i24], iArr[i29 + i7]); } i7++; i16 = 2; } i24++; i7 = 0; i16 = 2; } i22 += i23 << 3; i21++; i7 = 0; i16 = 2; } a(bitMatrix, z, i6, a5); if (z) { a(bitMatrix, i6 / 2, 5); } else { int i30 = i6 / 2; a(bitMatrix, i30, 7); int i31 = 0; int i32 = 0; while (i31 < (i15 / 2) - 1) { for (int i33 = i30 & 1; i33 < i6; i33 += 2) { int i34 = i30 - i32; bitMatrix.c(i34, i33); int i35 = i30 + i32; bitMatrix.c(i35, i33); bitMatrix.c(i33, i34); bitMatrix.c(i33, i35); } i31 += 15; i32 += 16; } } AztecCode aztecCode = new AztecCode(); aztecCode.a(z); aztecCode.c(i6); aztecCode.b(i4); aztecCode.a(h3); aztecCode.a(bitMatrix); return aztecCode; } private static BitArray b(BitArray bitArray, int i, int i2) { int h = bitArray.h() / i2; ReedSolomonEncoder reedSolomonEncoder = new ReedSolomonEncoder(a(i2)); int i3 = i / i2; int[] a2 = a(bitArray, i2, i3); reedSolomonEncoder.a(a2, i3 - h); BitArray bitArray2 = new BitArray(); bitArray2.a(0, i % i2); for (int i4 : a2) { bitArray2.a(i4, i2); } return bitArray2; } private static void a(BitMatrix bitMatrix, int i, int i2) { for (int i3 = 0; i3 < i2; i3 += 2) { int i4 = i - i3; int i5 = i4; while (true) { int i6 = i + i3; if (i5 <= i6) { bitMatrix.c(i5, i4); bitMatrix.c(i5, i6); bitMatrix.c(i4, i5); bitMatrix.c(i6, i5); i5++; } } } int i7 = i - i2; bitMatrix.c(i7, i7); int i8 = i7 + 1; bitMatrix.c(i8, i7); bitMatrix.c(i7, i8); int i9 = i + i2; bitMatrix.c(i9, i7); bitMatrix.c(i9, i8); bitMatrix.c(i9, i9 - 1); } static BitArray a(boolean z, int i, int i2) { BitArray bitArray = new BitArray(); if (z) { bitArray.a(i - 1, 2); bitArray.a(i2 - 1, 6); return b(bitArray, 28, 4); } bitArray.a(i - 1, 5); bitArray.a(i2 - 1, 11); return b(bitArray, 40, 4); } private static void a(BitMatrix bitMatrix, boolean z, int i, BitArray bitArray) { int i2 = i / 2; int i3 = 0; if (z) { while (i3 < 7) { int i4 = (i2 - 3) + i3; if (bitArray.a(i3)) { bitMatrix.c(i4, i2 - 5); } if (bitArray.a(i3 + 7)) { bitMatrix.c(i2 + 5, i4); } if (bitArray.a(20 - i3)) { bitMatrix.c(i4, i2 + 5); } if (bitArray.a(27 - i3)) { bitMatrix.c(i2 - 5, i4); } i3++; } return; } while (i3 < 10) { int i5 = (i2 - 5) + i3 + (i3 / 5); if (bitArray.a(i3)) { bitMatrix.c(i5, i2 - 7); } if (bitArray.a(i3 + 10)) { bitMatrix.c(i2 + 7, i5); } if (bitArray.a(29 - i3)) { bitMatrix.c(i5, i2 + 7); } if (bitArray.a(39 - i3)) { bitMatrix.c(i2 - 7, i5); } i3++; } } private static int[] a(BitArray bitArray, int i, int i2) { int[] iArr = new int[i2]; int h = bitArray.h() / i; for (int i3 = 0; i3 < h; i3++) { int i4 = 0; for (int i5 = 0; i5 < i; i5++) { i4 |= bitArray.a((i3 * i) + i5) ? 1 << ((i - i5) - 1) : 0; } iArr[i3] = i4; } return iArr; } private static GenericGF a(int i) { if (i == 4) { return GenericGF.k; } if (i == 6) { return GenericGF.j; } if (i == 8) { return GenericGF.n; } if (i == 10) { return GenericGF.i; } if (i == 12) { return GenericGF.h; } throw new IllegalArgumentException("Unsupported word size ".concat(String.valueOf(i))); } static BitArray a(BitArray bitArray, int i) { BitArray bitArray2 = new BitArray(); int h = bitArray.h(); int i2 = (1 << i) - 2; int i3 = 0; while (i3 < h) { int i4 = 0; for (int i5 = 0; i5 < i; i5++) { int i6 = i3 + i5; if (i6 >= h || bitArray.a(i6)) { i4 |= 1 << ((i - 1) - i5); } } int i7 = i4 & i2; if (i7 == i2) { bitArray2.a(i7, i); } else if (i7 == 0) { bitArray2.a(i4 | 1, i); } else { bitArray2.a(i4, i); i3 += i; } i3--; i3 += i; } return bitArray2; } }