package com.google.zxing.aztec.encoder; import com.google.zxing.common.BitArray; import java.util.Iterator; import java.util.LinkedList; /* loaded from: classes3.dex */ public final class State { public static final State INITIAL_STATE = new State(Token.EMPTY, 0, 0, 0); public final int binaryShiftByteCount; public final int bitCount; public final int mode; public final Token token; public int getBinaryShiftByteCount() { return this.binaryShiftByteCount; } public int getBitCount() { return this.bitCount; } public int getMode() { return this.mode; } public State(Token token, int i, int i2, int i3) { this.token = token; this.mode = i; this.binaryShiftByteCount = i2; this.bitCount = i3; } public State latchAndAppend(int i, int i2) { int i3 = this.bitCount; Token token = this.token; int i4 = this.mode; if (i != i4) { int i5 = HighLevelEncoder.LATCH_TABLE[i4][i]; int i6 = 65535 & i5; int i7 = i5 >> 16; token = token.add(i6, i7); i3 += i7; } int i8 = i == 2 ? 4 : 5; return new State(token.add(i2, i8), i, 0, i3 + i8); } public State shiftAndAppend(int i, int i2) { Token token = this.token; int i3 = this.mode; int i4 = i3 == 2 ? 4 : 5; return new State(token.add(HighLevelEncoder.SHIFT_TABLE[i3][i], i4).add(i2, 5), this.mode, 0, this.bitCount + i4 + 5); } public State addBinaryShiftChar(int i) { Token token = this.token; int i2 = this.mode; int i3 = this.bitCount; if (i2 == 4 || i2 == 2) { int i4 = HighLevelEncoder.LATCH_TABLE[i2][0]; int i5 = 65535 & i4; int i6 = i4 >> 16; token = token.add(i5, i6); i3 += i6; i2 = 0; } int i7 = this.binaryShiftByteCount; State state = new State(token, i2, i7 + 1, i3 + ((i7 == 0 || i7 == 31) ? 18 : i7 == 62 ? 9 : 8)); return state.binaryShiftByteCount == 2078 ? state.endBinaryShift(i + 1) : state; } public State endBinaryShift(int i) { int i2 = this.binaryShiftByteCount; return i2 == 0 ? this : new State(this.token.addBinaryShift(i - i2, i2), this.mode, 0, this.bitCount); } public boolean isBetterThanOrEqualTo(State state) { int i; int i2 = this.bitCount + (HighLevelEncoder.LATCH_TABLE[this.mode][state.mode] >> 16); int i3 = state.binaryShiftByteCount; if (i3 > 0 && ((i = this.binaryShiftByteCount) == 0 || i > i3)) { i2 += 10; } return i2 <= state.bitCount; } public BitArray toBitArray(byte[] bArr) { LinkedList linkedList = new LinkedList(); for (Token token = endBinaryShift(bArr.length).token; token != null; token = token.getPrevious()) { linkedList.addFirst(token); } BitArray bitArray = new BitArray(); Iterator it = linkedList.iterator(); while (it.hasNext()) { ((Token) it.next()).appendTo(bitArray, bArr); } return bitArray; } public String toString() { return String.format("%s bits=%d bytes=%d", HighLevelEncoder.MODE_NAMES[this.mode], Integer.valueOf(this.bitCount), Integer.valueOf(this.binaryShiftByteCount)); } }