package com.google.zxing.aztec; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.Writer; import com.google.zxing.aztec.encoder.AztecCode; import com.google.zxing.aztec.encoder.Encoder; import com.google.zxing.common.BitMatrix; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Map; /* loaded from: classes.dex */ public final class AztecWriter implements Writer { @Override // com.google.zxing.Writer public BitMatrix a(String str, BarcodeFormat barcodeFormat, int i, int i2, Map map) { Charset charset; int i3; int i4; Charset charset2 = StandardCharsets.ISO_8859_1; if (map != null) { if (map.containsKey(EncodeHintType.CHARACTER_SET)) { charset2 = Charset.forName(map.get(EncodeHintType.CHARACTER_SET).toString()); } int parseInt = map.containsKey(EncodeHintType.ERROR_CORRECTION) ? Integer.parseInt(map.get(EncodeHintType.ERROR_CORRECTION).toString()) : 33; if (map.containsKey(EncodeHintType.AZTEC_LAYERS)) { charset = charset2; i3 = parseInt; i4 = Integer.parseInt(map.get(EncodeHintType.AZTEC_LAYERS).toString()); return a(str, barcodeFormat, i, i2, charset, i3, i4); } charset = charset2; i3 = parseInt; } else { charset = charset2; i3 = 33; } i4 = 0; return a(str, barcodeFormat, i, i2, charset, i3, i4); } private static BitMatrix a(String str, BarcodeFormat barcodeFormat, int i, int i2, Charset charset, int i3, int i4) { if (barcodeFormat == BarcodeFormat.AZTEC) { return a(Encoder.a(str.getBytes(charset), i3, i4), i, i2); } throw new IllegalArgumentException("Can only encode AZTEC, but got ".concat(String.valueOf(barcodeFormat))); } private static BitMatrix a(AztecCode aztecCode, int i, int i2) { BitMatrix a = aztecCode.a(); if (a != null) { int k = a.k(); int i3 = a.i(); int max = Math.max(i, k); int max2 = Math.max(i2, i3); int min = Math.min(max / k, max2 / i3); int i4 = (max - (k * min)) / 2; int i5 = (max2 - (i3 * min)) / 2; BitMatrix bitMatrix = new BitMatrix(max, max2); int i6 = 0; while (i6 < i3) { int i7 = i4; int i8 = 0; while (i8 < k) { if (a.b(i8, i6)) { bitMatrix.a(i7, i5, min, min); } i8++; i7 += min; } i6++; i5 += min; } return bitMatrix; } throw new IllegalStateException(); } }