| 1 | // license:BSD-3-Clause\r |
| 2 | // copyright-holders:Aaron Giles\r |
| 3 | /***************************************************************************\r |
| 4 | \r |
| 5 | bitstream.h\r |
| 6 | \r |
| 7 | Helper classes for reading/writing at the bit level.\r |
| 8 | \r |
| 9 | ***************************************************************************/\r |
| 10 | \r |
| 11 | #pragma once\r |
| 12 | \r |
| 13 | #ifndef __BITSTREAM_H__\r |
| 14 | #define __BITSTREAM_H__\r |
| 15 | \r |
| 16 | #include <stdint.h>\r |
| 17 | \r |
| 18 | //**************************************************************************\r |
| 19 | // TYPE DEFINITIONS\r |
| 20 | //**************************************************************************\r |
| 21 | \r |
| 22 | // helper class for reading from a bit buffer\r |
| 23 | struct bitstream\r |
| 24 | {\r |
| 25 | uint32_t buffer; // current bit accumulator\r |
| 26 | int bits; // number of bits in the accumulator\r |
| 27 | const uint8_t * read; // read pointer\r |
| 28 | uint32_t doffset; // byte offset within the data\r |
| 29 | uint32_t dlength; // length of the data\r |
| 30 | };\r |
| 31 | \r |
| 32 | struct bitstream* create_bitstream(const void *src, uint32_t srclength);\r |
| 33 | int bitstream_overflow(struct bitstream* bitstream);\r |
| 34 | uint32_t bitstream_read_offset(struct bitstream* bitstream);\r |
| 35 | \r |
| 36 | uint32_t bitstream_read(struct bitstream* bitstream, int numbits);\r |
| 37 | uint32_t bitstream_peek(struct bitstream* bitstream, int numbits);\r |
| 38 | void bitstream_remove(struct bitstream* bitstream, int numbits);\r |
| 39 | uint32_t bitstream_flush(struct bitstream* bitstream);\r |
| 40 | \r |
| 41 | \r |
| 42 | #endif\r |