public void start() { buffer0 = reader.readbyte(); buffer1 = reader.readbyte(); c = BinaryOperation.bit32ShiftL((buffer0 ^ 0xff), 16); readbyte(); c = BinaryOperation.bit32ShiftL(c, 7); counter -= 7; a = 0x80000000l; }
public int get2DCode() { int tuple0, tuple1; if (bufferLength == 0) { buffer = (reader.readbyte() & 0xff); bufferLength = 8; noOfbytesRead++; int lookup = (int)((BinaryOperation.bit32ShiftR(buffer, 1)) & 0x7f); tuple0 = twoDimensionalTable1[lookup, 0]; tuple1 = twoDimensionalTable1[lookup, 1]; } else if (bufferLength == 8) { int lookup = (int)((BinaryOperation.bit32ShiftR(buffer, 1)) & 0x7f); tuple0 = twoDimensionalTable1[lookup, 0]; tuple1 = twoDimensionalTable1[lookup, 1]; } else { int lookup = (int)((BinaryOperation.bit32ShiftL(buffer, (int)(7 - bufferLength))) & 0x7f); tuple0 = twoDimensionalTable1[lookup, 0]; tuple1 = twoDimensionalTable1[lookup, 1]; if (tuple0 < 0 || tuple0 > (int)bufferLength) { int right = (reader.readbyte() & 0xff); long left = (BinaryOperation.bit32ShiftL(buffer, 8)); buffer = left | right; bufferLength += 8; noOfbytesRead++; int look = (int)(BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 7)) & 0x7f); tuple0 = twoDimensionalTable1[look, 0]; tuple1 = twoDimensionalTable1[look, 1]; } } if (tuple0 < 0) { return(0); } bufferLength -= tuple0; return(tuple1); }
private int decodeIntBit(ArithmeticDecoderStats stats) { int bit; bit = decodeBit(previous, stats); if (previous < 0x100) { previous = BinaryOperation.bit32ShiftL(previous, 1) | bit; } else { previous = (((BinaryOperation.bit32ShiftL(previous, 1)) | bit) & 0x1ff) | 0x100; } return(bit); }
private void readbyte() { if (buffer0 == 0xff) { if (buffer1 > 0x8f) { counter = 8; } else { buffer0 = buffer1; buffer1 = reader.readbyte(); c = c + 0xfe00 - (BinaryOperation.bit32ShiftL(buffer0, 9)); counter = 7; } } else { buffer0 = buffer1; buffer1 = reader.readbyte(); c = c + 0xff00 - (BinaryOperation.bit32ShiftL(buffer0, 8)); counter = 8; } }
public int getBlackCode() { int tuple0, tuple1; long code; if (bufferLength == 0) { buffer = (reader.readbyte() & 0xff); bufferLength = 8; noOfbytesRead++; } while (true) { if (bufferLength >= 6 && ((BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 6))) & 0x3f) == 0) { if (bufferLength <= 13) { code = BinaryOperation.bit32ShiftL(buffer, (int)(13 - bufferLength)); } else { code = BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 13)); } tuple0 = blackTable1[(int)(code & 0x7f), 0]; tuple1 = blackTable1[(int)(code & 0x7f), 1]; } else if (bufferLength >= 4 && ((buffer >> ((int)bufferLength - 4)) & 0x0f) == 0) { if (bufferLength <= 12) { code = BinaryOperation.bit32ShiftL(buffer, (int)(12 - bufferLength)); } else { code = BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 12)); } int lookup = (int)((code & 0xff) - 64); if (lookup >= 0) { tuple0 = blackTable2[lookup, 0]; tuple1 = blackTable2[lookup, 1]; } else { tuple0 = blackTable1[blackTable1.Length + lookup, 0]; tuple1 = blackTable1[blackTable1.Length + lookup, 1]; } } else { if (bufferLength <= 6) { code = BinaryOperation.bit32ShiftL(buffer, (int)(6 - bufferLength)); } else { code = BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 6)); } int lookup = (int)(code & 0x3f); if (lookup >= 0) { tuple0 = blackTable3[lookup, 0]; tuple1 = blackTable3[lookup, 1]; } else { tuple0 = blackTable2[blackTable2.Length + lookup, 0]; tuple1 = blackTable2[blackTable2.Length + lookup, 1]; } } if (tuple0 > 0 && tuple0 <= (int)bufferLength) { bufferLength -= tuple0; return(tuple1); } if (bufferLength >= 13) { break; } buffer = ((BinaryOperation.bit32ShiftL(buffer, 8)) | (reader.readbyte() & 0xff)); bufferLength += 8; noOfbytesRead++; } bufferLength--; return(1); }
public int getWhiteCode() { int tuple0, tuple1; long code; if (bufferLength == 0) { buffer = (reader.readbyte() & 0xff); bufferLength = 8; noOfbytesRead++; } while (true) { if (bufferLength >= 7 && ((BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 7))) & 0x7f) == 0) { if (bufferLength <= 12) { code = BinaryOperation.bit32ShiftL(buffer, (int)(12 - bufferLength)); } else { code = BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 12)); } tuple0 = whiteTable1[(int)(code & 0x1f), 0]; tuple1 = whiteTable1[(int)(code & 0x1f), 1]; } else { if (bufferLength <= 9) { code = BinaryOperation.bit32ShiftL(buffer, (int)(9 - bufferLength)); } else { code = BinaryOperation.bit32ShiftR(buffer, (int)(bufferLength - 9)); } int lookup = (int)(code & 0x1ff); if (lookup >= 0) { tuple0 = whiteTable2[lookup, 0]; tuple1 = whiteTable2[lookup, 1]; } else { tuple0 = whiteTable2[whiteTable2.Length + lookup, 0]; tuple1 = whiteTable2[whiteTable2.Length + lookup, 1]; } } if (tuple0 > 0 && tuple0 <= (int)bufferLength) { bufferLength -= tuple0; return(tuple1); } if (bufferLength >= 12) { break; } buffer = ((BinaryOperation.bit32ShiftL(buffer, 8)) | reader.readbyte() & 0xff); bufferLength += 8; noOfbytesRead++; } bufferLength--; return(1); }
public int decodeBit(long context, ArithmeticDecoderStats stats) { int iCX = BinaryOperation.bit8Shift(stats.getContextCodingTableValue((int)context), 1, BinaryOperation.RIGHT_SHIFT); int mpsCX = stats.getContextCodingTableValue((int)context) & 1; int qe = qeTable[iCX]; a -= qe; int bit; if (c < a) { if ((a & 0x80000000) != 0) { bit = mpsCX; } else { if (a < qe) { bit = 1 - mpsCX; if (switchTable[iCX] != 0) { stats.setContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | (1 - mpsCX)); } else { stats.setContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | mpsCX); } } else { bit = mpsCX; stats.setContextCodingTableValue((int)context, (nmpsTable[iCX] << 1) | mpsCX); } do { if (counter == 0) { readbyte(); } a = BinaryOperation.bit32ShiftL(a, 1); c = BinaryOperation.bit32ShiftL(c, 1); counter--; } while ((a & 0x80000000) == 0); } } else { c -= a; if (a < qe) { bit = mpsCX; stats.setContextCodingTableValue((int)context, (nmpsTable[iCX] << 1) | mpsCX); } else { bit = 1 - mpsCX; if (switchTable[iCX] != 0) { stats.setContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | (1 - mpsCX)); } else { stats.setContextCodingTableValue((int)context, (nlpsTable[iCX] << 1) | mpsCX); } } a = qe; do { if (counter == 0) { readbyte(); } a = BinaryOperation.bit32ShiftL(a, 1); c = BinaryOperation.bit32ShiftL(c, 1); counter--; } while ((a & 0x80000000) == 0); } return(bit); }
public DecodeIntResult decodeInt(ArithmeticDecoderStats stats) { long value; previous = 1; int s = decodeIntBit(stats); if (decodeIntBit(stats) != 0) { if (decodeIntBit(stats) != 0) { if (decodeIntBit(stats) != 0) { if (decodeIntBit(stats) != 0) { if (decodeIntBit(stats) != 0) { value = 0; for (int i = 0; i < 32; i++) { value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); } value += 4436; } else { value = 0; for (int i = 0; i < 12; i++) { value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); } value += 340; } } else { value = 0; for (int i = 0; i < 8; i++) { value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); } value += 84; } } else { value = 0; for (int i = 0; i < 6; i++) { value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); } value += 20; } } else { value = decodeIntBit(stats); value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); value += 4; } } else { value = decodeIntBit(stats); value = BinaryOperation.bit32ShiftL(value, 1) | decodeIntBit(stats); } int decodedInt; if (s != 0) { if (value == 0) { return(new DecodeIntResult((int)value, false)); } decodedInt = (int)-value; } else { decodedInt = (int)value; } return(new DecodeIntResult(decodedInt, true)); }