mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 01:02:48 +01:00
astc: Make InputBitStream constexpr
This commit is contained in:
parent
0efc230381
commit
d22a689250
1 changed files with 11 additions and 11 deletions
|
@ -39,25 +39,25 @@ constexpr u32 Popcnt(u32 n) {
|
||||||
|
|
||||||
class InputBitStream {
|
class InputBitStream {
|
||||||
public:
|
public:
|
||||||
explicit InputBitStream(const u8* ptr, std::size_t start_offset = 0)
|
constexpr explicit InputBitStream(const u8* ptr, std::size_t start_offset = 0)
|
||||||
: cur_byte(ptr), next_bit(start_offset % 8) {}
|
: cur_byte{ptr}, next_bit{start_offset % 8} {}
|
||||||
|
|
||||||
std::size_t GetBitsRead() const {
|
constexpr std::size_t GetBitsRead() const {
|
||||||
return m_BitsRead;
|
return bits_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ReadBit() {
|
constexpr bool ReadBit() {
|
||||||
u32 bit = *cur_byte >> next_bit++;
|
const bool bit = (*cur_byte >> next_bit++) & 1;
|
||||||
while (next_bit >= 8) {
|
while (next_bit >= 8) {
|
||||||
next_bit -= 8;
|
next_bit -= 8;
|
||||||
cur_byte++;
|
cur_byte++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_BitsRead++;
|
bits_read++;
|
||||||
return bit & 1;
|
return bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ReadBits(std::size_t nBits) {
|
constexpr u32 ReadBits(std::size_t nBits) {
|
||||||
u32 ret = 0;
|
u32 ret = 0;
|
||||||
for (std::size_t i = 0; i < nBits; ++i) {
|
for (std::size_t i = 0; i < nBits; ++i) {
|
||||||
ret |= (ReadBit() & 1) << i;
|
ret |= (ReadBit() & 1) << i;
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t nBits>
|
template <std::size_t nBits>
|
||||||
u32 ReadBits() {
|
constexpr u32 ReadBits() {
|
||||||
u32 ret = 0;
|
u32 ret = 0;
|
||||||
for (std::size_t i = 0; i < nBits; ++i) {
|
for (std::size_t i = 0; i < nBits; ++i) {
|
||||||
ret |= (ReadBit() & 1) << i;
|
ret |= (ReadBit() & 1) << i;
|
||||||
|
@ -77,7 +77,7 @@ public:
|
||||||
private:
|
private:
|
||||||
const u8* cur_byte;
|
const u8* cur_byte;
|
||||||
std::size_t next_bit = 0;
|
std::size_t next_bit = 0;
|
||||||
std::size_t m_BitsRead = 0;
|
std::size_t bits_read = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OutputBitStream {
|
class OutputBitStream {
|
||||||
|
|
Loading…
Reference in a new issue