mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 20:33:10 +00:00
LibGfx/JPEG: Use peek_bits
in next_symbol
This allows us to read all bits in a single shot instead of one by one.
This commit is contained in:
parent
5ec2aa4dcc
commit
f4014f898d
|
@ -229,15 +229,16 @@ public:
|
|||
|
||||
ErrorOr<u8> next_symbol(HuffmanTableSpec const& table)
|
||||
{
|
||||
unsigned code = 0;
|
||||
u16 const code = peek_bits(16);
|
||||
u64 code_cursor = 0;
|
||||
|
||||
for (int i = 0; i < 16; i++) { // Codes can't be longer than 16 bits.
|
||||
auto result = TRY(read_bits());
|
||||
code = (code << 1) | result;
|
||||
auto const result = code >> (15 - i);
|
||||
for (int j = 0; j < table.code_counts[i]; j++) {
|
||||
if (code == table.codes[code_cursor])
|
||||
if (result == table.codes[code_cursor]) {
|
||||
discard_bits(i + 1);
|
||||
return table.symbols[code_cursor];
|
||||
}
|
||||
code_cursor++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue