MCPcopy Create free account
hub / github.com/Traneptora/jxlatte / Bitreader

Class Bitreader

java/com/traneptora/jxlatte/io/Bitreader.java:9–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import com.traneptora.jxlatte.util.MathHelper;
8
9public class Bitreader extends InputStream {
10
11 private InputStream in;
12 private long cache = 0;
13 private int cacheBits = 0;
14 private long bitsRead = 0;
15
16 public Bitreader(InputStream in) {
17 this.in = in;
18 }
19
20 @Override
21 public int read(byte[] buffer) throws IOException {
22 return read(buffer, 0, buffer.length);
23 }
24
25 public boolean readBool() throws IOException {
26 return readBits(1) != 0;
27 }
28
29 public int readU32(int c0, int u0, int c1, int u1, int c2, int u2, int c3, int u3) throws IOException {
30 int choice = readBits(2);
31 int[] c = new int[]{c0, c1, c2, c3};
32 int[] u = new int[]{u0, u1, u2, u3};
33 return c[choice] + readBits(u[choice]);
34 }
35
36 public long readU64() throws IOException {
37 int index = readBits(2);
38 if (index == 0)
39 return 0L;
40 if (index == 1)
41 return 1L + readBits(4);
42 if (index == 2)
43 return 17L + readBits(8);
44 long value = readBits(12);
45 int shift = 12;
46 while (readBool()) {
47 if (shift == 60) {
48 value |= (long)readBits(4) << shift;
49 break;
50 }
51 value |= (long)readBits(8) << shift;
52 shift += 8;
53 }
54 return value;
55 }
56
57 public float readF16() throws IOException {
58 int bits16 = readBits(16);
59 float f = MathHelper.floatFromF16(bits16);
60 if (!Float.isFinite(f))
61 throw new InvalidBitstreamException("Illegal infinite/NaN float16");
62 return f;
63 }
64
65 public int readEnum() throws IOException {
66 int constant = readU32(0, 0, 1, 0, 2, 4, 18, 6);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected