mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
72 lines
2.8 KiB
Java
72 lines
2.8 KiB
Java
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: classes3.dex */
|
|
public final class AztecWriter implements Writer {
|
|
@Override // com.google.zxing.Writer
|
|
public BitMatrix encode(String str, BarcodeFormat barcodeFormat, int i, int i2) {
|
|
return encode(str, barcodeFormat, i, i2, null);
|
|
}
|
|
|
|
@Override // com.google.zxing.Writer
|
|
public BitMatrix encode(String str, BarcodeFormat barcodeFormat, int i, int i2, Map<EncodeHintType, ?> map) {
|
|
Charset charset = StandardCharsets.ISO_8859_1;
|
|
int i3 = 0;
|
|
if (map != null) {
|
|
if (map.containsKey(EncodeHintType.CHARACTER_SET)) {
|
|
charset = Charset.forName(map.get(EncodeHintType.CHARACTER_SET).toString());
|
|
}
|
|
r0 = map.containsKey(EncodeHintType.ERROR_CORRECTION) ? Integer.parseInt(map.get(EncodeHintType.ERROR_CORRECTION).toString()) : 33;
|
|
if (map.containsKey(EncodeHintType.AZTEC_LAYERS)) {
|
|
i3 = Integer.parseInt(map.get(EncodeHintType.AZTEC_LAYERS).toString());
|
|
}
|
|
}
|
|
return encode(str, barcodeFormat, i, i2, charset, r0, i3);
|
|
}
|
|
|
|
private static BitMatrix encode(String str, BarcodeFormat barcodeFormat, int i, int i2, Charset charset, int i3, int i4) {
|
|
if (barcodeFormat != BarcodeFormat.AZTEC) {
|
|
throw new IllegalArgumentException("Can only encode AZTEC, but got ".concat(String.valueOf(barcodeFormat)));
|
|
}
|
|
return renderResult(Encoder.encode(str.getBytes(charset), i3, i4), i, i2);
|
|
}
|
|
|
|
private static BitMatrix renderResult(AztecCode aztecCode, int i, int i2) {
|
|
BitMatrix matrix = aztecCode.getMatrix();
|
|
if (matrix == null) {
|
|
throw new IllegalStateException();
|
|
}
|
|
int width = matrix.getWidth();
|
|
int height = matrix.getHeight();
|
|
int max = Math.max(i, width);
|
|
int max2 = Math.max(i2, height);
|
|
int min = Math.min(max / width, max2 / height);
|
|
int i3 = (max - (width * min)) / 2;
|
|
int i4 = (max2 - (height * min)) / 2;
|
|
BitMatrix bitMatrix = new BitMatrix(max, max2);
|
|
int i5 = 0;
|
|
while (i5 < height) {
|
|
int i6 = 0;
|
|
int i7 = i3;
|
|
while (i6 < width) {
|
|
if (matrix.get(i6, i5)) {
|
|
bitMatrix.setRegion(i7, i4, min, min);
|
|
}
|
|
i6++;
|
|
i7 += min;
|
|
}
|
|
i5++;
|
|
i4 += min;
|
|
}
|
|
return bitMatrix;
|
|
}
|
|
}
|