package com.google.zxing.multi.qrcode; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; import com.google.zxing.NotFoundException; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.ResultMetadataType; import com.google.zxing.ResultPoint; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.DetectorResult; import com.google.zxing.multi.MultipleBarcodeReader; import com.google.zxing.multi.qrcode.detector.MultiDetector; import com.google.zxing.qrcode.QRCodeReader; import com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData; import java.io.ByteArrayOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; /* loaded from: classes3.dex */ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBarcodeReader { private static final Result[] EMPTY_RESULT_ARRAY = new Result[0]; private static final ResultPoint[] NO_POINTS = new ResultPoint[0]; @Override // com.google.zxing.multi.MultipleBarcodeReader public Result[] decodeMultiple(BinaryBitmap binaryBitmap) throws NotFoundException { return decodeMultiple(binaryBitmap, null); } @Override // com.google.zxing.multi.MultipleBarcodeReader public Result[] decodeMultiple(BinaryBitmap binaryBitmap, Map map) throws NotFoundException { ArrayList arrayList = new ArrayList(); for (DetectorResult detectorResult : new MultiDetector(binaryBitmap.getBlackMatrix()).detectMulti(map)) { try { DecoderResult decode = getDecoder().decode(detectorResult.getBits(), map); ResultPoint[] points = detectorResult.getPoints(); if (decode.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decode.getOther()).applyMirroredCorrection(points); } Result result = new Result(decode.getText(), decode.getRawBytes(), points, BarcodeFormat.QR_CODE); List byteSegments = decode.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String eCLevel = decode.getECLevel(); if (eCLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, eCLevel); } if (decode.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, Integer.valueOf(decode.getStructuredAppendSequenceNumber())); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, Integer.valueOf(decode.getStructuredAppendParity())); } arrayList.add(result); } catch (ReaderException unused) { } } return arrayList.isEmpty() ? EMPTY_RESULT_ARRAY : (Result[]) processStructuredAppend(arrayList).toArray(EMPTY_RESULT_ARRAY); } static List processStructuredAppend(List list) { ArrayList arrayList = new ArrayList(); ArrayList arrayList2 = new ArrayList(); for (Result result : list) { if (result.getResultMetadata().containsKey(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)) { arrayList2.add(result); } else { arrayList.add(result); } } if (arrayList2.isEmpty()) { return list; } Collections.sort(arrayList2, new SAComparator()); StringBuilder sb = new StringBuilder(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream(); for (Result result2 : arrayList2) { sb.append(result2.getText()); byte[] rawBytes = result2.getRawBytes(); byteArrayOutputStream.write(rawBytes, 0, rawBytes.length); Iterable iterable = (Iterable) result2.getResultMetadata().get(ResultMetadataType.BYTE_SEGMENTS); if (iterable != null) { for (byte[] bArr : iterable) { byteArrayOutputStream2.write(bArr, 0, bArr.length); } } } Result result3 = new Result(sb.toString(), byteArrayOutputStream.toByteArray(), NO_POINTS, BarcodeFormat.QR_CODE); if (byteArrayOutputStream2.size() > 0) { result3.putMetadata(ResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(byteArrayOutputStream2.toByteArray())); } arrayList.add(result3); return arrayList; } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public static final class SAComparator implements Serializable, Comparator { private SAComparator() { } @Override // java.util.Comparator public int compare(Result result, Result result2) { return Integer.compare(((Integer) result.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)).intValue(), ((Integer) result2.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE)).intValue()); } } }