197 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			197 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.google.zxing.oned;
 | |
| 
 | |
| 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.ReaderException;
 | |
| import com.google.zxing.Result;
 | |
| import com.google.zxing.ResultMetadataType;
 | |
| import com.google.zxing.ResultPoint;
 | |
| import com.google.zxing.common.BitArray;
 | |
| import java.util.Arrays;
 | |
| import java.util.EnumMap;
 | |
| import java.util.Map;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public abstract class OneDReader implements Reader {
 | |
|     private Result b(BinaryBitmap binaryBitmap, Map<DecodeHintType, ?> map) throws NotFoundException {
 | |
|         int i;
 | |
|         int i2;
 | |
|         int c = binaryBitmap.c();
 | |
|         int b = binaryBitmap.b();
 | |
|         BitArray bitArray = new BitArray(c);
 | |
|         char c2 = 0;
 | |
|         int i3 = 1;
 | |
|         boolean z = map != null && map.containsKey(DecodeHintType.TRY_HARDER);
 | |
|         int max = Math.max(1, b >> (z ? 8 : 5));
 | |
|         int i4 = z ? b : 15;
 | |
|         int i5 = b / 2;
 | |
|         Map<DecodeHintType, ?> map2 = map;
 | |
|         int i6 = 0;
 | |
|         while (i6 < i4) {
 | |
|             int i7 = i6 + 1;
 | |
|             int i8 = i7 / 2;
 | |
|             if (!((i6 & 1) == 0)) {
 | |
|                 i8 = -i8;
 | |
|             }
 | |
|             int i9 = (i8 * max) + i5;
 | |
|             if (i9 < 0 || i9 >= b) {
 | |
|                 break;
 | |
|             }
 | |
|             try {
 | |
|                 bitArray = binaryBitmap.a(i9, bitArray);
 | |
|                 Map<DecodeHintType, ?> map3 = map2;
 | |
|                 int i10 = 0;
 | |
|                 while (i10 < 2) {
 | |
|                     if (i10 == i3) {
 | |
|                         bitArray.j();
 | |
|                         if (map3 != null && map3.containsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) {
 | |
|                             EnumMap enumMap = new EnumMap(DecodeHintType.class);
 | |
|                             enumMap.putAll(map3);
 | |
|                             enumMap.remove(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
 | |
|                             map3 = enumMap;
 | |
|                         }
 | |
|                     }
 | |
|                     try {
 | |
|                         Result a = a(i9, bitArray, map3);
 | |
|                         if (i10 == i3) {
 | |
|                             a.a(ResultMetadataType.ORIENTATION, 180);
 | |
|                             ResultPoint[] d = a.d();
 | |
|                             if (d != null) {
 | |
|                                 float f = c;
 | |
|                                 i2 = c;
 | |
|                                 try {
 | |
|                                     d[0] = new ResultPoint((f - d[c2].a()) - 1.0f, d[c2].b());
 | |
|                                     try {
 | |
|                                         d[1] = new ResultPoint((f - d[1].a()) - 1.0f, d[1].b());
 | |
|                                     } catch (ReaderException unused) {
 | |
|                                         continue;
 | |
|                                         i10++;
 | |
|                                         c = i2;
 | |
|                                         c2 = 0;
 | |
|                                         i3 = 1;
 | |
|                                     }
 | |
|                                 } catch (ReaderException unused2) {
 | |
|                                     i10++;
 | |
|                                     c = i2;
 | |
|                                     c2 = 0;
 | |
|                                     i3 = 1;
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                         return a;
 | |
|                     } catch (ReaderException unused3) {
 | |
|                         i2 = c;
 | |
|                     }
 | |
|                 }
 | |
|                 i = c;
 | |
|                 map2 = map3;
 | |
|             } catch (NotFoundException unused4) {
 | |
|                 i = c;
 | |
|             }
 | |
|             i6 = i7;
 | |
|             c = i;
 | |
|             c2 = 0;
 | |
|             i3 = 1;
 | |
|         }
 | |
|         throw NotFoundException.getNotFoundInstance();
 | |
|     }
 | |
| 
 | |
|     public abstract Result a(int i, BitArray bitArray, Map<DecodeHintType, ?> map) throws NotFoundException, ChecksumException, FormatException;
 | |
| 
 | |
|     @Override // com.google.zxing.Reader
 | |
|     public Result a(BinaryBitmap binaryBitmap, Map<DecodeHintType, ?> map) throws NotFoundException, FormatException {
 | |
|         try {
 | |
|             return b(binaryBitmap, map);
 | |
|         } catch (NotFoundException e) {
 | |
|             if (!(map != null && map.containsKey(DecodeHintType.TRY_HARDER)) || !binaryBitmap.d()) {
 | |
|                 throw e;
 | |
|             }
 | |
|             binaryBitmap.e();
 | |
|             throw null;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.zxing.Reader
 | |
|     public void reset() {
 | |
|     }
 | |
| 
 | |
|     protected static void a(BitArray bitArray, int i, int[] iArr) throws NotFoundException {
 | |
|         int length = iArr.length;
 | |
|         int i2 = 0;
 | |
|         Arrays.fill(iArr, 0, length, 0);
 | |
|         int h = bitArray.h();
 | |
|         if (i < h) {
 | |
|             boolean z = !bitArray.a(i);
 | |
|             while (i < h) {
 | |
|                 if (bitArray.a(i) == z) {
 | |
|                     i2++;
 | |
|                     if (i2 == length) {
 | |
|                         break;
 | |
|                     }
 | |
|                     iArr[i2] = 1;
 | |
|                     z = !z;
 | |
|                 } else {
 | |
|                     iArr[i2] = iArr[i2] + 1;
 | |
|                 }
 | |
|                 i++;
 | |
|             }
 | |
|             if (i2 != length) {
 | |
|                 if (i2 != length - 1 || i != h) {
 | |
|                     throw NotFoundException.getNotFoundInstance();
 | |
|                 }
 | |
|                 return;
 | |
|             }
 | |
|             return;
 | |
|         }
 | |
|         throw NotFoundException.getNotFoundInstance();
 | |
|     }
 | |
| 
 | |
|     protected static float a(int[] iArr, int[] iArr2, float f) {
 | |
|         int length = iArr.length;
 | |
|         int i = 0;
 | |
|         int i2 = 0;
 | |
|         for (int i3 = 0; i3 < length; i3++) {
 | |
|             i += iArr[i3];
 | |
|             i2 += iArr2[i3];
 | |
|         }
 | |
|         if (i < i2) {
 | |
|             return Float.POSITIVE_INFINITY;
 | |
|         }
 | |
|         float f2 = i;
 | |
|         float f3 = f2 / i2;
 | |
|         float f4 = f * f3;
 | |
|         float f5 = 0.0f;
 | |
|         for (int i4 = 0; i4 < length; i4++) {
 | |
|             float f6 = iArr2[i4] * f3;
 | |
|             float f7 = iArr[i4];
 | |
|             float f8 = f7 > f6 ? f7 - f6 : f6 - f7;
 | |
|             if (f8 > f4) {
 | |
|                 return Float.POSITIVE_INFINITY;
 | |
|             }
 | |
|             f5 += f8;
 | |
|         }
 | |
|         return f5 / f2;
 | |
|     }
 | |
| 
 | |
|     protected static void b(BitArray bitArray, int i, int[] iArr) throws NotFoundException {
 | |
|         int length = iArr.length;
 | |
|         boolean a = bitArray.a(i);
 | |
|         while (i > 0 && length >= 0) {
 | |
|             i--;
 | |
|             if (bitArray.a(i) != a) {
 | |
|                 length--;
 | |
|                 a = !a;
 | |
|             }
 | |
|         }
 | |
|         if (length < 0) {
 | |
|             a(bitArray, i + 1, iArr);
 | |
|             return;
 | |
|         }
 | |
|         throw NotFoundException.getNotFoundInstance();
 | |
|     }
 | |
| }
 |