142 lines
5.3 KiB
Java
142 lines
5.3 KiB
Java
package com.google.zxing.qrcode;
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
import com.google.zxing.BinaryBitmap;
|
|
import com.google.zxing.ChecksumException;
|
|
import com.google.zxing.DecodeHintType;
|
|
import com.google.zxing.FormatException;
|
|
import com.google.zxing.NotFoundException;
|
|
import com.google.zxing.Reader;
|
|
import com.google.zxing.Result;
|
|
import com.google.zxing.ResultMetadataType;
|
|
import com.google.zxing.ResultPoint;
|
|
import com.google.zxing.common.BitMatrix;
|
|
import com.google.zxing.common.DecoderResult;
|
|
import com.google.zxing.common.DetectorResult;
|
|
import com.google.zxing.qrcode.decoder.Decoder;
|
|
import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData;
|
|
import com.google.zxing.qrcode.detector.Detector;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class QRCodeReader implements Reader {
|
|
private static final ResultPoint[] b = new ResultPoint[0];
|
|
private final Decoder a = new Decoder();
|
|
|
|
@Override // com.google.zxing.Reader
|
|
public final Result a(BinaryBitmap binaryBitmap, Map<DecodeHintType, ?> map) throws NotFoundException, ChecksumException, FormatException {
|
|
ResultPoint[] b2;
|
|
DecoderResult decoderResult;
|
|
if (map == null || !map.containsKey(DecodeHintType.PURE_BARCODE)) {
|
|
DetectorResult a = new Detector(binaryBitmap.a()).a(map);
|
|
DecoderResult a2 = this.a.a(a.a(), map);
|
|
b2 = a.b();
|
|
decoderResult = a2;
|
|
} else {
|
|
decoderResult = this.a.a(a(binaryBitmap.a()), map);
|
|
b2 = b;
|
|
}
|
|
if (decoderResult.d() instanceof QRCodeDecoderMetaData) {
|
|
((QRCodeDecoderMetaData) decoderResult.d()).a(b2);
|
|
}
|
|
Result result = new Result(decoderResult.h(), decoderResult.e(), b2, BarcodeFormat.QR_CODE);
|
|
List<byte[]> a3 = decoderResult.a();
|
|
if (a3 != null) {
|
|
result.a(ResultMetadataType.BYTE_SEGMENTS, a3);
|
|
}
|
|
String b3 = decoderResult.b();
|
|
if (b3 != null) {
|
|
result.a(ResultMetadataType.ERROR_CORRECTION_LEVEL, b3);
|
|
}
|
|
if (decoderResult.i()) {
|
|
result.a(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, Integer.valueOf(decoderResult.g()));
|
|
result.a(ResultMetadataType.STRUCTURED_APPEND_PARITY, Integer.valueOf(decoderResult.f()));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@Override // com.google.zxing.Reader
|
|
public void reset() {
|
|
}
|
|
|
|
private static BitMatrix a(BitMatrix bitMatrix) throws NotFoundException {
|
|
int[] j = bitMatrix.j();
|
|
int[] b2 = bitMatrix.b();
|
|
if (j != null && b2 != null) {
|
|
float a = a(j, bitMatrix);
|
|
int i = j[1];
|
|
int i2 = b2[1];
|
|
int i3 = j[0];
|
|
int i4 = b2[0];
|
|
if (i3 < i4 && i < i2) {
|
|
int i5 = i2 - i;
|
|
if (i5 != i4 - i3 && (i4 = i3 + i5) >= bitMatrix.k()) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
int round = Math.round(((i4 - i3) + 1) / a);
|
|
int round2 = Math.round((i5 + 1) / a);
|
|
if (round <= 0 || round2 <= 0) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
if (round2 == round) {
|
|
int i6 = (int) (a / 2.0f);
|
|
int i7 = i + i6;
|
|
int i8 = i3 + i6;
|
|
int i9 = (((int) ((round - 1) * a)) + i8) - i4;
|
|
if (i9 > 0) {
|
|
if (i9 > i6) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
i8 -= i9;
|
|
}
|
|
int i10 = (((int) ((round2 - 1) * a)) + i7) - i2;
|
|
if (i10 > 0) {
|
|
if (i10 > i6) {
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
i7 -= i10;
|
|
}
|
|
BitMatrix bitMatrix2 = new BitMatrix(round, round2);
|
|
for (int i11 = 0; i11 < round2; i11++) {
|
|
int i12 = ((int) (i11 * a)) + i7;
|
|
for (int i13 = 0; i13 < round; i13++) {
|
|
if (bitMatrix.b(((int) (i13 * a)) + i8, i12)) {
|
|
bitMatrix2.c(i13, i11);
|
|
}
|
|
}
|
|
}
|
|
return bitMatrix2;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
|
|
private static float a(int[] iArr, BitMatrix bitMatrix) throws NotFoundException {
|
|
int i = bitMatrix.i();
|
|
int k = bitMatrix.k();
|
|
int i2 = iArr[0];
|
|
boolean z = true;
|
|
int i3 = iArr[1];
|
|
int i4 = 0;
|
|
while (i2 < k && i3 < i) {
|
|
if (z != bitMatrix.b(i2, i3)) {
|
|
i4++;
|
|
if (i4 == 5) {
|
|
break;
|
|
}
|
|
z = !z;
|
|
}
|
|
i2++;
|
|
i3++;
|
|
}
|
|
if (i2 != k && i3 != i) {
|
|
return (i2 - iArr[0]) / 7.0f;
|
|
}
|
|
throw NotFoundException.getNotFoundInstance();
|
|
}
|
|
}
|