mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
LibGfx/JPEG: Make generate_huffman_codes
be a method of HuffmanTable
And call it when reading the table definition instead of when starting to decode the stream.
This commit is contained in:
parent
8cba8ed25a
commit
9389177e5f
1 changed files with 12 additions and 17 deletions
|
@ -186,6 +186,16 @@ struct HuffmanTable {
|
||||||
u8 code_counts[16] = { 0 };
|
u8 code_counts[16] = { 0 };
|
||||||
Vector<u8> symbols;
|
Vector<u8> symbols;
|
||||||
Vector<u16> codes;
|
Vector<u16> codes;
|
||||||
|
|
||||||
|
void generate_codes()
|
||||||
|
{
|
||||||
|
unsigned code = 0;
|
||||||
|
for (auto number_of_codes : code_counts) {
|
||||||
|
for (int i = 0; i < number_of_codes; i++)
|
||||||
|
codes.append(code++);
|
||||||
|
code <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HuffmanStream {
|
class HuffmanStream {
|
||||||
|
@ -378,16 +388,6 @@ struct JPEGLoadingContext {
|
||||||
Optional<ByteBuffer> icc_data;
|
Optional<ByteBuffer> icc_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void generate_huffman_codes(HuffmanTable& table)
|
|
||||||
{
|
|
||||||
unsigned code = 0;
|
|
||||||
for (auto number_of_codes : table.code_counts) {
|
|
||||||
for (int i = 0; i < number_of_codes; i++)
|
|
||||||
table.codes.append(code++);
|
|
||||||
code <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline auto* get_component(Macroblock& block, unsigned component)
|
static inline auto* get_component(Macroblock& block, unsigned component)
|
||||||
{
|
{
|
||||||
switch (component) {
|
switch (component) {
|
||||||
|
@ -671,13 +671,6 @@ static void reset_decoder(JPEGLoadingContext& context)
|
||||||
|
|
||||||
static ErrorOr<void> decode_huffman_stream(JPEGLoadingContext& context, Vector<Macroblock>& macroblocks)
|
static ErrorOr<void> decode_huffman_stream(JPEGLoadingContext& context, Vector<Macroblock>& macroblocks)
|
||||||
{
|
{
|
||||||
// Compute huffman codes for DC and AC tables.
|
|
||||||
for (auto it = context.dc_tables.begin(); it != context.dc_tables.end(); ++it)
|
|
||||||
generate_huffman_codes(it->value);
|
|
||||||
|
|
||||||
for (auto it = context.ac_tables.begin(); it != context.ac_tables.end(); ++it)
|
|
||||||
generate_huffman_codes(it->value);
|
|
||||||
|
|
||||||
for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) {
|
for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) {
|
||||||
for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) {
|
for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) {
|
||||||
u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor;
|
u32 i = vcursor * context.mblock_meta.hpadded_count + hcursor;
|
||||||
|
@ -900,6 +893,8 @@ static ErrorOr<void> read_huffman_table(Stream& stream, JPEGLoadingContext& cont
|
||||||
table.symbols.append(symbol);
|
table.symbols.append(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.generate_codes();
|
||||||
|
|
||||||
auto& huffman_table = table.type == 0 ? context.dc_tables : context.ac_tables;
|
auto& huffman_table = table.type == 0 ? context.dc_tables : context.ac_tables;
|
||||||
huffman_table.set(table.destination_id, table);
|
huffman_table.set(table.destination_id, table);
|
||||||
VERIFY(huffman_table.size() <= 2);
|
VERIFY(huffman_table.size() <= 2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue