mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +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
1 changed files with 5 additions and 4 deletions
|
@ -229,15 +229,16 @@ public:
|
||||||
|
|
||||||
ErrorOr<u8> next_symbol(HuffmanTableSpec const& table)
|
ErrorOr<u8> next_symbol(HuffmanTableSpec const& table)
|
||||||
{
|
{
|
||||||
unsigned code = 0;
|
u16 const code = peek_bits(16);
|
||||||
u64 code_cursor = 0;
|
u64 code_cursor = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) { // Codes can't be longer than 16 bits.
|
for (int i = 0; i < 16; i++) { // Codes can't be longer than 16 bits.
|
||||||
auto result = TRY(read_bits());
|
auto const result = code >> (15 - i);
|
||||||
code = (code << 1) | result;
|
|
||||||
for (int j = 0; j < table.code_counts[i]; j++) {
|
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];
|
return table.symbols[code_cursor];
|
||||||
|
}
|
||||||
code_cursor++;
|
code_cursor++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue