Rabbit-R1/android (non root)/java/sources/com/google/zxing/pdf417/PDF417Writer.java
2024-05-21 17:08:36 -04:00

101 lines
4.4 KiB
Java

package com.google.zxing.pdf417;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.Writer;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.pdf417.encoder.Compaction;
import com.google.zxing.pdf417.encoder.Dimensions;
import com.google.zxing.pdf417.encoder.PDF417;
import java.lang.reflect.Array;
import java.nio.charset.Charset;
import java.util.Map;
/* loaded from: classes3.dex */
public final class PDF417Writer implements Writer {
private static final int DEFAULT_ERROR_CORRECTION_LEVEL = 2;
private static final int WHITE_SPACE = 30;
@Override // com.google.zxing.Writer
public BitMatrix encode(String str, BarcodeFormat barcodeFormat, int i, int i2, Map<EncodeHintType, ?> map) throws WriterException {
if (barcodeFormat != BarcodeFormat.PDF_417) {
throw new IllegalArgumentException("Can only encode PDF_417, but got ".concat(String.valueOf(barcodeFormat)));
}
PDF417 pdf417 = new PDF417();
if (map != null) {
if (map.containsKey(EncodeHintType.PDF417_COMPACT)) {
pdf417.setCompact(Boolean.parseBoolean(map.get(EncodeHintType.PDF417_COMPACT).toString()));
}
if (map.containsKey(EncodeHintType.PDF417_COMPACTION)) {
pdf417.setCompaction(Compaction.valueOf(map.get(EncodeHintType.PDF417_COMPACTION).toString()));
}
if (map.containsKey(EncodeHintType.PDF417_DIMENSIONS)) {
Dimensions dimensions = (Dimensions) map.get(EncodeHintType.PDF417_DIMENSIONS);
pdf417.setDimensions(dimensions.getMaxCols(), dimensions.getMinCols(), dimensions.getMaxRows(), dimensions.getMinRows());
}
r6 = map.containsKey(EncodeHintType.MARGIN) ? Integer.parseInt(map.get(EncodeHintType.MARGIN).toString()) : 30;
r8 = map.containsKey(EncodeHintType.ERROR_CORRECTION) ? Integer.parseInt(map.get(EncodeHintType.ERROR_CORRECTION).toString()) : 2;
if (map.containsKey(EncodeHintType.CHARACTER_SET)) {
pdf417.setEncoding(Charset.forName(map.get(EncodeHintType.CHARACTER_SET).toString()));
}
}
return bitMatrixFromEncoder(pdf417, str, r8, i, i2, r6);
}
@Override // com.google.zxing.Writer
public BitMatrix encode(String str, BarcodeFormat barcodeFormat, int i, int i2) throws WriterException {
return encode(str, barcodeFormat, i, i2, null);
}
private static BitMatrix bitMatrixFromEncoder(PDF417 pdf417, String str, int i, int i2, int i3, int i4) throws WriterException {
boolean z;
pdf417.generateBarcodeLogic(str, i);
byte[][] scaledMatrix = pdf417.getBarcodeMatrix().getScaledMatrix(1, 4);
if ((i3 > i2) != (scaledMatrix[0].length < scaledMatrix.length)) {
scaledMatrix = rotateArray(scaledMatrix);
z = true;
} else {
z = false;
}
int min = Math.min(i2 / scaledMatrix[0].length, i3 / scaledMatrix.length);
if (min > 1) {
byte[][] scaledMatrix2 = pdf417.getBarcodeMatrix().getScaledMatrix(min, min << 2);
if (z) {
scaledMatrix2 = rotateArray(scaledMatrix2);
}
return bitMatrixFromBitArray(scaledMatrix2, i4);
}
return bitMatrixFromBitArray(scaledMatrix, i4);
}
private static BitMatrix bitMatrixFromBitArray(byte[][] bArr, int i) {
int i2 = i * 2;
BitMatrix bitMatrix = new BitMatrix(bArr[0].length + i2, bArr.length + i2);
bitMatrix.clear();
int height = (bitMatrix.getHeight() - i) - 1;
int i3 = 0;
while (i3 < bArr.length) {
byte[] bArr2 = bArr[i3];
for (int i4 = 0; i4 < bArr[0].length; i4++) {
if (bArr2[i4] == 1) {
bitMatrix.set(i4 + i, height);
}
}
i3++;
height--;
}
return bitMatrix;
}
private static byte[][] rotateArray(byte[][] bArr) {
byte[][] bArr2 = (byte[][]) Array.newInstance((Class<?>) Byte.TYPE, bArr[0].length, bArr.length);
for (int i = 0; i < bArr.length; i++) {
int length = (bArr.length - i) - 1;
for (int i2 = 0; i2 < bArr[0].length; i2++) {
bArr2[i2][length] = bArr[i][i2];
}
}
return bArr2;
}
}